|
| 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 | +}); |
0 commit comments