import { expect, test } from '@playwright/test'; /** * Homepage flows: page shell, article feed, and client-side navigation * between pages via React Router links (no full page reloads). */ test.describe('home page', () => { test('renders the page shell, branding and navigation', async ({ page }) => { await page.goto('/'); await expect(page).toHaveTitle(/newzy/i); // Layout structure: header, main content, footer. await expect(page.getByRole('banner')).toBeVisible(); await expect(page.getByRole('main')).toBeVisible(); await expect(page.getByRole('contentinfo')).toBeVisible(); // Brand links to home. await expect(page.getByRole('link', { name: 'newzy' })).toHaveAttribute('href', '/'); // Primary navigation uses React Router links. const nav = page.getByRole('navigation', { name: 'Main navigation' }); await expect(nav.getByRole('link', { name: /home/i })).toHaveAttribute('href', '/'); await expect(nav.getByRole('link', { name: /articles/i })).toHaveAttribute( 'href', '/articles', ); await expect(nav.getByRole('link', { name: /categories/i })).toHaveAttribute( 'href', '/categories', ); }); test('renders the featured article and article grid with data', async ({ page }) => { await page.goto('/'); // Hero with the featured article. const featured = page.getByRole('region', { name: 'Featured article' }); await expect(featured).toBeVisible(); await expect(featured.getByRole('heading', { level: 1 })).toContainText( 'Inside the new wave of open-source language models', ); // Article grid rendered from data (sample feed while the backend article // endpoints are not available yet). const cards = page.getByTestId('article-card'); await expect(cards.first()).toBeVisible(); expect(await cards.count()).toBeGreaterThanOrEqual(5); await expect(page.getByTestId('sample-data-note')).toBeVisible(); }); test('navigates between pages via router links without a full page reload', async ({ page, }) => { const loadEvents: string[] = []; page.on('load', () => loadEvents.push(page.url())); await page.goto('/'); const nav = page.getByRole('navigation', { name: 'Main navigation' }); // Home -> Articles await nav.getByRole('link', { name: /articles/i }).click(); await expect(page).toHaveURL(/\/articles$/); await expect( page.getByRole('heading', { level: 1, name: 'Articles' }), ).toBeVisible(); // Articles -> Categories await nav.getByRole('link', { name: /categories/i }).click(); await expect(page).toHaveURL(/\/categories$/); await expect( page.getByRole('heading', { level: 1, name: 'Categories' }), ).toBeVisible(); // Categories -> Home await nav.getByRole('link', { name: /home/i }).click(); await expect(page).toHaveURL(/\/$/); // Only the initial goto fired a document load — the rest was // client-side React Router navigation. expect(loadEvents).toHaveLength(1); }); test('opens an article detail placeholder from a card', async ({ page }) => { await page.goto('/'); const firstCard = page.getByTestId('article-card').first(); await firstCard.getByRole('link').first().click(); await expect(page).toHaveURL(/\/articles\/\d+$/); await expect(page.getByRole('heading', { level: 1 })).toContainText('Article #'); }); test('has no unexpected console errors or uncaught page errors', async ({ page }) => { const consoleErrors: string[] = []; const pageErrors: string[] = []; page.on('console', (message) => { if (message.type() === 'error') consoleErrors.push(message.text()); }); page.on('pageerror', (error) => pageErrors.push(error.message)); await page.goto('/'); await expect(page.getByTestId('article-card').first()).toBeVisible(); // Uncaught exceptions are never acceptable. expect(pageErrors).toEqual([]); // Expected noise: the article feed fetch 404s/502s when the backend // article endpoints are unavailable (the UI falls back to sample data). const unexpected = consoleErrors.filter( (text) => !/failed to load resource|net::err/i.test(text), ); expect(unexpected).toEqual([]); }); });