import { defineConfig, devices } from '@playwright/test'

/**
 * Конфиг Playwright Test для UI-deep тестирования стейджа.
 * Запуск: pnpm exec playwright test (или `npx playwright test`).
 *
 * Env:
 *   E2E_ADMIN_URL — базовый URL (default https://test.admin.food-market.kz)
 *   CI=1 — включает workers=1, full retry off
 */
const baseURL = process.env.E2E_ADMIN_URL ?? 'https://test.admin.food-market.kz'

export default defineConfig({
  testDir: './scenarios',
  testMatch: /stage-ui-.*\.spec\.ts$/,
  fullyParallel: false, // тесты делят tenant-данные через API, серий безопаснее
  forbidOnly: !!process.env.CI,
  retries: 0,
  workers: 1,
  reporter: [
    ['list'],
    ['html', { outputFolder: 'reports/playwright-html', open: 'never' }],
  ],
  use: {
    baseURL,
    headless: true,
    ignoreHTTPSErrors: true,
    viewport: { width: 1280, height: 800 },
    actionTimeout: 15_000,
    navigationTimeout: 30_000,
    screenshot: 'only-on-failure',
    trace: 'retain-on-failure',
    video: 'retain-on-failure',
  },
  outputDir: 'reports/playwright-artifacts',
  projects: [
    { name: 'chromium-desktop', use: { ...devices['Desktop Chrome'], viewport: { width: 1280, height: 800 } } },
  ],
})
