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

const authFile = path.join(__dirname, '../playwright/.auth/user.json');

setup('Manually authenticate with Microsoft Entra ID', async ({ page }) => {
  // Give provision of 2 minutes to complete SSO and MFA manually
  setup.setTimeout(120_000);

  // 1. Open your Angular app
  await page.goto('/');

  // 2. Click Sign-in button (remove this line if you want to click it yourself)
  await page.getByRole('button', { name: /sign in|login/i }).click();

  // 3. Wait until logging into Microsoft Entra ID is completed and redirected back
  // Replace the locator below with an element that only appears once logged in
  // (e.g. Logout button or user profile)
  await expect(page.getByRole(
    'button', { name: /logout|sign out/i })).toBeVisible({
    timeout: 120_000,
  });

  // 4. Save the authenticated MSAL session to disk
  await page.context().storageState({ path: authFile });
});

