272 lines
10 KiB
JavaScript
272 lines
10 KiB
JavaScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Admin - Arquivos/Files', () => {
|
|
// 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(/\/admin\/dashboard/);
|
|
// });
|
|
|
|
test.describe('Lista de Arquivos', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files');
|
|
});
|
|
|
|
test('deve mostrar lista de arquivos', async ({ page }) => {
|
|
await expect(page.getByText(/arquivos|files/i)).toBeVisible();
|
|
});
|
|
|
|
test('deve ter botão de upload', async ({ page }) => {
|
|
await expect(page.getByRole('link', { name: /upload|adicionar|novo/i })).toBeVisible();
|
|
});
|
|
|
|
test('deve mostrar informações do arquivo', async ({ page }) => {
|
|
const fileRow = page.locator('tr').nth(1); // Pular header
|
|
if (await fileRow.isVisible()) {
|
|
await expect(fileRow.getByText(/\.(pdf|doc|png|jpg)/i)).toBeVisible();
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('Upload de Arquivo', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/add');
|
|
});
|
|
|
|
test('deve mostrar formulário de upload', async ({ page }) => {
|
|
await expect(page.getByLabelText(/título|title/i)).toBeVisible();
|
|
await expect(page.getByLabelText(/arquivo|file/i)).toBeVisible();
|
|
await expect(page.getByRole('combobox', { name: /categoria/i })).toBeVisible();
|
|
await expect(page.getByRole('button', { name: /upload|salvar/i })).toBeVisible();
|
|
});
|
|
|
|
test('deve aceitar upload de arquivo PDF', async ({ page }) => {
|
|
// TODO: Criar arquivo PDF temporário
|
|
// const fileInput = page.getByLabelText(/arquivo/i);
|
|
// await fileInput.setInputFiles('tests/fixtures/test.pdf');
|
|
|
|
await page.getByLabelText(/título|title/i).fill('Arquivo Teste PDF');
|
|
|
|
const categorySelect = page.getByRole('combobox', { name: /categoria/i });
|
|
if (await categorySelect.isVisible()) {
|
|
await categorySelect.selectOption({ index: 0 });
|
|
}
|
|
|
|
// await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
// await expect(page).toHaveURL(/\/admin\/dashboard\/files/, { timeout: 15000 });
|
|
});
|
|
|
|
test('deve aceitar upload de arquivo de imagem', async ({ page }) => {
|
|
// const fileInput = page.getByLabelText(/arquivo/i);
|
|
// await fileInput.setInputFiles('tests/fixtures/test.png');
|
|
|
|
await page.getByLabelText(/título|title/i).fill('Imagem Teste');
|
|
|
|
// await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
});
|
|
|
|
test('deve validar título obrigatório', async ({ page }) => {
|
|
await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
|
|
await expect(page.getByText(/título.*obrigatório|title.*required/i)).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe('Upload por Turma', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
// TODO: Usar ID de turma de teste
|
|
await page.goto('/files/class/class-id/add');
|
|
});
|
|
|
|
test('deve pré-selecionar turma no formulário', async ({ page }) => {
|
|
// Deve mostrar informações da turma ou ter turma pré-selecionada
|
|
await expect(page.getByText(/turma|class/i)).toBeVisible();
|
|
});
|
|
|
|
test('deve fazer upload para turma específica', async ({ page }) => {
|
|
await page.getByLabelText(/título|title/i).fill('Material da Turma');
|
|
|
|
// const fileInput = page.getByLabelText(/arquivo/i);
|
|
// await fileInput.setInputFiles('tests/fixtures/material.pdf');
|
|
|
|
// await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
|
|
// Deve redirecionar para detalhes da turma
|
|
await expect(page).toHaveURL(/\/admin\/dashboard\/class/, { timeout: 10000 });
|
|
});
|
|
});
|
|
|
|
test.describe('Editar Arquivo', () => {
|
|
test('deve carregar dados do arquivo', async ({ page }) => {
|
|
// TODO: Usar ID de arquivo de teste
|
|
await page.goto('/admin/dashboard/files/edit/file-id');
|
|
|
|
await expect(page.getByLabelText(/título|title/i)).not.toBeEmpty();
|
|
});
|
|
|
|
test('deve permitir modificar título e descrição', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/edit/file-id');
|
|
|
|
await page.getByLabelText(/título|title/i).fill('Arquivo Editado');
|
|
|
|
const descField = page.getByLabelText(/descrição|description/i);
|
|
if (await descField.isVisible()) {
|
|
await descField.fill('Descrição atualizada');
|
|
}
|
|
|
|
await page.getByRole('button', { name: /salvar|atualizar/i }).click();
|
|
|
|
await expect(page).toHaveURL(/\/admin\/dashboard\/files/, { timeout: 10000 });
|
|
});
|
|
|
|
test('deve permitir trocar categoria', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/edit/file-id');
|
|
|
|
const categorySelect = page.getByRole('combobox', { name: /categoria/i });
|
|
if (await categorySelect.isVisible()) {
|
|
const originalValue = await categorySelect.inputValue();
|
|
await categorySelect.selectOption({ index: 1 });
|
|
|
|
await page.getByRole('button', { name: /salvar|atualizar/i }).click();
|
|
|
|
// Verificar se mudou
|
|
// await page.goto('/admin/dashboard/files/edit/file-id');
|
|
// const newValue = await categorySelect.inputValue();
|
|
// expect(newValue).not.toBe(originalValue);
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('Download de Arquivo', () => {
|
|
test('deve ter botão de download', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files');
|
|
|
|
const downloadButton = page.getByRole('link', { name: /download|baixar/i }).first();
|
|
if (await downloadButton.isVisible()) {
|
|
const downloadPromise = page.waitForEvent('download');
|
|
|
|
await downloadButton.click();
|
|
|
|
const download = await downloadPromise;
|
|
expect(download.suggestedFilename()).toBeTruthy();
|
|
}
|
|
});
|
|
|
|
test('deve abrir arquivo em nova aba', async ({ page }) => {
|
|
const openButton = page.getByRole('link', { name: /abrir|open/i }).first();
|
|
if (await openButton.isVisible()) {
|
|
const newPagePromise = page.waitForEvent('popup');
|
|
|
|
await openButton.click();
|
|
|
|
const newPage = await newPagePromise;
|
|
await expect(newPage).toHaveURL(/\.pdf|\.png|\.jpg/i);
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('Excluir Arquivo', () => {
|
|
test('deve confirmar antes de excluir', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files');
|
|
|
|
const deleteButton = page.getByRole('button', { name: /excluir|delete/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 arquivo da lista após excluir', async ({ page }) => {
|
|
// TODO: Implementar
|
|
// await page.goto('/admin/dashboard/files');
|
|
// const fileName = 'Arquivo Para Excluir';
|
|
|
|
// const initialCount = await page.getByText(fileName).count();
|
|
|
|
// await page.getByRole('button', { name: /excluir/i }).first().click();
|
|
// await page.getByRole('button', { name: /confirmar/i }).click();
|
|
|
|
// await expect(page.getByText(fileName)).toHaveCount(initialCount - 1);
|
|
});
|
|
});
|
|
|
|
test.describe('Upload Múltiplo', () => {
|
|
test('deve aceitar múltiplos arquivos de uma vez', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/add');
|
|
|
|
// const fileInput = page.getByLabelText(/arquivo/i);
|
|
// Se suportar múltiplos:
|
|
// await fileInput.setInputFiles([
|
|
// 'tests/fixtures/file1.pdf',
|
|
// 'tests/fixtures/file2.pdf'
|
|
// ]);
|
|
|
|
// await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
|
|
// Deve processar todos os arquivos
|
|
});
|
|
|
|
test('deve mostrar barra de progresso durante upload', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/add');
|
|
|
|
// Após selecionar arquivo e iniciar upload
|
|
// await expect(page.getByText(/enviando|uploading|progresso/i)).toBeVisible();
|
|
// await expect(page.getByText(/concluído|sucesso/i)).toBeVisible({ timeout: 15000 });
|
|
});
|
|
});
|
|
|
|
test.describe('Validações de Upload', () => {
|
|
test('deve rejeitar arquivo muito grande', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/add');
|
|
|
|
// Criar arquivo temporário grande
|
|
// const largeFile = Buffer.alloc(20 * 1024 * 1024); // 20MB
|
|
// await page.getByLabelText(/arquivo/i).setInputFiles({
|
|
// name: 'large.pdf',
|
|
// mimeType: 'application/pdf',
|
|
// buffer: largeFile
|
|
// });
|
|
|
|
await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
|
|
await expect(page.getByText(/arquivo muito grande|tamanho máximo/i)).toBeVisible();
|
|
});
|
|
|
|
test('deve rejeitar formato não suportado', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/add');
|
|
|
|
// await page.getByLabelText(/arquivo/i).setInputFiles('tests/fixtures/file.exe');
|
|
|
|
await page.getByRole('button', { name: /upload|salvar/i }).click();
|
|
|
|
await expect(page.getByText(/formato não suportado|tipo inválido/i)).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe('Preview de Arquivo', () => {
|
|
test('deve mostrar preview de imagem', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/edit/image-file-id');
|
|
|
|
const preview = page.locator('img[src*="/uploads/"]').first();
|
|
if (await preview.isVisible()) {
|
|
await expect(preview).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('deve mostrar ícone para PDF', async ({ page }) => {
|
|
await page.goto('/admin/dashboard/files/edit/pdf-file-id');
|
|
|
|
const pdfIcon = page.locator('[class*="pdf"]').first();
|
|
if (await pdfIcon.isVisible()) {
|
|
await expect(pdfIcon).toBeVisible();
|
|
}
|
|
});
|
|
});
|
|
});
|