/**
 * Cross-browser smoke matrix. Tagged `@smoke` so playwright.config.ts can run
 * it across the mobile UA projects (chromium-pixel7, samsung-internet,
 * edge-android, chrome-ios, webkit-iphone, firefox-android, etc.).
 *
 * Asserts the bare-minimum end-to-end: a guest can join, see the feed, and
 * sign out. If this fails on a specific UA project, the engine has a real
 * divergence and we need either a workaround or a `@known-issue` tag.
 */
import { test, expect } from '../../fixtures/test';
import { JoinPage, AccountPage } from '../../page-objects';

test.describe('@smoke cross-UA happy path', () => {
  test('join → feed → leave', async ({ page }, testInfo) => {
    const join = new JoinPage(page);
    await join.goto();

    // Make the name unique per UA project so concurrent runs (different
    // projects against the same DB) don't collide on the case-insensitive
    // UNIQUE constraint.
    const name = `Smoke_${testInfo.project.name}_${Date.now().toString(36)}`;
    const { pin } = await join.joinAs(name);
    expect(pin).toMatch(/^\d{4}$/);

    await join.continueToFeed();
    await expect(page).toHaveURL(/\/feed$/);

    // Bottom nav must be visible and tappable
    await expect(page.getByRole('link', { name: 'Galerie' })).toBeVisible();
    await expect(page.getByRole('button', { name: 'Hochladen' })).toBeVisible();
    await expect(page.getByRole('link', { name: 'Konto' })).toBeVisible();

    // Leave the event — proves the JWT round-trip works
    const account = new AccountPage(page);
    await account.goto();
    await account.leaveEvent();
    await expect(page).toHaveURL(/\/join$/);
  });
});
