Open History to see the last commit
1import { createRef } from "react";
2import { EnvironmentId, ProjectId } from "@t3tools/contracts";
3import { expect, it, vi } from "vite-plus/test";
4import { act, render } from "../../../test/render";
5import { PullRequestReviewForm } from "./PullRequestReviewForm";
6import { pullRequestReviewKey, usePullRequestReviewStore } from "./pullRequestReviewStore";
7
8const mocks = vi.hoisted(() => ({
9 submit: vi.fn().mockResolvedValue({ _tag: "Success" }),
10 queue: vi.fn<(submit: (text: string) => void) => void>(),
11}));
12vi.mock("~/speech/useTextFieldSpeech", () => ({
13 TextFieldSpeechControls: () => null,
14 useTextFieldSpeech: () => ({ blocksSubmission: true, submitAfterDictation: mocks.queue }),
15}));
16vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => mocks.submit }));
17vi.mock(import("~/state/pullRequests"), async (original) => ({
18 ...(await original()),
19 pullRequestEnvironment: { submitReview: {} } as never,
20}));
21
22it("submits only the line comments still in the draft when dictation finishes", async () => {
23 mocks.submit.mockClear();
24 mocks.queue.mockClear();
25 const reference = { projectId: ProjectId.make("test"), repository: "test/repo", number: 1 };
26 const key = pullRequestReviewKey(reference);
27 const store = usePullRequestReviewStore.getState();
28 store.clear(key);
29 store.addComment(key, {
30 id: "removed",
31 body: "Do not post",
32 path: "a.ts",
33 position: { kind: "added", newLine: 1 },
34 });
35 await using screen = await render(
36 <PullRequestReviewForm
37 active
38 environmentId={EnvironmentId.make("test")}
39 reference={reference}
40 completionScope={null}
41 term="pull request"
42 verdicts={["comment"]}
43 requestChangesSummaryRequired={false}
44 textareaRef={createRef()}
45 pending={false}
46 onPendingChange={vi.fn()}
47 onSubmitted={vi.fn()}
48 />,
49 );
50 await screen.getByRole("button", { name: "Submit review" }).click();
51 await act(() => store.clear(key));
52 await act(() => mocks.queue.mock.calls[0]);
53 expect(mocks.submit).toHaveBeenCalledWith(
54 expect.objectContaining({
55 input: expect.objectContaining({ body: "Dictated summary", comments: [] }),
56 }),
57 );
58});