feat: Remplacer le champ UUID par une recherche autocomplete pour la liaison parent-élève

L'ajout d'un parent à un élève nécessitait de connaître et coller
manuellement l'UUID du compte parent, ce qui était source d'erreurs
et très peu ergonomique pour les administrateurs.

Le nouveau composant ParentSearchInput offre une recherche par nom/email
avec autocomplétion (debounce 300ms, navigation clavier, ARIA combobox).
Les parents déjà liés sont exclus des résultats, et la sélection se
réinitialise proprement quand l'admin retape dans le champ.
This commit is contained in:
2026-03-12 00:41:41 +01:00
parent 8c70ed1324
commit 8f83dafb7a
6 changed files with 861 additions and 45 deletions

View File

@@ -15,12 +15,13 @@ const ADMIN_EMAIL = 'e2e-childselector-admin@example.com';
const ADMIN_PASSWORD = 'AdminCSTest123';
const PARENT_EMAIL = 'e2e-childselector-parent@example.com';
const PARENT_PASSWORD = 'ChildSelectorTest123';
const PARENT_FIRST_NAME = 'CSParent';
const PARENT_LAST_NAME = 'TestSelector';
const STUDENT1_EMAIL = 'e2e-childselector-student1@example.com';
const STUDENT1_PASSWORD = 'Student1Test123';
const STUDENT2_EMAIL = 'e2e-childselector-student2@example.com';
const STUDENT2_PASSWORD = 'Student2Test123';
let parentUserId: string;
let student1UserId: string;
let student2UserId: string;
@@ -42,7 +43,7 @@ async function loginAsAdmin(page: Page) {
]);
}
async function addGuardianIfNotLinked(page: Page, studentId: string, guardianId: string, relationship: string) {
async function addGuardianIfNotLinked(page: Page, studentId: string, parentSearchTerm: string, relationship: string) {
await page.goto(`${ALPHA_URL}/admin/students/${studentId}`);
await expect(page.locator('.guardian-section')).toBeVisible({ timeout: 10000 });
await expect(
@@ -53,11 +54,24 @@ async function addGuardianIfNotLinked(page: Page, studentId: string, guardianId:
const addButton = page.getByRole('button', { name: /ajouter un parent/i });
if (!(await addButton.isVisible())) return;
// Skip if parent is already linked (email visible in guardian list)
const sectionText = await page.locator('.guardian-section').textContent();
if (sectionText && sectionText.includes(parentSearchTerm)) return;
await addButton.click();
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible({ timeout: 5000 });
await dialog.getByLabel(/id du parent/i).fill(guardianId);
const searchInput = dialog.getByRole('combobox', { name: /rechercher/i });
await searchInput.fill(parentSearchTerm);
const listbox = dialog.locator('#parent-search-listbox');
await expect(listbox).toBeVisible({ timeout: 10000 });
const option = listbox.locator('[role="option"]').first();
await option.click();
await expect(dialog.getByText(/sélectionné/i)).toBeVisible();
await dialog.getByLabel(/type de relation/i).selectOption(relationship);
await dialog.getByRole('button', { name: 'Ajouter' }).click();
@@ -99,11 +113,10 @@ test.describe('Child Selector', () => {
);
// Create parent user
const parentOutput = execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${PARENT_EMAIL} --password=${PARENT_PASSWORD} --role=ROLE_PARENT 2>&1`,
execSync(
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-user --tenant=ecole-alpha --email=${PARENT_EMAIL} --password=${PARENT_PASSWORD} --role=ROLE_PARENT --firstName=${PARENT_FIRST_NAME} --lastName=${PARENT_LAST_NAME} 2>&1`,
{ encoding: 'utf-8' }
);
parentUserId = extractUserId(parentOutput);
// Create student 1
const student1Output = execSync(
@@ -122,8 +135,8 @@ test.describe('Child Selector', () => {
// Use admin UI to link parent to both students
const page = await browser.newPage();
await loginAsAdmin(page);
await addGuardianIfNotLinked(page, student1UserId, parentUserId, 'tuteur');
await addGuardianIfNotLinked(page, student2UserId, parentUserId, 'tutrice');
await addGuardianIfNotLinked(page, student1UserId, PARENT_EMAIL, 'tuteur');
await addGuardianIfNotLinked(page, student2UserId, PARENT_EMAIL, 'tutrice');
await page.close();
});
@@ -192,7 +205,7 @@ test.describe('Child Selector', () => {
// Restore the second link via admin UI for clean state
const restorePage = await browser.newPage();
await loginAsAdmin(restorePage);
await addGuardianIfNotLinked(restorePage, student2UserId, parentUserId, 'tutrice');
await addGuardianIfNotLinked(restorePage, student2UserId, PARENT_EMAIL, 'tutrice');
await restorePage.close();
});
});