diff options
Diffstat (limited to 'frontend/src/App.test.tsx')
| -rw-r--r-- | frontend/src/App.test.tsx | 21 |
1 files changed, 20 insertions, 1 deletions
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/'); + }); }); }); |
