|
1 | | -import { renderHook, waitFor } from "@testing-library/react"; |
2 | | -import { describe, it, expect, beforeEach } from "vitest"; |
3 | | -import { AppShell } from "../components/appshell"; |
| 1 | +import { renderHook, waitFor, cleanup } from "@testing-library/react"; |
| 2 | +import { describe, it, expect, afterEach } from "vitest"; |
4 | 3 | import { useNavItems } from "./navigation"; |
5 | 4 | import { defineModule, defineResource, hidden } from "@/resource"; |
| 5 | +import { |
| 6 | + AppShellConfigContext, |
| 7 | + AppShellDataContext, |
| 8 | + buildConfigurations, |
| 9 | +} from "@/contexts/appshell-context"; |
| 10 | +import { RouterContainer } from "@/routing/router"; |
6 | 11 |
|
7 | 12 | const renderNavItems = ( |
8 | 13 | modules: Array<ReturnType<typeof defineModule>>, |
9 | 14 | path = "/dashboard/overview", |
10 | 15 | ) => { |
11 | | - window.history.pushState({}, "", path); |
| 16 | + const configurations = buildConfigurations({ modules, locale: "en" }); |
| 17 | + |
12 | 18 | return renderHook(() => useNavItems(), { |
13 | 19 | wrapper: ({ children }) => ( |
14 | | - <AppShell title="My App" modules={modules}> |
15 | | - {children} |
16 | | - </AppShell> |
| 20 | + <AppShellConfigContext.Provider value={{ configurations }}> |
| 21 | + <AppShellDataContext.Provider value={{ contextData: {} }}> |
| 22 | + <RouterContainer memory initialEntries={[path]}> |
| 23 | + {children} |
| 24 | + </RouterContainer> |
| 25 | + </AppShellDataContext.Provider> |
| 26 | + </AppShellConfigContext.Provider> |
17 | 27 | ), |
18 | 28 | }); |
19 | 29 | }; |
20 | 30 |
|
21 | 31 | describe("useNavItems", () => { |
22 | | - beforeEach(() => { |
23 | | - window.history.pushState({}, "", "/dashboard/overview"); |
| 32 | + afterEach(() => { |
| 33 | + cleanup(); |
24 | 34 | }); |
25 | 35 |
|
26 | 36 | it("builds nav items for visible modules and resources", async () => { |
|
0 commit comments