Complete apartment form validation flow (#46)

This commit is contained in:
nessar committed 2026-08-17 14:18:16 +02:00
1 parent c1e7964f2e
commit d1cdc6eaeb
11 files changed
+351 -21

No files matched your search

+59
View File
@@ -259,6 +259,65 @@ test('keeps apartment add and edit workflows usable', async ({ page }) => {
await expectNoHorizontalOverflow(page);
});
test('keeps private-area validation focused and clears the structured server error on correction', async ({
page,
}) => {
const apartments: object[] = [];
let createAttempts = 0;
await mockUser(page, true);
await page.route('**/api/apartments', async (route) => {
if (route.request().method() === 'GET') {
await route.fulfill({ contentType: 'application/json', json: apartments });
return;
}
createAttempts += 1;
if (createAttempts === 1) {
await route.fulfill({
status: 400,
contentType: 'application/json',
json: {
code: 'validation_failed',
errors: [{ field: 'privateAreas[0].label', code: 'not_blank' }],
},
});
return;
}
const apartment = { id: 'apt-private-area', ...route.request().postDataJSON() };
apartments.push(apartment);
await route.fulfill({ contentType: 'application/json', json: apartment });
});
await page.goto('/');
await page
.getByTestId('primary-navigation')
.getByRole('button', { name: 'Appartements' })
.click();
await page.locator('.page-heading > .primary-action').click();
await page.getByLabel("Nom de l'appartement").fill('Studio Croix-Rousse');
await page.getByLabel('Adresse complète').fill('8 montée de la Boucle, Lyon');
await page.getByLabel("Prix d'acquisition").fill('125000');
await page.getByRole('button', { name: 'Ajouter un espace' }).click();
const label = page.getByLabel('Libellé');
await page.getByRole('button', { name: 'Enregistrer' }).click();
await expect(page.getByText('Renseignez le libellé de chaque espace privatif.')).toBeVisible();
await expect(label).toBeFocused();
expect(createAttempts).toBe(0);
await label.fill('Chambre');
await page.getByRole('button', { name: 'Enregistrer' }).click();
await expect(page.getByText('Le libellé est obligatoire.')).toBeVisible();
await label.fill('Chambre 1');
await expect(page.getByText('Le libellé est obligatoire.')).toBeHidden();
await page.getByRole('button', { name: 'Enregistrer' }).click();
await expect(page.getByRole('heading', { name: 'Studio Croix-Rousse' })).toBeVisible();
expect(createAttempts).toBe(2);
});
test('keeps the secured API check and logout available', async ({ page }) => {
let logoutMethod = '';
await mockUser(page, true);