aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/App.test.tsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-12-06 18:55:57 +0900
committernsfisis <nsfisis@gmail.com>2025-12-06 18:55:57 +0900
commitf655585cc81ab4af5d27cebb1fa9390e93e0a4bf (patch)
treea7e6bbcb9816f85ec8dff7a8c6a8ac5dbcb7c395 /src/client/App.test.tsx
parent516e26f5ca72f2db724fd68584663c0732c77f77 (diff)
downloadkioku-f655585cc81ab4af5d27cebb1fa9390e93e0a4bf.tar.gz
kioku-f655585cc81ab4af5d27cebb1fa9390e93e0a4bf.tar.zst
kioku-f655585cc81ab4af5d27cebb1fa9390e93e0a4bf.zip
feat(client): add protected route handling with login redirect
Unauthenticated users accessing protected pages (like HomePage) are now redirected to the login page. Includes ProtectedRoute component with loading state support. 🤖 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.tsx31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/client/App.test.tsx b/src/client/App.test.tsx
index f4e3541..321f073 100644
--- a/src/client/App.test.tsx
+++ b/src/client/App.test.tsx
@@ -52,10 +52,33 @@ afterEach(() => {
});
describe("App routing", () => {
- it("renders home page at /", () => {
- renderWithRouter("/");
- expect(screen.getByRole("heading", { name: "Kioku" })).toBeDefined();
- expect(screen.getByText("Spaced repetition learning app")).toBeDefined();
+ describe("when authenticated", () => {
+ beforeEach(() => {
+ vi.mocked(apiClient.getTokens).mockReturnValue({
+ accessToken: "access-token",
+ refreshToken: "refresh-token",
+ });
+ vi.mocked(apiClient.isAuthenticated).mockReturnValue(true);
+ });
+
+ it("renders home page at /", () => {
+ renderWithRouter("/");
+ expect(screen.getByRole("heading", { name: "Kioku" })).toBeDefined();
+ expect(screen.getByText("Spaced repetition learning app")).toBeDefined();
+ });
+ });
+
+ describe("when not authenticated", () => {
+ beforeEach(() => {
+ vi.mocked(apiClient.getTokens).mockReturnValue(null);
+ vi.mocked(apiClient.isAuthenticated).mockReturnValue(false);
+ });
+
+ it("redirects to login when accessing / without authentication", () => {
+ renderWithRouter("/");
+ // Should not render home page content
+ expect(screen.queryByRole("heading", { name: "Kioku" })).toBeNull();
+ });
});
it("renders login page at /login", () => {