Showing the changes to apps/web/src/components/pullRequest/pullRequestReviewStore.test.ts (1 of 172 files). Show all
Unified · Split
| @@ -1,6 +1,11 @@ | |||
| 1 | import { beforeEach, describe, expect, it } from "vite-plus/test"; | 1 | import { beforeEach, describe, expect, it } from "vite-plus/test"; |
| 2 | import { ProjectId } from "@t3tools/contracts"; | ||
| 2 | 3 | ||
| 3 | import { type PendingReviewComment, usePullRequestReviewStore } from "./pullRequestReviewStore"; | 4 | import { |
| 5 | type PendingReviewComment, | ||
| 6 | pullRequestReviewKey, | ||
| 7 | usePullRequestReviewStore, | ||
| 8 | } from "./pullRequestReviewStore"; | ||
| 4 | 9 | ||
| 5 | function comment(id: string, body = id): PendingReviewComment { | 10 | function comment(id: string, body = id): PendingReviewComment { |
| 6 | return { id, body, path: "src/app.ts", position: { kind: "added", newLine: 1 } }; | 11 | return { id, body, path: "src/app.ts", position: { kind: "added", newLine: 1 } }; |
| @@ -36,6 +41,30 @@ describe("pull request review drafts", () => { · 29 unmodified lines | |||
| 36 | }); | 41 | }); |
| 37 | }); | 42 | }); |
| 38 | 43 | ||
| 44 | it("keeps drafts on different hosts separate when a thread reviews the same repository and number", () => { | ||
| 45 | const reference = { | ||
| 46 | projectId: ProjectId.make("project-a"), | ||
| 47 | repository: "owner/repo", | ||
| 48 | number: 7, | ||
| 49 | }; | ||
| 50 | const publicKey = pullRequestReviewKey({ ...reference, host: "github.com" }); | ||
| 51 | const enterpriseKey = pullRequestReviewKey({ ...reference, host: "github.example.com" }); | ||
| 52 | const store = usePullRequestReviewStore.getState(); | ||
| 53 | store.addComment(publicKey, comment("public")); | ||
| 54 | store.setSummary(publicKey, "Public review"); | ||
| 55 | |||
| 56 | expect(usePullRequestReviewStore.getState().drafts[enterpriseKey]).toBeUndefined(); | ||
| 57 | expect(usePullRequestReviewStore.getState().summaries[enterpriseKey]).toBeUndefined(); | ||
| 58 | |||
| 59 | store.addComment(enterpriseKey, comment("enterprise")); | ||
| 60 | store.setSummary(enterpriseKey, "Enterprise review"); | ||
| 61 | store.clear(enterpriseKey); | ||
| 62 | store.clearSummary(enterpriseKey, "Enterprise review"); | ||
| 63 | |||
| 64 | expect(usePullRequestReviewStore.getState().drafts[publicKey]).toEqual([comment("public")]); | ||
| 65 | expect(usePullRequestReviewStore.getState().summaries[publicKey]).toBe("Public review"); | ||
| 66 | }); | ||
| 67 | |||
| 39 | it("does not clear a summary revised while submission is in flight", () => { | 68 | it("does not clear a summary revised while submission is in flight", () => { |
| 40 | const store = usePullRequestReviewStore.getState(); | 69 | const store = usePullRequestReviewStore.getState(); |
| 41 | store.setSummary("review-a", "Submitted body"); | 70 | store.setSummary("review-a", "Submitted body"); |