From e31b68197ec16d2805ec14c2bf532a03f4739e92 Mon Sep 17 00:00:00 2001
From: Adam Mathes <adam@adammathes.com>
Date: Fri, 13 Feb 2026 07:01:40 -0800
Subject: Implement Frontend Logout with tests

---
 frontend/src/App.test.tsx | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

(limited to 'frontend/src/App.test.tsx')

diff --git a/frontend/src/App.test.tsx b/frontend/src/App.test.tsx
index 37a7fab..5614d7d 100644
--- a/frontend/src/App.test.tsx
+++ b/frontend/src/App.test.tsx
@@ -1,6 +1,6 @@
 import React from 'react';
 import '@testing-library/jest-dom';
-import { render, screen, waitFor } from '@testing-library/react';
+import { render, screen, waitFor, fireEvent } from '@testing-library/react';
 import App from './App';
 import { describe, it, expect, vi, beforeEach } from 'vitest';
 
@@ -30,5 +30,24 @@ describe('App', () => {
         await waitFor(() => {
             expect(screen.getByText(/neko reader/i)).toBeInTheDocument();
         });
+
+        // Test Logout
+        const logoutBtn = screen.getByText(/logout/i);
+        expect(logoutBtn).toBeInTheDocument();
+
+        // Mock window.location
+        Object.defineProperty(window, 'location', {
+            configurable: true,
+            value: { href: '' },
+        });
+
+        (global.fetch as any).mockResolvedValueOnce({ ok: true });
+
+        fireEvent.click(logoutBtn);
+
+        await waitFor(() => {
+            expect(global.fetch).toHaveBeenCalledWith('/api/logout', expect.objectContaining({ method: 'POST' }));
+            expect(window.location.href).toBe('/login/');
+        });
     });
 });
-- 
cgit v1.2.3

