search.test.js
1,625 bytes
| 1 | import { afterEach, describe, expect, it } from "vitest"; |
|---|---|
| 2 | import { createShare, makeHarness } from "./helpers.js"; |
| 3 | |
| 4 | describe("snapshot search", () => { |
| 5 | let harness; |
| 6 | afterEach(() => harness.close()); |
| 7 | |
| 8 | it("finds code, commits, and repositories without leaving the snapshot", async () => { |
| 9 | harness = makeHarness(); |
| 10 | const { id } = await createShare(harness, [101, 202]); |
| 11 | |
| 12 | const code = await harness.agent.get(`/s/${id}/search?q=Project+details`).expect(200); |
| 13 | expect(code.text).toContain("docs/guide.md"); |
| 14 | expect(code.text).toContain(`repositories/101?file=docs%2Fguide.md&view=source#L3`); |
| 15 | expect(code.text).toContain(`repositories/202?file=docs%2Fguide.md&view=source#L3`); |
| 16 | |
| 17 | const commits = await harness.agent.get(`/s/${id}/search?q=Finish&type=commits`).expect(200); |
| 18 | expect(commits.text).toContain("Finish atlas viewer"); |
| 19 | expect(commits.text).toContain("Finish ledger viewer"); |
| 20 | |
| 21 | const repositories = await harness.agent.get(`/s/${id}/search?q=expense&type=repositories`).expect(200); |
| 22 | expect(repositories.text).toContain("ledger"); |
| 23 | expect(repositories.text).not.toContain(">atlas</a>"); |
| 24 | }); |
| 25 | |
| 26 | it("can limit results to the current repository", async () => { |
| 27 | harness = makeHarness(); |
| 28 | const { id } = await createShare(harness, [101, 202]); |
| 29 | const page = await harness.agent.get(`/s/${id}/search?q=Snapshot&repository=101`).expect(200); |
| 30 | expect(page.text).toContain("Search atlas"); |
| 31 | expect(page.text).toContain(`repositories/101?file=README.md&view=source#L3`); |
| 32 | expect(page.text).not.toContain(`repositories/202?file=README.md`); |
| 33 | }); |
| 34 | }); |
| 35 | |