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

test.describe('language switch maps page↔page (J5, ROUTING_SPEC §3)', () => {
  test('deep NO case-study URL → EN twin', async ({ page }) => {
    await page.goto('/no/prosjekter/jobtrack/');
    await page.locator('header [role="group"] a', { hasText: 'EN' }).first().click();
    await expect(page).toHaveURL(/\/projects\/jobtrack\/$/);
    await expect(page.locator('html')).toHaveAttribute('lang', 'en-GB');
  });

  test('EN about → NO twin with localised slug', async ({ page }) => {
    await page.goto('/about/');
    await page.locator('header [role="group"] a', { hasText: 'NO' }).first().click();
    await expect(page).toHaveURL(/\/no\/om-meg\/$/);
  });

  test('switch works without JavaScript (links, not scripts)', async ({ browser }) => {
    const context = await browser.newContext({ javaScriptEnabled: false });
    const page = await context.newPage();
    await page.goto('/no/erfaring/');
    await page.locator('header [role="group"] a', { hasText: 'EN' }).first().click();
    await expect(page).toHaveURL(/\/experience\/$/);
    await context.close();
  });
});
