-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDashboardPage.test.tsx
More file actions
49 lines (45 loc) · 1.53 KB
/
DashboardPage.test.tsx
File metadata and controls
49 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from "react";
import { render, screen } from "@testing-library/react";
import DashboardPageInternal from "@/pages/dashboard";
import * as auth0 from "@auth0/nextjs-auth0/client";
describe("DashboardPageInternal", () => {
afterEach(() => jest.restoreAllMocks());
it("shows spinner on load", () => {
jest
.spyOn(auth0, "useUser")
.mockReturnValue({ user: null, error: null, isLoading: true });
render(<DashboardPageInternal />);
expect(screen.getByRole("img", { hidden: true })).toBeInTheDocument();
});
it("prompts login when no session", async () => {
jest
.spyOn(auth0, "useUser")
.mockReturnValue({ user: null, error: null, isLoading: false });
render(<DashboardPageInternal />);
expect(await screen.findByText(/please log in/i)).toBeInTheDocument();
});
it("renders stats when session exists", async () => {
jest
.spyOn(auth0, "useUser")
.mockReturnValue({ user: { sub: "u1" }, error: null, isLoading: false });
const mockData = {
userSub: "u1",
totalProjects: 2,
totalTasks: 5,
doneTasks: 3,
todoTasks: 1,
inProgressTasks: 1,
topProjects: [],
largestProjectName: "",
smallestProjectName: "",
projectStats: [],
allProjects: [],
};
global.fetch = jest
.fn()
.mockResolvedValue({ ok: true, json: async () => mockData });
render(<DashboardPageInternal />);
expect(await screen.findByText(/2/)).toBeInTheDocument();
expect(screen.getByText(/5/)).toBeInTheDocument();
});
});