1- import { TimeEntriesSummary , TimeDetails } from '../models/time.entry.summary' ;
2- import { NewEntry , Entry } from './../../shared/models' ;
1+ import { TimeEntriesSummary , TimeDetails } from '../models/time.entry.summary' ;
2+ import { NewEntry , Entry } from './../../shared/models' ;
33import * as actions from './entry.actions' ;
4- import { entryReducer , EntryState } from './entry.reducer' ;
4+ import { entryReducer , EntryState } from './entry.reducer' ;
55
66describe ( 'entryReducer' , ( ) => {
77
8- const emptyTimeDetails : TimeDetails = { hours : '--:--' , minutes : '--:--' , seconds : '--:--' } ;
9- const emptyTimeEntriesSummary : TimeEntriesSummary = { day : emptyTimeDetails , week : emptyTimeDetails , month : emptyTimeDetails } ;
8+ const emptyTimeDetails : TimeDetails = { hours : '--:--' , minutes : '--:--' , seconds : '--:--' } ;
9+ const emptyTimeEntriesSummary : TimeEntriesSummary = { day : emptyTimeDetails , week : emptyTimeDetails , month : emptyTimeDetails } ;
10+
1011
1112 const initialState : EntryState = {
1213 active : null ,
@@ -15,7 +16,8 @@ describe('entryReducer', () => {
1516 message : '' ,
1617 createError : null ,
1718 updateError : null ,
18- timeEntriesSummary : emptyTimeEntriesSummary
19+ timeEntriesSummary : emptyTimeEntriesSummary ,
20+ entriesForReport : [ ]
1921 } ;
2022
2123 const entry : NewEntry = {
@@ -25,6 +27,19 @@ describe('entryReducer', () => {
2527 technologies : [ 'angular' , 'typescript' ] ,
2628 } ;
2729
30+ const entryList : Entry [ ] = [
31+ {
32+ project_id : '123' ,
33+ comments : 'description' ,
34+ technologies : [ 'angular' , 'javascript' ] ,
35+ uri : 'uri' ,
36+ id : 'id' ,
37+ start_date : new Date ( ) ,
38+ end_date : new Date ( ) ,
39+ activity_id : 'activity' ,
40+ }
41+ ] ;
42+
2843 it ( 'sets timeEntriesSummary from action on LOAD_ENTRIES_SUMMARY_SUCCESS' , ( ) => {
2944 const payload = null ;
3045 const action = new actions . LoadEntriesSummarySuccess ( payload ) ;
@@ -64,7 +79,7 @@ describe('entryReducer', () => {
6479
6580 it ( 'on LoadActiveEntrySuccess, activeEntryFound are saved in the store' , ( ) => {
6681 const activeEntryFound : NewEntry [ ] = [
67- { project_id : '123' , description : 'description' , technologies : [ 'angular' , 'javascript' ] , activity_id : 'xyz' } ,
82+ { project_id : '123' , description : 'description' , technologies : [ 'angular' , 'javascript' ] , activity_id : 'xyz' } ,
6883 ] ;
6984 const action = new actions . LoadActiveEntrySuccess ( activeEntryFound ) ;
7085 const state = entryReducer ( initialState , action ) ;
@@ -109,15 +124,15 @@ describe('entryReducer', () => {
109124 } ) ;
110125
111126 it ( 'on CreateEntry, isLoading is true' , ( ) => {
112- const entryToCreate : NewEntry = { project_id : '1' , start_date : '2020-04-21T19:51:36.559000+00:00' } ;
127+ const entryToCreate : NewEntry = { project_id : '1' , start_date : '2020-04-21T19:51:36.559000+00:00' } ;
113128 const action = new actions . CreateEntry ( entryToCreate ) ;
114129 const state = entryReducer ( initialState , action ) ;
115130
116131 expect ( state . isLoading ) . toEqual ( true ) ;
117132 } ) ;
118133
119134 it ( 'on CreateEntrySuccess, message is updated' , ( ) => {
120- const entryToCreate : NewEntry = { project_id : '1' , start_date : '2020-04-21T19:51:36.559000+00:00' } ;
135+ const entryToCreate : NewEntry = { project_id : '1' , start_date : '2020-04-21T19:51:36.559000+00:00' } ;
121136 const action = new actions . CreateEntrySuccess ( entryToCreate ) ;
122137 const state = entryReducer ( initialState , action ) ;
123138
@@ -158,6 +173,8 @@ describe('entryReducer', () => {
158173 message : '' ,
159174 createError : null ,
160175 updateError : null ,
176+ entriesForReport : [ ]
177+
161178 } ;
162179 const action = new actions . DeleteEntrySuccess ( 'id' ) ;
163180 const state = entryReducer ( currentState , action ) ;
@@ -196,7 +213,8 @@ describe('entryReducer', () => {
196213 message : '' ,
197214 createError : null ,
198215 updateError : null ,
199- timeEntriesSummary : emptyTimeEntriesSummary
216+ timeEntriesSummary : emptyTimeEntriesSummary ,
217+ entriesForReport : [ ]
200218 } ;
201219 const entryUpdated : Entry = {
202220 id : 'id' ,
@@ -257,4 +275,43 @@ describe('entryReducer', () => {
257275
258276 expect ( state . isLoading ) . toBeFalsy ( ) ;
259277 } ) ;
278+
279+ it ( 'sets timeEntriesSummary from action on LOAD_ENTRIES_SUMMARY_SUCCESS' , ( ) => {
280+ const payload = null ;
281+ const action = new actions . LoadEntriesSummarySuccess ( payload ) ;
282+ const state = entryReducer ( initialState , action ) ;
283+ expect ( state . timeEntriesSummary ) . toBe ( payload ) ;
284+ } ) ;
285+
286+ it ( 'sets message on LOAD_ACTIVE_ENTRY_FAIL' , ( ) => {
287+ const action = new actions . LoadActiveEntryFail ( '' ) ;
288+ const state = entryReducer ( initialState , action ) ;
289+ expect ( state . message ) . toBe ( 'Something went wrong fetching active entry!' ) ;
290+ } ) ;
291+
292+ it ( 'on LoadEntriesByTimeRange, the state has isLoading is true' , ( ) => {
293+ const action = new actions . LoadEntriesByTimeRange ( null ) ;
294+
295+ const state = entryReducer ( initialState , action ) ;
296+
297+ expect ( state . isLoading ) . toBeTrue ( ) ;
298+ } ) ;
299+
300+ it ( 'on LoadEntriesByTimeRangeSuccess, the entriesForReport is populated with the payload info from the action' , ( ) => {
301+ const payload = entryList ;
302+ const action = new actions . LoadEntriesByTimeRangeSuccess ( payload ) ;
303+
304+ const state = entryReducer ( initialState , action ) ;
305+
306+ expect ( state . entriesForReport ) . toEqual ( payload ) ;
307+ } ) ;
308+
309+ it ( 'on LoadEntriesByTimeRangeFail, the state has isLoading is false and the entriesForReport is an empty array ' , ( ) => {
310+ const action = new actions . LoadEntriesByTimeRangeFail ( ) ;
311+
312+ const state = entryReducer ( initialState , action ) ;
313+
314+ expect ( state . isLoading ) . toBeFalse ( ) ;
315+ expect ( state . entriesForReport ) . toEqual ( [ ] ) ;
316+ } ) ;
260317} ) ;
0 commit comments