-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsystem-prompt-editor.test.tsx
57 lines (46 loc) · 1.61 KB
/
system-prompt-editor.test.tsx
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
import { render, waitFor } from "@/lib/test-utils";
import { expect, test } from "vitest";
import { SystemPromptEditor } from "../system-prompt-editor";
import userEvent from "@testing-library/user-event";
import { server } from "@/mocks/msw/node";
import { http, HttpResponse } from "msw";
vi.mock("../../lib/post-system-prompt");
vi.mock("@monaco-editor/react", () => {
const FakeEditor = vi.fn((props) => {
return (
<textarea
data-auto={props.wrapperClassName}
onChange={(e) => props.onChange(e.target.value)}
value={props.value}
></textarea>
);
});
return { default: FakeEditor };
});
const renderComponent = () =>
render(<SystemPromptEditor isArchived={false} workspaceName="foo" />);
test("can update system prompt", async () => {
server.use(
http.get("*/api/v1/workspaces/:name/system-prompt", () => {
return HttpResponse.json({ prompt: "initial prompt from server" });
})
);
const { getByRole } = renderComponent();
await waitFor(() => {
expect(getByRole("textbox")).toBeVisible();
});
const input = getByRole("textbox");
expect(input).toHaveTextContent("initial prompt from server");
await userEvent.clear(input);
await userEvent.type(input, "new prompt from test");
expect(input).toHaveTextContent("new prompt from test");
await userEvent.click(getByRole("button", { name: /Save/i }));
server.use(
http.get("*/api/v1/workspaces/:name/system-prompt", () => {
return HttpResponse.json({ prompt: "new prompt from test" });
})
);
await waitFor(() => {
expect(input).toHaveTextContent("new prompt from test");
});
});