Skip to content

Commit b9cda45

Browse files
committed
test(shadcn): Add tests
1 parent ce065f2 commit b9cda45

File tree

11 files changed

+461
-15
lines changed

11 files changed

+461
-15
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"build:translations": "pnpm --filter=@firebase-ui/translations run build",
1010
"build:react": "pnpm --filter=@firebase-ui/react run build",
1111
"build:angular": "pnpm --filter=@firebase-ui/angular run build",
12+
"build:shadcn": "pnpm --filter=@firebase-ui/shadcn run build",
1213
"lint:check": "eslint",
1314
"format:check": "prettier --check **/{src,tests}/**/*.{ts,tsx}",
1415
"format:write": "prettier --write **/{src,tests}/**/*.{ts,tsx}",
15-
"test": "pnpm run test:core && pnpm run test:react && pnpm run test:translations && pnpm run test:styles",
16+
"test": "pnpm run test:core && pnpm run test:react && pnpm run test:translations && pnpm run test:styles && pnpm run test:shadcn",
1617
"test:core": "pnpm --filter=@firebase-ui/core run test",
1718
"test:react": "pnpm --filter=@firebase-ui/react run test",
1819
"test:angular": "pnpm --filter=@firebase-ui/angular run test",
1920
"test:translations": "pnpm --filter=@firebase-ui/translations run test",
2021
"test:styles": "pnpm --filter=@firebase-ui/styles run test",
22+
"test:shadcn": "pnpm --filter=@firebase-ui/shadcn run test",
2123
"test:watch": "pnpm run test:core:watch & pnpm run test:react:watch & pnpm run test:angular:watch",
2224
"test:core:watch": "pnpm --filter=@firebase-ui/core run test:unit:watch",
2325
"test:react:watch": "pnpm --filter=@firebase-ui/react run test:unit:watch",

packages/react/src/auth/forms/sign-in-auth-form.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("<SignInAuthForm />", () => {
164164
vi.clearAllMocks();
165165
});
166166

