Skip to content

Commit 36765fd

Browse files
authored
Merge pull request #193 from ioet/191-increase-coverage
fix: #191 Adding tests for some code with no tests
2 parents 3acd1e8 + 2319528 commit 36765fd

File tree

9 files changed

+48
-25
lines changed

9 files changed

+48
-25
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,5 @@ export function activityManagementReducer(state: ActivityState = initialState, a
133133
};
134134
}
135135

136-
default:
137-
return state;
138136
}
139137
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as selectors from './activity-management.selectors';
2+
3+
describe('ActivityManagement Selectors', () => {
4+
5+
it('reads activityIdtoEdit from state', () => {
6+
const activityId = 'id';
7+
const activityIdFound = selectors.activityIdtoEdit.projector({ activityIdToEdit: activityId });
8+
expect(activityIdFound).toBe(activityId);
9+
});
10+
11+
it('returns the activity with id that matches from the list', () => {
12+
const activityId = 'id';
13+
const activities = [{id: 'id', name: 'abc', description: 'xxx'},
14+
{id: '2', name: 'xyz', description: 'yyy'}];
15+
const activityFound = selectors.getActivityById.projector(activities, activityId);
16+
expect(activityFound).toEqual(activities[0]);
17+
});
18+
19+
});

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing';
44

55
import { CreateCustomerComponent } from './create-customer';
66
import { CustomerState, CreateCustomer } from 'src/app/modules/customer-management/store';
7-
import { LoadCustomers, ResetCustomerToEdit } from './../../../../store/customer-management.actions';
7+
import { LoadCustomers, ResetCustomerToEdit, UpdateCustomer } from './../../../../store/customer-management.actions';
88
import { Customer } from 'src/app/modules/shared/models';
99

1010
describe('CreateCustomerComponent', () => {
@@ -22,7 +22,6 @@ describe('CreateCustomerComponent', () => {
2222
const customerData: Customer = {
2323
name: 'aa',
2424
description: 'bb',
25-
tenant_id: 'cc',
2625
};
2726

2827
beforeEach(async(() => {
@@ -48,6 +47,15 @@ describe('CreateCustomerComponent', () => {
4847
expect(component).toBeTruthy();
4948
});
5049

50+
it('onSubmit dispatchs UpdateCustomer action', () => {
51+
spyOn(store, 'dispatch');
52+
component.customerToEdit = {id: 'id', name: 'xyz'};
53+
54+
component.onSubmit({ name: 'abc'});
55+
56+
expect(store.dispatch).toHaveBeenCalledWith(new UpdateCustomer({id: 'id', name: 'abc'}));
57+
});
58+
5159
it('should call resetCustomerForm', () => {
5260
spyOn(component.customerForm, 'reset');
5361

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2-
32
import { provideMockStore, MockStore } from '@ngrx/store/testing';
43
import { NgxPaginationModule } from 'ngx-pagination';
54

5+
import { DeleteProjectType, SetProjectTypeToEdit } from './../../store/project-type.actions';
66
import { allProjectTypes, ProjectTypeState } from '../../store';
77
import { ProjectTypeListComponent } from './project-type-list.component';
88

@@ -57,4 +57,20 @@ describe('ProjectTypeTableListComponent', () => {
5757
expect(component.projectTypes).toBe(state.data);
5858
});
5959

60+
it('dispatchs DeleteProjectType on deleteProjectType', () => {
61+
spyOn(store, 'dispatch');
62+
63+
component.deleteProjectType('id');
64+
65+
expect(store.dispatch).toHaveBeenCalledWith(new DeleteProjectType('id'));
66+
});
67+
68+
it('dispatchs UpdateProjectType on updateProjectType', () => {
69+
spyOn(store, 'dispatch');
70+
71+
component.updateProjectType('id');
72+
73+
expect(store.dispatch).toHaveBeenCalledWith(new SetProjectTypeToEdit('id'));
74+
});
75+
6076
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('CustomerService', () => {
2727
));
2828

2929
it('create customer using POST from baseUrl', () => {
30-
const customer: Customer[] = [{ name: 'aa', description: 'bb', tenant_id: 'cc' }];
30+
const customer: Customer[] = [{ name: 'aa', description: 'bb'}];
3131

3232
service.baseUrl = 'customers';
3333

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ describe('CustomerManagmentActions', () => {
55
const createActivity = new actions.CreateCustomer({
66
name: 'aa',
77
description: 'bb',
8-
tenant_id: 'cc',
98
});
109
expect(createActivity.type).toEqual(actions.CustomerManagementActionTypes.CREATE_CUSTOMER);
1110
});
@@ -14,7 +13,6 @@ describe('CustomerManagmentActions', () => {
1413
const createActivitySuccess = new actions.CreateCustomerSuccess({
1514
name: 'aa',
1615
description: 'bb',
17-
tenant_id: 'cc',
1816
});
1917
expect(createActivitySuccess.type).toEqual(actions.CustomerManagementActionTypes.CREATE_CUSTOMER_SUCCESS);
2018
});
@@ -53,7 +51,6 @@ describe('CustomerManagmentActions', () => {
5351
const updateCustomer = new actions.UpdateCustomer({
5452
name: 'aa',
5553
description: 'bb',
56-
tenant_id: 'cc',
5754
});
5855
expect(updateCustomer.type).toEqual(actions.CustomerManagementActionTypes.UPDATE_CUSTOMER);
5956
});
@@ -62,7 +59,6 @@ describe('CustomerManagmentActions', () => {
6259
const updateCustomerSucess = new actions.UpdateCustomerSuccess({
6360
name: 'aa',
6461
description: 'bb',
65-
tenant_id: 'cc',
6662
});
6763
expect(updateCustomerSucess.type).toEqual(actions.CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS);
6864
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as actions from './customer-management.actions';
44

55
describe('customerManagementReducer', () => {
66
const initialState: CustomerState = { data: [], isLoading: false, message: '', customerIdToEdit: '' };
7-
const customer: Customer = { name: 'aa', description: 'bb', tenant_id: 'cc' };
7+
const customer: Customer = { name: 'aa', description: 'bb'};
88

99
it('on LoadCustomer, isLoading is true ', () => {
1010
const action = new actions.LoadCustomers();

src/app/modules/shared/models/customer.model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export interface Customer {
22
id?: string;
33
name: string;
44
description?: string;
5-
tenant_id: string;
65
}

src/app/modules/time-clock/store/entry.selectors.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ import { EntryState } from './entry.reducer';
44

55
const getEntryState = createFeatureSelector('entries');
66

7-
export const allEntries = createSelector(getEntryState, (state: EntryState) => {
8-
return state;
9-
});
10-
11-
export const selectProjects = (state) => state.projects.projectList;
12-
export const selectEntries = (state) => state.entries.active;
13-
147
export const getActiveTimeEntry = createSelector(getEntryState, (state: EntryState) => {
158
return state.active;
169
});
17-
18-
export const getStatusMessage = createSelector(getEntryState, (state: EntryState) => {
19-
if (state) {
20-
return state.message;
21-
}
22-
});

0 commit comments

Comments
 (0)