fix(sprint-6/etapa-3): localStorage key en ProfileSheet + eliminar setTimeout(350) + specs E2E de auth
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
This commit is contained in:
56
tests/e2e/auth-real.spec.ts
Normal file
56
tests/e2e/auth-real.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Sprint 6 Etapa 3 Parte C — Validación de que el auth E2E funciona realmente
|
||||
* (no solo que el storageState se carga, sino que Supabase devuelve datos reales
|
||||
* del usuario autenticado).
|
||||
*
|
||||
* No existe data-testid="app-header-user-avatar" en AppHeader.tsx — el trigger del
|
||||
* dropdown es un <button title={user.name}> dentro del <header> (mismo selector que
|
||||
* ya usa tests/e2e/sprint-4-smoke.spec.ts: 'header button[title]').
|
||||
*/
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { readFileSync, existsSync } from 'fs'
|
||||
import { resolve } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
test.use({ storageState: 'tests/e2e/setup/auth-state.json' })
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
||||
const ROOT = resolve(__dirname, '../..')
|
||||
|
||||
function loadEnvFile(filename: string): Record<string, string> {
|
||||
const path = resolve(ROOT, filename)
|
||||
if (!existsSync(path)) return {}
|
||||
const out: Record<string, string> = {}
|
||||
for (const line of readFileSync(path, 'utf-8').split('\n')) {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed || trimmed.startsWith('#')) continue
|
||||
const idx = trimmed.indexOf('=')
|
||||
if (idx === -1) continue
|
||||
out[trimmed.slice(0, idx)] = trimmed.slice(idx + 1)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
const testEnv = loadEnvFile('.env.test')
|
||||
const TEST_USER_EMAIL = testEnv.TEST_USER_EMAIL
|
||||
|
||||
test('auth E2E: Supabase devuelve datos reales del usuario autenticado', async ({ page }) => {
|
||||
test.skip(!TEST_USER_EMAIL, 'TEST_USER_EMAIL no configurada en .env.test — ver .env.example')
|
||||
|
||||
await page.goto('/')
|
||||
|
||||
// Esperar a que AppHeader muestre el trigger del dropdown de usuario
|
||||
// (confirma que AuthContext cargó la sesión y el avatar renderiza con user.name real)
|
||||
const avatarTrigger = page.locator('header button[title]').first()
|
||||
await expect(avatarTrigger).toBeVisible({ timeout: 10_000 })
|
||||
|
||||
// El título del botón es el nombre real del usuario — no debe estar vacío
|
||||
const titleAttr = await avatarTrigger.getAttribute('title')
|
||||
expect(titleAttr, 'el trigger debe tener el nombre real del usuario, no vacío').toBeTruthy()
|
||||
|
||||
// Abrir el dropdown y confirmar que el email del usuario de test aparece —
|
||||
// esto requiere que AuthContext haya construido el AuthUser real desde la sesión
|
||||
// de Supabase (no un mock ni un valor placeholder).
|
||||
await avatarTrigger.click()
|
||||
await expect(page.getByText(TEST_USER_EMAIL)).toBeVisible({ timeout: 5_000 })
|
||||
})
|
||||
Reference in New Issue
Block a user