Skip to content

Commit 9c91466

Browse files
test: write render tests for dashboard
1 parent bfdafa0 commit 9c91466

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { vi } from "vitest";
2+
import { render, screen } from "@testing-library/react";
3+
import { describe, it, expect, beforeEach } from "vitest";
4+
import DashboardPage from "../page";
5+
6+
// Mock next/navigation to prevent redirect calls
7+
vi.mock("next/navigation", () => ({
8+
redirect: vi.fn(),
9+
}));
10+
11+
// Mock Supabase server client to return a fake authenticated user
12+
vi.mock("../../../lib/supabase/server", () => ({
13+
createClient: vi.fn(async () => ({
14+
auth: {
15+
getUser: vi.fn(async () => ({
16+
data: {
17+
user: {
18+
19+
id: "test-user-id",
20+
},
21+
},
22+
})),
23+
signOut: vi.fn(),
24+
},
25+
})),
26+
}));
27+
28+
describe("Dashboard Page Tests", () => {
29+
beforeEach(() => {
30+
vi.clearAllMocks();
31+
});
32+
33+
it("should render the dashboard heading", async () => {
34+
const page = await DashboardPage();
35+
render(page);
36+
expect(screen.getByText("Dashboard")).toBeInTheDocument();
37+
});
38+
39+
it("should display the user email", async () => {
40+
const page = await DashboardPage();
41+
render(page);
42+
expect(screen.getByText("[email protected]")).toBeInTheDocument();
43+
});
44+
45+
it("should render the home link", async () => {
46+
const page = await DashboardPage();
47+
render(page);
48+
expect(screen.getByRole("link", { name: /Go home/i })).toBeInTheDocument();
49+
});
50+
51+
it("should render the logout button", async () => {
52+
const page = await DashboardPage();
53+
render(page);
54+
expect(screen.getByRole("button", { name: /Log out/i })).toBeInTheDocument();
55+
});
56+
57+
it("should render the tutorial link", async () => {
58+
const page = await DashboardPage();
59+
render(page);
60+
expect(screen.getByRole("link", { name: /Hello World Tutorial/i })).toBeInTheDocument();
61+
});
62+
});

0 commit comments

Comments
 (0)