|
| 1 | +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; |
| 2 | +import { render } from "@testing-library/react"; |
| 3 | +import { EmailLinkAuthScreen } from "~/auth/screens/email-link-auth-screen"; |
| 4 | +import * as hooks from "~/hooks"; |
| 5 | + |
| 6 | +// Mock the hooks |
| 7 | +vi.mock("~/hooks", () => ({ |
| 8 | + useConfig: vi.fn(), |
| 9 | + useTranslations: vi.fn(), |
| 10 | +})); |
| 11 | + |
| 12 | +// Mock dependencies |
| 13 | +vi.mock("@firebase-ui/core", () => ({ |
| 14 | + getTranslation: vi.fn((category, key) => { |
| 15 | + if (category === "labels" && key === "signIn") return "Sign In"; |
| 16 | + if (category === "prompts" && key === "signInToAccount") |
| 17 | + return "Sign in to your account"; |
| 18 | + if (category === "messages" && key === "dividerOr") return "or"; |
| 19 | + return key; |
| 20 | + }), |
| 21 | +})); |
| 22 | + |
| 23 | +// Mock the EmailLinkForm component |
| 24 | +vi.mock("~/auth/forms/email-link-form", () => ({ |
| 25 | + EmailLinkForm: () => <div data-testid="email-link-form">Email Link Form</div>, |
| 26 | +})); |
| 27 | + |
| 28 | +describe("EmailLinkAuthScreen", () => { |
| 29 | + beforeEach(() => { |
| 30 | + // Setup default mock values |
| 31 | + vi.mocked(hooks.useConfig).mockReturnValue({ |
| 32 | + language: "en", |
| 33 | + } as any); |
| 34 | + |
| 35 | + vi.mocked(hooks.useTranslations).mockReturnValue({} as any); |
| 36 | + }); |
| 37 | + |
| 38 | + afterEach(() => { |
| 39 | + vi.clearAllMocks(); |
| 40 | + }); |
| 41 | + |
| 42 | + it("renders with correct title and subtitle", () => { |
| 43 | + const { getByText } = render(<EmailLinkAuthScreen />); |
| 44 | + |
| 45 | + expect(getByText("Sign In")).toBeInTheDocument(); |
| 46 | + expect(getByText("Sign in to your account")).toBeInTheDocument(); |
| 47 | + }); |
| 48 | + |
| 49 | + it("calls useConfig to get the language", () => { |
| 50 | + render(<EmailLinkAuthScreen />); |
| 51 | + |
| 52 | + expect(hooks.useConfig).toHaveBeenCalled(); |
| 53 | + }); |
| 54 | + |
| 55 | + it("includes the EmailLinkForm component", () => { |
| 56 | + const { getByTestId } = render(<EmailLinkAuthScreen />); |
| 57 | + |
| 58 | + expect(getByTestId("email-link-form")).toBeInTheDocument(); |
| 59 | + }); |
| 60 | + |
| 61 | + it("does not render divider and children when no children are provided", () => { |
| 62 | + const { queryByText } = render(<EmailLinkAuthScreen />); |
| 63 | + |
| 64 | + expect(queryByText("or")).not.toBeInTheDocument(); |
| 65 | + }); |
| 66 | + |
| 67 | + it("renders divider and children when children are provided", () => { |
| 68 | + const { getByText } = render( |
| 69 | + <EmailLinkAuthScreen> |
| 70 | + <div>Test Child</div> |
| 71 | + </EmailLinkAuthScreen> |
| 72 | + ); |
| 73 | + |
| 74 | + expect(getByText("or")).toBeInTheDocument(); |
| 75 | + expect(getByText("Test Child")).toBeInTheDocument(); |
| 76 | + }); |
| 77 | +}); |
0 commit comments