file-browser.test.js
2,676 bytes
| 1 | import { afterEach, describe, expect, it } from "vitest"; |
|---|---|
| 2 | import { createShare, makeHarness } from "./helpers.js"; |
| 3 | |
| 4 | describe("file browser", () => { |
| 5 | let harness; |
| 6 | afterEach(() => harness.close()); |
| 7 | |
| 8 | it("opens nested folders and displays file contents as code", async () => { |
| 9 | harness = makeHarness(); |
| 10 | const { id } = await createShare(harness); |
| 11 | const folder = await harness.agent.get(`/s/${id}/repositories/101?path=src`).expect(200); |
| 12 | expect(folder.text).toContain("index.js"); |
| 13 | const file = await harness.agent.get(`/s/${id}/repositories/101?path=src&file=src%2Findex.js`).expect(200); |
| 14 | expect(file.text).toContain("export const ready = true;"); |
| 15 | expect(file.text).toContain('id="L1"'); |
| 16 | expect(file.text).toContain('href="#L1"'); |
| 17 | expect(file.text).toContain('data-copy-text="src/index.js"'); |
| 18 | expect(file.text).toContain("?history=src%2Findex.js"); |
| 19 | |
| 20 | const history = await harness.agent.get(`/s/${id}/repositories/101?history=src%2Findex.js`).expect(200); |
| 21 | expect(history.text).toContain("History for <code>src/index.js</code>"); |
| 22 | expect(history.text).toContain("Finish atlas viewer"); |
| 23 | expect(history.text).not.toContain("Start atlas"); |
| 24 | }); |
| 25 | |
| 26 | it("previews Markdown and keeps source lines addressable", async () => { |
| 27 | harness = makeHarness(); |
| 28 | const { id } = await createShare(harness); |
| 29 | |
| 30 | const preview = await harness.agent |
| 31 | .get(`/s/${id}/repositories/101?file=docs%2Fguide.md`) |
| 32 | .expect(200); |
| 33 | expect(preview.text).toContain("<h1>Guide</h1>"); |
| 34 | expect(preview.text).toContain('class="active"'); |
| 35 | expect(preview.text).toContain("?file=docs%2Fguide.md&view=source"); |
| 36 | expect(preview.text).not.toContain('id="L1"'); |
| 37 | |
| 38 | const source = await harness.agent |
| 39 | .get(`/s/${id}/repositories/101?file=docs%2Fguide.md&view=source`) |
| 40 | .expect(200); |
| 41 | expect(source.text).toContain("# Guide"); |
| 42 | expect(source.text).toContain('id="L1"'); |
| 43 | expect(source.text).toContain('aria-current="page">Source</a>'); |
| 44 | |
| 45 | const large = await harness.agent |
| 46 | .get(`/s/${id}/repositories/101?file=docs%2Flarge.md`) |
| 47 | .expect(200); |
| 48 | expect(large.text).toContain("because it is larger than the snapshot preview limit."); |
| 49 | }); |
| 50 | |
| 51 | it("displays safe raster images stored in the snapshot", async () => { |
| 52 | harness = makeHarness(); |
| 53 | const { id } = await createShare(harness); |
| 54 | |
| 55 | const image = await harness.agent |
| 56 | .get(`/s/${id}/repositories/101?file=assets%2Flogo.png`) |
| 57 | .expect(200); |
| 58 | expect(image.text).toContain('src="data:image/png;base64,iVBORw0KGgo'); |
| 59 | expect(image.text).toContain('alt="logo.png"'); |
| 60 | expect(image.text).not.toContain("Download"); |
| 61 | }); |
| 62 | }); |
| 63 | |