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:
@@ -147,6 +147,13 @@ test.describe('Homework Rules - Soft Warning (Story 5.4)', () => {
|
||||
});
|
||||
|
||||
test.beforeEach(async () => {
|
||||
// homework_submissions has NO CASCADE on homework_id — 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}')`,
|
||||
@@ -155,6 +162,11 @@ test.describe('Homework Rules - Soft Warning (Story 5.4)', () => {
|
||||
// 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 */ }
|
||||
|
||||
// NOTE: Do NOT call clearRules() here — it deletes rules for the shared
|
||||
// tenant and creates race conditions with other spec files running in
|
||||
// parallel. Each test seeds its own rules via seedSoftRules() which uses
|
||||
@@ -287,11 +299,11 @@ test.describe('Homework Rules - Soft Warning (Story 5.4)', () => {
|
||||
// Click modify date
|
||||
await warningDialog.getByRole('button', { name: /modifier la date/i }).click();
|
||||
|
||||
// Warning closes, create form reopens
|
||||
await expect(warningDialog).not.toBeVisible({ timeout: 3000 });
|
||||
// Warning closes, create form reopens (state transition may take time)
|
||||
await expect(warningDialog).not.toBeVisible({ timeout: 5000 });
|
||||
const createDialog = page.getByRole('dialog');
|
||||
await expect(createDialog).toBeVisible();
|
||||
await expect(createDialog.locator('#hw-due-date')).toBeVisible();
|
||||
await expect(createDialog).toBeVisible({ timeout: 10000 });
|
||||
await expect(createDialog.locator('#hw-due-date')).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Change to a compliant date (15 days from now)
|
||||
const farDate = getNextWeekday(15);
|
||||
|
||||
Reference in New Issue
Block a user