-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraftResponsePanel.test.tsx
More file actions
128 lines (114 loc) · 3.53 KB
/
Copy pathDraftResponsePanel.test.tsx
File metadata and controls
128 lines (114 loc) · 3.53 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// @vitest-environment jsdom
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { DraftResponsePanel } from "./DraftResponsePanel";
vi.mock("./ResponsePanel", () => ({
ResponsePanel: ({ response }: { response: string }) => (
<div data-testid="response-panel">{response || "empty"}</div>
),
}));
vi.mock("./AlternativePanel", () => ({
AlternativePanel: () => <div data-testid="alternative-panel" />,
}));
vi.mock("./SavedResponsesSuggestion", () => ({
SavedResponsesSuggestion: () => <div data-testid="saved-suggestion" />,
}));
function makeProps(
overrides: Partial<Parameters<typeof DraftResponsePanel>[0]> = {},
) {
return {
suggestions: [],
suggestionsDismissed: false,
onSuggestionApply: vi.fn(),
onSuggestionDismiss: vi.fn(),
response: "",
streamingText: "",
isStreaming: false,
sources: [],
generating: false,
metrics: null,
confidence: null,
grounding: [],
savedDraftId: null,
hasInput: false,
isResponseEdited: false,
loadedModelName: null,
currentTicketId: null,
onSaveDraft: vi.fn(),
onCancel: vi.fn(),
onResponseChange: vi.fn(),
onGenerateAlternative: vi.fn(),
generatingAlternative: false,
onSaveAsTemplate: vi.fn(),
alternatives: [],
onChooseAlternative: vi.fn(),
onUseAlternative: vi.fn(),
...overrides,
};
}
describe("DraftResponsePanel", () => {
afterEach(() => cleanup());
it("renders the response panel by itself when no suggestions or alternatives are present", () => {
render(<DraftResponsePanel {...makeProps()} />);
expect(screen.getByTestId("response-panel")).toBeTruthy();
expect(screen.queryByTestId("saved-suggestion")).toBeNull();
expect(screen.queryByTestId("alternative-panel")).toBeNull();
});
it("shows the saved-responses suggestion when suggestions exist, no response, and not dismissed", () => {
render(
<DraftResponsePanel
{...makeProps({
suggestions: [
{
id: "t1",
name: "t",
content: "snippet",
created_at: "",
updated_at: "",
usage_count: 0,
} as unknown as Parameters<
typeof DraftResponsePanel
>[0]["suggestions"][number],
],
})}
/>,
);
expect(screen.getByTestId("saved-suggestion")).toBeTruthy();
});
it("hides the suggestion once the user has a response", () => {
render(
<DraftResponsePanel {...makeProps({ response: "generated text" })} />,
);
expect(screen.queryByTestId("saved-suggestion")).toBeNull();
expect(screen.getByTestId("response-panel").textContent).toBe(
"generated text",
);
});
it("shows the alternative panel only when alternatives exist and generation is idle", () => {
const baseAlt = {
id: "a",
original_text: "o",
alternative_text: "new",
created_at: "",
chosen: null,
} as unknown as Parameters<
typeof DraftResponsePanel
>[0]["alternatives"][number];
const { rerender } = render(
<DraftResponsePanel
{...makeProps({ response: "x", alternatives: [baseAlt] })}
/>,
);
expect(screen.getByTestId("alternative-panel")).toBeTruthy();
rerender(
<DraftResponsePanel
{...makeProps({
response: "x",
alternatives: [baseAlt],
generating: true,
})}
/>,
);
expect(screen.queryByTestId("alternative-panel")).toBeNull();
});
});