Skip to content

Commit 073bd1e

Browse files
authored
TT-665 IResolve Code Cov errors (#875)
* Implementing ordered activities test * Implementing form status before doing submit * Implementing test for allActiveActivities selector * Implementing tests when the date value is null, undefined and empty * TT-665 clean code * TT-665 clean code * TT-665 clean code * Implementing test when the ngOnChanges method is the first change, the onSubmit method id not called * TT-665 clean code Co-authored-by: Nicole Garcia <nicolsss>
1 parent ad6e04c commit 073bd1e

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,49 @@ describe('ActivityManagement Selectors', () => {
2424
expect(selectors.allActivities.projector(activityState)).toBe(activities);
2525
});
2626

27+
it('should return all the ordered data in the state when the selector allAtiveActivities is called', () => {
28+
const activities = [
29+
{
30+
id: '001',
31+
name: 'Meeting',
32+
description: 'Some description'
33+
},
34+
{
35+
id: '002',
36+
name: 'ABC',
37+
description: 'Some description'
38+
},
39+
{
40+
id: '003',
41+
name: 'XYZ',
42+
description: 'Some description'
43+
},
44+
];
45+
46+
const activitiesOrdered = [
47+
{
48+
id: '002',
49+
name: 'ABC',
50+
description: 'Some description'
51+
},
52+
{
53+
id: '001',
54+
name: 'Meeting',
55+
description: 'Some description'
56+
},
57+
{
58+
id: '003',
59+
name: 'XYZ',
60+
description: 'Some description'
61+
},
62+
];
63+
64+
const activityState = { data: activities };
65+
66+
expect(selectors.allActiveActivities.projector(activityState)).toEqual(activitiesOrdered);
67+
68+
});
69+
2770
it('should return all active data in the state when the selector allActiveActivities is called', () => {
2871
const activities = [{ id: 'id', name: 'abc', description: 'xxx', status: 'active' },
2972
{ id: '2', name: 'xyz', description: 'yyy', status: 'inactive' },

src/app/modules/reports/components/time-range-form/time-range.component.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ describe('Reports Page', () => {
115115
expect(component.onSubmit).toHaveBeenCalled();
116116
});
117117

118+
it('triggers onSubmit with the form status valid', () => {
119+
const valid = component.reportForm.valid;
120+
spyOn(component, 'onSubmit');
121+
122+
component.setInitialDataOnScreen();
123+
124+
expect(valid).toBeTruthy();
125+
expect(component.onSubmit).toHaveBeenCalled();
126+
});
127+
118128
it('When the ngOnChanges method is called, the onSubmit method is called', () => {
119129
const userId = 'abcd';
120130
spyOn(component, 'onSubmit');
@@ -124,6 +134,15 @@ describe('Reports Page', () => {
124134
expect(component.onSubmit).toHaveBeenCalled();
125135
});
126136

137+
it('When the ngOnChanges method is the first change, the onSubmit method is not called', () => {
138+
const userId = 'abcd';
139+
spyOn(component, 'onSubmit');
140+
141+
component.ngOnChanges({userId: new SimpleChange(null, userId, true)});
142+
143+
expect(component.onSubmit).not.toHaveBeenCalled();
144+
});
145+
127146
afterEach(() => {
128147
fixture.destroy();
129148
});

src/app/modules/shared/formatters/parse-date-time-offset/parse-date-time-offset.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,31 @@ describe('ParseDateToUtcComponent', () => {
2020
expect(parseTimeOffset.parseDateTimeOffset(date, timezoneOffset)).toEqual(dateOffset);
2121
});
2222

23+
it('returns "In progress" text when the date value is null', () => {
24+
const parseTimeOffset = new ParseDateTimeOffset();
25+
const date = null;
26+
const timezoneOffset = 420;
27+
const dateOffset = '09:30';
28+
29+
expect(parseTimeOffset.parseDateTimeOffset(date, timezoneOffset)).toEqual('In progress');
30+
});
31+
32+
it('returns "In progress" text when the date value is undefined', () => {
33+
const parseTimeOffset = new ParseDateTimeOffset();
34+
const date = undefined;
35+
const timezoneOffset = 420;
36+
const dateOffset = '09:30';
37+
38+
expect(parseTimeOffset.parseDateTimeOffset(date, timezoneOffset)).toEqual('In progress');
39+
});
40+
41+
it('returns "In progress" text when the date value is empty', () => {
42+
const parseTimeOffset = new ParseDateTimeOffset();
43+
const date = '';
44+
const timezoneOffset = 420;
45+
const dateOffset = '09:30';
46+
47+
expect(parseTimeOffset.parseDateTimeOffset(date, timezoneOffset)).toEqual('In progress');
48+
});
49+
2350
});

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,54 @@ describe('EntryFieldsComponent', () => {
361361
expect(component.activities).toEqual(action.payload);
362362
});
363363

364+
it('activites are ordered using the payload of the action', () => {
365+
const activities = [
366+
{
367+
id: '004',
368+
name: 'Meeting',
369+
description: 'Some description'
370+
},
371+
{
372+
id: '005',
373+
name: 'ABCD',
374+
description: 'Some description'
375+
},
376+
{
377+
id: '006',
378+
name: 'XYZA',
379+
description: 'Some description'
380+
},
381+
];
382+
383+
const activitiesOrdered = [
384+
{
385+
id: '005',
386+
name: 'ABCD',
387+
description: 'Some description'
388+
},
389+
{
390+
id: '004',
391+
name: 'Meeting',
392+
description: 'Some description'
393+
},
394+
{
395+
id: '006',
396+
name: 'XYZA',
397+
description: 'Some description'
398+
},
399+
];
400+
401+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
402+
const action = {
403+
type: ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS,
404+
payload: activities,
405+
};
406+
407+
actionSubject.next(action);
408+
409+
expect(component.activities).toEqual(activitiesOrdered);
410+
});
411+
364412
it('LoadActiveEntry is dispatchen after LOAD_ACTIVITIES_SUCCESS', () => {
365413
spyOn(store, 'dispatch');
366414

0 commit comments

Comments
 (0)