Skip to content

Commit 673c472

Browse files
committed
fix: TT-29
1 parent 083ad7d commit 673c472

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ describe('CustomerTableListComponent', () => {
104104
expect(store.dispatch).toHaveBeenCalledWith(new SetCustomerToEdit('1'));
105105
});
106106

107+
it('when you click close modal, if the idToEdit is equal currentCustomerIdToEdit should dispatch ResetCustomerToEdit', () => {
108+
109+
spyOn(store, 'dispatch');
110+
111+
component.idToEdit = '1';
112+
component.currentCustomerIdToEdit = '1';
113+
component.closeModal();
114+
115+
expect(store.dispatch).toHaveBeenCalledWith(new ResetCustomerToEdit());
116+
});
117+
107118
it('onClick delete, dispatch DeleteCustomer', () => {
108119
spyOn(store, 'dispatch');
109120
component.idToDelete = '1';
@@ -112,12 +123,12 @@ describe('CustomerTableListComponent', () => {
112123
expect(store.dispatch).toHaveBeenCalledWith(new DeleteCustomer('1'));
113124
});
114125

115-
it('onClick delete, if idToDelete is equal to idToEdit should dispatch ResetCustomerToEdit', () => {
126+
it('onClick delete, if idToDelete is equal to currentCustomerIdToEdit should dispatch ResetCustomerToEdit', () => {
116127

117128
spyOn(store, 'dispatch');
118129

119130
component.idToDelete = '1';
120-
component.idToEdit = '1';
131+
component.currentCustomerIdToEdit = '1';
121132
component.deleteCustomer();
122133

123134
expect(store.dispatch).toHaveBeenCalledWith(new ResetCustomerToEdit());

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
3939
showModal = false;
4040
idToDelete: string;
4141
idToEdit: string;
42+
currentCustomerIdToEdit: string;
4243
message: string;
4344
isLoading$: Observable<boolean>;
4445

@@ -55,7 +56,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
5556

5657
const customerIdToEdit$ = this.store.pipe(select(customerIdtoEdit));
5758
this.customerIdToEditSubscription = customerIdToEdit$.subscribe((customerId: string) => {
58-
this.idToEdit = customerId;
59+
this.currentCustomerIdToEdit = customerId;
5960
});
6061

6162
this.loadCustomersSubscription = this.actionsSubject$
@@ -110,6 +111,9 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
110111
this.showModal = false;
111112
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
112113
this.resetProjectFieldsToEdit();
114+
if (this.currentCustomerIdToEdit === this.idToEdit) {
115+
this.store.dispatch(new ResetCustomerToEdit());
116+
}
113117
this.store.dispatch(new SetCustomerToEdit(this.idToEdit));
114118
}
115119

@@ -121,7 +125,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
121125
}
122126

123127
deleteCustomer() {
124-
if (this.idToDelete === this.idToEdit) {
128+
if (this.idToDelete === this.currentCustomerIdToEdit) {
125129
this.store.dispatch(new ResetCustomerToEdit());
126130
this.resetProjectFieldsToEdit();
127131
}

0 commit comments

Comments
 (0)