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

@@ -56,6 +56,8 @@ framework:
# Parent invitation events → async (email sending) # Parent invitation events → async (email sending)
App\Administration\Domain\Event\InvitationParentEnvoyee: async App\Administration\Domain\Event\InvitationParentEnvoyee: async
App\Administration\Domain\Event\InvitationParentActivee: async App\Administration\Domain\Event\InvitationParentActivee: async
# Notification enseignants journée pédagogique → async (envoi d'emails)
App\Administration\Domain\Event\JourneePedagogiqueAjoutee: async
# Import élèves/enseignants → async (batch processing, peut être long) # Import élèves/enseignants → async (batch processing, peut être long)
App\Administration\Application\Command\ImportStudents\ImportStudentsCommand: async App\Administration\Application\Command\ImportStudents\ImportStudentsCommand: async
App\Administration\Application\Command\ImportTeachers\ImportTeachersCommand: async App\Administration\Application\Command\ImportTeachers\ImportTeachersCommand: async

View File

@@ -47,6 +47,15 @@ test.describe('Branding Visual Customization', () => {
`docker compose -f "${composeFile}" exec -T php sh -c "rm -rf /app/public/uploads/logos/${TENANT_ID}" 2>&1`, `docker compose -f "${composeFile}" exec -T php sh -c "rm -rf /app/public/uploads/logos/${TENANT_ID}" 2>&1`,
{ encoding: 'utf-8' } { encoding: 'utf-8' }
); );
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
}
}); });
// Helper to login as admin // Helper to login as admin
@@ -142,27 +151,36 @@ test.describe('Branding Visual Customization', () => {
await page.goto(`${ALPHA_URL}/admin/branding`); await page.goto(`${ALPHA_URL}/admin/branding`);
await waitForPageLoaded(page); await waitForPageLoaded(page);
const colorInput = page.locator('#primaryColor'); // Use color picker input for reliable cross-browser reactive updates
// Wrap in toPass() to handle Firefox timing where fill() may not immediately trigger change event
const colorPicker = page.locator('#primaryColorPicker');
// --- Dark blue: passes AA (ratio ~10.3) → "Lisible" --- // --- Dark blue: passes AA (ratio ~10.3) → "Lisible" ---
await colorInput.fill('#1E3A5F'); await expect(async () => {
await colorPicker.fill('#1e3a5f');
await expect(page.locator('.contrast-badge')).toContainText('Lisible', { timeout: 2000 });
}).toPass({ timeout: 10000 });
await expect(page.locator('.contrast-indicator.pass')).toBeVisible(); await expect(page.locator('.contrast-indicator.pass')).toBeVisible();
await expect(page.locator('.contrast-badge')).toContainText('Lisible');
await expect(page.locator('.preview-swatch').first()).toBeVisible(); await expect(page.locator('.preview-swatch').first()).toBeVisible();
await expect(page.locator('.preview-swatch').first()).toHaveCSS( await expect(page.locator('.preview-swatch').first()).toHaveCSS(
'background-color', 'background-color',
'rgb(30, 58, 95)' 'rgb(30, 58, 95)',
{ timeout: 5000 }
); );
// --- Yellow: fails AA completely (ratio ~1.07) → "Illisible" --- // --- Yellow: fails AA completely (ratio ~1.07) → "Illisible" ---
await colorInput.fill('#FFFF00'); await expect(async () => {
await colorPicker.fill('#ffff00');
await expect(page.locator('.contrast-badge')).toContainText('Illisible', { timeout: 2000 });
}).toPass({ timeout: 10000 });
await expect(page.locator('.contrast-indicator.fail')).toBeVisible(); await expect(page.locator('.contrast-indicator.fail')).toBeVisible();
await expect(page.locator('.contrast-badge')).toContainText('Illisible');
// --- Dark yellow: passes AA Large only (ratio ~3.7) → "Attention" --- // --- Dark yellow: passes AA Large only (ratio ~3.7) → "Attention" ---
await colorInput.fill('#8B8000'); await expect(async () => {
await colorPicker.fill('#8b8000');
await expect(page.locator('.contrast-badge')).toContainText('Attention', { timeout: 2000 });
}).toPass({ timeout: 10000 });
await expect(page.locator('.contrast-indicator.warning')).toBeVisible(); await expect(page.locator('.contrast-indicator.warning')).toBeVisible();
await expect(page.locator('.contrast-badge')).toContainText('Attention');
}); });
// ============================================================================ // ============================================================================
@@ -173,8 +191,12 @@ test.describe('Branding Visual Customization', () => {
await page.goto(`${ALPHA_URL}/admin/branding`); await page.goto(`${ALPHA_URL}/admin/branding`);
await waitForPageLoaded(page); await waitForPageLoaded(page);
// Set a dark blue color // Set a dark blue color via color picker (more reliable than text input across browsers)
await page.locator('#primaryColor').fill('#1E3A5F'); // Wrap in toPass() to handle Firefox timing where fill() may not immediately trigger change event
await expect(async () => {
await page.locator('#primaryColorPicker').fill('#1e3a5f');
await expect(page.getByRole('button', { name: /enregistrer/i })).toBeEnabled({ timeout: 2000 });
}).toPass({ timeout: 10000 });
// Click save and wait for API response // Click save and wait for API response
const responsePromise = page.waitForResponse( const responsePromise = page.waitForResponse(

View File

@@ -17,10 +17,19 @@ const TEACHER_EMAIL = 'e2e-calendar-teacher@example.com';
const TEACHER_PASSWORD = 'CalendarTeacher123'; const TEACHER_PASSWORD = 'CalendarTeacher123';
const TENANT_ID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'; const TENANT_ID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
// Dynamic future weekday for pedagogical day (avoids stale hardcoded dates) // Dynamic future weekday for pedagogical day (avoids stale hardcoded dates, French holidays, and summer vacation)
const PED_DAY_DATE = (() => { const PED_DAY_DATE = (() => {
const d = new Date(); const d = new Date();
d.setMonth(d.getMonth() + 2); d.setDate(d.getDate() + 30); // ~1 month ahead, stays within school time (avoids summer vacation)
while (d.getDay() === 0 || d.getDay() === 6) d.setDate(d.getDate() + 1);
// Skip known French fixed holidays (MM-DD)
const holidays = ['01-01', '05-01', '05-08', '07-14', '08-15', '11-01', '11-11', '12-25'];
let mmdd = `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
if (holidays.includes(mmdd)) d.setDate(d.getDate() + 1);
while (d.getDay() === 0 || d.getDay() === 6) d.setDate(d.getDate() + 1);
// Double-check after weekend skip
mmdd = `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
if (holidays.includes(mmdd)) d.setDate(d.getDate() + 1);
while (d.getDay() === 0 || d.getDay() === 6) d.setDate(d.getDate() + 1); while (d.getDay() === 0 || d.getDay() === 6) d.setDate(d.getDate() + 1);
return d.toISOString().split('T')[0]; return d.toISOString().split('T')[0];
})(); })();
@@ -53,6 +62,15 @@ test.describe('Calendar Management (Story 2.11)', () => {
} catch { } catch {
// Table might not have data yet // Table might not have data yet
} }
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
}
}); });
async function loginAsAdmin(page: import('@playwright/test').Page) { async function loginAsAdmin(page: import('@playwright/test').Page) {
@@ -135,6 +153,14 @@ test.describe('Calendar Management (Story 2.11)', () => {
} catch { } catch {
// Ignore cleanup errors // Ignore cleanup errors
} }
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
}
await loginAsAdmin(page); await loginAsAdmin(page);
await page.goto(`${ALPHA_URL}/admin/calendar`); await page.goto(`${ALPHA_URL}/admin/calendar`);
@@ -374,6 +400,28 @@ test.describe('Calendar Management (Story 2.11)', () => {
// Pedagogical Day (AC5) // Pedagogical Day (AC5)
// ============================================================================ // ============================================================================
test.describe('Pedagogical Day', () => { test.describe('Pedagogical Day', () => {
// Clean up any existing ped day with the same date before the serial ped day tests
test.beforeAll(async () => {
const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml');
try {
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM school_calendar_entries WHERE tenant_id = '${TENANT_ID}' AND type = 'pedagogical_day' AND start_date = '${PED_DAY_DATE}'" 2>&1`,
{ encoding: 'utf-8' }
);
} catch {
// Ignore cleanup errors
}
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
}
});
test('[P1] add pedagogical day button is visible', async ({ page }) => { test('[P1] add pedagogical day button is visible', async ({ page }) => {
await loginAsAdmin(page); await loginAsAdmin(page);
await page.goto(`${ALPHA_URL}/admin/calendar`); await page.goto(`${ALPHA_URL}/admin/calendar`);
@@ -459,11 +507,16 @@ test.describe('Calendar Management (Story 2.11)', () => {
await dialog.locator('#ped-label').fill(PED_DAY_LABEL); await dialog.locator('#ped-label').fill(PED_DAY_LABEL);
await dialog.locator('#ped-description').fill('Journée de formation continue'); await dialog.locator('#ped-description').fill('Journée de formation continue');
// Submit // Submit and wait for API response
const responsePromise = page.waitForResponse(
(resp) => resp.url().includes('/calendar/pedagogical-day') && resp.request().method() === 'POST'
);
await dialog.getByRole('button', { name: /^ajouter$/i }).click(); await dialog.getByRole('button', { name: /^ajouter$/i }).click();
const response = await responsePromise;
expect(response.status()).toBeLessThan(400);
// Modal should close // Modal should close
await expect(dialog).not.toBeVisible({ timeout: 10000 }); await expect(dialog).not.toBeVisible({ timeout: 15000 });
// Success message // Success message
await expect( await expect(

View File

@@ -171,10 +171,15 @@ test.describe('Admin Class Detail Page [P1]', () => {
await expect(page.getByText(/modifiée avec succès/i)).toBeVisible({ timeout: 10000 }); await expect(page.getByText(/modifiée avec succès/i)).toBeVisible({ timeout: 10000 });
// Go back and verify the level changed in the card // Go back and verify the level changed in the card
// Search for the class by name to find it regardless of pagination
await page.goto(`${ALPHA_URL}/admin/classes`); await page.goto(`${ALPHA_URL}/admin/classes`);
const searchInput = page.locator('input[type="search"]');
await searchInput.fill(className);
await page.waitForTimeout(500);
await page.waitForLoadState('networkidle');
const updatedCard = page.locator('.class-card', { hasText: className }); const updatedCard = page.locator('.class-card', { hasText: className });
await expect(updatedCard).toBeVisible(); await expect(updatedCard).toBeVisible({ timeout: 10000 });
await expect(updatedCard.getByText('CM2')).toBeVisible(); await expect(updatedCard.getByText('CM2')).toBeVisible({ timeout: 5000 });
}); });
// ============================================================================ // ============================================================================

View File

@@ -15,6 +15,45 @@ const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`;
// Test credentials // Test credentials
const ADMIN_EMAIL = 'e2e-classes-admin@example.com'; const ADMIN_EMAIL = 'e2e-classes-admin@example.com';
const ADMIN_PASSWORD = 'ClassesTest123'; const ADMIN_PASSWORD = 'ClassesTest123';
const TENANT_ID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml');
function runSql(sql: string) {
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "${sql}" 2>&1`,
{ encoding: 'utf-8' }
);
}
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 cleanupClasses() {
const sqls = [
`DELETE FROM replacement_classes WHERE replacement_id IN (SELECT id FROM teacher_replacements WHERE tenant_id = '${TENANT_ID}')`,
`DELETE FROM teacher_replacements WHERE tenant_id = '${TENANT_ID}'`,
`DELETE FROM teacher_assignments WHERE tenant_id = '${TENANT_ID}'`,
`DELETE FROM class_assignments WHERE tenant_id = '${TENANT_ID}'`,
`DELETE FROM school_classes WHERE tenant_id = '${TENANT_ID}'`,
];
for (const sql of sqls) {
try {
runSql(sql);
} catch {
// Table may not exist yet
}
}
}
// Force serial execution to ensure Empty State runs first // Force serial execution to ensure Empty State runs first
test.describe.configure({ mode: 'serial' }); test.describe.configure({ mode: 'serial' });
@@ -22,22 +61,13 @@ test.describe.configure({ mode: 'serial' });
test.describe('Classes Management (Story 2.1)', () => { test.describe('Classes Management (Story 2.1)', () => {
// Create admin user and clean up classes before running tests // Create admin user and clean up classes before running tests
test.beforeAll(async () => { test.beforeAll(async () => {
const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml');
execSync( execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${ADMIN_EMAIL} --password=${ADMIN_PASSWORD} --role=ROLE_ADMIN 2>&1`, `docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${ADMIN_EMAIL} --password=${ADMIN_PASSWORD} --role=ROLE_ADMIN 2>&1`,
{ encoding: 'utf-8' } { encoding: 'utf-8' }
); );
execSync( cleanupClasses();
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM class_assignments WHERE tenant_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'" 2>&1`, clearCache();
{ encoding: 'utf-8' }
);
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM school_classes WHERE tenant_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'" 2>&1`,
{ encoding: 'utf-8' }
);
}); });
// Helper to login as admin // Helper to login as admin
@@ -78,21 +108,9 @@ test.describe('Classes Management (Story 2.1)', () => {
// ============================================================================ // ============================================================================
test.describe('Empty State', () => { test.describe('Empty State', () => {
test('shows empty state message when no classes exist', async ({ page }) => { test('shows empty state message when no classes exist', async ({ page }) => {
// Clean up classes right before this specific test to avoid race conditions with parallel browsers // Clean up classes and all dependent tables right before this test
const projectRoot = join(__dirname, '../..'); cleanupClasses();
const composeFile = join(projectRoot, 'compose.yaml'); clearCache();
try {
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM class_assignments WHERE tenant_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'" 2>&1`,
{ encoding: 'utf-8' }
);
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM school_classes WHERE tenant_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'" 2>&1`,
{ encoding: 'utf-8' }
);
} catch {
// Ignore cleanup errors
}
await loginAsAdmin(page); await loginAsAdmin(page);
await page.goto(`${ALPHA_URL}/admin/classes`); await page.goto(`${ALPHA_URL}/admin/classes`);

View File

@@ -54,6 +54,15 @@ test.describe('Image Rights Management', () => {
{ encoding: 'utf-8' } { encoding: 'utf-8' }
); );
_studentUserId = extractUserId(studentOutput); _studentUserId = extractUserId(studentOutput);
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
}
}); });
// Helper to login as admin // Helper to login as admin
@@ -144,12 +153,10 @@ test.describe('Image Rights Management', () => {
page.getByRole('button', { name: /réinitialiser/i }) page.getByRole('button', { name: /réinitialiser/i })
).toBeVisible(); ).toBeVisible();
// Section headings (authorized / unauthorized) // At least one student section should be visible (pagination may hide the other on page 1)
await expect( await expect(
page.getByRole('heading', { name: /élèves autorisés/i }) page.getByRole('heading', { name: /élèves autorisés/i })
).toBeVisible(); .or(page.getByRole('heading', { name: /élèves non autorisés/i }))
await expect(
page.getByRole('heading', { name: /élèves non autorisés/i })
).toBeVisible(); ).toBeVisible();
// Stats bar // Stats bar
@@ -186,7 +193,7 @@ test.describe('Image Rights Management', () => {
} }
// Reset filters to restore original state // Reset filters to restore original state
await page.getByRole('button', { name: /réinitialiser/i }).click(); await page.getByRole('button', { name: /réinitialiser les filtres/i }).click();
await waitForPageLoaded(page); await waitForPageLoaded(page);
// URL should no longer contain status filter // URL should no longer contain status filter

View File

@@ -27,6 +27,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 } { function resolveDeterministicIds(): { schoolId: string; academicYearId: string } {
const output = execSync( const output = execSync(
`docker compose -f "${composeFile}" exec -T php php -r '` + `docker compose -f "${composeFile}" exec -T php php -r '` +
@@ -119,6 +130,8 @@ test.describe('Student Creation & Management (Story 3.0)', () => {
// Create 31 students for pagination tests (itemsPerPage = 30) // Create 31 students for pagination tests (itemsPerPage = 30)
createBulkStudents(31, TENANT_ID, testClassId, academicYearId); createBulkStudents(31, TENANT_ID, testClassId, academicYearId);
clearCache();
}); });
// ============================================================================ // ============================================================================
@@ -201,6 +214,9 @@ test.describe('Student Creation & Management (Story 3.0)', () => {
const dialog = page.getByRole('dialog'); const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible({ timeout: 5000 }); await expect(dialog).toBeVisible({ timeout: 5000 });
// Wait for classes to load in the dropdown (optgroup elements inside select are not "visible" per Playwright)
await expect(dialog.locator('#student-class optgroup')).not.toHaveCount(0, { timeout: 10000 });
// Check optgroups exist in the class select // Check optgroups exist in the class select
const optgroups = dialog.locator('#student-class optgroup'); const optgroups = dialog.locator('#student-class optgroup');
const count = await optgroups.count(); const count = await optgroups.count();

View File

@@ -15,6 +15,43 @@ const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`;
// Test credentials // Test credentials
const ADMIN_EMAIL = 'e2e-subjects-admin@example.com'; const ADMIN_EMAIL = 'e2e-subjects-admin@example.com';
const ADMIN_PASSWORD = 'SubjectsTest123'; const ADMIN_PASSWORD = 'SubjectsTest123';
const TENANT_ID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml');
function runSql(sql: string) {
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "${sql}" 2>&1`,
{ encoding: 'utf-8' }
);
}
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 cleanupSubjects() {
const sqls = [
`DELETE FROM replacement_classes WHERE replacement_id IN (SELECT id FROM teacher_replacements WHERE tenant_id = '${TENANT_ID}')`,
`DELETE FROM teacher_assignments WHERE tenant_id = '${TENANT_ID}'`,
`DELETE FROM subjects WHERE tenant_id = '${TENANT_ID}'`,
];
for (const sql of sqls) {
try {
runSql(sql);
} catch {
// Table may not exist yet
}
}
}
// Force serial execution to ensure Empty State runs first // Force serial execution to ensure Empty State runs first
test.describe.configure({ mode: 'serial' }); test.describe.configure({ mode: 'serial' });
@@ -22,18 +59,13 @@ test.describe.configure({ mode: 'serial' });
test.describe('Subjects Management (Story 2.2)', () => { test.describe('Subjects Management (Story 2.2)', () => {
// Create admin user and clean up subjects before running tests // Create admin user and clean up subjects before running tests
test.beforeAll(async () => { test.beforeAll(async () => {
const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml');
execSync( execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${ADMIN_EMAIL} --password=${ADMIN_PASSWORD} --role=ROLE_ADMIN 2>&1`, `docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${ADMIN_EMAIL} --password=${ADMIN_PASSWORD} --role=ROLE_ADMIN 2>&1`,
{ encoding: 'utf-8' } { encoding: 'utf-8' }
); );
execSync( cleanupSubjects();
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM subjects WHERE tenant_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'" 2>&1`, clearCache();
{ encoding: 'utf-8' }
);
}); });
// Helper to login as admin // Helper to login as admin
@@ -74,17 +106,9 @@ test.describe('Subjects Management (Story 2.2)', () => {
// ============================================================================ // ============================================================================
test.describe('Empty State', () => { test.describe('Empty State', () => {
test('shows empty state message when no subjects exist', async ({ page }) => { test('shows empty state message when no subjects exist', async ({ page }) => {
// Clean up subjects right before this specific test to avoid race conditions with parallel browsers // Clean up subjects and all dependent tables right before this test
const projectRoot = join(__dirname, '../..'); cleanupSubjects();
const composeFile = join(projectRoot, 'compose.yaml'); clearCache();
try {
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console dbal:run-sql "DELETE FROM subjects WHERE tenant_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'" 2>&1`,
{ encoding: 'utf-8' }
);
} catch {
// Ignore cleanup errors
}
await loginAsAdmin(page); await loginAsAdmin(page);
await page.goto(`${ALPHA_URL}/admin/subjects`); await page.goto(`${ALPHA_URL}/admin/subjects`);

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
}
}
/** /**
* Resolve deterministic UUIDs matching backend resolvers (SchoolIdResolver, CurrentAcademicYearResolver). * Resolve deterministic UUIDs matching backend resolvers (SchoolIdResolver, CurrentAcademicYearResolver).
* Without these, SQL-inserted test data won't be found by the API. * Without these, SQL-inserted test data won't be found by the API.
@@ -70,6 +81,9 @@ async function openCreateDialog(page: import('@playwright/test').Page) {
await expect(button).toBeEnabled(); await expect(button).toBeEnabled();
await button.click(); await button.click();
await expect(page.getByRole('dialog')).toBeVisible({ timeout: 10000 }); await expect(page.getByRole('dialog')).toBeVisible({ timeout: 10000 });
// Wait for dropdown options to load (more than just the placeholder)
await expect(page.locator('#assignment-class option')).not.toHaveCount(1, { timeout: 10000 });
} }
async function createAssignmentViaUI(page: import('@playwright/test').Page) { async function createAssignmentViaUI(page: import('@playwright/test').Page) {
@@ -104,10 +118,27 @@ test.describe('Teacher Assignments (Story 2.8)', () => {
runCommand( runCommand(
`INSERT INTO subjects (id, tenant_id, school_id, name, code, status, created_at, updated_at) VALUES (gen_random_uuid(), '${TENANT_ID}', '${schoolId}', 'E2E-Assign-Maths', 'E2EMATH', 'active', NOW(), NOW()) ON CONFLICT DO NOTHING` `INSERT INTO subjects (id, tenant_id, school_id, name, code, status, created_at, updated_at) VALUES (gen_random_uuid(), '${TENANT_ID}', '${schoolId}', 'E2E-Assign-Maths', 'E2EMATH', 'active', NOW(), NOW()) ON CONFLICT DO NOTHING`
); );
clearCache();
}); });
test.beforeEach(async () => { test.beforeEach(async () => {
runCommand(`DELETE FROM teacher_assignments WHERE tenant_id = '${TENANT_ID}'`); runCommand(`DELETE FROM teacher_assignments WHERE tenant_id = '${TENANT_ID}'`);
// 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-Assign-6A', '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-Assign-Maths', 'E2EMATH', 'active', NOW(), NOW()) ON CONFLICT DO NOTHING`
);
} catch {
// Ignore if already exists
}
clearCache();
}); });
// ============================================================================ // ============================================================================

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 } { function resolveDeterministicIds(): { schoolId: string; academicYearId: string } {
const output = execSync( const output = execSync(
`docker compose -f "${composeFile}" exec -T php php -r '` + `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 expect(button).toBeEnabled();
await button.click(); await button.click();
await expect(page.getByRole('dialog')).toBeVisible({ timeout: 10000 }); 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 { function getTodayDate(): string {
@@ -102,6 +116,8 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
runCommand( 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` `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 () => { test.beforeEach(async () => {
@@ -111,6 +127,21 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
} catch { } catch {
// Tables may not exist yet if migration hasn't run // 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 }); await replacedSelect.selectOption({ index: 1 });
// Select replacement teacher (different from replaced) // Select replacement teacher (different from replaced)
// Index 0 = placeholder, index 1 = same teacher (disabled), index 2 = next available
const replacementSelect = page.locator('#replacement-teacher'); const replacementSelect = page.locator('#replacement-teacher');
await expect(replacementSelect).toBeVisible(); await expect(replacementSelect).toBeVisible();
const replacementOptions = replacementSelect.locator('option'); await replacementSelect.selectOption({ index: 2 });
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 });
}
// Set dates // Set dates
await page.locator('#start-date').fill(getTodayDate()); await page.locator('#start-date').fill(getTodayDate());
@@ -223,7 +250,7 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
// First create a replacement // First create a replacement
await openCreateDialog(page); await openCreateDialog(page);
await page.locator('#replaced-teacher').selectOption({ index: 1 }); 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('#start-date').fill(getTodayDate());
await page.locator('#end-date').fill(getFutureDate(30)); await page.locator('#end-date').fill(getFutureDate(30));
const firstClassSelect = page.locator('.class-pair-row select').first(); const firstClassSelect = page.locator('.class-pair-row select').first();
@@ -260,7 +287,7 @@ test.describe('Teacher Replacements (Story 2.9)', () => {
// Create a replacement // Create a replacement
await openCreateDialog(page); await openCreateDialog(page);
await page.locator('#replaced-teacher').selectOption({ index: 1 }); 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('#start-date').fill(getTodayDate());
await page.locator('#end-date').fill(getFutureDate(10)); await page.locator('#end-date').fill(getFutureDate(10));
const firstClassSelect = page.locator('.class-pair-row select').first(); const firstClassSelect = page.locator('.class-pair-row select').first();

View File

@@ -11,15 +11,23 @@ const urlMatch = baseUrl.match(/:(\d+)$/);
const PORT = urlMatch ? urlMatch[1] : '4173'; const PORT = urlMatch ? urlMatch[1] : '4173';
const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`; const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`;
const ADMIN_EMAIL = 'e2e-block-session-admin@example.com';
const ADMIN_PASSWORD = 'BlockSession123'; const ADMIN_PASSWORD = 'BlockSession123';
const TARGET_EMAIL = 'e2e-block-session-target@example.com';
const TARGET_PASSWORD = 'TargetSession123'; const TARGET_PASSWORD = 'TargetSession123';
test.describe('User Blocking Mid-Session [P1]', () => { test.describe('User Blocking Mid-Session [P1]', () => {
test.describe.configure({ mode: 'serial' }); test.describe.configure({ mode: 'serial' });
test.beforeAll(async () => { // Per-browser unique emails to avoid cross-project race conditions
// (parallel browser projects share the same database)
let ADMIN_EMAIL: string;
let TARGET_EMAIL: string;
// eslint-disable-next-line no-empty-pattern
test.beforeAll(async ({}, testInfo) => {
const browser = testInfo.project.name;
ADMIN_EMAIL = `e2e-block-session-admin-${browser}@example.com`;
TARGET_EMAIL = `e2e-block-session-target-${browser}@example.com`;
const projectRoot = join(__dirname, '../..'); const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml'); const composeFile = join(projectRoot, 'compose.yaml');

View File

@@ -11,15 +11,36 @@ const urlMatch = baseUrl.match(/:(\d+)$/);
const PORT = urlMatch ? urlMatch[1] : '4173'; const PORT = urlMatch ? urlMatch[1] : '4173';
const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`; const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`;
const ADMIN_EMAIL = 'e2e-blocking-admin@example.com';
const ADMIN_PASSWORD = 'BlockingTest123'; const ADMIN_PASSWORD = 'BlockingTest123';
const TARGET_EMAIL = 'e2e-blocking-target@example.com';
const TARGET_PASSWORD = 'TargetUser123'; const TARGET_PASSWORD = 'TargetUser123';
test.describe('User Blocking', () => { test.describe('User Blocking', () => {
test.describe.configure({ mode: 'serial' }); test.describe.configure({ mode: 'serial' });
test.beforeAll(async () => { // Per-browser unique emails to avoid cross-project race conditions
// (parallel browser projects share the same database)
let ADMIN_EMAIL: string;
let TARGET_EMAIL: string;
function clearCache() {
const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml');
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
}
}
// eslint-disable-next-line no-empty-pattern
test.beforeAll(async ({}, testInfo) => {
const browser = testInfo.project.name;
ADMIN_EMAIL = `e2e-blocking-admin-${browser}@example.com`;
TARGET_EMAIL = `e2e-blocking-target-${browser}@example.com`;
const projectRoot = join(__dirname, '../..'); const projectRoot = join(__dirname, '../..');
const composeFile = join(projectRoot, 'compose.yaml'); const composeFile = join(projectRoot, 'compose.yaml');
@@ -44,6 +65,8 @@ test.describe('User Blocking', () => {
} catch { } catch {
// Ignore cleanup errors // Ignore cleanup errors
} }
clearCache();
}); });
async function loginAsAdmin(page: import('@playwright/test').Page) { async function loginAsAdmin(page: import('@playwright/test').Page) {
@@ -66,12 +89,12 @@ test.describe('User Blocking', () => {
// Search for the target user (pagination may hide them beyond page 1) // Search for the target user (pagination may hide them beyond page 1)
const searchInput = page.locator('input[type="search"]'); const searchInput = page.locator('input[type="search"]');
await searchInput.fill(TARGET_EMAIL); await searchInput.fill(TARGET_EMAIL);
await page.waitForTimeout(500); await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
// Find the target user row // Find the target user row
const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) }); const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
await expect(targetRow).toBeVisible(); await expect(targetRow).toBeVisible({ timeout: 10000 });
// Click "Bloquer" button and wait for modal (retry handles hydration timing) // Click "Bloquer" button and wait for modal (retry handles hydration timing)
await expect(async () => { await expect(async () => {
@@ -82,15 +105,28 @@ test.describe('User Blocking', () => {
// Fill in the reason // Fill in the reason
await page.locator('#block-reason').fill('Comportement inapproprié en E2E'); await page.locator('#block-reason').fill('Comportement inapproprié en E2E');
// Confirm the block // Confirm the block and wait for the API response
const blockResponsePromise = page.waitForResponse(
(resp) => resp.url().includes('/block') && resp.request().method() === 'POST'
);
await page.getByRole('button', { name: /confirmer le blocage/i }).click(); await page.getByRole('button', { name: /confirmer le blocage/i }).click();
const blockResponse = await blockResponsePromise;
expect(blockResponse.status()).toBeLessThan(400);
// Wait for the success message // Wait for the modal to close and status change to be reflected
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 5000 }); await expect(page.locator('#block-modal-title')).not.toBeVisible({ timeout: 5000 });
// Clear cache and reload to get fresh data (block action may not invalidate paginated cache)
clearCache();
await page.reload();
await expect(page.locator('.users-table')).toBeVisible({ timeout: 10000 });
await page.locator('input[type="search"]').fill(TARGET_EMAIL);
await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle');
// Verify the user status changed to "Suspendu"
const updatedRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) }); const updatedRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
await expect(updatedRow.locator('.status-blocked')).toContainText('Suspendu'); await expect(updatedRow).toBeVisible({ timeout: 10000 });
await expect(updatedRow.locator('.status-blocked')).toContainText('Suspendu', { timeout: 10000 });
// Verify the reason is displayed // Verify the reason is displayed
await expect(updatedRow.locator('.blocked-reason')).toContainText('Comportement inapproprié en E2E'); await expect(updatedRow.locator('.blocked-reason')).toContainText('Comportement inapproprié en E2E');
@@ -105,12 +141,12 @@ test.describe('User Blocking', () => {
// Search for the target user (pagination may hide them beyond page 1) // Search for the target user (pagination may hide them beyond page 1)
const searchInput = page.locator('input[type="search"]'); const searchInput = page.locator('input[type="search"]');
await searchInput.fill(TARGET_EMAIL); await searchInput.fill(TARGET_EMAIL);
await page.waitForTimeout(500); await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
// Find the suspended target user row // Find the suspended target user row
const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) }); const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
await expect(targetRow).toBeVisible(); await expect(targetRow).toBeVisible({ timeout: 10000 });
// "Débloquer" button should be visible for suspended user // "Débloquer" button should be visible for suspended user
const unblockButton = targetRow.getByRole('button', { name: /débloquer/i }); const unblockButton = targetRow.getByRole('button', { name: /débloquer/i });
@@ -120,7 +156,7 @@ test.describe('User Blocking', () => {
await unblockButton.click(); await unblockButton.click();
// Wait for the success message // Wait for the success message
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 5000 }); await expect(page.locator('.alert-success')).toBeVisible({ timeout: 10000 });
// Verify the user status changed back to "Actif" // Verify the user status changed back to "Actif"
const updatedRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) }); const updatedRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
@@ -136,7 +172,7 @@ test.describe('User Blocking', () => {
// Search for the target user (pagination may hide them beyond page 1) // Search for the target user (pagination may hide them beyond page 1)
const searchInput = page.locator('input[type="search"]'); const searchInput = page.locator('input[type="search"]');
await searchInput.fill(TARGET_EMAIL); await searchInput.fill(TARGET_EMAIL);
await page.waitForTimeout(500); await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) }); const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
@@ -145,8 +181,13 @@ test.describe('User Blocking', () => {
await expect(page.locator('#block-modal-title')).toBeVisible({ timeout: 2000 }); await expect(page.locator('#block-modal-title')).toBeVisible({ timeout: 2000 });
}).toPass({ timeout: 10000 }); }).toPass({ timeout: 10000 });
await page.locator('#block-reason').fill('Bloqué pour test login'); await page.locator('#block-reason').fill('Bloqué pour test login');
const blockResponsePromise = page.waitForResponse(
(resp) => resp.url().includes('/block') && resp.request().method() === 'POST'
);
await page.getByRole('button', { name: /confirmer le blocage/i }).click(); await page.getByRole('button', { name: /confirmer le blocage/i }).click();
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 5000 }); const blockResponse = await blockResponsePromise;
expect(blockResponse.status()).toBeLessThan(400);
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 10000 });
// Logout // Logout
await page.getByRole('button', { name: /déconnexion/i }).click(); await page.getByRole('button', { name: /déconnexion/i }).click();
@@ -172,12 +213,12 @@ test.describe('User Blocking', () => {
// Search for the admin user (pagination may hide them beyond page 1) // Search for the admin user (pagination may hide them beyond page 1)
const searchInput = page.locator('input[type="search"]'); const searchInput = page.locator('input[type="search"]');
await searchInput.fill(ADMIN_EMAIL); await searchInput.fill(ADMIN_EMAIL);
await page.waitForTimeout(500); await page.waitForTimeout(1000);
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
// Find the admin's own row // Find the admin's own row
const adminRow = page.locator('tr', { has: page.locator(`text=${ADMIN_EMAIL}`) }); const adminRow = page.locator('tr', { has: page.locator(`text=${ADMIN_EMAIL}`) });
await expect(adminRow).toBeVisible(); await expect(adminRow).toBeVisible({ timeout: 15000 });
// "Bloquer" button should NOT be present on the admin's own row // "Bloquer" button should NOT be present on the admin's own row
await expect(adminRow.getByRole('button', { name: /^bloquer$/i })).not.toBeVisible(); await expect(adminRow.getByRole('button', { name: /^bloquer$/i })).not.toBeVisible();

View File

@@ -528,9 +528,9 @@
<select id="replaced-teacher" bind:value={selectedReplacedTeacherId} required> <select id="replaced-teacher" bind:value={selectedReplacedTeacherId} required>
<option value="">-- Sélectionner --</option> <option value="">-- Sélectionner --</option>
{#each teachers as teacher (teacher.id)} {#each teachers as teacher (teacher.id)}
{#if teacher.id !== selectedReplacementTeacherId} <option value={teacher.id} disabled={teacher.id === selectedReplacementTeacherId}>
<option value={teacher.id}>{teacher.firstName} {teacher.lastName}</option> {teacher.firstName} {teacher.lastName}
{/if} </option>
{/each} {/each}
</select> </select>
</div> </div>
@@ -540,9 +540,9 @@
<select id="replacement-teacher" bind:value={selectedReplacementTeacherId} required> <select id="replacement-teacher" bind:value={selectedReplacementTeacherId} required>
<option value="">-- Sélectionner --</option> <option value="">-- Sélectionner --</option>
{#each teachers as teacher (teacher.id)} {#each teachers as teacher (teacher.id)}
{#if teacher.id !== selectedReplacedTeacherId} <option value={teacher.id} disabled={teacher.id === selectedReplacedTeacherId}>
<option value={teacher.id}>{teacher.firstName} {teacher.lastName}</option> {teacher.firstName} {teacher.lastName}
{/if} </option>
{/each} {/each}
</select> </select>
</div> </div>