forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

gmail-compose-box.test.tsx40 lines, 1.7 KiBHistoryRawDownload
1import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library";
2import { GmailComposeBox } from "@/components/messages/gmail-compose-box";
3import { PreferencesProvider } from "@/stores/preferences-context";
4
5vi.mock("@/stores/auth-context", () => ({
6 useAuth: () => ({ user: () => ({ id: "user-1", username: "teacher", role: "teacher" }) }),
7}));
8vi.mock("@/api/messages", () => ({ postMessage: vi.fn() }));
9// The real picker searches the API; a plain button stands in for choosing someone.
10vi.mock("@/components/users/user-search-select", () => ({
11 UserSearchSelect: (props: { onChange: (id: string) => void }) => (
12 <button type="button" onClick={() => props.onChange("user-2")}>pick recipient</button>
13 ),
14}));
15vi.mock("@/components/ui/rich-text-editor", () => ({ RichTextEditor: () => <div /> }));
16
17afterEach(cleanup);
18
19test("send stays disabled until there is a recipient and a subject, and says what is missing", () => {
20 render(() => (
21 <PreferencesProvider>
22 <GmailComposeBox open onClose={() => {}} onSuccess={() => {}} />
23 </PreferencesProvider>
24 ));
25
26 const send = screen.getByRole("button", { name: "Send" }) as HTMLButtonElement;
27 expect(send.disabled).toBe(true);
28 expect(screen.getByText("Choose a recipient to send.")).toBeTruthy();
29
30 fireEvent.click(screen.getByText("pick recipient"));
31 expect(send.disabled).toBe(true);
32 expect(screen.getByText("Add a subject to send.")).toBeTruthy();
33
34 fireEvent.input(screen.getByLabelText("Subject"), { target: { value: " " } });
35 expect(send.disabled).toBe(true);
36
37 fireEvent.input(screen.getByLabelText("Subject"), { target: { value: "Veli toplantısı" } });
38 expect(send.disabled).toBe(false);
39 expect(screen.queryByText("Add a subject to send.")).toBeNull();
40});