Skip to content

Commit d283ed7

Browse files
authored
test: TT-281 UI Test Coverage Second Part (#800)
* test: TT-281 UI Test Coverage Second Part * test: TT-281 UI Test Coverage Second Part * test: TT-281 UI Test Coverage Second Part * test: TT-281 UI Test Coverage Second Part
1 parent 5d29b8e commit d283ed7

25 files changed

+388
-32
lines changed

src/app/modules/activities-management/store/activity-management.actions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export enum ActivityManagementActionTypes {
2020
UNARCHIVE_ACTIVITY_FAIL = '[ActivityManagement] UNARCHIVE_ACTIVITY_FAIL',
2121
SET_ACTIVITY_ID_TO_EDIT = '[ActivityManagement] SET_ACTIVITY_ID_TO_EDIT',
2222
RESET_ACTIVITY_ID_TO_EDIT = '[ActivityManagement] RESET_ACTIVITY_ID_TO_EDIT',
23+
DEFAULT_ACTIVITY = '[ActivityManagement] DEFAULT_ACTIVITY',
2324
}
2425

2526
export class LoadActivities implements Action {
@@ -118,6 +119,10 @@ export class ResetActivityToEdit implements Action {
118119
public readonly type = ActivityManagementActionTypes.RESET_ACTIVITY_ID_TO_EDIT;
119120
}
120121

122+
export class DefaultActivities implements Action {
123+
public readonly type = ActivityManagementActionTypes.DEFAULT_ACTIVITY;
124+
}
125+
121126
export type ActivityManagementActions =
122127
| LoadActivities
123128
| LoadActivitiesSuccess
@@ -135,4 +140,5 @@ export type ActivityManagementActions =
135140
| UnarchiveActivitySuccess
136141
| UnarchiveActivityFail
137142
| SetActivityToEdit
138-
| ResetActivityToEdit;
143+
| ResetActivityToEdit
144+
| DefaultActivities;

src/app/modules/activities-management/store/activity-management.reducers.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,25 @@ describe('activityManagementReducer', () => {
142142
expect(state.message).toEqual('Something went wrong unarchiving activities!');
143143
expect(state.isLoading).toBeFalse();
144144
});
145+
146+
it('on SetActivityidToEdit, message equal to \"Set activityIdToEdit property\"', () => {
147+
const action = new actions.SetActivityToEdit('1');
148+
const state = activityManagementReducer(initialState, action);
149+
expect(state.message).toEqual('Set activityIdToEdit property');
150+
expect(state.isLoading).toBeFalse();
151+
});
152+
153+
it('on ResetActivityIdToEdit, message equal to \"Reset activityIdToEdit property\"', () => {
154+
const action = new actions.ResetActivityToEdit();
155+
const state = activityManagementReducer(initialState, action);
156+
expect(state.message).toEqual('Reset activityIdToEdit property');
157+
expect(state.isLoading).toBeFalse();
158+
});
159+
160+
it('on DefaultAction, state equal to initial state', () => {
161+
const action = new actions.DefaultActivities();
162+
const state = activityManagementReducer(initialState, action);
163+
expect(state.data).toEqual(initialState.data);
164+
});
165+
145166
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
33
import { ManagementCustomerProjectsComponent } from './management-customer-projects.component';
44
import { MockStore, provideMockStore } from '@ngrx/store/testing';
55
import { CustomerState } from '../../store';
6+
import { of } from 'rxjs';
67

78
describe('ManagmentCustomerProjectsComponent', () => {
89
let component: ManagementCustomerProjectsComponent;
@@ -38,6 +39,18 @@ describe('ManagmentCustomerProjectsComponent', () => {
3839
expect(component).toBeTruthy();
3940
});
4041

42+
it('set customerName on ngOnInit', () => {
43+
spyOn(store, 'dispatch');
44+
spyOn(store, 'pipe').and.returnValue(of({
45+
id: 1,
46+
name: 'project 4',
47+
description: 'project 1 to test methos projectss',
48+
status: 'inactive'
49+
}));
50+
component.ngOnInit();
51+
expect(component.customerName).toEqual('project 4');
52+
});
53+
4154
it('should be enable tabs', () => {
4255
component.areTabsActive = false;
4356
component.activeTabs(true);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NgxPaginationModule } from 'ngx-pagination';
55
import { DeleteProjectType, SetProjectTypeToEdit } from './../../store/project-type.actions';
66
import { allProjectTypes, ProjectTypeState } from '../../store';
77
import { ProjectTypeListComponent } from './project-type-list.component';
8+
import { ProjectType } from 'src/app/modules/shared/models';
89

910
describe('ProjectTypeTableListComponent', () => {
1011
let component: ProjectTypeListComponent;
@@ -68,4 +69,16 @@ describe('ProjectTypeTableListComponent', () => {
6869
expect(store.dispatch).toHaveBeenCalledWith(new SetProjectTypeToEdit('id'));
6970
});
7071

72+
it('open the modal with the correct parameters', () => {
73+
const item: ProjectType = {
74+
id: `1`,
75+
name: `Project 1`,
76+
description: `Description project 1`
77+
};
78+
component.openModal(item);
79+
expect(component.idToDelete).toEqual(item.id);
80+
expect(component.message).toEqual(`Are you sure you want to delete ${item.name}?`);
81+
expect(component.showModal).toBe(true);
82+
});
83+
7184
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('projectTypeReducer', () => {
66
const initialState: ProjectTypeState = { data: [], isLoading: false, message: '', projectTypeIdToEdit: '' };
77
const projectType: ProjectType = { id: '1', name: 'Training', description: 'It is good for learning' };
88

9-
it('on Default, ', () => {
9+
it('on DefaultAction, state equal to initial state', () => {
1010
const action = new actions.DefaultProjectTypes();
1111
const state = projectTypeReducer(initialState, action);
1212
expect(state.data).toEqual(initialState.data);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ describe('ProjectService', () => {
4848
}
4949
));
5050

51+
it('all projects are read using GET from url', () => {
52+
const projectsFoundSize = projectsList.length;
53+
service.getAllProjects().subscribe((projectsInResponse) => {
54+
expect(projectsInResponse.length).toBe(projectsFoundSize);
55+
});
56+
const getProjectsRequest = httpMock.expectOne(service.url);
57+
expect(getProjectsRequest.request.method).toBe('GET');
58+
getProjectsRequest.flush(projectsList);
59+
});
60+
5161
it('projects are read using GET from url', () => {
5262
const projectsFoundSize = projectsList.length;
5363
service.url = '/projects';

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export enum ProjectActionTypes {
2525
UNARCHIVE_PROJECT = '[Projects] UNARCHIVE_PROJECT',
2626
UNARCHIVE_PROJECT_SUCCESS = '[Projects] UNARCHIVE_PROJECT_SUCCESS',
2727
UNARCHIVE_PROJECT_FAIL = '[Projects] UNARCHIVE_PROJECT_FAIL',
28+
DEFAULT_PROJECT = '[Projects] DEFAULT_PROJECTS',
2829
}
2930

3031
export class CleanCustomerProjects implements Action {
@@ -154,6 +155,10 @@ export class UnarchiveProjectFail implements Action {
154155
constructor(public error: string) {}
155156
}
156157

158+
export class DefaultProjects implements Action {
159+
public readonly type = ProjectActionTypes.DEFAULT_PROJECT;
160+
}
161+
157162
export type ProjectActions =
158163
| CleanCustomerProjects
159164
| LoadProjects
@@ -177,4 +182,5 @@ export type ProjectActions =
177182
| DeleteProjectFail
178183
| UnarchiveProject
179184
| UnarchiveProjectSuccess
180-
| UnarchiveProjectFail;
185+
| UnarchiveProjectFail
186+
| DefaultProjects;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ describe('projectReducer', () => {
2222
});
2323

2424
it('on LoadProjects, isLoading is true', () => {
25+
const action = new actions.LoadProjects();
26+
const state = projectReducer(initialState, action);
27+
expect(state.isLoading).toEqual(true);
28+
});
29+
30+
it('on LoadProjectsSucces, projectsFound are saved in the store', () => {
31+
const projectsFound: Project[] = [project];
32+
const action = new actions.LoadProjectsSuccess(projectsFound);
33+
const state = projectReducer(initialState, action);
34+
expect(action.payload).toEqual([project]);
35+
expect(state.isLoading).toEqual(false);
36+
});
37+
38+
it('on LoadProjectsFail, loadProject equal []', () => {
39+
const action = new actions.LoadProjectsFail('error');
40+
const state = projectReducer(initialState, action);
41+
expect(state.isLoading).toEqual(false);
42+
});
43+
44+
it('on LoadCustomerProjects, isLoading is true', () => {
2545
const action = new actions.LoadCustomerProjects('1');
2646
const state = projectReducer(initialState, action);
2747
expect(state.isLoading).toEqual(true);
@@ -201,4 +221,11 @@ describe('projectReducer', () => {
201221
expect(state.message).toEqual('Something went wrong unarchiving projects!');
202222
expect(state.isLoading).toEqual(false);
203223
});
224+
225+
it('on DefaultAction, state equal to initial state', () => {
226+
const action = new actions.DefaultProjects();
227+
const state = projectReducer(initialState, action);
228+
expect(state).toEqual(initialState);
229+
});
230+
204231
});

src/app/modules/customer-management/store/customer-management.actions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export enum CustomerManagementActionTypes {
1919
UNARCHIVE_CUSTOMER = '[CustomerManagement] UNARCHIVE_CUSTOMER',
2020
UNARCHIVE_CUSTOMER_SUCCESS = '[CustomerManagement] UNARCHIVE_CUSTOMER_SUCCESS',
2121
UNARCHIVE_CUSTOMER_FAIL = '[CustomerManagement] UNARCHIVE_CUSTOMER_FAIL',
22+
DEFAULT_CUSTOMER = '[CustomerManagement] DEFAULT_CUSTOMER',
2223
}
2324

2425
export class LoadCustomers implements Action {
@@ -118,6 +119,10 @@ export class UnarchiveCustomerFail implements Action {
118119
constructor(public error: string) {}
119120
}
120121

122+
export class DefaultCustomer implements Action {
123+
public readonly type = CustomerManagementActionTypes.DEFAULT_CUSTOMER;
124+
}
125+
121126
export type CustomerManagementActions =
122127
| CreateCustomer
123128
| CreateCustomerSuccess
@@ -135,4 +140,5 @@ export type CustomerManagementActions =
135140
| ResetCustomerToEdit
136141
| UnarchiveCustomer
137142
| UnarchiveCustomerSuccess
138-
| UnarchiveCustomerFail;
143+
| UnarchiveCustomerFail
144+
| DefaultCustomer;

src/app/modules/customer-management/store/customer-management.reducers.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,10 @@ describe('customerManagementReducer', () => {
166166
expect(state.message).toEqual('Something went wrong unarchiving customer!');
167167
expect(state.isLoading).toEqual(false);
168168
});
169+
170+
it('on DefaultAction, state equal to initial state', () => {
171+
const action = new actions.DefaultCustomer();
172+
const state = customerManagementReducer(initialState, action);
173+
expect(state.data).toEqual(initialState.data);
174+
});
169175
});

0 commit comments

Comments
 (0)