Align apartment core validation errors (#43)

This commit is contained in:
nessar committed 2026-08-17 14:18:16 +02:00
1 parent 878da155bd
commit b9f5540394
13 files changed
+454 -56

No files matched your search

@@ -50,7 +50,7 @@ describe('ApartmentForm', () => {
form.save();
expect(form.error()).toContain('Veuillez remplir tous les champs obligatoires');
expect(form.error()).toContain('Le nom de l’appartement est obligatoire.');
expect(saved).not.toHaveBeenCalled();
});
@@ -70,10 +70,70 @@ describe('ApartmentForm', () => {
form.save();
expect(form.error()).toContain('Veuillez remplir tous les champs obligatoires');
expect(form.nameError()).toBe('Le nom de l’appartement est obligatoire.');
expect(form.addressError()).toBe('L’adresse complète est obligatoire.');
expect(saved).not.toHaveBeenCalled();
});
it('accepts every strictly positive purchase price, including a sub-euro value', () => {
const fixture = TestBed.createComponent(ApartmentForm);
const form = fixture.componentInstance;
const saved = vi.fn();
form.saved.subscribe(saved);
form.apartmentModel.set({
name: 'T2',
address: '1 rue de Paris',
purchasePrice: 0.5,
description: '',
privateAreas: [],
legalProfile: emptyApartmentLegalProfile(),
});
form.save();
expect(saved).toHaveBeenCalledWith(expect.objectContaining({ purchasePrice: 0.5 }));
});
it('shows backend core errors beside their controls and clears one when it is edited', async () => {
const fixture = TestBed.createComponent(ApartmentForm);
const form = fixture.componentInstance;
const changed = vi.fn();
form.fieldChanged.subscribe(changed);
fixture.componentRef.setInput('saveFieldErrors', [
{ field: 'name', code: 'not_blank' },
{ field: 'address', code: 'not_blank' },
]);
fixture.detectChanges();
await fixture.whenStable();
expect(form.nameError()).toBe('Le nom de l’appartement est obligatoire.');
fixture.detectChanges();
expect(fixture.nativeElement.querySelectorAll('.field-error')[0].textContent).toContain(
'Le nom de l’appartement est obligatoire.',
);
expect(fixture.nativeElement.querySelectorAll('.field-error')[1].textContent).toContain(
'L’adresse complète est obligatoire.',
);
fixture.nativeElement.querySelector('input#name').dispatchEvent(new Event('input'));
expect(changed).toHaveBeenCalledWith('name');
});
it('keeps unknown server validation codes in the generic save alert', async () => {
const fixture = TestBed.createComponent(ApartmentForm);
fixture.componentRef.setInput('saveError', 'Veuillez corriger les champs signalés.');
fixture.componentRef.setInput('saveFieldErrors', [{ field: 'name', code: 'unknown' }]);
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('.field-error')).toBeNull();
expect(fixture.nativeElement.querySelector('.alert-error').textContent).toContain(
'Veuillez corriger les champs signalés.',
);
});
it('emits a trimmed apartment draft when valid', () => {
const fixture = TestBed.createComponent(ApartmentForm);
const form = fixture.componentInstance;