Skip to content

Commit 247c20e

Browse files
committed
test: Add unit tests for PasswordResetScreen
1 parent 6c32dc2 commit 247c20e

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2+
import { render, fireEvent } from "@testing-library/react";
3+
import { PasswordResetScreen } from "~/auth/screens/password-reset-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 === "resetPassword")
16+
return "Reset Password";
17+
if (category === "prompts" && key === "enterEmailToReset")
18+
return "Enter your email to reset your password";
19+
return key;
20+
}),
21+
}));
22+
23+
// Mock the ForgotPasswordForm component
24+
vi.mock("~/auth/forms/forgot-password-form", () => ({
25+
ForgotPasswordForm: ({
26+
onBackToSignInClick,
27+
}: {
28+
onBackToSignInClick?: () => void;
29+
}) => (
30+
<div data-testid="forgot-password-form">
31+
<button onClick={onBackToSignInClick} data-testid="back-button">
32+
Back to Sign In
33+
</button>
34+
</div>
35+
),
36+
}));
37+
38+
describe("PasswordResetScreen", () => {
39+
const mockOnBackToSignInClick = vi.fn();
40+
41+
beforeEach(() => {
42+
// Setup default mock values
43+
vi.mocked(hooks.useConfig).mockReturnValue({
44+
language: "en",
45+
} as any);
46+
47+
vi.mocked(hooks.useTranslations).mockReturnValue({} as any);
48+
});
49+
50+
afterEach(() => {
51+
vi.clearAllMocks();
52+
});
53+
54+
it("renders with correct title and subtitle", () => {
55+
const { getByText } = render(<PasswordResetScreen />);
56+
57+
expect(getByText("Reset Password")).toBeInTheDocument();
58+
expect(
59+
getByText("Enter your email to reset your password")
60+
).toBeInTheDocument();
61+
});
62+
63+
it("calls useConfig to get the language", () => {
64+
render(<PasswordResetScreen />);
65+
66+
expect(hooks.useConfig).toHaveBeenCalled();
67+
});
68+
69+
it("includes the ForgotPasswordForm component", () => {
70+
const { getByTestId } = render(<PasswordResetScreen />);
71+
72+
expect(getByTestId("forgot-password-form")).toBeInTheDocument();
73+
});
74+
75+
it("passes onBackToSignInClick to ForgotPasswordForm", () => {
76+
const { getByTestId } = render(
77+
<PasswordResetScreen onBackToSignInClick={mockOnBackToSignInClick} />
78+
);
79+
80+
// Click the back button in the mocked form
81+
fireEvent.click(getByTestId("back-button"));
82+
83+
// Verify the callback was called
84+
expect(mockOnBackToSignInClick).toHaveBeenCalledTimes(1);
85+
});
86+
});

0 commit comments

Comments
 (0)