Skip to content

Commit e5c051d

Browse files
authored
fix: TT-203 Customers Page: review the actions to ResetProjectToEdit … (#659)
* fix: TT-203 Customers Page: review the actions to ResetProjectToEdit and ResetProjectTypeToEdit * fix: TT-203 add blank lines and change test name
1 parent 3326b1e commit e5c051d

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +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';
15+
import { ResetProjectToEdit, SetProjectToEdit } from '../../../projects/components/store/project.actions';
16+
import { ResetProjectTypeToEdit, SetProjectTypeToEdit } from '../../../projects-type/store';
1717

1818
describe('CustomerTableListComponent', () => {
1919
let component: CustomerListComponent;
@@ -58,7 +58,6 @@ describe('CustomerTableListComponent', () => {
5858
expect(store.dispatch).toHaveBeenCalledWith(new LoadCustomers());
5959
});
6060

61-
6261
it('Onclick Edit, if there are changes, the modal must be presented ', () => {
6362
component.hasChange = true;
6463
const expectMessage = 'Do you have changes in a client, do you want to discard them?';
@@ -86,6 +85,8 @@ describe('CustomerTableListComponent', () => {
8685

8786
component.editCustomer('1');
8887

88+
expect(store.dispatch).toHaveBeenCalledWith(new SetProjectToEdit(null));
89+
expect(store.dispatch).toHaveBeenCalledWith(new SetProjectTypeToEdit(null));
8990
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectToEdit());
9091
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectTypeToEdit());
9192
});

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import {
1111
LoadCustomers,
1212
SetCustomerToEdit,
1313
} from './../../../../store/customer-management.actions';
14-
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
15-
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
14+
import { ResetProjectToEdit, SetProjectToEdit } from '../../../projects/components/store/project.actions';
15+
import { ResetProjectTypeToEdit, SetProjectTypeToEdit } from '../../../projects-type/store';
16+
1617
@Component({
1718
selector: 'app-customer-list',
1819
templateUrl: './customer-list.component.html',
@@ -101,6 +102,8 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
101102
}
102103

103104
private resetProjectFieldsToEdit() {
105+
this.store.dispatch(new SetProjectTypeToEdit(null));
106+
this.store.dispatch(new SetProjectToEdit(null));
104107
this.store.dispatch(new ResetProjectToEdit());
105108
this.store.dispatch(new ResetProjectTypeToEdit());
106109
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { FormBuilder } from '@angular/forms';
33
import { provideMockStore, MockStore } from '@ngrx/store/testing';
4-
4+
import { ReactiveFormsModule } from '@angular/forms';
55
import { CreateProjectTypeComponent } from './create-project-type.component';
66
import {
77
ProjectTypeState,
@@ -40,6 +40,7 @@ describe('InputProjectTypeComponent', () => {
4040

4141
beforeEach(waitForAsync(() => {
4242
TestBed.configureTestingModule({
43+
imports: [ReactiveFormsModule],
4344
declarations: [CreateProjectTypeComponent],
4445
providers: [FormBuilder, provideMockStore({ initialState: state })],
4546
}).compileComponents();
@@ -121,6 +122,15 @@ describe('InputProjectTypeComponent', () => {
121122
expect(store.dispatch).toHaveBeenCalledWith(new CreateProjectType(projectTypeData));
122123
});
123124

125+
it('should reset projectTypeForm if projectTypeIdToEdit is null', () => {
126+
127+
spyOn(component.projectTypeForm, 'reset');
128+
129+
store.overrideSelector(projectTypeIdToEdit, null);
130+
store.refreshState();
131+
expect(component.projectTypeForm.reset).toHaveBeenCalled();
132+
});
133+
124134
it('should get name using projectTypeForm', () => {
125135
spyOn(component.projectTypeForm, 'get');
126136
// tslint:disable-next-line:no-unused-expression

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FormBuilder, Validators, FormGroup } from '@angular/forms';
33
import { Store, select } from '@ngrx/store';
44

55
import { ProjectType } from '../../../../../shared/models';
6-
import { ProjectTypeState } from '../../store';
6+
import { projectTypeIdToEdit, ProjectTypeState } from '../../store';
77
import { CreateProjectType, ResetProjectTypeToEdit, UpdateProjectType, getProjectTypeById } from '../../store';
88
import { getCustomerId } from 'src/app/modules/customer-management/store/customer-management.selectors';
99
import { Subscription } from 'rxjs';
@@ -20,6 +20,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
2020
projectTypeToEdit: ProjectType;
2121
customerId: string;
2222
getCustomerIdSubscription: Subscription;
23+
projectTypeIdToEditSubscription: Subscription;
2324

2425
constructor(private formBuilder: FormBuilder, private store: Store<ProjectTypeState>) {
2526
this.projectTypeForm = this.formBuilder.group({
@@ -29,6 +30,13 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
2930
}
3031

3132
ngOnInit(): void {
33+
const projectTypeIdToEdit$ = this.store.pipe(select(projectTypeIdToEdit));
34+
this.projectTypeIdToEditSubscription = projectTypeIdToEdit$.subscribe((projectTypeId: string) => {
35+
if (projectTypeId === null) {
36+
this.projectTypeForm.reset();
37+
}
38+
});
39+
3240
const projectType$ = this.store.pipe(select(getProjectTypeById));
3341
projectType$.subscribe((projectType) => {
3442
this.projectTypeToEdit = projectType;
@@ -79,6 +87,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
7987

8088
ngOnDestroy(): void {
8189
this.getCustomerIdSubscription.unsubscribe();
90+
this.projectTypeIdToEditSubscription.unsubscribe();
8291
}
8392

8493
onInputChangeProjectType(searchValue: string): void {

src/app/modules/customer-management/components/projects-type/store/project-type.selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { ProjectTypeState } from './project-type.reducers';
55
const getProjectTypeState = createFeatureSelector<ProjectTypeState>('projectType');
66

77
export const allProjectTypes = createSelector(getProjectTypeState, (state: ProjectTypeState) => {
8-
return state.data;
8+
return state?.data;
99
});
1010

1111
export const projectTypeIdToEdit = createSelector(getProjectTypeState, (state: ProjectTypeState) => {
12-
return state.projectTypeIdToEdit;
12+
return state?.projectTypeIdToEdit;
1313
});
1414

1515
export const getProjectTypeById = createSelector(

0 commit comments

Comments
 (0)