| 6 | import { messages } from "../lib/i18n"; |
| 7 | |
| 8 | function mockProjectsFetch(extra?: (url: string, init?: RequestInit) => Response | undefined) { |
| 9 | const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => { |
| 10 | const url = String(input); |
| 11 | const overridden = extra?.(url, init); |
| 12 | if (overridden) return overridden; |
| 13 | if (url === "/rpc") { |
| 14 | return new Response(JSON.stringify({ |
| 15 | result: { content: [{ text: JSON.stringify({ projects: [] }) }] }, |
| 16 | }), { status: 200, headers: { "Content-Type": "application/json" } }); |
| 17 | } |
| 18 | if (url.startsWith("/api/ui-config")) { |
| 19 | return new Response(JSON.stringify({ lang: "en" }), { |
| 20 | status: 200, |
| 21 | headers: { "Content-Type": "application/json" }, |
| 22 | }); |
| 23 | } |
| 24 | if (url.startsWith("/api/browse")) { |
| 25 | return new Response(JSON.stringify({ |
| 26 | path: "/home/dev", |
| 27 | parent: "/home", |
| 28 | dirs: ["alpha", "beta"], |
| 29 | roots: ["/", "D:/"], |
| 30 | }), { status: 200, headers: { "Content-Type": "application/json" } }); |
| 31 | } |
| 32 | if (url === "/api/index") { |
| 33 | return new Response(JSON.stringify({ status: "indexing", slot: 0 }), { |
| 34 | status: 202, |
| 35 | headers: { "Content-Type": "application/json" }, |
| 36 | }); |
| 37 | } |
| 38 | return new Response("{}", { status: 200 }); |
| 39 | }); |
| 40 | vi.stubGlobal("fetch", fetchMock); |
| 41 | return fetchMock; |
| 42 | } |
| 43 | |
| 44 | describe("StatsTab index modal", () => { |
| 45 | afterEach(() => { |