Skip to content

Commit 9bf4304

Browse files
committed
fix: #198 include all list projects on time-clock
1 parent 7a77d36 commit 9bf4304

File tree

19 files changed

+175
-81
lines changed

19 files changed

+175
-81
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Activity } from '../../shared/models';
55
import { ActivityService } from './../services/activity.service';
66
import { ActivitiesManagementComponent } from './activities-management.component';
77
import { ActionsSubject } from '@ngrx/store';
8+
import { ActivityManagementActionTypes } from '../store';
89

910
describe('ActivitiesManagementComponent', () => {
1011
let component: ActivitiesManagementComponent;
@@ -45,6 +46,12 @@ describe('ActivitiesManagementComponent', () => {
4546
expect(component.setDataNotification).toHaveBeenCalledWith(action.type);
4647
});
4748

49+
it('has a succesfull message on CREATE_ACTIVITY_SUCCESS', () => {
50+
component.setDataNotification(ActivityManagementActionTypes.CREATE_ACTIVITY_SUCCESS);
51+
52+
expect(component.notificationMsg).toBe('The activity has been saved successfully.');
53+
});
54+
4855
it('should destroy the subscription', () => {
4956
component.actionsSubscription = new Subscription();
5057
const subscription = spyOn(component.actionsSubscription, 'unsubscribe');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ResetCustomerToEdit,
1313
} from 'src/app/modules/customer-management/store';
1414
import { LoadProjectTypes } from '../../../projects-type/store';
15-
import { LoadProjects } from '../../../projects/components/store/project.actions';
15+
import { LoadCustomerProjects } from '../../../projects/components/store/project.actions';
1616

1717
@Component({
1818
selector: 'app-create-customer',
@@ -86,7 +86,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
8686
setDataToUpdate(customerData: Customer) {
8787
if (customerData) {
8888
this.store.dispatch(new LoadProjectTypes(customerData.id));
89-
this.store.dispatch(new LoadProjects(customerData.id));
89+
this.store.dispatch(new LoadCustomerProjects(customerData.id));
9090
this.changeValueAreTabsActives.emit(true);
9191
this.customerForm.setValue({
9292
name: customerData.name,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ describe('InputProjectComponent', () => {
1515
let getProjectToEditMock;
1616

1717
const state = {
18-
projectList: [{ id: '', name: '', project_type_id: '' }],
18+
projects: [{ id: '', name: '', project_type_id: '' }],
19+
customerProjects: [{ id: '', name: '', project_type_id: '' }],
1920
isLoading: false,
2021
message: '',
2122
projectToEdit: undefined,
@@ -75,6 +76,8 @@ describe('InputProjectComponent', () => {
7576

7677
it('should reset form #onSubmit and dispatch UpdateProject action', () => {
7778
const currentState = {
79+
projects: [],
80+
customerProjects: [],
7881
data: [project],
7982
isLoading: false,
8083
message: '',

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1+
import { getProjects } from './../store/project.selectors';
12
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
23
import { MockStore, provideMockStore } from '@ngrx/store/testing';
34
import { NgxPaginationModule } from 'ngx-pagination';
45
import { Subscription } from 'rxjs';
56
import { ProjectListComponent } from './project-list.component';
67
import { ProjectState } from '../store/project.reducer';
7-
import { allProjects } from '../store/project.selectors';
8+
import { getCustomerProjects } from '../store/project.selectors';
89
import { SetProjectToEdit, DeleteProject } from '../store/project.actions';
910
import { FilterProjectPipe } from '../../../../../shared/pipes';
1011

1112
describe('ProjectListComponent', () => {
1213
let component: ProjectListComponent;
1314
let fixture: ComponentFixture<ProjectListComponent>;
1415
let store: MockStore<ProjectState>;
15-
let allProjectsSelectorMock;
16+
let getCustomerProjectsSelectorMock;
17+
let allCustomerProjectsSelectorMock;
1618

17-
const state = {
18-
projectList: [{ id: 'id', name: 'name', project_type_id: '' }],
19+
const state: ProjectState = {
20+
projects: [],
21+
customerProjects: [],
1922
isLoading: false,
2023
message: '',
2124
projectToEdit: undefined,
2225
};
2326

2427
const project = { id: '123', name: 'aaa', description: 'xxx', project_type_id: '1234' };
2528

26-
beforeEach(async(() => {
29+
beforeEach(
30+
() => {
2731
TestBed.configureTestingModule({
2832
imports: [NgxPaginationModule],
2933
declarations: [ProjectListComponent, FilterProjectPipe],
3034
providers: [provideMockStore({ initialState: state })],
3135
}).compileComponents();
32-
}));
3336

34-
beforeEach(() => {
3537
fixture = TestBed.createComponent(ProjectListComponent);
3638
component = fixture.componentInstance;
37-
fixture.detectChanges();
3839

3940
store = TestBed.inject(MockStore);
4041
store.setState(state);
41-
allProjectsSelectorMock = store.overrideSelector(allProjects, state);
42+
getCustomerProjectsSelectorMock = store.overrideSelector(getCustomerProjects, state);
43+
allCustomerProjectsSelectorMock = store.overrideSelector(getProjects, state.projects);
4244
component.projectsSubscription = new Subscription();
4345
});
4446

@@ -50,6 +52,12 @@ describe('ProjectListComponent', () => {
5052
expect(component).toBeTruthy();
5153
});
5254

55+
it('loads projects from state onInit', () => {
56+
component.ngOnInit();
57+
58+
expect(component.projects).toBe(state.customerProjects);
59+
});
60+
5361
it('should destroy the subscriptions', () => {
5462
component.projectsSubscription = new Subscription();
5563
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');
@@ -60,10 +68,12 @@ describe('ProjectListComponent', () => {
6068
});
6169

6270
it('updateProject, should dispatch SetProjectToEdit action', () => {
71+
spyOn(store, 'dispatch');
6372
component.projectsSubscription = new Subscription();
6473
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');
65-
spyOn(store, 'dispatch');
74+
6675
component.updateProject(project);
76+
6777
component.ngOnDestroy();
6878

6979
expect(subscription).toHaveBeenCalledTimes(1);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Subscription } from 'rxjs';
44
import { ITEMS_PER_PAGE } from 'src/environments/environment';
55
import { Project } from 'src/app/modules/shared/models';
66
import { ProjectState } from '../store/project.reducer';
7-
import { allProjects } from '../store/project.selectors';
7+
import { getCustomerProjects } from '../store/project.selectors';
88
import * as actions from '../store/project.actions';
99

1010
@Component({
@@ -24,10 +24,10 @@ export class ProjectListComponent implements OnInit, OnDestroy {
2424
constructor(private store: Store<ProjectState>) {}
2525

2626
ngOnInit(): void {
27-
const projects$ = this.store.pipe(select(allProjects));
27+
const projects$ = this.store.pipe(select(getCustomerProjects));
2828
this.projectsSubscription = projects$.subscribe((response) => {
2929
this.isLoading = response.isLoading;
30-
this.projects = response.projectList;
30+
this.projects = response.customerProjects;
3131
});
3232
}
3333

src/app/modules/customer-management/components/projects/components/services/project.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class ProjectService {
1818
return this.http.get<Project[]>(this.url, { params });
1919
}
2020

21+
getAllProjects(): Observable<Project[]> {
22+
return this.http.get<Project[]>(this.url);
23+
}
24+
2125
createProject(projectData): Observable<any> {
2226
return this.http.post<Project[]>(this.url, projectData);
2327
}

src/app/modules/customer-management/components/projects/components/store/project.actions.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as actions from './project.actions';
22

33
describe('Actions for Projects', () => {
4-
it('LoadProjectsSuccess type is ProjectActionTypes.LOAD_PROJECTS_SUCCESS', () => {
5-
const loadProjectsSuccess = new actions.LoadProjectsSuccess([]);
6-
expect(loadProjectsSuccess.type).toEqual(actions.ProjectActionTypes.LOAD_PROJECTS_SUCCESS);
4+
it('LoadCustomerProjectsSuccess type is ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS', () => {
5+
const LoadCustomerProjectsSuccess = new actions.LoadCustomerProjectsSuccess([]);
6+
expect(LoadCustomerProjectsSuccess.type).toEqual(actions.ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS);
77
});
88

9-
it('LoadProjectsFail type is ProjectActionTypes.LOAD_PROJECTS_FAIL', () => {
10-
const loadProjectsFail = new actions.LoadProjectsFail('error');
11-
expect(loadProjectsFail.type).toEqual(actions.ProjectActionTypes.LOAD_PROJECTS_FAIL);
9+
it('LoadCustomerProjectsFail type is ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL', () => {
10+
const LoadCustomerProjectsFail = new actions.LoadCustomerProjectsFail('error');
11+
expect(LoadCustomerProjectsFail.type).toEqual(actions.ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL);
1212
});
1313

1414
it('CreateProjectSuccess type is ProjectActionTypes.CREATE_PROJECT_SUCCESS', () => {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export enum ProjectActionTypes {
55
LOAD_PROJECTS = '[Projects] LOAD_PROJECTS',
66
LOAD_PROJECTS_SUCCESS = '[Projects] LOAD_PROJECTS_SUCCESS',
77
LOAD_PROJECTS_FAIL = '[Projects] LOAD_PROJECTS_FAIL',
8+
LOAD_CUSTOMER_PROJECTS = '[Projects] LOAD_CUSTOMER_PROJECTS',
9+
LOAD_CUSTOMER_PROJECTS_SUCCESS = '[Projects] LOAD_CUSTOMER_PROJECTS_SUCCESS',
10+
LOAD_CUSTOMER_PROJECTS_FAIL = '[Projects] LOAD_CUSTOMER_PROJECTS_FAIL',
811
CREATE_PROJECT = '[Projects] CREATE_PROJECT',
912
CREATE_PROJECT_SUCCESS = '[Projects] CREATE_PROJECT_SUCCESS',
1013
CREATE_PROJECT_FAIL = '[Projects] CREATE_PROJECT_FAIL',
@@ -20,7 +23,7 @@ export enum ProjectActionTypes {
2023

2124
export class LoadProjects implements Action {
2225
public readonly type = ProjectActionTypes.LOAD_PROJECTS;
23-
constructor(public customerId?: string) {}
26+
constructor() {}
2427
}
2528

2629
export class LoadProjectsSuccess implements Action {
@@ -30,7 +33,22 @@ export class LoadProjectsSuccess implements Action {
3033

3134
export class LoadProjectsFail implements Action {
3235
public readonly type = ProjectActionTypes.LOAD_PROJECTS_FAIL;
36+
constructor(public error: string) {}
37+
}
38+
39+
40+
export class LoadCustomerProjects implements Action {
41+
public readonly type = ProjectActionTypes.LOAD_CUSTOMER_PROJECTS;
42+
constructor(public customerId: string) {}
43+
}
44+
45+
export class LoadCustomerProjectsSuccess implements Action {
46+
readonly type = ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS;
47+
constructor(readonly payload: Project[]) {}
48+
}
3349

50+
export class LoadCustomerProjectsFail implements Action {
51+
public readonly type = ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL;
3452
constructor(public error: string) {}
3553
}
3654

@@ -102,6 +120,9 @@ export type ProjectActions =
102120
| LoadProjects
103121
| LoadProjectsSuccess
104122
| LoadProjectsFail
123+
| LoadCustomerProjects
124+
| LoadCustomerProjectsSuccess
125+
| LoadCustomerProjectsFail
105126
| CreateProject
106127
| CreateProjectSuccess
107128
| CreateProjectFail

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@ export class ProjectEffects {
1313
@Effect()
1414
loadProjects$: Observable<Action> = this.actions$.pipe(
1515
ofType(actions.ProjectActionTypes.LOAD_PROJECTS),
16+
mergeMap(() =>
17+
this.projectService.getAllProjects().pipe(
18+
map((projects) => {
19+
return new actions.LoadProjectsSuccess(projects);
20+
}),
21+
catchError((error) => of(new actions.LoadProjectsFail(error)))
22+
)
23+
)
24+
);
25+
26+
@Effect()
27+
loadCustomerProjects$: Observable<Action> = this.actions$.pipe(
28+
ofType(actions.ProjectActionTypes.LOAD_CUSTOMER_PROJECTS),
1629
mergeMap((customerId) =>
1730
this.projectService.getProjects(customerId).pipe(
1831
map((project) => {
19-
return new actions.LoadProjectsSuccess(project);
32+
return new actions.LoadCustomerProjectsSuccess(project);
2033
}),
21-
catchError((error) => of(new actions.LoadProjectsFail(error)))
34+
catchError((error) => of(new actions.LoadCustomerProjectsFail(error)))
2235
)
2336
)
2437
);

src/app/modules/customer-management/components/projects/components/store/project.reducer.spec.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ import * as actions from './project.actions';
33
import { projectReducer, ProjectState } from './project.reducer';
44

55
describe('projectReducer', () => {
6-
const initialState: ProjectState = { projectList: [], isLoading: false, message: '', projectToEdit: undefined };
6+
const initialState: ProjectState = {
7+
projects: [{ id: 'id', name: 'name', project_type_id: '' }],
8+
customerProjects: [], isLoading: false, message: '', projectToEdit: undefined
9+
};
710
const project: Project = { id: '1', name: 'aaa', description: 'bbb', project_type_id: '123' };
811

912
it('on LoadProjects, isLoading is true', () => {
10-
const action = new actions.LoadProjects();
13+
const action = new actions.LoadCustomerProjects('1');
1114
const state = projectReducer(initialState, action);
1215
expect(state.isLoading).toEqual(true);
1316
});
1417

15-
it('on LoadProjectsSuccess, projectsFound are saved in the store', () => {
18+
it('on LoadCustomerProjectsSuccess, projectsFound are saved in the store', () => {
1619
const projectsFound: Project[] = [{ id: '', name: '', description: '', project_type_id: '123' }];
17-
const action = new actions.LoadProjectsSuccess(projectsFound);
20+
const action = new actions.LoadCustomerProjectsSuccess(projectsFound);
1821
const state = projectReducer(initialState, action);
19-
expect(state.projectList).toEqual(projectsFound);
22+
expect(state.customerProjects).toEqual(projectsFound);
2023
});
2124

22-
it('on LoadProjectsFail, projectList equal []', () => {
23-
const action = new actions.LoadProjectsFail('error');
25+
it('on LoadCustomerProjectsFail, customerProjects equal []', () => {
26+
const action = new actions.LoadCustomerProjectsFail('error');
2427
const state = projectReducer(initialState, action);
25-
expect(state.projectList).toEqual([]);
28+
expect(state.customerProjects).toEqual([]);
2629
});
2730

2831
it('on CreateProject, isLoading is true', () => {
@@ -36,15 +39,15 @@ describe('projectReducer', () => {
3639
const action = new actions.CreateProjectSuccess(project);
3740
const state = projectReducer(initialState, action);
3841

39-
expect(state.projectList).toEqual([project]);
42+
expect(state.customerProjects).toEqual([project]);
4043
expect(state.isLoading).toEqual(false);
4144
});
4245

43-
it('on CreateProjectFail, projectList equal []', () => {
46+
it('on CreateProjectFail, customerProjects equal []', () => {
4447
const action = new actions.CreateProjectFail('error');
4548
const state = projectReducer(initialState, action);
4649

47-
expect(state.projectList).toEqual([]);
50+
expect(state.customerProjects).toEqual([]);
4851
expect(state.isLoading).toEqual(false);
4952
});
5053

@@ -57,23 +60,24 @@ describe('projectReducer', () => {
5760

5861
it('on UpdateProjectSuccess, project is saved in the store', () => {
5962
const currentState: ProjectState = {
60-
projectList: [project],
63+
projects: [project],
64+
customerProjects: [project],
6165
isLoading: false,
6266
message: '',
6367
projectToEdit: project,
6468
};
6569
const action = new actions.UpdateProjectSuccess(project);
6670
const state = projectReducer(currentState, action);
6771

68-
expect(state.projectList).toEqual([project]);
72+
expect(state.customerProjects).toEqual([project]);
6973
expect(state.isLoading).toEqual(false);
7074
});
7175

72-
it('on UpdateProjectFail, projectList equal []', () => {
76+
it('on UpdateProjectFail, customerProjects equal []', () => {
7377
const action = new actions.UpdateProjectFail('error');
7478
const state = projectReducer(initialState, action);
7579

76-
expect(state.projectList).toEqual([]);
80+
expect(state.customerProjects).toEqual(state.customerProjects);
7781
expect(state.isLoading).toEqual(false);
7882
});
7983

@@ -106,7 +110,8 @@ describe('projectReducer', () => {
106110

107111
it('on DeleteProjectSuccess, message equal to Project removed successfully!', () => {
108112
const currentState: ProjectState = {
109-
projectList: [project],
113+
projects: [project],
114+
customerProjects: [project],
110115
isLoading: false,
111116
message: '',
112117
projectToEdit: undefined,
@@ -115,7 +120,7 @@ describe('projectReducer', () => {
115120
const action = new actions.DeleteProjectSuccess(projectIdToDelete);
116121

117122
const state = projectReducer(currentState, action);
118-
expect(state.projectList).toEqual([]);
123+
expect(state.customerProjects).toEqual([]);
119124
expect(state.message).toEqual('Project removed successfully!');
120125
});
121126

@@ -124,7 +129,7 @@ describe('projectReducer', () => {
124129
const action = new actions.DeleteProjectFail(projectToEdit);
125130

126131
const state = projectReducer(initialState, action);
127-
expect(state.projectList).toEqual([]);
132+
expect(state.customerProjects).toEqual([]);
128133
expect(state.isLoading).toEqual(false);
129134
expect(state.message).toEqual('Something went wrong deleting the project!');
130135
});

0 commit comments

Comments
 (0)