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

import { clickEverythingOnPage } from '../../helpers/click-everything';
import { login } from '../smoke/helpers';

const PORTAL_PAGES = ['/portal/yachts', '/portal/memberships', '/portal/my-tenancies'];

test.describe('exhaustive: client portal', () => {
  test.beforeEach(async ({ page }) => {
    // Portal sessions reuse the same auth; the portal layout itself routes
    // by client-membership rather than role.
    await login(page, 'super_admin');
  });

  for (const path of PORTAL_PAGES) {
    test(`${path} renders and every visible button is clickable`, async ({ page }) => {
      await page.goto(path);
      await page.waitForLoadState('networkidle');

      // Some portal pages redirect to login if the user has no client linkage.
      // Skip rather than fail in that case - portal coverage requires its own
      // seeded portal fixture.
      if (page.url().includes('/login')) {
        test.skip(true, 'portal page redirected to login (no portal user seeded)');
        return;
      }

      const result = await clickEverythingOnPage(page);
      expect(result.errors, JSON.stringify(result.errors, null, 2)).toEqual([]);
    });
  }
});
