diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-12-07 17:44:14 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-12-07 17:44:14 +0900 |
| commit | ef40cc0f3b1b3013046820b84e8482f1c6a29533 (patch) | |
| tree | e0951e308793684efee8f1369068e7e61ca9994e /src/client/App.test.tsx | |
| parent | 797ef2fcfaa7ac63355c13809a644401a76250bc (diff) | |
| download | kioku-ef40cc0f3b1b3013046820b84e8482f1c6a29533.tar.gz kioku-ef40cc0f3b1b3013046820b84e8482f1c6a29533.tar.zst kioku-ef40cc0f3b1b3013046820b84e8482f1c6a29533.zip | |
feat(client): add deck list page with empty state and list view
Implement HomePage to display user's decks fetched from the API.
Includes loading state, error handling with retry, and empty state
messaging. Also adds comprehensive tests for the deck list page.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/client/App.test.tsx')
| -rw-r--r-- | src/client/App.test.tsx | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/client/App.test.tsx b/src/client/App.test.tsx index 516cbeb..bdc281a 100644 --- a/src/client/App.test.tsx +++ b/src/client/App.test.tsx @@ -15,6 +15,14 @@ vi.mock("./api/client", () => ({ logout: vi.fn(), isAuthenticated: vi.fn(), getTokens: vi.fn(), + getAuthHeader: vi.fn(), + rpc: { + api: { + decks: { + $get: vi.fn(), + }, + }, + }, }, ApiClientError: class ApiClientError extends Error { constructor( @@ -28,6 +36,12 @@ vi.mock("./api/client", () => ({ }, })); +// Helper to create mock responses compatible with Hono's ClientResponse +// biome-ignore lint/suspicious/noExplicitAny: Test helper needs flexible typing +function mockResponse(data: { ok: boolean; status?: number; json: () => Promise<any> }) { + return data as unknown as Awaited<ReturnType<typeof apiClient.rpc.api.decks.$get>>; +} + function renderWithRouter(path: string) { const { hook } = memoryLocation({ path, static: true }); return render( @@ -58,12 +72,21 @@ describe("App routing", () => { refreshToken: "refresh-token", }); vi.mocked(apiClient.isAuthenticated).mockReturnValue(true); + vi.mocked(apiClient.getAuthHeader).mockReturnValue({ + Authorization: "Bearer access-token", + }); + vi.mocked(apiClient.rpc.api.decks.$get).mockResolvedValue( + mockResponse({ + ok: true, + json: async () => ({ decks: [] }), + }), + ); }); it("renders home page at /", () => { renderWithRouter("/"); expect(screen.getByRole("heading", { name: "Kioku" })).toBeDefined(); - expect(screen.getByText("Spaced repetition learning app")).toBeDefined(); + expect(screen.getByRole("heading", { name: "Your Decks" })).toBeDefined(); }); }); |
