Skip to content

Commit 6f6d322

Browse files
committed
test: useBreadcrumb
1 parent 25563d3 commit 6f6d322

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { renderHook } from "@testing-library/react";
2+
import { vi } from "vitest";
3+
import { useBreadcrumb } from "../useBreadcrumb";
4+
import { MemoryRouter } from "react-router-dom";
5+
6+
vi.mock("../usePromptsStore", () => ({
7+
usePromptsStore: vi.fn(() => ({
8+
currentPromptId: "test-chat-id",
9+
prompts: [
10+
{
11+
chat_id: "test-chat-id",
12+
question_answers: [
13+
{
14+
question: { message: "Fake question" },
15+
answer: { message: "Fake answer" },
16+
},
17+
],
18+
},
19+
],
20+
})),
21+
}));
22+
23+
describe("useBreadcrumb", () => {
24+
afterEach(() => {
25+
vi.clearAllMocks();
26+
});
27+
28+
it.each([
29+
{ path: "/certificates/security", expected: "Certificate Security" },
30+
{ path: "/certificates", expected: "Certificate Download" },
31+
{ path: "/help/continue-setup", expected: "Continue Setup" },
32+
{ path: "/help/copilot-setup", expected: "Copilot Setup" },
33+
{ path: "/prompt/", expected: "Fake question" },
34+
{ path: "/", expected: "" },
35+
])("returns breadcrumb for path $path", ({ path, expected }) => {
36+
const wrapper = ({ children }: { children: React.ReactNode }) => (
37+
<MemoryRouter initialEntries={[path]}>{children}</MemoryRouter>
38+
);
39+
40+
const { result } = renderHook(() => useBreadcrumb(), { wrapper });
41+
42+
expect(result.current).toBe(expected);
43+
});
44+
});

src/hooks/__tests__/useSee.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { renderHook, act } from "@testing-library/react";
22
import { vi } from "vitest";
33
import { useSse } from "../useSse";
44

5+
vi.mock("react-router-dom", () => ({
6+
useLocation: vi.fn(() => ({ pathname: "/" })),
7+
}));
8+
59
const mockSendNotification = vi.fn();
610
vi.mock("../useBrowserNotification", () => ({
711
useBrowserNotification: vi.fn(() => {
@@ -40,10 +44,6 @@ let originalEventSource: typeof EventSource;
4044

4145
describe("useSse", () => {
4246
beforeAll(() => {
43-
vi.mock("react-router-dom", () => ({
44-
useLocation: vi.fn(() => ({ pathname: "/" })),
45-
}));
46-
4747
vi.useFakeTimers();
4848
originalEventSource = global.EventSource;
4949
global.EventSource = MockEventSource as unknown as typeof EventSource;

0 commit comments

Comments
 (0)