Files
course-plat/tests/e2e/admin/classes.spec.js
T
2026-08-31 14:10:20 -03:00

196 lines
7.1 KiB
JavaScript

import { test, expect } from '@playwright/test';
test.describe('Admin - Turmas (Classes)', () => {
// TODO: Fazer login como admin antes de cada teste
// test.beforeEach(async ({ page }) => {
// 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.waitForURL(/\/admin\/dashboard/);
// });
test.describe('Lista de Turmas', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/admin/dashboard/class');
});
test('deve mostrar lista de turmas', async ({ page }) => {
await expect(page.getByText(/turmas|classes/i)).toBeVisible();
});
test('deve ter botão de adicionar nova turma', async ({ page }) => {
await expect(page.getByRole('link', { name: /adicionar|nova|criar/i })).toBeVisible();
});
test('deve ter busca funcionando', async ({ page }) => {
const searchInput = page.getByPlaceholder(/buscar|pesquisar|search/i);
if (await searchInput.isVisible()) {
await searchInput.fill('Inglês');
await page.waitForTimeout(500);
// Verificar se filtrou
}
});
});
test.describe('Criar Nova Turma', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
});
test('deve mostrar formulário de criação', async ({ page }) => {
await expect(page.getByLabel(/tipo de classe|class type/i)).toBeVisible();
await expect(page.getByLabel(/título/i)).toBeVisible();
await expect(page.getByLabel(/data de início|start date/i)).toBeVisible();
await expect(page.getByLabel(/horário|time/i)).toBeVisible();
await expect(page.getByText(/dias da semana/i)).toBeVisible();
await expect(page.getByText(/professores/i)).toBeVisible();
});
test('deve validar campos obrigatórios', async ({ page }) => {
await page.getByRole('button', { name: /salvar|criar/i }).click();
await expect(page.getByText(/obrigatório|required/i)).toBeVisible();
});
test('deve validar data de término posterior a data de início', async ({ page }) => {
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|criar/i }).click();
await expect(page.getByText(/término não pode ser anterior|data inválida/i)).toBeVisible();
});
test('deve criar turma com dados válidos', async ({ page }) => {
const timestamp = Date.now();
// Selecionar tipo de classe
await page.getByLabel(/tipo de classe/i).selectOption({ index: 0 });
// Preencher título
await page.getByLabel(/título/i).fill(`Turma Teste ${timestamp}`);
// Data de início
await page.getByLabel(/data de início/i).fill('2025-01-01');
// Horário
await page.getByLabel(/horário/i).fill('19:00');
// Selecionar professores
const teacherCheckbox = page.locator('input[type="checkbox"]').first();
if (await teacherCheckbox.isVisible()) {
await teacherCheckbox.check();
}
// Selecionar dias da semana
await page.getByText(/seg/i).click();
// Salvar
await page.getByRole('button', { name: /salvar|criar/i }).click();
// Deve redirecionar para lista
await expect(page).toHaveURL(/\/admin\/dashboard\/class/, { timeout: 15000 });
});
});
test.describe('Editar Turma Existente', () => {
test('deve carregar dados da turma', async ({ page }) => {
// TODO: Usar ID de turma de teste
await page.goto('/admin/dashboard/class/edit/6975e7cfb41e291a99a79ece');
await expect(page.getByLabel(/título/i)).not.toBeEmpty();
});
test('deve permitir modificar professores', async ({ page }) => {
await page.goto('/admin/dashboard/class/edit/6975e7cfb41e291a99a79ece');
// Desmarcar professor selecionado
const checkedTeacher = page.locator('input[type="checkbox"]:checked').first();
if (await checkedTeacher.isVisible()) {
await checkedTeacher.uncheck();
}
});
test('deve permitir adicionar alunos via select', async ({ page }) => {
await page.goto('/admin/dashboard/class/edit/6975e7cfb41e291a99a79ece');
const studentSelect = page.getByRole('combobox').filter({ hasText: /adicionar aluno/i });
if (await studentSelect.isVisible()) {
// Selecionar primeiro aluno disponível
await studentSelect.selectOption({ index: 1 });
// Verificar se apareceu tag do aluno
await expect(page.locator('.student-tag')).toBeVisible();
}
});
test('deve permitir remover aluno da seleção', async ({ page }) => {
await page.goto('/admin/dashboard/class/edit/6975e7cfb41e291a99a79ece');
// Se há tags de alunos, tentar remover
const studentTag = page.locator('.student-tag').first();
if (await studentTag.isVisible()) {
await studentTag.getByRole('button').click();
// Verificar se foi removido
}
});
test('deve salvar alterações com sucesso', async ({ page }) => {
await page.goto('/admin/dashboard/class/edit/6975e7cfb41e291a99a79ece');
const originalTitle = await page.getByLabel(/título/i).inputValue();
await page.getByLabel(/título/i).fill(`${originalTitle} (editado)`);
await page.getByRole('button', { name: /salvar|atualizar/i }).click();
await expect(page).toHaveURL(/\/admin\/dashboard\/class/, { timeout: 15000 });
});
});
test.describe('Dias da Semana - Checkbox', () => {
test('deve mostrar todos os dias', async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
const days = ['Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab', 'Dom'];
for (const day of days) {
await expect(page.getByText(day, { exact: true })).toBeVisible();
}
});
test('deve permitir selecionar múltiplos dias', async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
await page.getByText('Seg').click();
await page.getByText('Qua').click();
await page.getByText('Sex').click();
// Verificar se estão marcados
const segCheckbox = page.getByText('Seg').locator('input[type="checkbox"]');
await expect(segCheckbox).toBeChecked();
});
});
test.describe('Professores - Checkbox', () => {
test('deve mostrar lista de professores disponíveis', async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
await expect(page.getByText(/professores/i)).toBeVisible();
});
test('deve permitir selecionar múltiplos professores', async ({ page }) => {
await page.goto('/admin/dashboard/class/add');
const checkboxes = page.locator('input[type="checkbox"]');
const count = await checkboxes.count();
if (count >= 2) {
await checkboxes.nth(0).check();
await checkboxes.nth(1).check();
await expect(checkboxes.nth(0)).toBeChecked();
await expect(checkboxes.nth(1)).toBeChecked();
}
});
});
});