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

test.describe('Homepage', () => {
  test('loads and displays platform title', async ({ page }) => {
    await page.goto('/');

    await expect(page.locator('h1')).toContainText('GoodGo Platform');
    await expect(page.locator('p')).toContainText('Vietnam Real Estate Platform');
  });

  test('has correct page title', async ({ page }) => {
    await page.goto('/');

    await expect(page).toHaveTitle(/GoodGo/i);
  });

  test('renders without console errors', async ({ page }) => {
    const errors: string[] = [];
    page.on('console', (msg) => {
      if (msg.type() === 'error') errors.push(msg.text());
    });

    await page.goto('/');
    await page.waitForLoadState('networkidle');

    expect(errors).toHaveLength(0);
  });

  test('is responsive — mobile viewport', async ({ page }) => {
    await page.setViewportSize({ width: 375, height: 667 });
    await page.goto('/');

    const main = page.locator('main');
    await expect(main).toBeVisible();

    const h1 = page.locator('h1');
    await expect(h1).toBeVisible();
  });
});
