diff options
Diffstat (limited to 'frontend/src/App.test.tsx')
| -rw-r--r-- | frontend/src/App.test.tsx | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/frontend/src/App.test.tsx b/frontend/src/App.test.tsx index f1572a7..8e3d805 100644 --- a/frontend/src/App.test.tsx +++ b/frontend/src/App.test.tsx @@ -1,10 +1,32 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import App from './App'; -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; describe('App', () => { - it('renders heading', () => { + beforeEach(() => { + vi.resetAllMocks(); + global.fetch = vi.fn(); + }); + + it('renders login on initial load (unauthenticated)', async () => { + (global.fetch as any).mockResolvedValueOnce({ + ok: false, + }); + window.history.pushState({}, 'Test page', '/v2/login'); render(<App />); - expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument(); // Adjust based on actual App content + expect(screen.getByRole('button', { name: /login/i })).toBeInTheDocument(); + }); + + it('renders dashboard when authenticated', async () => { + (global.fetch as any).mockResolvedValueOnce({ + ok: true, + }); + + window.history.pushState({}, 'Test page', '/v2/'); + render(<App />); + + await waitFor(() => { + expect(screen.getByText(/dashboard/i)).toBeInTheDocument(); + }); }); }); |
