import { test as setup } from '@playwright/test'
import { mkdirSync } from 'node:fs'
import { fileURLToPath } from 'url'
import path from 'path'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const authFile = path.join(__dirname, '.auth/user.json')

setup('autenticacion', async ({ page }) => {
    await page.goto('/login')
    await page.locator('input[id^="username"]').fill('demo')
    await page.locator('input[id^="password"]').fill('demo123')
    await page.click('button[type="submit"]')
    await page.waitForURL(/dashboard/, { timeout: 60000 })
    mkdirSync(path.dirname(authFile), { recursive: true })
    await page.context().storageState({ path: authFile })
})