Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestReviewDrafts.test.ts

46 lines1.4 KB

1import { describe, expect, it } from "vite-plus/test";
2import {
3 clearSubmittedReview,
4 reviewDraftReplacement,
5 type ReviewDraft,
6} from "./pullRequestReviewDrafts";
7const comment = {
8 id: "one",
9 path: "renamed.ts",
10 oldPath: "old.ts",
11 position: { kind: "deleted" as const, oldLine: 9 },
12 body: "Keep this",
13 headSha: "abc",
14 code: "old line",
15};
16const draft: ReviewDraft = {
17 summary: "Review",
18 comment: "Separate PR comment",
19 comments: [comment],
20};
21describe("mobile review draft recovery", () => {
22 it("clears a submitted snapshot while retaining edits made during the request", () => {
23 const current = {
24 ...draft,
25 summary: "New summary",
26 comments: [
27 { ...comment, body: "New feedback" },
28 { ...comment, id: "two" },
29 ],
30 };
31 expect(clearSubmittedReview(current, draft)).toEqual(current);
32 expect(clearSubmittedReview(draft, draft)).toEqual({
33 summary: "",
34 comment: draft.comment,
35 comments: [],
36 });
37 });
38​
39 it("keeps replacing an outdated draft until it is moved to the current head", () => {
40 expect(reviewDraftReplacement(draft, null, "one")).toStrictEqual({});
41 expect(reviewDraftReplacement(draft, "def", "one")).toStrictEqual({ draftId: "one" });
42 expect(reviewDraftReplacement(draft, "abc", "one")).toStrictEqual({
43 resetOnReload: { replacingDraftId: undefined },
44 });
45 });
46});