Files
course-plat/tests/e2e/error-cases.spec.js
2026-08-31 14:10:20 -03:00

244 lines
9.4 KiB
JavaScript

import { test, expect } from '@playwright/test';
test.describe('Casos de Erro Importantes', () => {
test.describe('Acesso Não Autorizado', () => {
test('usuário não logado tenta acessar rota protegida', async ({ page }) => {
await page.goto('/admin/dashboard');
// Deve redirecionar para login
await expect(page).toHaveURL(/\/auth\/login/, { timeout: 5000 });
});
test('usuário com role errado tenta acessar rota admin', async ({ page }) => {
// TODO: Fazer login como aluno
// await page.goto('/auth/login');
// await page.getByLabel(/email/i).fill('[email protected]');
// await page.getByLabel(/senha/i).fill('123456');
// await page.getByRole('button', { name: /entrar/i }).click();
// await page.goto('/admin/dashboard');
// Deve mostrar "Não autorizado" ou redirecionar
// await expect(page.getByText(/não autorizado|not authorized|acesso negado/i)).toBeVisible();
});
test('usuário tenta acessar dashboard de outro role', async ({ page }) => {
// TODO: Fazer login como aluno
// await page.goto('/auth/login');
// await page.getByLabel(/email/i).fill('[email protected]');
// await page.getByLabel(/senha/i).fill('123456');
// await page.getByRole('button', { name: /entrar/i }).click();
// Tentar acessar dashboard de professor
// await page.goto('/dashboard/teacher');
// Deve redirecionar ou mostrar erro
// await expect(page.getByText(/não autorizado|not authorized/i)).toBeVisible();
});
});
test.describe('Sessão Expirada', () => {
test('deve redirecionar para login quando sessão expira', async ({ page }) => {
// TODO: Simular sessão expirada limpando cookies
// await page.goto('/dashboard/student');
// await page.context().clearCookies();
// await page.reload();
// await expect(page).toHaveURL(/\/auth\/login/);
});
});
test.describe('Erros de Validação - Formulários', () => {
test('email inválido no cadastro', async ({ page }) => {
await page.goto('/auth/register');
await page.getByLabel(/email/i).fill('email@invalido');
await page.getByRole('button', { name: /cadastrar/i }).click();
await expect(page.getByText(/email inválido/i)).toBeVisible();
});
test('senha muito curta', async ({ page }) => {
await page.goto('/auth/register');
await page.getByLabel(/senha/i).fill('123');
await page.getByLabel(/confirmar senha/i).fill('123');
await page.getByRole('button', { name: /cadastrar/i }).click();
await expect(page.getByText(/mínimo.*\d+.*caracteres/i)).toBeVisible();
});
test('senhas não conferem', async ({ page }) => {
await page.goto('/auth/register');
await page.getByLabel(/senha/i).fill('123456');
await page.getByLabel(/confirmar senha/i).fill('654321');
await page.getByRole('button', { name: /cadastrar/i }).click();
await expect(page.getByText(/senhas não conferem/i)).toBeVisible();
});
});
test.describe('Erros de Validação - Turma', () => {
test('data de término anterior à data de início', async ({ page }) => {
// TODO: Fazer login como admin
await page.goto('/admin/dashboard/class/add');
await page.getByLabel(/data de início/i).fill('2025-01-10');
await page.getByLabel(/data de término|end date/i).fill('2025-01-01');
await page.getByRole('button', { name: /salvar/i }).click();
await expect(page.getByText(/término não pode ser anterior|data inválida/i)).toBeVisible();
});
test('campos obrigatórios faltando', async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
await page.getByRole('button', { name: /salvar/i }).click();
await expect(page.getByText(/obrigatório|required/i)).toBeVisible();
});
test('sem professores selecionados', async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
await page.getByLabel(/título/i).fill('Turma Sem Professor');
await page.getByLabel(/data de início/i).fill('2025-01-01');
await page.getByLabel(/horário/i).fill('19:00');
await page.getByRole('button', { name: /salvar/i }).click();
await expect(page.getByText(/professor.*obrigatório/i)).toBeVisible();
});
});
test.describe('Erros de Upload', () => {
test('arquivo muito grande', async ({ page }) => {
// TODO: Testar upload de arquivo grande
// await page.goto('/files/upload');
// const fileInput = page.getByRole('input').first();
// await fileInput.setInputFiles('path/to/large-file.pdf');
// await expect(page.getByText(/arquivo muito grande|tamanho máximo/i)).toBeVisible();
});
test('formato não suportado', async ({ page }) => {
// TODO: Testar upload de arquivo não suportado
// await page.goto('/files/upload');
// const fileInput = page.getByRole('input').first();
// await fileInput.setInputFiles('path/to/file.exe');
// await expect(page.getByText(/formato não suportado/i)).toBeVisible();
});
});
test.describe('Provas - Restrições', () => {
test('não pode iniciar prova após prazo', async ({ page }) => {
// TODO: Tentar acessar prova expirada
// await page.goto('/dashboard/student/assignments/expired-id/take');
// await expect(page.getByText(/prazo expirado|não disponível/i)).toBeVisible();
});
test('não pode submeter prova duas vezes', async ({ page }) => {
// TODO: Submeter prova e tentar submeter novamente
// await page.goto('/dashboard/student/assignments/assignment-id/take');
// // Submeter primeira vez
// await page.getByRole('button', { name: /submeter/i }).click();
// await page.getByRole('button', { name: /confirmar/i }).click();
// // Tentar submeter novamente
// await page.goto('/dashboard/student/assignments/assignment-id/take');
// await expect(page.getByText(/já submetida|não disponível/i)).toBeVisible();
});
test('não pode editar após submeter', async ({ page }) => {
// TODO: Acessar prova já submetida
// await page.goto('/dashboard/student/assignments/submitted-id/take');
// As opções devem estar desabilitadas
// const radioButtons = page.locator('input[type="radio"]');
// for (const radio of await radioButtons.all()) {
// await expect(radio).toBeDisabled();
// }
});
});
test.describe('Erros de Conexão', () => {
test('deve mostrar mensagem amigável quando API falha', async ({ page }) => {
// TODO: Simular erro de API
// await page.route('**/api/**', route => route.abort());
// await page.goto('/dashboard/student');
// await expect(page.getByText(/erro de conexão|tente novamente/i)).toBeVisible();
});
});
test.describe('Email Já Existe', () => {
test('cadastro com email duplicado', async ({ page }) => {
await page.goto('/auth/register');
// Email que já existe no banco
await page.getByLabel(/nome completo/i).fill('Usuário Teste');
await page.getByLabel(/email/i).fill('[email protected]'); // Assumindo que existe
await page.getByLabel(/senha/i).fill('123456');
await page.getByLabel(/confirmar senha/i).fill('123456');
await page.getByRole('button', { name: /cadastrar/i }).click();
await expect(page.getByText(/email já cadastrado|já existe/i)).toBeVisible();
});
});
test.describe('Exclusão com Dependências', () => {
test('não pode excluir categoria com arquivos vinculados', async ({ page }) => {
// TODO: Testar exclusão de categoria em uso
// await page.goto('/admin/dashboard/categories/edit/category-id');
// await page.getByRole('button', { name: /excluir/i }).click();
// await expect(page.getByText(/categoria em uso|possui arquivos/i)).toBeVisible();
});
test('não pode excluir template com tentativas', async ({ page }) => {
// TODO: Testar exclusão de template usado
// await page.goto('/admin/dashboard/exam-templates/edit/template-id');
// await page.getByRole('button', { name: /excluir/i }).click();
// await expect(page.getByText(/possui tentativas|em uso/i)).toBeVisible();
});
});
test.describe('Ward - Email Duplicado', () => {
test('não pode cadastrar ward com email existente', async ({ page }) => {
// TODO: Fazer login como guardian
// await page.goto('/dashboard/guardian/register-student');
// await page.getByLabel(/nome do aluno/i).fill('Aluno Teste');
// await page.getByLabel(/email/i).fill('[email protected]'); // Já existe
// await page.getByLabel(/senha/i).fill('123456');
// await page.getByLabel(/confirmar senha/i).fill('123456');
// await page.getByRole('button', { name: /cadastrar/i }).click();
// await expect(page.getByText(/email já cadastrado/i)).toBeVisible();
});
});
test.describe('Pagamentos - Confirmação', () => {
test('deve confirmar antes de excluir obrigação', async ({ page }) => {
// TODO: Testar exclusão com confirmação
// await page.goto('/admin/dashboard/payments');
// const deleteButton = page.getByRole('button', { name: /excluir/i }).first();
// await deleteButton.click();
// await expect(page.getByText(/tem certeza|deseja excluir/i)).toBeVisible();
// await expect(page.getByRole('button', { name: /confirmar/i })).toBeVisible();
// await expect(page.getByRole('button', { name: /cancelar/i })).toBeVisible();
});
});
});