g1t/apps/web/app/lib/search.test.ts
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Search across all of g1t, Explore, and a command palette | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { isValue, qualifier, searchHref, shortCount, tokens, withIs, withQualifier } from "./search.ts"; | |
| 5 | ||
| 6 | test("quoted runs stay whole", () => { | |
| 7 | assert.deepEqual(tokens('parse "two words" label:"good first issue" x'), [ | |
| 8 | "parse", | |
| 9 | '"two words"', | |
| 10 | 'label:"good first issue"', | |
| 11 | "x", | |
| 12 | ]); | |
| 13 | }); | |
| 14 | ||
| 15 | test("a qualifier is read, quotes and all", () => { | |
| 16 | assert.equal(qualifier("x language:rust", "language"), "rust"); | |
| 17 | assert.equal(qualifier('x label:"good first issue"', "label"), "good first issue"); | |
| 18 | assert.equal(qualifier("x", "language"), null); | |
| 19 | }); | |
| 20 | ||
| 21 | test("a filter replaces its qualifier and keeps the rest", () => { | |
| 22 | assert.equal(withQualifier("parse language:go repo:a/b", "language", "rust"), "parse repo:a/b language:rust"); | |
| 23 | assert.equal(withQualifier("parse language:go", "language", null), "parse"); | |
| 24 | assert.equal(withQualifier("crash", "label", "good first issue"), 'crash label:"good first issue"'); | |
| 25 | assert.equal(withQualifier("x workspace:acme", "org", "beta", ["workspace"]), "x org:beta"); | |
| 26 | }); | |
| 27 | ||
| 28 | test("is: values of one family replace each other", () => { | |
| 29 | assert.equal(withIs("crash is:open is:pr", ["open", "closed", "merged"], "closed"), "crash is:pr is:closed"); | |
| 30 | assert.equal(withIs("crash is:open", ["open", "closed"], null), "crash"); | |
| 31 | assert.equal(isValue("crash is:Closed", ["open", "closed"]), "closed"); | |
| 32 | assert.equal(isValue("crash", ["open", "closed"]), null); | |
| 33 | }); | |
| 34 | ||
| 35 | test("addresses carry the query, the tab and the page", () => { | |
| 36 | assert.equal(searchHref(" fn main ", "code"), "/search?q=fn+main&type=code"); | |
| 37 | assert.equal(searchHref("x", null, 3), "/search?q=x&page=3"); | |
| 38 | assert.equal(searchHref("x", "issues", 1), "/search?q=x&type=issues"); | |
| 39 | }); | |
| 40 | ||
| 41 | test("counts stop at the cap", () => { | |
| 42 | assert.equal(shortCount(12), "12"); | |
| 43 | assert.equal(shortCount(1000), "1k+"); | |
| 44 | }); |