Skip to content

Commit 770adc6

Browse files
committed
test: Add unit tests for PhoneAuthScreen
1 parent 247c20e commit 770adc6

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, it, expect, vi } from "vitest";
2+
import { render } from "@testing-library/react";
3+
import { PhoneAuthScreen } from "~/auth/screens/phone-auth-screen";
4+
5+
// Mock the hooks
6+
vi.mock("~/hooks", () => ({
7+
useConfig: () => ({ language: "en" }),
8+
useTranslations: () => ({}),
9+
}));
10+
11+
// Mock the translation function
12+
vi.mock("@firebase-ui/core", () => ({
13+
getTranslation: vi.fn((category, key) => {
14+
if (category === "labels" && key === "signIn") return "Sign in";
15+
if (category === "prompts" && key === "signInToAccount")
16+
return "Sign in to your account";
17+
if (category === "messages" && key === "dividerOr") return "OR";
18+
return key;
19+
}),
20+
}));
21+
22+
// Mock the PhoneForm component
23+
vi.mock("~/auth/forms/phone-form", () => ({
24+
PhoneForm: ({ resendDelay }: { resendDelay?: number }) => (
25+
<div data-testid="phone-form" data-resend-delay={resendDelay}>
26+
Phone Form
27+
</div>
28+
),
29+
}));
30+
31+
describe("PhoneAuthScreen", () => {
32+
it("displays the correct title and subtitle", () => {
33+
const { getByText } = render(<PhoneAuthScreen />);
34+
35+
expect(getByText("Sign in")).toBeInTheDocument();
36+
expect(getByText("Sign in to your account")).toBeInTheDocument();
37+
});
38+
39+
it("calls useConfig to retrieve the language", () => {
40+
const { getByText } = render(<PhoneAuthScreen />);
41+
42+
expect(getByText("Sign in")).toBeInTheDocument();
43+
});
44+
45+
it("includes the PhoneForm with the correct resendDelay prop", () => {
46+
const { getByTestId } = render(<PhoneAuthScreen resendDelay={60} />);
47+
48+
const phoneForm = getByTestId("phone-form");
49+
expect(phoneForm).toBeInTheDocument();
50+
expect(phoneForm.getAttribute("data-resend-delay")).toBe("60");
51+
});
52+
53+
it("renders children when provided", () => {
54+
const { getByText, getByTestId } = render(
55+
<PhoneAuthScreen>
56+
<button data-testid="test-button">Test Button</button>
57+
</PhoneAuthScreen>
58+
);
59+
60+
expect(getByTestId("test-button")).toBeInTheDocument();
61+
expect(getByText("OR")).toBeInTheDocument();
62+
});
63+
64+
it("does not render children or divider when not provided", () => {
65+
const { queryByText } = render(<PhoneAuthScreen />);
66+
67+
expect(queryByText("OR")).not.toBeInTheDocument();
68+
});
69+
});

0 commit comments

Comments
 (0)