commits.test.js
2,364 bytes
| 1 | import { afterEach, describe, expect, it } from "vitest"; |
|---|---|
| 2 | import { createShare, makeHarness } from "./helpers.js"; |
| 3 | |
| 4 | describe("commits", () => { |
| 5 | let harness; |
| 6 | afterEach(() => harness.close()); |
| 7 | |
| 8 | it("opens a commit and shows its changed lines", async () => { |
| 9 | harness = makeHarness(); |
| 10 | const { id } = await createShare(harness); |
| 11 | const sha = "101".padEnd(40, "a"); |
| 12 | const page = await harness.agent.get(`/s/${id}/repositories/101?commit=${sha}`).expect(200); |
| 13 | expect(page.text).toContain("Finish atlas viewer"); |
| 14 | expect(page.text).toContain("-false"); |
| 15 | expect(page.text).toContain("+true"); |
| 16 | expect(page.text).toContain("Line changes are not available for this file."); |
| 17 | const emptySha = "101".padEnd(40, "b"); |
| 18 | const empty = await harness.agent.get(`/s/${id}/repositories/101?commit=${emptySha}`).expect(200); |
| 19 | expect(empty.text).toContain("No changed files are available for this commit."); |
| 20 | }); |
| 21 | |
| 22 | it("renders the diff as a numbered table with hunk headers and a change summary", async () => { |
| 23 | harness = makeHarness(); |
| 24 | const { id } = await createShare(harness); |
| 25 | const sha = "101".padEnd(40, "a"); |
| 26 | const page = await harness.agent.get(`/s/${id}/repositories/101?commit=${sha}`).expect(200); |
| 27 | |
| 28 | expect(page.text).toContain("<strong>2</strong> changed files"); |
| 29 | expect(page.text).toContain('<span class="hunk-range">@@ -1 +1 @@</span>'); |
| 30 | expect(page.text).toMatch( |
| 31 | /diff-row-deletion[\s\S]*?diff-gutter">1<\/td>[\s\S]*?diff-gutter"><\/td>[\s\S]*?-false/, |
| 32 | ); |
| 33 | expect(page.text).toMatch( |
| 34 | /diff-row-addition[\s\S]*?diff-gutter"><\/td>[\s\S]*?diff-gutter">1<\/td>[\s\S]*?\+true/, |
| 35 | ); |
| 36 | expect(page.text).toContain("data-diff-wrap"); |
| 37 | expect(page.text).toContain("Jump to a changed file"); |
| 38 | }); |
| 39 | |
| 40 | it("numbers a patch that has no hunk header", async () => { |
| 41 | harness = makeHarness(); |
| 42 | const { id } = await createShare(harness); |
| 43 | const branchSha = "102".padEnd(40, "c"); |
| 44 | const page = await harness.agent |
| 45 | .get(`/s/${id}/repositories/101?ref=review-notes&refType=branch&commit=${branchSha}`) |
| 46 | .expect(200); |
| 47 | expect(page.text).toMatch(/<strong>1<\/strong> changed file\s/); |
| 48 | expect(page.text).toMatch( |
| 49 | /diff-row-addition[\s\S]*?diff-gutter">1<\/td>[\s\S]*?\+export const branch/, |
| 50 | ); |
| 51 | expect(page.text).not.toContain("hunk-range"); |
| 52 | }); |
| 53 | }); |
| 54 | |