Skip to content

Commit d7c9bfe

Browse files
committed
test: Add unit tests for SignUpAuthScreen
1 parent aad7564 commit d7c9bfe

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { render, screen } from "@testing-library/react";
3+
import { SignUpAuthScreen } from "~/auth/screens/sign-up-auth-screen";
4+
import * as Hooks from "~/hooks";
5+
import { getTranslation } from "@firebase-ui/core";
6+
7+
// Mock hooks
8+
vi.mock("~/hooks", () => ({
9+
useConfig: vi.fn(),
10+
useTranslations: vi.fn(),
11+
}));
12+
13+
// Mock translations
14+
vi.mock("@firebase-ui/core", () => ({
15+
getTranslation: vi.fn((category, key) => {
16+
if (category === "labels" && key === "register") return "Create Account";
17+
if (category === "prompts" && key === "enterDetailsToCreate")
18+
return "Enter your details to create an account";
19+
if (category === "messages" && key === "dividerOr") return "OR";
20+
return `${category}.${key}`;
21+
}),
22+
}));
23+
24+
// Mock RegisterForm component
25+
vi.mock("~/auth/forms/register-form", () => ({
26+
RegisterForm: ({
27+
onBackToSignInClick,
28+
}: {
29+
onBackToSignInClick?: () => void;
30+
}) => (
31+
<div data-testid="register-form">
32+
<button
33+
data-testid="back-to-sign-in-button"
34+
onClick={onBackToSignInClick}
35+
>
36+
Back to Sign In
37+
</button>
38+
</div>
39+
),
40+
}));
41+
42+
describe("SignUpAuthScreen", () => {
43+
beforeEach(() => {
44+
vi.mocked(Hooks.useConfig).mockReturnValue({
45+
language: "en",
46+
} as any);
47+
vi.mocked(Hooks.useTranslations).mockReturnValue({} as any);
48+
});
49+
50+
it("renders the correct title and subtitle", () => {
51+
render(<SignUpAuthScreen />);
52+
53+
expect(screen.getByText("Create Account")).toBeInTheDocument();
54+
expect(
55+
screen.getByText("Enter your details to create an account")
56+
).toBeInTheDocument();
57+
});
58+
59+
it("retrieves the language from the config", () => {
60+
render(<SignUpAuthScreen />);
61+
62+
expect(Hooks.useConfig).toHaveBeenCalled();
63+
expect(getTranslation).toHaveBeenCalledWith(
64+
"labels",
65+
"register",
66+
expect.anything(),
67+
"en"
68+
);
69+
});
70+
71+
it("includes the RegisterForm component", () => {
72+
render(<SignUpAuthScreen />);
73+
74+
expect(screen.getByTestId("register-form")).toBeInTheDocument();
75+
});
76+
77+
it("passes the onBackToSignInClick prop to the RegisterForm", async () => {
78+
const onBackToSignInClick = vi.fn();
79+
render(<SignUpAuthScreen onBackToSignInClick={onBackToSignInClick} />);
80+
81+
const backButton = screen.getByTestId("back-to-sign-in-button");
82+
backButton.click();
83+
84+
expect(onBackToSignInClick).toHaveBeenCalled();
85+
});
86+
87+
it("renders children when provided", () => {
88+
render(
89+
<SignUpAuthScreen>
90+
<div data-testid="test-child">Child element</div>
91+
</SignUpAuthScreen>
92+
);
93+
94+
expect(screen.getByTestId("test-child")).toBeInTheDocument();
95+
expect(screen.getByText("OR")).toBeInTheDocument();
96+
});
97+
98+
it("does not render divider or children container when no children are provided", () => {
99+
render(<SignUpAuthScreen />);
100+
101+
expect(screen.queryByText("OR")).not.toBeInTheDocument();
102+
});
103+
});

0 commit comments

Comments
 (0)