aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/App.test.tsx
blob: 8e3d805399485612e1c76af4ba530da0de18e5c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { render, screen, waitFor } from '@testing-library/react';
import App from './App';
import { describe, it, expect, vi, beforeEach } from 'vitest';

describe('App', () => {
    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('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();
        });
    });
});