aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/App.test.tsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-12-06 18:36:10 +0900
committernsfisis <nsfisis@gmail.com>2025-12-06 18:36:10 +0900
commita2569837aa07ef48f27884fc2869b5be47087a4e (patch)
tree5f2236441d751f6a3a7d0865c644e9a8c3259960 /src/client/App.test.tsx
parent3923eb2f86c304bbd90c4eae9a338f7bc21c9e90 (diff)
downloadkioku-a2569837aa07ef48f27884fc2869b5be47087a4e.tar.gz
kioku-a2569837aa07ef48f27884fc2869b5be47087a4e.tar.zst
kioku-a2569837aa07ef48f27884fc2869b5be47087a4e.zip
feat(client): implement Register page with form validation
Add functional registration form with: - Username and password fields with confirm password - Client-side validation (password match, minimum length) - Error display for API failures - Redirect to home when already authenticated - Loading state during submission 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/client/App.test.tsx')
-rw-r--r--src/client/App.test.tsx35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/client/App.test.tsx b/src/client/App.test.tsx
index cd448bf..4a7af14 100644
--- a/src/client/App.test.tsx
+++ b/src/client/App.test.tsx
@@ -2,22 +2,53 @@
* @vitest-environment jsdom
*/
import { cleanup, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { Router } from "wouter";
import { memoryLocation } from "wouter/memory-location";
+import { apiClient } from "./api/client";
import { App } from "./App";
+import { AuthProvider } from "./stores";
+
+vi.mock("./api/client", () => ({
+ apiClient: {
+ login: vi.fn(),
+ register: vi.fn(),
+ logout: vi.fn(),
+ isAuthenticated: vi.fn(),
+ getTokens: vi.fn(),
+ },
+ ApiClientError: class ApiClientError extends Error {
+ constructor(
+ message: string,
+ public status: number,
+ public code?: string,
+ ) {
+ super(message);
+ this.name = "ApiClientError";
+ }
+ },
+}));
function renderWithRouter(path: string) {
const { hook } = memoryLocation({ path, static: true });
return render(
<Router hook={hook}>
- <App />
+ <AuthProvider>
+ <App />
+ </AuthProvider>
</Router>,
);
}
+beforeEach(() => {
+ vi.clearAllMocks();
+ vi.mocked(apiClient.getTokens).mockReturnValue(null);
+ vi.mocked(apiClient.isAuthenticated).mockReturnValue(false);
+});
+
afterEach(() => {
cleanup();
+ vi.restoreAllMocks();
});
describe("App routing", () => {