Open History to see the last commit
1import { beforeEach, describe, expect, it } from "vite-plus/test";
2
3import { type PendingReviewComment, usePullRequestReviewStore } from "./pullRequestReviewStore";
4
5function comment(id: string, body = id): PendingReviewComment {
6 return { id, body, path: "src/app.ts", line: 1, side: "right" };
7}
8
9describe("pull request review drafts", () => {
10 beforeEach(() => {
11 usePullRequestReviewStore.setState({ drafts: {}, summaries: {} });
12 });
13
14 it("removes only the line comments included in a submitted snapshot", () => {
15 const store = usePullRequestReviewStore.getState();
16 store.addComment("review-a", comment("submitted"));
17 const submittedIds =
18 usePullRequestReviewStore.getState().drafts["review-a"]?.map((entry) => entry.id) ?? [];
19
20 usePullRequestReviewStore.getState().addComment("review-a", comment("added-in-flight"));
21 usePullRequestReviewStore.getState().removeComments("review-a", submittedIds);
22
23 expect(usePullRequestReviewStore.getState().drafts["review-a"]).toEqual([
24 comment("added-in-flight"),
25 ]);
26 });
27
28 it("keeps summary bodies isolated by review key", () => {
29 const store = usePullRequestReviewStore.getState();
30 store.setSummary("review-a", "Summary A");
31 store.setSummary("review-b", "Summary B");
32 store.clearSummary("review-a", "Summary A");
33
34 expect(usePullRequestReviewStore.getState().summaries).toEqual({
35 "review-b": "Summary B",
36 });
37 });
38
39 it("does not clear a summary revised while submission is in flight", () => {
40 const store = usePullRequestReviewStore.getState();
41 store.setSummary("review-a", "Submitted body");
42 usePullRequestReviewStore.getState().setSummary("review-a", "Revised body");
43 usePullRequestReviewStore.getState().clearSummary("review-a", "Submitted body");
44
45 expect(usePullRequestReviewStore.getState().summaries["review-a"]).toBe("Revised body");
46 });
47});