Skip to content

Commit d3156e3

Browse files
committed
fix: #232 Cancel button should hide tabs
1 parent 3b8234e commit d3156e3

File tree

8 files changed

+26
-3
lines changed

8 files changed

+26
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ describe('CreateCustomerComponent', () => {
6666

6767
it('should call resetCustomerForm', () => {
6868
spyOn(component.customerForm, 'reset');
69+
spyOn(component.closeCustomerComponent, 'emit');
6970

7071
component.resetCustomerForm();
7172

7273
expect(component.customerForm.reset).toHaveBeenCalled();
74+
expect(component.closeCustomerComponent.emit).toHaveBeenCalledWith(false);
7375
});
7476

7577
it('onSubmit, dispatch CreateCustomer and LoadCustomers actions', () => {
@@ -84,12 +86,14 @@ describe('CreateCustomerComponent', () => {
8486
it('should call resetCustomerForm', () => {
8587
spyOn(component.customerForm, 'reset');
8688
spyOn(store, 'dispatch');
89+
spyOn(component.closeCustomerComponent, 'emit');
8790

8891
component.resetCustomerForm();
8992

9093
expect(store.dispatch).toHaveBeenCalledTimes(1);
9194
expect(store.dispatch).toHaveBeenCalledWith(new ResetCustomerToEdit());
9295
expect(component.customerForm.reset).toHaveBeenCalled();
96+
expect(component.closeCustomerComponent.emit).toHaveBeenCalledWith(false);
9397
});
9498

9599
it('should be enable tabs and show message Customer created successfully! ', () => {

src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
2424
customerForm: FormGroup;
2525
@Input() areTabsActive: boolean;
2626
@Output() changeValueAreTabsActives = new EventEmitter<boolean>();
27+
@Output() closeCustomerComponent = new EventEmitter<boolean>();
2728
customerToEdit: Customer;
2829
editSubscription: Subscription;
2930

@@ -88,5 +89,6 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
8889
resetCustomerForm() {
8990
this.customerForm.reset();
9091
this.store.dispatch(new ResetCustomerToEdit());
92+
this.closeCustomerComponent.emit(false);
9193
}
9294
}

src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<app-create-customer
5252
[areTabsActive]="areTabsActive"
5353
(changeValueAreTabsActives)="activeTabs($event)"
54+
(closeCustomerComponent)="closeCustomer($event)"
5455
></app-create-customer>
5556
</div>
5657
<div

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ describe('ManagmentCustomerProjectsComponent', () => {
4848
component.showTab('projects');
4949
expect(component.activeTab).toEqual('projects');
5050
});
51+
it('should call close customer function', () => {
52+
spyOn(component.closeCustemerForm, 'emit');
53+
component.closeCustomer(false);
54+
expect(component.closeCustemerForm.emit).toHaveBeenCalledWith(false);
55+
});
5156
});

src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Component } from '@angular/core';
1+
import { Component, Output, EventEmitter } from '@angular/core';
22

33
@Component({
44
selector: 'app-management-customer-projects',
55
templateUrl: './management-customer-projects.component.html',
66
styleUrls: ['./management-customer-projects.component.scss'],
77
})
88
export class ManagementCustomerProjectsComponent {
9+
@Output() closeCustemerForm = new EventEmitter<boolean>();
910
areTabsActive: boolean;
1011
activeTab: string;
1112
constructor() {}
@@ -17,6 +18,10 @@ export class ManagementCustomerProjectsComponent {
1718
}, 1);
1819
}
1920

21+
closeCustomer(event) {
22+
this.closeCustemerForm.emit(event);
23+
}
24+
2025
showTab(activeTab: string) {
2126
this.activeTab = activeTab;
2227
}

src/app/modules/customer-management/pages/customer.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
></app-customer-list>
1111
<div class="row" *ngIf="showCustomerForm">
1212
<div class="col">
13-
<app-management-customer-projects></app-management-customer-projects>
13+
<app-management-customer-projects (closeCustemerForm)="closeCustomerForm($event)"></app-management-customer-projects>
1414
</div>
1515
</div>
1616
</div>

src/app/modules/customer-management/pages/customer.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ describe('CustomerComponent', () => {
2727
component.activateCustomerForm();
2828
expect(component.showCustomerForm).toBeTruthy();
2929
});
30+
it('should call close customer function', () => {
31+
component.closeCustomerForm(false);
32+
expect(component.showCustomerForm).toBe(false);
33+
});
3034
});

src/app/modules/customer-management/pages/customer.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { Component } from '@angular/core';
66
styleUrls: ['./customer.component.scss'],
77
})
88
export class CustomerComponent {
9-
109
showCustomerForm = false;
1110

1211
activateCustomerForm() {
1312
this.showCustomerForm = true;
1413
}
14+
closeCustomerForm(event) {
15+
this.showCustomerForm = event;
16+
}
1517
}

0 commit comments

Comments
 (0)