hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; |
| 2 | import { GmailComposeBox } from "@/components/messages/gmail-compose-box"; |
| 3 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 4 | |
| 5 | vi.mock("@/stores/auth-context", () => ({ |
| 6 | useAuth: () => ({ user: () => ({ id: "user-1", username: "teacher", role: "teacher" }) }), |
| 7 | })); |
| 8 | vi.mock("@/api/messages", () => ({ postMessage: vi.fn() })); |
| 9 | // The real picker searches the API; a plain button stands in for choosing someone. |
| 10 | vi.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 | })); |
| 15 | vi.mock("@/components/ui/rich-text-editor", () => ({ RichTextEditor: () => <div /> })); |
| 16 | |
| 17 | afterEach(cleanup); |
| 18 | |
| 19 | test("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 | }); |