import { test, expect } from '@playwright/test';

test.describe('us.elect.info', () => {
  test('homepage loads with title', async ({ page }) => {
    await page.goto('/');
    await expect(page).toHaveTitle(/US Elections/i);
    await page.screenshot({ path: '/app/test-output/us-homepage.png' });
  });

  test('entity stats display', async ({ page }) => {
    await page.goto('/');
    // Wait for stats to load from OpenSearch
    await expect(page.locator('#count-candidates')).not.toHaveText('-');
  });

  test('search input works', async ({ page }) => {
    await page.goto('/');
    const searchInput = page.locator('#query');
    await expect(searchInput).toBeVisible();
    await searchInput.fill('Biden');
    await searchInput.press('Enter');
    // Results section should appear
    await expect(page.locator('#results')).toHaveClass(/active/);
  });

  test('CSS assets load', async ({ page }) => {
    const response = await page.goto('/css/style.css');
    expect(response?.status()).toBe(200);
  });

  test('JS assets load', async ({ page }) => {
    const response = await page.goto('/js/entity-search.js');
    expect(response?.status()).toBe(200);
  });

  test('404 page works', async ({ page }) => {
    const response = await page.goto('/nonexistent-page');
    expect(response?.status()).toBe(404);
  });
});
