diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html index 8279155e5..5acbefdb9 100644 --- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html +++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html @@ -8,6 +8,7 @@ formControlName="name" placeholder="Customer name" [class.is-invalid]="customerForm.invalid && customerForm.touched" + (input)="onInputChangeCustomer($event.target.value)" required /> diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts index df28e9d44..3f712e92e 100644 --- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts +++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts @@ -140,4 +140,23 @@ describe('CreateCustomerComponent', () => { expect(component.changeValueAreTabsActives.emit).toHaveBeenCalledWith(component.areTabsActive); }); + it('if detect changes in customer information, it should emit a true', () => { + component.hasChange = true; + spyOn(component.hasChangedEvent, 'emit'); + + component.onInputChangeCustomer('changes text'); + + expect(component.hasChange).toBe(true); + expect(component.hasChangedEvent.emit).toHaveBeenCalledWith(component.hasChange); + }); + + it('if not detect changes in customer information, it should emit a false', () => { + component.hasChange = false; + spyOn(component.hasChangedEvent, 'emit'); + + component.onInputChangeCustomer(''); + + expect(component.hasChange).toBe(false); + expect(component.hasChangedEvent.emit).toHaveBeenCalledWith(component.hasChange); + }); }); diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts index 9cb14ae8d..6e0c4cf05 100644 --- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts +++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts @@ -23,6 +23,8 @@ import { LoadCustomerProjects, CleanCustomerProjects } from '../../../projects/c export class CreateCustomerComponent implements OnInit, OnDestroy { customerForm: FormGroup; @Input() areTabsActive: boolean; + @Input() hasChange: boolean; + @Output() hasChangedEvent = new EventEmitter(); @Output() changeValueAreTabsActives = new EventEmitter(); @Output() closeCustomerComponent = new EventEmitter(); customerToEdit: Customer; @@ -68,6 +70,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy { this.store.dispatch(new LoadProjectTypes(customerData.id)); this.store.dispatch(new LoadCustomerProjects(customerData.id)); this.changeValueAreTabsActives.emit(true); + this.hasChangedEvent.emit(this.hasChange = false); this.customerForm.setValue({ name: customerData.name, description: customerData.description, @@ -94,4 +97,9 @@ export class CreateCustomerComponent implements OnInit, OnDestroy { this.store.dispatch(new ResetCustomerToEdit()); this.closeCustomerComponent.emit(false); } + + onInputChangeCustomer(searchValue: string): void { + return searchValue ? this.hasChangedEvent.emit(this.hasChange = true) : + this.hasChangedEvent.emit(this.hasChange = false); + } } diff --git a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html index 09b7a0b76..62db0a46f 100644 --- a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html +++ b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html @@ -20,12 +20,15 @@ {{ customer.name }} +