-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseDraftChecklist.test.ts
More file actions
74 lines (64 loc) · 2.15 KB
/
Copy pathuseDraftChecklist.test.ts
File metadata and controls
74 lines (64 loc) · 2.15 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
66
67
68
69
70
71
72
73
74
// @vitest-environment jsdom
import { act, renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useDraftChecklist } from "./useDraftChecklist";
function makeOptions(
overrides: Partial<Parameters<typeof useDraftChecklist>[0]> = {},
) {
return {
input: "user vpn disconnects",
ocrText: null,
diagnosticNotes: "",
treeResult: null,
currentTicket: null,
modelLoaded: true,
generateChecklist: vi
.fn()
.mockResolvedValue({ items: [{ id: "a", label: "Ping gateway" }] }),
updateChecklist: vi
.fn()
.mockResolvedValue({ items: [{ id: "a", label: "Ping gateway" }] }),
onShowError: vi.fn(),
...overrides,
};
}
describe("useDraftChecklist", () => {
it("generates a checklist and stores items", async () => {
const options = makeOptions();
const { result } = renderHook(() => useDraftChecklist(options));
await act(async () => {
await result.current.handleChecklistGenerate();
});
expect(options.generateChecklist).toHaveBeenCalledWith(
expect.objectContaining({ user_input: "user vpn disconnects" }),
);
expect(result.current.checklistItems).toHaveLength(1);
expect(result.current.checklistError).toBeNull();
});
it("sets a local error when prompt input is empty", async () => {
const options = makeOptions({
input: "",
ocrText: null,
currentTicket: null,
});
const { result } = renderHook(() => useDraftChecklist(options));
await act(async () => {
await result.current.handleChecklistGenerate();
});
expect(result.current.checklistError).toMatch(
/add ticket details or notes/i,
);
expect(options.generateChecklist).not.toHaveBeenCalled();
});
it("toggles completion state per id", () => {
const { result } = renderHook(() => useDraftChecklist(makeOptions()));
act(() => {
result.current.handleChecklistToggle("a");
});
expect(result.current.checklistCompleted).toEqual({ a: true });
act(() => {
result.current.handleChecklistToggle("a");
});
expect(result.current.checklistCompleted).toEqual({ a: false });
});
});