Skip to content

Commit 1c36c7a

Browse files
IzumiSyCopilot
andauthored
fix: use memory router in navigation.test.tsx (#346)
* Initial plan: fix navigation.test.tsx to use memory router Co-authored-by: IzumiSy <982850+IzumiSy@users.noreply.github.com> * fix: use memory router in navigation.test.tsx to prevent unhandled async errors Co-authored-by: IzumiSy <982850+IzumiSy@users.noreply.github.com> * chore: drop unrelated docs edits from navigation fix --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: IzumiSy <982850+IzumiSy@users.noreply.github.com>
1 parent 6b72db1 commit 1c36c7a

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

packages/core/src/routing/navigation.test.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
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";
43
import { useNavItems } from "./navigation";
54
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";
611

712
const renderNavItems = (
813
modules: Array<ReturnType<typeof defineModule>>,
914
path = "/dashboard/overview",
1015
) => {
11-
window.history.pushState({}, "", path);
16+
const configurations = buildConfigurations({ modules, locale: "en" });
17+
1218
return renderHook(() => useNavItems(), {
1319
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>
1727
),
1828
});
1929
};
2030

2131
describe("useNavItems", () => {
22-
beforeEach(() => {
23-
window.history.pushState({}, "", "/dashboard/overview");
32+
afterEach(() => {
33+
cleanup();
2434
});
2535

2636
it("builds nav items for visible modules and resources", async () => {

0 commit comments

Comments
 (0)