Rebasely Beta: data may be purged

justintsus-experiment Public

TypeScript · 113 lines · 7.0 KiB · at 8e57616

// unit/search/pages (repo/list-search.ts, search/edit.ts, ui/search.ts): how the Issues and Pull// requests lists read ?q= (the default is:open, the old state= and label= links), the canonical links// they make (tabs, label chips, pages), and the page with an invalid query: the input kept as typed,// each error under the box with its span marked by more than color, no rows, the syntax help.import { test } from "node:test";import assert from "node:assert/strict";import { listSearchOf, searchHref } from "../../../apps/web/src/repo/list-search.ts";import { parseQuery, serializeQuery } from "../../../apps/web/src/search/api.ts";import { hasFilters, stateTab, withState, withTerm } from "../../../apps/web/src/search/edit.ts";import { issuesListBody } from "../../../apps/web/src/ui/issues.ts";import { pullsListBody } from "../../../apps/web/src/ui/pulls.ts";const repo = { org: "rebasely", repo: "docs", visibility: "public" as const };const P = (s: string) => new URLSearchParams(s);test("?q= as typed, the default is:open, and the old links' state= and label=", () => {  assert.equal(listSearchOf(P(""), "issues").input, "is:open");  assert.equal(listSearchOf(P("state=closed&label=Needs%20Review"), "issues").input, 'is:closed label:"needs review"');  assert.equal(listSearchOf(P("state=all&label=bug"), "issues").input, "label:bug");  assert.equal(listSearchOf(P("state=merged"), "pulls").input, "is:merged");  assert.equal(listSearchOf(P("state=merged"), "issues").input, "is:open");  assert.equal(listSearchOf(P("label=bug"), "pulls").input, "is:open");  assert.equal(listSearchOf(P("q="), "issues").input, "");  assert.equal(listSearchOf(P("q=IS:OPEN%20%20bug&state=closed&page=3"), "issues").input, "is:open bug");  assert.equal(listSearchOf(P("q=bug&page=3"), "issues").page, 3);  assert.equal(listSearchOf(P("q=bug&page=-1"), "issues").page, 1);  const bad = listSearchOf(P("q=assignee:me%20%20bug"), "issues");  assert.equal(bad.input, "assignee:me  bug");  assert.equal(bad.query, null);  assert.deepEqual(bad.errors.map((e) => e.code), ["unknown_qualifier"]);});test("tabs replace the state term, chips add a label, links are canonical", () => {  const r = parseQuery("bug is:closed -is:draft label:x", "pulls");  assert.ok(!r.ok);  const q = parseQuery("bug is:closed -is:draft sort:updated-asc", "pulls");  assert.ok(q.ok);  assert.equal(stateTab(q.query), "closed");  assert.equal(serializeQuery(withState(q.query, "merged")), "is:merged bug -is:draft sort:updated-asc");  assert.equal(serializeQuery(withState(q.query, "all")), "bug -is:draft sort:updated-asc");  assert.equal(stateTab(withState(q.query, "all")), "all");  assert.equal(hasFilters(q.query), true);  const two = parseQuery("is:open is:closed", "issues");  assert.ok(two.ok);  assert.equal(stateTab(two.query), null);  assert.equal(serializeQuery(withState(two.query, "open")), "is:open");  const plain = parseQuery("is:open sort:created-asc", "issues");  assert.ok(plain.ok);  assert.equal(hasFilters(plain.query), false);  const i = parseQuery("is:open", "issues");  assert.ok(i.ok);  const chip = withTerm(i.query, { kind: "label", neg: false, value: "needs review" });  assert.ok(chip);  assert.equal(searchHref("/o/r/issues", chip), "/o/r/issues?q=is%3Aopen+label%3A%22needs+review%22");  assert.equal(searchHref("/o/r/issues", { target: "issues", terms: [] }), "/o/r/issues?q=");  assert.equal(searchHref("/o/r/issues", i.query, 2), "/o/r/issues?q=is%3Aopen&page=2");});const issueData = (search: { input: string; errors: ReturnType<typeof listSearchOf>["errors"] }) => ({  repo, nav: { member: false }, now: 1000, search, tab: search.errors.length ? null : ("open" as const),  tabHrefs: { open: "/rebasely/docs/issues?q=is%3Aopen", closed: "/rebasely/docs/issues?q=is%3Aclosed", all: "/rebasely/docs/issues?q=" },  filtered: false, clearHref: "/rebasely/docs/issues?q=is%3Aopen", labelHref: (l: string) => `/rebasely/docs/issues?q=label%3A${l}`, prevHref: null,  nextHref: "/rebasely/docs/issues?q=is%3Aopen&page=2",  items: [{ number: 3, title: "A title", body: "", state: "open" as const, labels: ["docs"], authorId: "u1", comments: 1, createdAt: 0, updatedAt: 0, closedAt: null, closedBy: null }],  counts: { open: 1, closed: 0 }, labels: new Map(), canOpen: false, signedIn: false, membersOnly: false, paused: false,});test("the issues list: canonical query in the box, syntax help without script, links that keep q", () => {  const s = issuesListBody(issueData({ input: "is:open", errors: [] })).s;  assert.match(s, /name="q" type="search" value="is:open"/);  assert.match(s, /<details class="search-help">\s*<summary>Search syntax<\/summary>/);  assert.match(s, /<code>no:label<\/code>/);  assert.doesNotMatch(s, /review-requested/);  assert.match(s, /href="\/rebasely\/docs\/issues\?q=label%3Adocs">docs<\/a>/);  assert.match(s, /href="\/rebasely\/docs\/issues\?q=is%3Aopen&amp;page=2" rel="next"/);  assert.match(s, /href="\/rebasely\/docs\/issues\?q=is%3Aclosed"/);  assert.match(s, /aria-current="page">Open/);  assert.doesNotMatch(s, /aria-invalid/);});test("an invalid query: kept as typed, each error under the box with its span marked and numbered, nothing listed", () => {  const input = 'is:open assignee:me "<b>x';  const r = parseQuery(input, "issues");  assert.ok(!r.ok);  const s = issuesListBody(issueData({ input, errors: r.errors })).s;  assert.match(s, /value="is:open assignee:me &quot;&lt;b&gt;x"/);  assert.match(s, /aria-invalid="true" aria-describedby="issue-q-errors"/);  assert.match(s, /id="issue-q-errors"/);  assert.match(s, /This search has 2 problems/);  assert.match(s, /<mark class="search-bad">assignee:me<sup class="search-bad-n" aria-hidden="true">1<\/sup><span class="visually-hidden"> \(problem 1\)<\/span><\/mark>/);  assert.match(s, /<mark class="search-bad">&quot;&lt;b&gt;x<sup/);  assert.match(s, /<li><code>assignee:me<\/code> assignee: is not something issues can be searched by/);  assert.doesNotMatch(s, /<b>x/);  assert.doesNotMatch(s, /pr-row/);  assert.doesNotMatch(s, /rel="next"/);});test("the pull requests list: its own help and tabs", () => {  const s = pullsListBody({    repo, nav: { member: false }, now: 1000, search: { input: "is:open", errors: [] }, tab: "open",    tabHrefs: { open: "/o?q=is%3Aopen", merged: "/o?q=is%3Amerged", closed: "/o?q=is%3Aclosed", all: "/o?q=" }, filtered: false, clearHref: "/o?q=is%3Aopen",    prevHref: "/o?q=is%3Aopen", nextHref: null, counts: { open: 1, closed: 2, merged: 3 }, labels: new Map(), canOpen: false, paused: false,    defaultBranch: "main", recent: [],    items: [{ number: 4, title: "Fix", state: "open", draft: true, authorKind: "agent", authorId: "u", baseRef: "refs/heads/main", headRef: "refs/heads/x", createdAt: 0, mergedAt: null, closedAt: null, comments: 2 }],  }).s;  assert.match(s, /<code>review-requested:@me<\/code>/);  assert.doesNotMatch(s, /<code>label:bug<\/code>/);  assert.match(s, /Merged <span class="count num">3<\/span>/);  assert.match(s, /Closed <span class="count num">5<\/span>/);  assert.match(s, /rel="prev"/);  assert.match(s, /<span class="tag">Draft<\/span>/);});