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

const envs = [
  { name: 'legado', port: 3700 },
  { name: 'hotfix-148213', port: 3200 },
  { name: 'edge-cases', port: 3500 },
]

for (const env of envs) {
  test(`${env.name}: login e home`, async ({ page }) => {
    await page.goto(`http://localhost:${env.port}/login`)
    await page.waitForLoadState('networkidle')
    const emailInput = page.locator('input[type="email"]')
    if (await emailInput.isVisible({ timeout: 5000 }).catch(() => false)) {
      await emailInput.fill('dcalixto.actdigital@rededor.com.br')
      await page.locator('button:has-text("Entrar")').click()
      await page.waitForLoadState('networkidle')
      await page.waitForTimeout(5000)
      await page.screenshot({ path: `/tmp/qa-final/${env.name}-home.png`, fullPage: true })
      console.log(`${env.name} URL: ${page.url()}`)
    } else {
      await page.screenshot({ path: `/tmp/qa-final/${env.name}-no-devlogin.png` })
      console.log(`${env.name}: NO DEV LOGIN`)
    }
  })
}
