From 42f1b4de384bcbbdab3b80d8e5cc53b36fcffd50 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Thu, 12 Feb 2026 21:50:56 -0800 Subject: Implement frontend login logic with >90% coverage --- frontend/src/App.test.tsx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'frontend/src/App.test.tsx') 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(); - 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(); + + await waitFor(() => { + expect(screen.getByText(/dashboard/i)).toBeInTheDocument(); + }); }); }); -- cgit v1.2.3