feat: refactor forms to use reactive forms with signals for improved state management
This commit is contained in:
1 parent
5d2abf4184
commit
ac5a7942c9
12 files changed
+281
-213
No files matched your search
@@ -15,8 +15,8 @@ describe('ApartmentForm', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const form = fixture.componentInstance;
|
||||
expect(form.name()).toBe('T2 Paris 15');
|
||||
expect(form.purchasePrice()).toBe(250000);
|
||||
expect(form.apartmentModel().name).toBe('T2 Paris 15');
|
||||
expect(form.apartmentModel().purchasePrice).toBe(250000);
|
||||
});
|
||||
|
||||
it('shows a validation error instead of emitting an incomplete apartment', () => {
|
||||
@@ -36,10 +36,12 @@ describe('ApartmentForm', () => {
|
||||
const form = fixture.componentInstance;
|
||||
const saved = vi.fn();
|
||||
form.saved.subscribe(saved);
|
||||
form.name.set(' T2 Paris 15 ');
|
||||
form.address.set(' 45 rue des Entrepreneurs ');
|
||||
form.purchasePrice.set(250000);
|
||||
form.description.set(' Cinquième étage ');
|
||||
form.apartmentModel.set({
|
||||
name: ' T2 Paris 15 ',
|
||||
address: ' 45 rue des Entrepreneurs ',
|
||||
purchasePrice: 250000,
|
||||
description: ' Cinquième étage ',
|
||||
});
|
||||
|
||||
form.save();
|
||||
|
||||
@@ -70,15 +72,18 @@ describe('ApartmentForm', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const form = fixture.componentInstance;
|
||||
form.name.set('T2 rénové');
|
||||
form.address.set('45 rue des Entrepreneurs');
|
||||
form.purchasePrice.set(265000);
|
||||
form.apartmentModel.set({
|
||||
name: 'T2 rénové',
|
||||
address: '45 rue des Entrepreneurs',
|
||||
purchasePrice: 265000,
|
||||
description: '',
|
||||
});
|
||||
fixture.componentRef.setInput('saveError', 'Impossible d’enregistrer cet appartement.');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(fixture.nativeElement.querySelector('input[name=name]').value).toBe('T2 rénové');
|
||||
expect(fixture.nativeElement.querySelector('input[name=address]').value).toBe(
|
||||
expect(fixture.nativeElement.querySelector('input#name').value).toBe('T2 rénové');
|
||||
expect(fixture.nativeElement.querySelector('input#address').value).toBe(
|
||||
'45 rue des Entrepreneurs',
|
||||
);
|
||||
expect(fixture.nativeElement.textContent).toContain(
|
||||
|
||||
Reference in new issue
Block a user