Validate private areas across apartment form (#44)
This commit is contained in:
1 parent
b9f5540394
commit
72d3f0ccfa
9 files changed
+323
-44
No files matched your search
@@ -94,6 +94,68 @@ describe('ApartmentForm', () => {
|
||||
expect(saved).toHaveBeenCalledWith(expect.objectContaining({ purchasePrice: 0.5 }));
|
||||
});
|
||||
|
||||
it('keeps invalid private-area cards visible, shows their inline error, and focuses the label', async () => {
|
||||
const fixture = TestBed.createComponent(ApartmentForm);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const form = fixture.componentInstance;
|
||||
const saved = vi.fn();
|
||||
form.saved.subscribe(saved);
|
||||
form.apartmentModel.set({
|
||||
name: 'Studio',
|
||||
address: '1 rue du Test',
|
||||
purchasePrice: 1,
|
||||
description: '',
|
||||
privateAreas: [
|
||||
{ id: 'area-1', family: 'PIECE_PRINCIPALE', subtype: 'OTHER', label: ' ' },
|
||||
],
|
||||
legalProfile: emptyApartmentLegalProfile(),
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
form.save();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(saved).not.toHaveBeenCalled();
|
||||
expect(form.error()).toContain('Renseignez le libellé de chaque espace privatif.');
|
||||
expect(fixture.nativeElement.querySelectorAll('mat-card')).toHaveLength(1);
|
||||
expect(fixture.nativeElement.textContent).toContain('Le libellé est obligatoire.');
|
||||
expect(document.activeElement).toBe(
|
||||
fixture.nativeElement.querySelector('.private-area-label'),
|
||||
);
|
||||
});
|
||||
|
||||
it('forwards only the edited private-area server error path', async () => {
|
||||
const fixture = TestBed.createComponent(ApartmentForm);
|
||||
fixture.componentRef.setInput('saveFieldErrors', [
|
||||
{ field: 'privateAreas[0].label', code: 'not_blank' },
|
||||
{ field: 'privateAreas[0].subtypeCompatibleWithFamily', code: 'assert_true' },
|
||||
]);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const changed = vi.fn();
|
||||
fixture.componentInstance.fieldChanged.subscribe(changed);
|
||||
fixture.componentInstance.apartmentModel.set({
|
||||
name: 'Studio',
|
||||
address: '1 rue du Test',
|
||||
purchasePrice: 1,
|
||||
description: '',
|
||||
privateAreas: [
|
||||
{ id: 'area-1', family: 'PIECE_PRINCIPALE', subtype: 'OTHER', label: 'Séjour' },
|
||||
],
|
||||
legalProfile: emptyApartmentLegalProfile(),
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement
|
||||
.querySelector('.private-area-label')
|
||||
.dispatchEvent(new Event('input'));
|
||||
|
||||
expect(changed).toHaveBeenCalledTimes(1);
|
||||
expect(changed).toHaveBeenCalledWith('privateAreas[0].label');
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user