fix: Corriger les 84 échecs E2E pré-existants
Les tests E2E échouaient pour trois raisons principales : 1. Initialisation asynchrone TipTap — L'éditeur rich-text s'initialise via des imports dynamiques dans onMount(). Les tests interagissaient avec .rich-text-content avant que l'élément n'existe dans le DOM. Ajout d'attentes explicites avant chaque interaction avec l'éditeur. 2. Pollution inter-tests — Les fonctions de nettoyage (classes, subjects) ne supprimaient pas les tables dépendantes (homework, evaluations, schedule_slots), provoquant des erreurs FK silencieuses dans les try/catch. De plus, homework_submissions n'a pas de ON DELETE CASCADE sur homework_id, nécessitant une suppression explicite. 3. État partagé du tenant — Les règles de devoirs (homework_rules) et le calendrier scolaire (school_calendar_entries avec Vacances de Printemps) persistaient entre les fichiers de test, bloquant la création de devoirs dans des tests non liés aux règles.
This commit is contained in:
@@ -103,6 +103,16 @@ function seedTeacherAssignments() {
|
||||
|
||||
test.describe('Homework Management (Story 5.1)', () => {
|
||||
test.beforeAll(async () => {
|
||||
// Clear rate limiter to prevent login throttling across serial tests
|
||||
try {
|
||||
execSync(
|
||||
`docker compose -f "${composeFile}" exec -T php php bin/console cache:pool:clear cache.rate_limiter --env=dev 2>&1`,
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
} catch {
|
||||
// Cache pool may not exist
|
||||
}
|
||||
|
||||
// Create teacher user
|
||||
execSync(
|
||||
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${TEACHER_EMAIL} --password=${TEACHER_PASSWORD} --role=ROLE_PROF 2>&1`,
|
||||
@@ -133,13 +143,41 @@ test.describe('Homework Management (Story 5.1)', () => {
|
||||
});
|
||||
|
||||
test.beforeEach(async () => {
|
||||
// Clean up homework data
|
||||
// Clear rate limiter to prevent login throttling across tests
|
||||
try {
|
||||
execSync(
|
||||
`docker compose -f "${composeFile}" exec -T php php bin/console cache:pool:clear cache.rate_limiter --env=dev 2>&1`,
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
} catch {
|
||||
// Cache pool may not exist
|
||||
}
|
||||
|
||||
// Clean up homework data (homework_submissions has NO CASCADE on homework_id,
|
||||
// so we must delete submissions first)
|
||||
try {
|
||||
runSql(`DELETE FROM submission_attachments WHERE submission_id IN (SELECT hs.id FROM homework_submissions hs JOIN homework h ON hs.homework_id = h.id WHERE h.tenant_id = '${TENANT_ID}' AND h.teacher_id IN (SELECT id FROM users WHERE email = '${TEACHER_EMAIL}' AND tenant_id = '${TENANT_ID}'))`);
|
||||
} catch { /* Table may not exist */ }
|
||||
try {
|
||||
runSql(`DELETE FROM homework_submissions WHERE homework_id IN (SELECT id FROM homework WHERE tenant_id = '${TENANT_ID}' AND teacher_id IN (SELECT id FROM users WHERE email = '${TEACHER_EMAIL}' AND tenant_id = '${TENANT_ID}'))`);
|
||||
} catch { /* Table may not exist */ }
|
||||
try {
|
||||
runSql(`DELETE FROM homework WHERE tenant_id = '${TENANT_ID}' AND teacher_id IN (SELECT id FROM users WHERE email = '${TEACHER_EMAIL}' AND tenant_id = '${TENANT_ID}')`);
|
||||
} catch {
|
||||
// Table may not exist
|
||||
}
|
||||
|
||||
// Disable any homework rules left by other test files (homework-rules-warning,
|
||||
// homework-rules-hard) to prevent rule warnings/blocks in duplicate tests.
|
||||
try {
|
||||
runSql(`UPDATE homework_rules SET enabled = false, updated_at = NOW() WHERE tenant_id = '${TENANT_ID}'`);
|
||||
} catch { /* Table may not exist */ }
|
||||
|
||||
// Clear school calendar entries that may block dates (Vacances de Printemps, etc.)
|
||||
try {
|
||||
runSql(`DELETE FROM school_calendar_entries WHERE tenant_id = '${TENANT_ID}'`);
|
||||
} catch { /* Table may not exist */ }
|
||||
|
||||
// Re-ensure data exists
|
||||
const { schoolId, academicYearId } = resolveDeterministicIds();
|
||||
try {
|
||||
@@ -216,8 +254,11 @@ test.describe('Homework Management (Story 5.1)', () => {
|
||||
// Fill title
|
||||
await page.locator('#hw-title').fill('Exercices chapitre 5');
|
||||
|
||||
// Fill description
|
||||
await page.locator('.modal .rich-text-content').click(); await page.locator('.modal .rich-text-content').pressSequentially('Pages 42-45, exercices 1 à 10');
|
||||
// Fill description (TipTap initializes asynchronously)
|
||||
const editorContent = page.locator('.modal .rich-text-content');
|
||||
await expect(editorContent).toBeVisible({ timeout: 10000 });
|
||||
await editorContent.click();
|
||||
await editorContent.pressSequentially('Pages 42-45, exercices 1 à 10');
|
||||
|
||||
// Set due date (next weekday, at least 2 days from now)
|
||||
await page.locator('#hw-due-date').fill(getNextWeekday(3));
|
||||
@@ -389,7 +430,10 @@ test.describe('Homework Management (Story 5.1)', () => {
|
||||
await page.locator('#hw-class').selectOption({ index: 1 });
|
||||
await page.locator('#hw-subject').selectOption({ index: 1 });
|
||||
await page.locator('#hw-title').fill('Devoir date passée');
|
||||
await page.locator('.modal .rich-text-content').click(); await page.locator('.modal .rich-text-content').pressSequentially('Test validation');
|
||||
const editorVal = page.locator('.modal .rich-text-content');
|
||||
await expect(editorVal).toBeVisible({ timeout: 10000 });
|
||||
await editorVal.click();
|
||||
await editorVal.pressSequentially('Test validation');
|
||||
|
||||
// Set a past date — fill() works with Svelte 5 bind:value
|
||||
const yesterday = new Date();
|
||||
@@ -686,7 +730,10 @@ test.describe('Homework Management (Story 5.1)', () => {
|
||||
await page.locator('#hw-class').selectOption({ index: 1 });
|
||||
await page.locator('#hw-subject').selectOption({ index: 1 });
|
||||
await page.locator('#hw-title').fill('Titre original');
|
||||
await page.locator('.modal .rich-text-content').click(); await page.locator('.modal .rich-text-content').pressSequentially('Description inchangée');
|
||||
const editorEdit = page.locator('.modal .rich-text-content');
|
||||
await expect(editorEdit).toBeVisible({ timeout: 10000 });
|
||||
await editorEdit.click();
|
||||
await editorEdit.pressSequentially('Description inchangée');
|
||||
await page.locator('#hw-due-date').fill(dueDate);
|
||||
await page.getByRole('button', { name: /créer le devoir/i }).click();
|
||||
await expect(page.getByRole('dialog')).not.toBeVisible({ timeout: 10000 });
|
||||
@@ -697,7 +744,8 @@ test.describe('Homework Management (Story 5.1)', () => {
|
||||
const editDialog = page.getByRole('dialog');
|
||||
await expect(editDialog).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Verify pre-filled values
|
||||
// Verify pre-filled values (TipTap may take time to initialize with content)
|
||||
await expect(page.locator('.modal .rich-text-content')).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.locator('.modal .rich-text-content')).toContainText('Description inchangée');
|
||||
await expect(page.locator('#edit-due-date')).toHaveValue(dueDate);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user