Skip to content

Commit df2761a

Browse files
authored
Merge pull request #570 from ioet/563_cannotCreateProject
closes: #563
2 parents 6648ce2 + d5b177c commit df2761a

File tree

6 files changed

+62
-34
lines changed

6 files changed

+62
-34
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
} from 'src/app/modules/customer-management/store';
1313
import { DataTablesModule } from 'angular-datatables';
1414
import { ActionsSubject } from '@ngrx/store';
15+
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
16+
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
1517

1618
describe('CustomerTableListComponent', () => {
1719
let component: CustomerListComponent;
@@ -65,6 +67,15 @@ describe('CustomerTableListComponent', () => {
6567
expect(component.showCustomerForm).toBeTruthy();
6668
});
6769

70+
it('onClick edit, dispatch clean Forms in project and project type', () => {
71+
spyOn(store, 'dispatch');
72+
73+
component.editCustomer('1');
74+
75+
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectToEdit());
76+
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectTypeToEdit());
77+
});
78+
6879
it('onClick delete, dispatch DeleteCustomer', () => {
6980
spyOn(store, 'dispatch');
7081
component.idToDelete = '1';
@@ -121,7 +132,7 @@ describe('CustomerTableListComponent', () => {
121132
const actionSubject = TestBed.inject(ActionsSubject);
122133
const action = {
123134
type: CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS,
124-
payload: state.data
135+
payload: state.data,
125136
};
126137
spyOn(component.dtElement.dtInstance, 'then');
127138

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ import {
99
CustomerManagementActionTypes,
1010
DeleteCustomer,
1111
LoadCustomers,
12-
SetCustomerToEdit
12+
SetCustomerToEdit,
1313
} from './../../../../store/customer-management.actions';
14+
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
15+
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
1416
@Component({
1517
selector: 'app-customer-list',
1618
templateUrl: './customer-list.component.html',
1719
styleUrls: ['./customer-list.component.scss'],
1820
})
1921
export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
20-
2122
@Input() showCustomerForm: boolean;
2223
@Output() changeValueShowCustomerForm = new EventEmitter<boolean>();
2324
@Input()
2425
customers: Customer[] = [];
2526
dtOptions: any = {};
2627
dtTrigger: Subject<any> = new Subject();
27-
@ViewChild(DataTableDirective, {static: false})
28+
@ViewChild(DataTableDirective, { static: false })
2829
dtElement: DataTableDirective;
2930
loadCustomersSubscription: Subscription;
3031
changeCustomerSubscription: Subscription;
@@ -40,33 +41,32 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
4041
ngOnInit(): void {
4142
this.dtOptions = {
4243
scrollY: '290px',
43-
paging: false
44+
paging: false,
4445
};
45-
this.loadCustomersSubscription = this.actionsSubject$.pipe(
46-
filter((action: any) => (
47-
action.type === CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS
48-
)
49-
)
50-
).subscribe((action) => {
51-
this.customers = action.payload;
52-
this.rerenderDataTable();
53-
});
46+
this.loadCustomersSubscription = this.actionsSubject$
47+
.pipe(filter((action: any) => action.type === CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS))
48+
.subscribe((action) => {
49+
this.customers = action.payload;
50+
this.rerenderDataTable();
51+
});
5452

55-
this.changeCustomerSubscription = this.actionsSubject$.pipe(
56-
filter((action: any) => (
57-
action.type === CustomerManagementActionTypes.DELETE_CUSTOMER_SUCCESS ||
58-
action.type === CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS ||
59-
action.type === CustomerManagementActionTypes.CREATE_CUSTOMER_SUCCESS
53+
this.changeCustomerSubscription = this.actionsSubject$
54+
.pipe(
55+
filter(
56+
(action: any) =>
57+
action.type === CustomerManagementActionTypes.DELETE_CUSTOMER_SUCCESS ||
58+
action.type === CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS ||
59+
action.type === CustomerManagementActionTypes.CREATE_CUSTOMER_SUCCESS
6060
)
6161
)
62-
).subscribe((action) => {
63-
this.store.dispatch(new LoadCustomers());
64-
this.showCustomerForm = false;
65-
});
62+
.subscribe((action) => {
63+
this.store.dispatch(new LoadCustomers());
64+
this.showCustomerForm = false;
65+
});
6666
this.store.dispatch(new LoadCustomers());
6767
}
6868

69-
ngAfterViewInit(): void {
69+
ngAfterViewInit(): void {
7070
this.rerenderDataTable();
7171
}
7272

@@ -80,6 +80,12 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
8080
this.showCustomerForm = true;
8181
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
8282
this.store.dispatch(new SetCustomerToEdit(customerId));
83+
this.resetProjectFieldsToEdit();
84+
}
85+
86+
private resetProjectFieldsToEdit() {
87+
this.store.dispatch(new ResetProjectToEdit());
88+
this.store.dispatch(new ResetProjectTypeToEdit());
8389
}
8490

8591
deleteCustomer() {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ describe('InputProjectTypeComponent', () => {
4141
beforeEach(async(() => {
4242
TestBed.configureTestingModule({
4343
declarations: [CreateProjectTypeComponent],
44-
providers: [
45-
FormBuilder,
46-
provideMockStore({ initialState: state })
47-
],
44+
providers: [FormBuilder, provideMockStore({ initialState: state })],
4845
}).compileComponents();
4946
}));
5047

@@ -153,6 +150,14 @@ describe('InputProjectTypeComponent', () => {
153150
expect(component.projectTypeForm.setValue).toHaveBeenCalledWith(projectTypeDataForm);
154151
});
155152

153+
it('shoud reset Project Type Form before set the data to Edit', () => {
154+
spyOn(component.projectTypeForm, 'reset');
155+
156+
component.setDataToUpdate(projectType);
157+
158+
expect(component.projectTypeForm.reset).toHaveBeenCalled();
159+
});
160+
156161
it('should dispatch a ResetProjectTypeToEdit action', () => {
157162
spyOn(store, 'dispatch');
158163

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
1919
customerId: string;
2020
getCustomerIdSubscription: Subscription;
2121

22-
constructor(private formBuilder: FormBuilder,
23-
private store: Store<ProjectTypeState>) {
22+
constructor(private formBuilder: FormBuilder, private store: Store<ProjectTypeState>) {
2423
this.projectTypeForm = this.formBuilder.group({
2524
name: ['', Validators.required],
2625
description: [''],
@@ -47,6 +46,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
4746
}
4847

4948
setDataToUpdate(projectTypeData: ProjectType) {
49+
this.projectTypeForm.reset();
5050
if (projectTypeData) {
5151
this.projectTypeForm.setValue({
5252
name: projectTypeData.name,

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ describe('InputProjectComponent', () => {
3838
beforeEach(async(() => {
3939
TestBed.configureTestingModule({
4040
declarations: [CreateProjectComponent],
41-
providers: [
42-
FormBuilder,
43-
provideMockStore({ initialState: state })
44-
],
41+
providers: [FormBuilder, provideMockStore({ initialState: state })],
4542
}).compileComponents();
4643
}));
4744

@@ -233,6 +230,14 @@ describe('InputProjectComponent', () => {
233230
expect(component.projectForm.setValue).toHaveBeenCalledWith(projectForm);
234231
});
235232

233+
it('shoud reset Project Form before set the data to Edit', () => {
234+
spyOn(component.projectForm, 'reset');
235+
236+
component.setDataToUpdate(project);
237+
238+
expect(component.projectForm.reset).toHaveBeenCalled();
239+
});
240+
236241
it('should dispatch a ResetActivityToEdit action', () => {
237242
spyOn(store, 'dispatch');
238243

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class CreateProjectComponent implements OnInit, OnDestroy {
8686
}
8787

8888
setDataToUpdate(projectData: Project) {
89+
this.projectForm.reset();
8990
if (projectData) {
9091
this.projectForm.setValue({
9192
name: projectData.name,

0 commit comments

Comments
 (0)