Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: TT-29
  • Loading branch information
LEON12699 committed Apr 14, 2021
commit 673c47240b761c609d86741116b2ceba7873c87f
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ describe('CustomerTableListComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new SetCustomerToEdit('1'));
});

it('when you click close modal, if the idToEdit is equal currentCustomerIdToEdit should dispatch ResetCustomerToEdit', () => {

spyOn(store, 'dispatch');

component.idToEdit = '1';
component.currentCustomerIdToEdit = '1';
component.closeModal();

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

it('onClick delete, dispatch DeleteCustomer', () => {
spyOn(store, 'dispatch');
component.idToDelete = '1';
Expand All @@ -112,12 +123,12 @@ describe('CustomerTableListComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new DeleteCustomer('1'));
});

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

spyOn(store, 'dispatch');

component.idToDelete = '1';
component.idToEdit = '1';
component.currentCustomerIdToEdit = '1';
component.deleteCustomer();

expect(store.dispatch).toHaveBeenCalledWith(new ResetCustomerToEdit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
showModal = false;
idToDelete: string;
idToEdit: string;
currentCustomerIdToEdit: string;
message: string;
isLoading$: Observable<boolean>;

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

const customerIdToEdit$ = this.store.pipe(select(customerIdtoEdit));
this.customerIdToEditSubscription = customerIdToEdit$.subscribe((customerId: string) => {
this.idToEdit = customerId;
this.currentCustomerIdToEdit = customerId;
});

this.loadCustomersSubscription = this.actionsSubject$
Expand Down Expand Up @@ -110,6 +111,9 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
this.showModal = false;
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
this.resetProjectFieldsToEdit();
if (this.currentCustomerIdToEdit === this.idToEdit) {
this.store.dispatch(new ResetCustomerToEdit());
}
this.store.dispatch(new SetCustomerToEdit(this.idToEdit));
}

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

deleteCustomer() {
if (this.idToDelete === this.idToEdit) {
if (this.idToDelete === this.currentCustomerIdToEdit) {
this.store.dispatch(new ResetCustomerToEdit());
this.resetProjectFieldsToEdit();
}
Expand Down