fix: Corriger les tests E2E après l'introduction du cache-aside paginé
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Naming Conventions (push) Has been cancelled
CI / Build Check (push) Has been cancelled

Le commit 23dd717 a introduit un cache Redis (paginated_queries.cache)
pour les requêtes paginées. Les tests E2E qui modifient les données via
SQL direct (beforeAll, cleanup) contournent la couche applicative et ne
déclenchent pas l'invalidation du cache, provoquant des données obsolètes.

De plus, plusieurs problèmes d'isolation entre tests ont été découverts :
- Les tests classes.spec.ts supprimaient les données d'autres specs via
  DELETE FROM school_classes sans nettoyer les FK dépendantes
- Les tests user-blocking utilisaient des emails partagés entre les
  projets Playwright (chromium/firefox/webkit) exécutés en parallèle,
  causant des race conditions sur l'état du compte utilisateur
- Le handler NotifyTeachersPedagogicalDayHandler s'exécutait de manière
  synchrone, bloquant la réponse HTTP pendant l'envoi des emails
- La sélection d'un enseignant remplaçant effaçait l'autre dropdown car
  {#if} supprimait l'option sélectionnée du DOM

Corrections appliquées :
- Ajout de cache:pool:clear après chaque modification SQL directe
- Nettoyage des FK dépendantes avant les DELETE (classes, subjects)
- Emails uniques par projet navigateur pour éviter les race conditions
- Routage de JourneePedagogiqueAjoutee vers le transport async
- Remplacement de {#if} par disabled sur les selects de remplacement
- Recherche par nom sur la page classes pour gérer la pagination
- Patterns toPass() pour la fiabilité Firefox sur les color pickers
This commit is contained in:
2026-03-01 23:33:42 +01:00
parent 23dd7177f2
commit 1db8a7a0b2
13 changed files with 353 additions and 99 deletions

View File

@@ -25,6 +25,17 @@ function runCommand(sql: string) {
);
}
function clearCache() {
try {
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console cache:pool:clear paginated_queries.cache 2>&1`,
{ encoding: 'utf-8' }
);
} catch {
// Cache pool may not exist in all environments
}
}
function resolveDeterministicIds(): { schoolId: string; academicYearId: string } {
const output = execSync(
`docker compose -f "${composeFile}" exec -T php php -r '` +
@@ -64,6 +75,9 @@ async function openCreateDialog(page: import('@playwright/test').Page) {
await expect(button).toBeEnabled();
await button.click();
await expect(page.getByRole('dialog')).toBeVisible({ timeout: 10000 });
// Wait for dropdown options to load (more than just the placeholder)
await expect(page.locator('#replaced-teacher option')).not.toHaveCount(1, { timeout: 10000 });
}
function getTodayDate(): string {
@@ -102,6 +116,8 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
runCommand(
`INSERT INTO subjects (id, tenant_id, school_id, name, code, status, created_at, updated_at) VALUES (gen_random_uuid(), '${TENANT_ID}', '${schoolId}', 'E2E-Repl-Français', 'E2EFRA', 'active', NOW(), NOW()) ON CONFLICT DO NOTHING`
);
clearCache();
});
test.beforeEach(async () => {
@@ -111,6 +127,21 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
} catch {
// Tables may not exist yet if migration hasn't run
}
// Re-ensure class and subject exist (may have been deleted by parallel specs)
const { schoolId, academicYearId } = resolveDeterministicIds();
try {
runCommand(
`INSERT INTO school_classes (id, tenant_id, school_id, academic_year_id, name, level, status, created_at, updated_at) VALUES (gen_random_uuid(), '${TENANT_ID}', '${schoolId}', '${academicYearId}', 'E2E-Repl-6B', '6ème', 'active', NOW(), NOW()) ON CONFLICT DO NOTHING`
);
runCommand(
`INSERT INTO subjects (id, tenant_id, school_id, name, code, status, created_at, updated_at) VALUES (gen_random_uuid(), '${TENANT_ID}', '${schoolId}', 'E2E-Repl-Français', 'E2EFRA', 'active', NOW(), NOW()) ON CONFLICT DO NOTHING`
);
} catch {
// Ignore if already exists
}
clearCache();
});
// ============================================================================
@@ -166,14 +197,10 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
await replacedSelect.selectOption({ index: 1 });
// Select replacement teacher (different from replaced)
// Index 0 = placeholder, index 1 = same teacher (disabled), index 2 = next available
const replacementSelect = page.locator('#replacement-teacher');
await expect(replacementSelect).toBeVisible();
const replacementOptions = replacementSelect.locator('option');
const count = await replacementOptions.count();
// Select a different teacher (index 1 should work since replaced teacher is filtered out)
if (count > 1) {
await replacementSelect.selectOption({ index: 1 });
}
await replacementSelect.selectOption({ index: 2 });
// Set dates
await page.locator('#start-date').fill(getTodayDate());
@@ -223,7 +250,7 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
// First create a replacement
await openCreateDialog(page);
await page.locator('#replaced-teacher').selectOption({ index: 1 });
await page.locator('#replacement-teacher').selectOption({ index: 1 });
await page.locator('#replacement-teacher').selectOption({ index: 2 });
await page.locator('#start-date').fill(getTodayDate());
await page.locator('#end-date').fill(getFutureDate(30));
const firstClassSelect = page.locator('.class-pair-row select').first();
@@ -260,7 +287,7 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
// Create a replacement
await openCreateDialog(page);
await page.locator('#replaced-teacher').selectOption({ index: 1 });
await page.locator('#replacement-teacher').selectOption({ index: 1 });
await page.locator('#replacement-teacher').selectOption({ index: 2 });
await page.locator('#start-date').fill(getTodayDate());
await page.locator('#end-date').fill(getFutureDate(10));
const firstClassSelect = page.locator('.class-pair-row select').first();