import { expect, test } from '@playwright/test'; import { watch } from './support'; const besidesAuthProbes = (problems: string[]) => problems.filter( (p) => !p.includes('/api/auth/') && !p.includes('/api/users/me') && !p.startsWith('console: Failed to load resource'), ); test('sign-in: the guard asks first, and the form lands on the requested page', async ({ page, }) => { const problems = watch(page); await page.goto('/indicadores/tea'); await expect(page).toHaveURL(/\/login\?next=%2Findicadores%2Ftea$/); await expect(page.getByRole('heading', { name: 'Inicio de sesión' })).toBeVisible(); await page.getByLabel('Usuario', { exact: true }).fill('admin@isssteleon.mx'); await page.getByLabel('Contraseña', { exact: true }).fill('solo-para-pruebas'); await page.getByRole('button', { name: 'Ingresar', exact: true }).click(); await expect(page).toHaveURL(/\/indicadores\/tea$/); await expect(page.getByRole('tab', { name: 'Resumen' })).toBeVisible(); expect(besidesAuthProbes(problems)).toEqual([]); }); test('sign-in: a wrong password shows the error and stays', async ({ page }) => { const problems = watch(page); await page.goto('/login'); await page.getByLabel('Usuario', { exact: true }).fill('admin@isssteleon.mx'); await page.getByLabel('Contraseña', { exact: true }).fill('solo-para-pruebas-pero-mal'); await page.getByRole('button', { name: 'Ingresar', exact: true }).click(); await expect(page.getByRole('alert')).toHaveText('Usuario o contraseña incorrectos.'); await expect(page).toHaveURL(/\/login$/); expect(besidesAuthProbes(problems)).toEqual([]); });