167-
it("should render the form correctly", () => {
167+
it.only("should render the form correctly", () => {
168168
const mockUI = createMockUI({
169169
locale: registerLocale("test", {
170170
labels: {

packages/shadcn/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"registry:build": "tsx build.ts https://ui.firebase.com",
9-
"lint": "eslint .",
10-
"preview": "vite preview"
8+
"build": "tsx build.ts https://ui.firebase.com",
9+
"preview": "vite preview",
10+
"test": "vitest run"
1111
},
1212
"devDependencies": {
13+
"@testing-library/jest-dom": "catalog:",
14+
"@testing-library/react": "catalog:",
15+
"@firebase-ui/translations": "workspace:*",
1316
"@tailwindcss/vite": "^4.1.14",
1417
"@types/node": "catalog:",
1518
"@types/react": "catalog:",
1619
"@types/react-dom": "catalog:",
1720
"@vitejs/plugin-react": "catalog:",
21+
"firebase": "catalog:",
1822
"react": "catalog:",
1923
"react-dom": "catalog:",
2024
"shadcn": "2.9.3-canary.0",
2125
"tailwindcss": "catalog:",
2226
"tw-animate-css": "^1.4.0",
2327
"typescript": "catalog:",
2428
"tsx": "^4.20.6",
25-
"vite": "catalog:"
29+
"vite": "catalog:",
30+
"vitest": "catalog:"
2631
},
2732
"dependencies": {
33+
"@firebase-ui/core": "workspace:*",
2834
"@firebase-ui/react": "workspace:*",
2935
"@hookform/resolvers": "^5.2.2",
3036
"@radix-ui/react-label": "^2.1.7",

packages/shadcn/setup-test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import "@testing-library/jest-dom/vitest";
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
18+
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
19+
import { Policies } from "./policies";
20+
import { createMockUI } from "../../tests/utils";
21+
import { registerLocale } from "@firebase-ui/translations";
22+
import { FirebaseUIProvider } from "@firebase-ui/react";
23+
24+
vi.mock("@firebase-ui/core", async (importOriginal) => {
25+
const mod = await importOriginal<typeof import("@firebase-ui/core")>();
26+
return {
27+
...mod,
28+
signInWithEmailAndPassword: vi.fn(),
29+
};
30+
});
31+
32+
vi.mock("@firebase-ui/react", async (importOriginal) => {
33+
const mod = await importOriginal<typeof import("@firebase-ui/react")>();
34+
return {
35+
...mod,
36+
useSignInAuthFormAction: vi.fn(),
37+
};
38+
});
39+
40+
describe("<Policies />", () => {
41+
beforeEach(() => {
42+
vi.clearAllMocks();
43+
});
44+
45+
afterEach(() => {
46+
cleanup();
47+
});
48+
49+
it("should return null when no policies are provided", () => {
50+
const mockUI = createMockUI();
51+
52+
const { container } = render(
53+
<FirebaseUIProvider ui={mockUI}>
54+
<Policies />
55+
</FirebaseUIProvider>
56+
);
57+
58+
expect(container.firstChild).toBeNull();
59+
});
60+
61+
it("should render policies with navigation callback", () => {
62+
const onNavigateMock = vi.fn();
63+
const mockUI = createMockUI({
64+
locale: registerLocale("test", {
65+
messages: {
66+
termsAndPrivacy: "{tos} and {privacy}",
67+
},
68+
labels: {
69+
termsOfService: "tos",
70+
privacyPolicy: "pp",
71+
},
72+
}),
73+
});
74+
75+
const mockPolicies = {
76+
termsOfServiceUrl: "https://example.com/terms",
77+
privacyPolicyUrl: "https://example.com/privacy",
78+
onNavigate: onNavigateMock,
79+
};
80+
81+
const { container } = render(
82+
<FirebaseUIProvider ui={mockUI} policies={mockPolicies}>
83+
<Policies />
84+
</FirebaseUIProvider>
85+
);
86+
87+
const buttons = container.querySelectorAll("button");
88+
expect(buttons).toHaveLength(2);
89+
90+
const termsButton = screen.getByText("tos");
91+
const privacyButton = screen.getByText("pp");
92+
93+
expect(termsButton).toBeInTheDocument();
94+
expect(privacyButton).toBeInTheDocument();
95+
96+
fireEvent.click(termsButton);
97+
expect(onNavigateMock).toHaveBeenCalledWith("https://example.com/terms");
98+
99+
fireEvent.click(privacyButton);
100+
expect(onNavigateMock).toHaveBeenCalledWith("https://example.com/privacy");
101+
});
102+
103+
it("should render policies with external links when no navigation callback", () => {
104+
const mockUI = createMockUI({
105+
locale: registerLocale("test", {
106+
messages: {
107+
termsAndPrivacy: "{tos} and {privacy}",
108+
},
109+
labels: {
110+
termsOfService: "tos",
111+
privacyPolicy: "pp",
112+
},
113+
}),
114+
});
115+
116+
const mockPolicies = {
117+
termsOfServiceUrl: "https://example.com/terms",
118+
privacyPolicyUrl: "https://example.com/privacy",
119+
onNavigate: undefined,
120+
};
121+
122+
const { container } = render(
123+
<FirebaseUIProvider ui={mockUI} policies={mockPolicies}>
124+
<Policies />
125+
</FirebaseUIProvider>
126+
);
127+
128+
const links = container.querySelectorAll("a");
129+
expect(links).toHaveLength(2);
130+
131+
const termsLink = screen.getByText("tos");
132+
const privacyLink = screen.getByText("pp");
133+
134+
expect(termsLink).toHaveAttribute("href", "https://example.com/terms");
135+
expect(termsLink).toHaveAttribute("target", "_blank");
136+
expect(termsLink).toHaveAttribute("rel", "noopener noreferrer");
137+
138+
expect(privacyLink).toHaveAttribute("href", "https://example.com/privacy");
139+
expect(privacyLink).toHaveAttribute("target", "_blank");
140+
expect(privacyLink).toHaveAttribute("rel", "noopener noreferrer");
141+
});
142+
});

0 commit comments

Comments
 (0)