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

test.describe('Authenticated tests', () => {
  // These tests will use the default auth state from global.setup.ts

  test('Has title Suno', async ({ page }) => {
    await page.goto('/');
    await expect(page).toHaveTitle(/Suno/);
  });

  test('Has visible Suno Logo', async ({ page }) => {
    await page.goto('/');
    await expect(page.getByRole('link', { name: 'Suno Logo' })).toBeVisible();
  });
});

test.describe('Unauthenticated tests', () => {
  // Override storage state for these tests to run without authentication
  test.use({ storageState: { cookies: [], origins: [] } });

  test('Preserves URL parameters when navigating to /home', async ({
    page,
  }) => {
    await page.goto('/home?hello=world');
    await expect(page).toHaveURL(/.*\/home\?hello=world/);
  });

  test('Auto-scrolls to pricing section and preserves hash fragment', async ({
    page,
  }) => {
    await page.goto('/home#pricing');

    // Verify hash is preserved in URL
    await expect(page).toHaveURL(/.*\/home#pricing$/);

    // Wait for the pricing section to be visible and auto-scroll to complete
    const pricingSection = page.locator('#pricing');
    await expect(pricingSection).toBeVisible({ timeout: 10000 });
    await page.waitForTimeout(1000);
    await expect(pricingSection).toBeInViewport();
  });
});
