|
1 | 1 | import { describe, expect, it, vi } from "vite-plus/test"; |
2 | 2 | import { createPanelRegistry } from "./panelRegistry"; |
3 | 3 |
|
| 4 | +const metadata = { |
| 5 | + title: "Diff", |
| 6 | + icon: () => null, |
| 7 | + launcherKey: "D", |
| 8 | + unavailableHint: "Unavailable.", |
| 9 | + unavailableReason: "Unavailable here.", |
| 10 | +}; |
| 11 | + |
4 | 12 | describe("panel registration", () => { |
5 | 13 | it("rejects duplicate ids without loading either panel", () => { |
6 | 14 | const load = vi.fn(); |
7 | | - const definition = { id: "diff", load } as const; |
| 15 | + const definition = { ...metadata, id: "diff", load } as const; |
8 | 16 | expect(() => createPanelRegistry([definition, definition])).toThrow("Duplicate panel id: diff"); |
9 | 17 | expect(load).not.toHaveBeenCalled(); |
10 | 18 | }); |
11 | 19 | it("retains lazy component identity without loading on lookup", () => { |
12 | 20 | const load = vi.fn(); |
13 | | - const registry = createPanelRegistry<Record<string, never>, string>([{ id: "diff", load }]); |
| 21 | + const registry = createPanelRegistry([{ ...metadata, id: "diff", load }]); |
14 | 22 | expect(registry.get("diff")?.Component).toBe(registry.get("diff")?.Component); |
15 | | - expect(registry.get("missing")).toBeUndefined(); |
| 23 | + expect(() => { |
| 24 | + // @ts-expect-error Unknown ids are refused at compile time and at runtime. |
| 25 | + registry.get("missing"); |
| 26 | + }).toThrow("Unknown panel id: missing"); |
16 | 27 | expect(load).not.toHaveBeenCalled(); |
17 | 28 | }); |
18 | 29 | }); |
0 commit comments