262 lines
10 KiB
JavaScript
262 lines
10 KiB
JavaScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Admin - Atribuição de Provas (Assignments)', () => {
|
|
// TODO: Fazer login como admin
|
|
// 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(/\/dispatcher/);
|
|
// await page.getByRole('button', { name: /admin/i }).click();
|
|
// });
|
|
|
|
test.describe('Lista de Atribuições', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments');
|
|
});
|
|
|
|
test('deve mostrar lista de atribuições', async ({ page }) => {
|
|
await expect(page.getByText(/atribuições|assignments/i)).toBeVisible();
|
|
});
|
|
|
|
test('deve ter botão de criar atribuição', async ({ page }) => {
|
|
await expect(page.getByRole('button', { name: /nova|criar/i })).toBeVisible();
|
|
});
|
|
|
|
test('deve mostrar turma, template e datas', async ({ page }) => {
|
|
const assignmentRow = page.locator('tr').nth(1);
|
|
if (await assignmentRow.isVisible()) {
|
|
await expect(assignmentRow.getByText(/\d{4}-\d{2}-\d{2}/)).toBeVisible(); // Data
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('Criar Nova Atribuição', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments/add');
|
|
});
|
|
|
|
test('deve mostrar formulário de criação', async ({ page }) => {
|
|
await expect(page.getByRole('combobox', { name: /turma|class/i })).toBeVisible();
|
|
await expect(page.getByRole('combobox', { name: /template/i })).toBeVisible();
|
|
await expect(page.getByLabel(/data início|start date/i)).toBeVisible();
|
|
await expect(page.getByLabel(/data fim|end date/i)).toBeVisible();
|
|
await expect(page.getByLabel(/tempo limite|time limit/i)).toBeVisible();
|
|
});
|
|
|
|
test('deve listar turmas disponíveis', async ({ page }) => {
|
|
const classSelect = page.getByRole('combobox', { name: /turma|class/i });
|
|
const options = await classSelect.locator('option').count();
|
|
|
|
expect(options).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('deve listar templates disponíveis', async ({ page }) => {
|
|
const templateSelect = page.getByRole('combobox', { name: /template/i });
|
|
const options = await templateSelect.locator('option').count();
|
|
|
|
// Pode ser 0 se não houver templates
|
|
expect(options).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
test('deve criar atribuição com dados válidos', async ({ page }) => {
|
|
const timestamp = Date.now();
|
|
|
|
// Selecionar turma
|
|
const classSelect = page.getByRole('combobox', { name: /turma|class/i });
|
|
if ((await classSelect.locator('option').count()) > 0) {
|
|
await classSelect.selectOption({ index: 0 });
|
|
}
|
|
|
|
// Selecionar template
|
|
const templateSelect = page.getByRole('combobox', { name: /template/i });
|
|
if ((await templateSelect.locator('option').count()) > 0) {
|
|
await templateSelect.selectOption({ index: 0 });
|
|
}
|
|
|
|
// Datas
|
|
await page.getByLabel(/data início|start date/i).fill('2025-02-01');
|
|
await page.getByLabel(/data fim|end date/i).fill('2025-02-28');
|
|
|
|
// Tempo limite (em minutos)
|
|
await page.getByLabel(/tempo limite|time limit/i).fill('60');
|
|
|
|
await page.getByRole('button', { name: /criar|salvar/i }).click();
|
|
|
|
await expect(page).toHaveURL(/\/admin\/dashboard\/assignments/, { timeout: 10000 });
|
|
});
|
|
|
|
test('deve validar data fim posterior a data início', async ({ page }) => {
|
|
await page.getByLabel(/data início|start date/i).fill('2025-02-15');
|
|
await page.getByLabel(/data fim|end date/i).fill('2025-02-01');
|
|
|
|
await page.getByRole('button', { name: /criar|salvar/i }).click();
|
|
|
|
await expect(page.getByText(/fim.*posterior|data inválida/i)).toBeVisible();
|
|
});
|
|
|
|
test('deve validar campos obrigatórios', async ({ page }) => {
|
|
await page.getByRole('button', { name: /criar|salvar/i }).click();
|
|
|
|
await expect(page.getByText(/obrigatório|required/i)).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe('Atribuição por Turma', () => {
|
|
test('deve pré-selecionar turma se vier da página da turma', async ({ page }) => {
|
|
// TODO: Testar vindo da página de detalhes da turma
|
|
// await page.goto('/admin/dashboard/class/edit/class-id');
|
|
// await page.getByRole('button', { name: /atribuir prova/i }).click();
|
|
|
|
// const classSelect = page.getByRole('combobox', { name: /turma/i });
|
|
// const value = await classSelect.inputValue();
|
|
// expect(value).toBe('class-id');
|
|
});
|
|
|
|
test('deve mostrar informações da turma', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments/add');
|
|
|
|
// Após selecionar turma, pode mostrar info
|
|
const classSelect = page.getByRole('combobox', { name: /turma/i });
|
|
if ((await classSelect.locator('option').count()) > 0) {
|
|
await classSelect.selectOption({ index: 0 });
|
|
|
|
// Pode mostrar número de alunos
|
|
// await expect(page.getByText(/\d+ alunos/i)).toBeVisible();
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('Editar Atribuição', () => {
|
|
test('deve carregar dados da atribuição', async ({ page }) => {
|
|
// TODO: Editar atribuição existente
|
|
await page.goto('/admin/dashboard/assignments/edit/assignment-id');
|
|
|
|
await expect(page.getByRole('combobox', { name: /turma/i })).not.toBeEmpty();
|
|
await expect(page.getByRole('combobox', { name: /template/i })).not.toBeEmpty();
|
|
});
|
|
|
|
test('deve permitir modificar datas e tempo', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments/edit/assignment-id');
|
|
|
|
await page.getByLabel(/data início|start date/i).fill('2025-03-01');
|
|
await page.getByLabel(/data fim|end date/i).fill('2025-03-31');
|
|
await page.getByLabel(/tempo limite|time limit/i).fill('90');
|
|
|
|
await page.getByRole('button', { name: /salvar|atualizar/i }).click();
|
|
|
|
await expect(page).toHaveURL(/\/admin\/dashboard\/assignments/, { timeout: 10000 });
|
|
});
|
|
|
|
test('não deve modificar turma da atribuição', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments/edit/assignment-id');
|
|
|
|
const classSelect = page.getByRole('combobox', { name: /turma/i });
|
|
const isDisabled = await classSelect.isDisabled();
|
|
|
|
// Geralmente não permite mudar a turma
|
|
expect(isDisabled).toBe(true);
|
|
});
|
|
});
|
|
|
|
test.describe('Excluir Atribuição', () => {
|
|
test('deve confirmar antes de excluir', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments');
|
|
|
|
const deleteButton = page.getByRole('button', { name: /excluir/i }).first();
|
|
if (await deleteButton.isVisible()) {
|
|
await deleteButton.click();
|
|
|
|
await expect(page.getByText(/tem certeza|deseja excluir/i)).toBeVisible();
|
|
await expect(page.getByRole('button', { name: /confirmar|sim/i })).toBeVisible();
|
|
await expect(page.getByRole('button', { name: /cancelar|não/i })).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('deve remover atribuição após excluir', async ({ page }) => {
|
|
// TODO: Implementar
|
|
// const beforeCount = await page.locator('[data-testid="assignment-row"]').count();
|
|
|
|
// await page.getByRole('button', { name: /excluir/i }).first().click();
|
|
// await page.getByRole('button', { name: /confirmar/i }).click();
|
|
|
|
// await expect(page.locator('[data-testid="assignment-row"]').count()).toBe(beforeCount - 1);
|
|
});
|
|
});
|
|
|
|
test.describe('Status da Atribuição', () => {
|
|
test('deve mostrar status da atribuição', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments');
|
|
|
|
// Status possíveis: draft, active, expired
|
|
const statusBadge = page.locator('[data-testid="status-badge"]').first();
|
|
if (await statusBadge.isVisible()) {
|
|
await expect(statusBadge).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('deve mostrar atribuições expiradas separadas', async ({ page }) => {
|
|
// Pode ter filtro ou aba para expiradas
|
|
const expiredFilter = page.getByRole('tab', { name: /expiradas/i });
|
|
if (await expiredFilter.isVisible()) {
|
|
await expiredFilter.click();
|
|
}
|
|
});
|
|
|
|
test('deve mostrar número de alunos que fizeram a prova', async ({ page }) => {
|
|
const assignmentRow = page.locator('tr').nth(1);
|
|
if (await assignmentRow.isVisible()) {
|
|
await expect(assignmentRow.getByText(/\d+\/\d+/)).toBeVisible(); // Ex: 5/18
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('Duplicar Atribuição', () => {
|
|
test('deve permitir duplicar atribuição existente', async ({ page }) => {
|
|
// TODO: Testar duplicação
|
|
// await page.goto('/admin/dashboard/assignments');
|
|
// await page.getByRole('button', { name: /duplicar/i }).first().click();
|
|
|
|
// await expect(page.getByLabel(/título/i)).toContainText('cópia');
|
|
// await page.getByRole('button', { name: /criar/i }).click();
|
|
|
|
// Deve criar nova atribuição com mesmos dados
|
|
});
|
|
|
|
test('deve incrementar nome ao duplicar', async ({ page }) => {
|
|
// TODO: Testar se nome é incrementado automaticamente
|
|
// await page.getByRole('button', { name: /duplicar/i }).first().click();
|
|
|
|
// const nameField = page.getByLabel(/título/i);
|
|
// const originalName = await nameField.inputValue();
|
|
// await expect(originalName).toMatch(/\(2\)|cópia/i);
|
|
});
|
|
});
|
|
|
|
test.describe('Visualização do Template', () => {
|
|
test('deve mostrar preview do template ao selecionar', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments/add');
|
|
|
|
const templateSelect = page.getByRole('combobox', { name: /template/i });
|
|
if ((await templateSelect.locator('option').count()) > 0) {
|
|
await templateSelect.selectOption({ index: 0 });
|
|
|
|
// Pode mostrar número de questões
|
|
// await expect(page.getByText(/\d+ questões/i)).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('deve linkar para página do template', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/assignments/add');
|
|
|
|
const templateLink = page.getByRole('link', { name: /ver template/i });
|
|
if (await templateLink.isVisible()) {
|
|
await templateLink.click();
|
|
|
|
await expect(page).toHaveURL(/\/exam-templates/i);
|
|
}
|
|
});
|
|
});
|
|
});
|