Repository navigation
Expand file tree
/
Copy pathpullRequestReviewStore.test.ts
More file actions
65 lines (53 loc) · 2.71 KB
/
Copy pathpullRequestReviewStore.test.ts
File metadata and controls
65 lines (53 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { beforeEach, describe, expect, it } from "vite-plus/test";
import { ProjectId } from "@t3tools/contracts";
import {
type PendingReviewComment,
pullRequestReviewKey,
usePullRequestReviewStore,
} from "./pullRequestReviewStore";
function comment(id: string, body = id): PendingReviewComment {
return { id, body, path: "src/app.ts", position: { kind: "added", newLine: 1 } };
}
describe("pull request review drafts", () => {
beforeEach(() => {
usePullRequestReviewStore.setState({ drafts: {}, summaries: {} });
});
it("removes only the line comments included in a submitted snapshot", () => {
const store = usePullRequestReviewStore.getState();
store.addComment("review-a", comment("submitted"));
const submittedIds =
usePullRequestReviewStore.getState().drafts["review-a"]?.map((entry) => entry.id) ?? [];
usePullRequestReviewStore.getState().addComment("review-a", comment("added-in-flight"));
usePullRequestReviewStore.getState().removeComments("review-a", submittedIds);
expect(usePullRequestReviewStore.getState().drafts["review-a"]).toEqual([
comment("added-in-flight"),
]);
});
it("keeps drafts on different hosts separate when a thread reviews the same repository and number", () => {
const reference = {
projectId: ProjectId.make("project-a"),
repository: "owner/repo",
number: 7,
};
const publicKey = pullRequestReviewKey({ ...reference, host: "github.com" });
const enterpriseKey = pullRequestReviewKey({ ...reference, host: "github.example.com" });
const store = usePullRequestReviewStore.getState();
store.addComment(publicKey, comment("public"));
store.setSummary(publicKey, "Public review");
expect(usePullRequestReviewStore.getState().drafts[enterpriseKey]).toBeUndefined();
expect(usePullRequestReviewStore.getState().summaries[enterpriseKey]).toBeUndefined();
store.addComment(enterpriseKey, comment("enterprise"));
store.setSummary(enterpriseKey, "Enterprise review");
store.clear(enterpriseKey);
store.clearSummary(enterpriseKey, "Enterprise review");
expect(usePullRequestReviewStore.getState().drafts[publicKey]).toEqual([comment("public")]);
expect(usePullRequestReviewStore.getState().summaries[publicKey]).toBe("Public review");
});
it("does not clear a summary revised while submission is in flight", () => {
const store = usePullRequestReviewStore.getState();
store.setSummary("review-a", "Submitted body");
usePullRequestReviewStore.getState().setSummary("review-a", "Revised body");
usePullRequestReviewStore.getState().clearSummary("review-a", "Submitted body");
expect(usePullRequestReviewStore.getState().summaries["review-a"]).toBe("Revised body");
});
});