import { test as base, expect } from '@playwright/test'; // Usuários de teste pré-configurados export const testUsers = { admin: { name: 'Admin Teste', email: 'admin@teste.com', password: '123456', roles: ['admin'], }, teacher: { name: 'Professor Teste', email: 'teacher@teste.com', password: '123456', roles: ['teacher'], }, student: { name: 'Aluno Teste', email: 'student@teste.com', password: '123456', roles: ['student'], }, guardian: { name: 'Responsável Teste', email: 'guardian@teste.com', password: '123456', roles: ['parent'], }, }; // Fixture extendido com login export const test = base.extend({ loginAs: async ({ page }, use) => { const loginAs = async (role) => { const user = testUsers[role]; await page.goto('/auth/login'); await page.getByLabel(/email/i).fill(user.email); await page.getByLabel(/senha/i).fill(user.password); await page.getByRole('button', { name: /entrar|login/i }).click(); // Aguardar redirecionamento await page.waitForURL(/\/(dispatcher|dashboard)/, { timeout: 5000 }); }; await use(loginAs); }, }); // Gerador de dados únicos export const generateUniqueData = () => { const timestamp = Date.now(); const random = Math.floor(Math.random() * 1000); return { name: `Usuário Teste ${timestamp}`, email: `teste${timestamp}@mail.com`, wardName: `Aluno Ward ${timestamp}`, wardEmail: `ward${timestamp}@mail.com`, classTitle: `Turma Teste ${timestamp}`, category: `Categoria ${timestamp}`, }; }; // Helper para aguardar modal export const waitForModal = async (page) => { await page.waitForSelector('.fixed.inset-0', { timeout: 5000 }); }; // Helper para fechar modal export const closeModal = async (page) => { const closeButton = page.locator('.fixed.inset-0').getByRole('button', { name: /✕|fechar|cancelar/i }).first(); if (await closeButton.isVisible()) { await closeButton.click(); } await page.waitForSelector('.fixed.inset-0', { state: 'hidden', timeout: 5000 }).catch(() => {}); }; // Helper para pegar toast/message export const getToastMessage = async (page) => { return page.locator('[data-testid="toast"], .toast, [role="alert"]').first(); }; // Helper para selecionar dias da semana export const selectDays = async (page, days) => { for (const day of days) { await page.getByText(day, { exact: true }).click(); } }; // Helper para selecionar professores/alunos export const selectFirstAvailable = async (page, type) => { const checkbox = page.locator('input[type="checkbox"]').first(); if (await checkbox.isVisible()) { await checkbox.check(); } };