forked from lee-to/aif-handoff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSmoke.test.tsx
More file actions
93 lines (76 loc) · 2.78 KB
/
Copy pathAppSmoke.test.tsx
File metadata and controls
93 lines (76 loc) · 2.78 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
// Stub network-dependent hooks so the component tree renders without real API calls.
vi.mock("@/hooks/useWebSocket", () => ({
useWebSocket: vi.fn(),
}));
function stubHookModule(keys: string[]) {
const stub = () => ({
data: undefined,
isLoading: false,
mutate: vi.fn(),
mutateAsync: vi.fn(),
isPending: false,
});
return Object.fromEntries(keys.map((key) => [key, vi.fn(stub)]));
}
vi.mock("@/hooks/useProjects", async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return stubHookModule(Object.keys(actual));
});
vi.mock("@/hooks/useTasks", async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return stubHookModule(Object.keys(actual));
});
vi.mock("@/hooks/useSettings", async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return stubHookModule(Object.keys(actual));
});
vi.mock("@/hooks/useRuntimeProfiles", async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return stubHookModule(Object.keys(actual));
});
vi.mock("@/lib/api", () => ({
api: new Proxy(
{},
{
get: () => vi.fn().mockResolvedValue([]),
},
),
}));
vi.mock("@tanstack/react-query", async (importOriginal) => {
const actual = await importOriginal<typeof import("@tanstack/react-query")>();
return {
...actual,
useQuery: vi.fn(() => ({ data: undefined, isLoading: false })),
useMutation: vi.fn(() => ({ mutate: vi.fn(), mutateAsync: vi.fn(), isPending: false })),
};
});
const App = (await import("../App")).default;
const { useProjectTaskOverviews } = await import("@/hooks/useProjects");
const { useTasks } = await import("@/hooks/useTasks");
describe("App smoke test", () => {
beforeEach(() => {
window.history.pushState(null, "", "/");
window.localStorage.clear();
vi.clearAllMocks();
});
afterEach(() => {
window.history.pushState(null, "", "/");
window.localStorage.clear();
});
it("renders without crashing (providers are wired correctly)", () => {
expect(() => render(<App />)).not.toThrow();
});
it("shows the empty-state message when no project is selected", () => {
render(<App />);
expect(screen.getByText("No projects yet")).toBeInTheDocument();
});
it("uses the project id from the URL for the initial task query", () => {
const projectId = "00000000-0000-4000-8000-000000000001";
window.history.pushState(null, "", `/project/${projectId}`);
render(<App />);
expect(vi.mocked(useTasks)).toHaveBeenCalledWith(projectId);
expect(vi.mocked(useProjectTaskOverviews)).toHaveBeenCalledWith(false);
});
});