Rebasely Beta: data may be purged

justintsus-experiment Public

TypeScript · 124 lines · 7.8 KiB · at 8e57616

// The list pages' side of the search (ui/search.ts, search/lists.ts, search/edit.tsus): the old// state= and label= links as terms, the tabs replacing the query's state, canonical links, and the// rendering of a query with errors (kept as typed, each span marked with its number, no list) and of// the syntax help.import assert from "node:assert/strict";import test from "node:test";import { parseQuery, serializeQuery, tabOf, withLabel, withState, type SearchQuery, type Target } from "../../../apps/web/src/search/api.ts";import { inputOf, linksOf, linksOfInvalid, pageOf } from "../../../apps/web/src/search/lists.ts";import { issuesListBody, type IssuesListData } from "../../../apps/web/src/ui/issues.ts";import { pullsListBody } from "../../../apps/web/src/ui/pulls.ts";import { searchBox } from "../../../apps/web/src/ui/search.ts";const repo = { org: "rebasely", repo: "docs", visibility: "public" as const };function q(input: string, t: Target = "issues"): SearchQuery {  const r = parseQuery(input, t);  assert.ok(r.ok, input);  return r.query;}test("without q the list is is:open, with the old state= and label= links as terms", () => {  const p = (s: string, t: Target = "issues") => inputOf(new URLSearchParams(s), t);  assert.equal(p(""), "is:open");  assert.equal(p("state=closed"), "is:closed");  assert.equal(p("state=all"), "");  assert.equal(p("state=merged", "pulls"), "is:merged");  assert.equal(p("state=merged"), "is:open");  assert.equal(p("label=needs review&state=all"), 'label:"needs review"');  // an old label= link is quoted as a value, so a quote in it cannot end the term  assert.equal(p('label=a"b\\'), 'is:open label:"a\\"b\\\\"');  assert.deepEqual(parseQuery(p('label=a"b\\'), "issues").ok, false);  assert.equal(p("q=&state=closed"), "");  assert.equal(p("q=bug&state=closed"), "bug");  assert.equal(pageOf("3"), 3);  assert.equal(pageOf("0"), 1);  assert.equal(pageOf("x"), 1);  assert.equal(pageOf("1e9"), 400);});test("the tabs replace the query's state term, and every link is canonical", () => {  const query = q("crash -is:closed author:@ME sort:updated-asc");  assert.equal(tabOf(query), null);  assert.equal(serializeQuery(withState(query, "open")), "is:open crash author:@me sort:updated-asc");  assert.equal(serializeQuery(withState(query, null)), "crash author:@me sort:updated-asc");  assert.equal(tabOf(q("is:closed bug")), "closed");  assert.equal(tabOf(q("is:closed is:open")), null);  assert.equal(tabOf(q("is:draft", "pulls")), null);  assert.equal(serializeQuery(withState(q("is:draft is:open", "pulls"), "merged")), "is:merged is:draft");  assert.equal(serializeQuery(withLabel(q("is:open"), "Needs Review")!), 'is:open label:"needs review"');  assert.equal(serializeQuery(withLabel(q("label:bug"), "bug")!), "label:bug");  assert.equal(withLabel(q("is:open", "pulls"), "bug"), null);  const l = linksOf("/o/r/issues", q("IS:OPEN Crash"), 2, true);  assert.equal(l.canonical, "is:open Crash");  assert.equal(l.tab, "open");  assert.equal(l.filtered, true);  assert.equal(l.tabHref("closed"), "/o/r/issues?q=is%3Aclosed+Crash");  assert.equal(l.tabHref(null), "/o/r/issues?q=Crash");  assert.deepEqual(l.pages, { prev: "/o/r/issues?q=is%3Aopen+Crash", next: "/o/r/issues?q=is%3Aopen+Crash&page=3" });  assert.equal(l.clear, "/o/r/issues?q=is%3Aopen");  const d = linksOf("/o/r/issues", q("is:open"), 1, false);  assert.equal(d.clear, null);  assert.equal(d.filtered, false);  assert.deepEqual(d.pages, { prev: null, next: null });  assert.equal(linksOf("/o/r/issues", q(""), 1, false).tab, "all");  assert.equal(linksOfInvalid("/o/r/pulls").tabHref("merged"), "/o/r/pulls?q=is%3Amerged");});function listData(over: Partial<IssuesListData>): IssuesListData {  return {    repo, nav: { member: false }, now: 0, search: { target: "issues", action: "/rebasely/docs/issues", value: "is:open", errors: [] }, tabs: [], filtered: false, tab: "open",    items: [], counts: { open: 0, closed: 0 }, labelHrefs: new Map(), pages: { prev: null, next: null }, clear: null, labels: new Map(),    canOpen: false, signedIn: false, membersOnly: false, paused: false, ...over,  };}test("a query with errors keeps the input, marks each span with its number, and lists nothing", () => {  const input = 'assignee:me crash <b>"x';  const r = parseQuery(input, "issues");  assert.ok(!r.ok);  const page = issuesListBody(listData({ search: { target: "issues", action: "/rebasely/docs/issues", value: input, errors: r.errors }, counts: null, tab: null, filtered: true })).s;  assert.match(page, /value="assignee:me crash &lt;b&gt;&quot;x"/);  assert.match(page, /aria-invalid="true"/);  assert.match(page, /aria-describedby="issue-q-help issue-q-errors"/);  assert.match(page, /id="issue-q-errors" role="alert"/);  assert.match(page, /<mark class="search-mark">assignee:me<sup>1<\/sup><\/mark> crash <mark class="search-mark">&lt;b&gt;&quot;x<sup>2<\/sup><\/mark>/);  assert.match(page, /<li><code>assignee:me<\/code> There is no assignee: qualifier/);  assert.match(page, /This search has 2 problems/);  assert.doesNotMatch(page, /class="list pr-list"|pr-empty/);  assert.doesNotMatch(page, /<b>/);});test("the syntax help lists the qualifiers of each list, in a <details>", () => {  const issues = searchBox({ target: "issues", action: "/x", value: "", errors: [] }).s;  const pulls = searchBox({ target: "pulls", action: "/x", value: "", errors: [] }).s;  assert.match(issues, /<details class="search-help">\n<summary>Search syntax<\/summary>/);  for (const k of ["is:open", "label:bug", "no:label", "author:@me", "created:&gt;=2026-10-01", "updated:&lt;7d", "sort:updated-desc", "#12"]) assert.ok(issues.includes(`<code>${k}</code>`), k);  assert.ok(!issues.includes("review-requested:"));  for (const k of ["is:open", "author:@me", "review-requested:@me", "sort:updated-desc"]) assert.ok(pulls.includes(`<code>${k}</code>`), k);  assert.ok(!pulls.includes("<code>label:") && !pulls.includes("<code>no:label"));  assert.doesNotMatch(issues + pulls, /—/);});test("the lists render the canonical box, the tabs, label chips and pages", () => {  const issue = { number: 3, title: "A", body: "", state: "open" as const, labels: ["needs review"], authorId: "u1", comments: 0, createdAt: 0, updatedAt: 0, closedAt: null, closedBy: null };  const page = issuesListBody(listData({    items: [issue], filtered: true, labelHrefs: new Map([["needs review", "/rebasely/docs/issues?q=is%3Aopen+label%3A%22needs+review%22"]]),    tabs: [{ label: "Open", href: "/a?q=is%3Aopen", count: 1, current: true }, { label: "Closed", href: "/a?q=is%3Aclosed", count: 0, current: false }],    pages: { prev: null, next: "/rebasely/docs/issues?q=is%3Aopen&page=2" }, clear: "/rebasely/docs/issues?q=is%3Aopen",  })).s;  assert.match(page, /href="\/a\?q=is%3Aopen" aria-current="page">Open <span class="count num">1<\/span>/);  assert.match(page, /<a class="tag" href="\/rebasely\/docs\/issues\?q=is%3Aopen\+label%3A%22needs\+review%22">needs review<\/a>/);  assert.match(page, /rel="next">Next page</);  assert.match(page, /Clear the search/);  const pulls = pullsListBody({    repo, nav: { member: false }, now: 0, search: { target: "pulls", action: "/rebasely/docs/pulls", value: "is:open", errors: [] }, tabs: [], filtered: false, tab: "open",    items: [{ number: 1, title: "<x>", state: "open", draft: true, authorId: "u1", ownerId: null, baseRef: "refs/heads/main", headRef: "refs/heads/f", createdAt: 0, mergedAt: null, closedAt: null, authorKind: "user", comments: 2 }],    openCount: 1, pages: { prev: null, next: null }, clear: null, labels: new Map(), canOpen: false, paused: false, defaultBranch: "main", recent: [],  }).s;  assert.match(pulls, /id="pr-q" name="q" type="search" value="is:open"/);  assert.match(pulls, /&lt;x&gt;<\/a><span class="tag">Draft<\/span>/);  assert.match(pulls, /<span class="num">2<\/span>/);});