@@ -2,6 +2,7 @@ import {TimeEntriesSummary, TimeDetails} from '../models/time.entry.summary';
22import { NewEntry , Entry } from './../../shared/models' ;
33import * as actions from './entry.actions' ;
44import { entryReducer , EntryState } from './entry.reducer' ;
5+ import { init } from 'protractor/built/launcher' ;
56
67describe ( 'entryReducer' , ( ) => {
78
@@ -20,25 +21,25 @@ describe('entryReducer', () => {
2021 entriesForReport : [ ]
2122 } ;
2223
23- const entry : NewEntry = {
24+ const newEntry : NewEntry = {
2425 start_date : 'start-date' ,
2526 description : 'description' ,
2627 project_id : '112' ,
2728 technologies : [ 'angular' , 'typescript' ] ,
2829 } ;
2930
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- ] ;
31+ const entry : Entry = {
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+ const entriesList : Entry [ ] = [ entry ] ;
4243
4344 it ( 'sets timeEntriesSummary from action on LOAD_ENTRIES_SUMMARY_SUCCESS' , ( ) => {
4445 const payload = null ;
@@ -100,21 +101,11 @@ describe('entryReducer', () => {
100101 } ) ;
101102
102103 it ( 'on LoadEntriesSuccess, get all Entries' , ( ) => {
103- const entries : Entry [ ] = [
104- {
105- project_id : '123' ,
106- comments : 'description' ,
107- technologies : [ 'angular' , 'javascript' ] ,
108- uri : 'uri' ,
109- id : 'id' ,
110- start_date : new Date ( ) ,
111- end_date : new Date ( ) ,
112- activity_id : 'activity' ,
113- } ,
114- ] ;
115- const action = new actions . LoadEntriesSuccess ( entries ) ;
104+ const action = new actions . LoadEntriesSuccess ( entriesList ) ;
105+
116106 const state = entryReducer ( initialState , action ) ;
117- expect ( state . entryList ) . toEqual ( entries ) ;
107+
108+ expect ( state . entryList ) . toEqual ( entriesList ) ;
118109 } ) ;
119110
120111 it ( 'on LoadEntriesFail, active tobe null' , ( ) => {
@@ -154,29 +145,9 @@ describe('entryReducer', () => {
154145 } ) ;
155146
156147 it ( 'on DeleteEntrySuccess' , ( ) => {
157- const currentState = {
158- timeEntriesSummary : emptyTimeEntriesSummary ,
159- active : null ,
160- entryList : [
161- {
162- project_id : '123' ,
163- comments : 'description' ,
164- technologies : [ 'angular' , 'javascript' ] ,
165- uri : 'uri' ,
166- id : 'id' ,
167- start_date : new Date ( ) ,
168- end_date : new Date ( ) ,
169- activity_id : 'activity' ,
170- } ,
171- ] ,
172- isLoading : false ,
173- message : '' ,
174- createError : null ,
175- updateError : null ,
176- entriesForReport : [ ]
177-
178- } ;
148+ const currentState = { ...initialState , entryList : entriesList } ;
179149 const action = new actions . DeleteEntrySuccess ( 'id' ) ;
150+
180151 const state = entryReducer ( currentState , action ) ;
181152 expect ( state . entryList ) . toEqual ( [ ] ) ;
182153 } ) ;
@@ -188,43 +159,16 @@ describe('entryReducer', () => {
188159 } ) ;
189160
190161 it ( 'on UpdateActiveEntry, isLoading is true' , ( ) => {
191- const action = new actions . UpdateActiveEntry ( entry ) ;
162+ const action = new actions . UpdateActiveEntry ( newEntry ) ;
192163 const state = entryReducer ( initialState , action ) ;
193164
194165 expect ( state . isLoading ) . toEqual ( true ) ;
195166 } ) ;
196167
197168 it ( 'on UpdateActiveEntrySuccess, loading is false' , ( ) => {
198- const currentState : EntryState = {
199- active : null ,
200- entryList : [
201- {
202- project_id : '123' ,
203- comments : 'description' ,
204- technologies : [ 'angular' , 'javascript' ] ,
205- uri : 'uri' ,
206- id : 'id' ,
207- start_date : new Date ( ) ,
208- end_date : new Date ( ) ,
209- activity_id : 'activity' ,
210- } ,
211- ] ,
212- isLoading : false ,
213- message : '' ,
214- createError : null ,
215- updateError : null ,
216- timeEntriesSummary : emptyTimeEntriesSummary ,
217- entriesForReport : [ ]
218- } ;
219- const entryUpdated : Entry = {
220- id : 'id' ,
221- start_date : new Date ( ) ,
222- end_date : new Date ( ) ,
223- activity_id : '' ,
224- technologies : [ 'abc' , 'abc' ] ,
225- } ;
226- const action = new actions . UpdateActiveEntrySuccess ( entryUpdated ) ;
227- const state = entryReducer ( currentState , action ) ;
169+ const action = new actions . UpdateActiveEntrySuccess ( entry ) ;
170+
171+ const state = entryReducer ( initialState , action ) ;
228172
229173 expect ( state . isLoading ) . toEqual ( false ) ;
230174 } ) ;
@@ -276,19 +220,6 @@ describe('entryReducer', () => {
276220 expect ( state . isLoading ) . toBeFalsy ( ) ;
277221 } ) ;
278222
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-
292223 it ( 'on LoadEntriesByTimeRange, the state has isLoading is true' , ( ) => {
293224 const action = new actions . LoadEntriesByTimeRange ( null ) ;
294225
@@ -298,7 +229,7 @@ describe('entryReducer', () => {
298229 } ) ;
299230
300231 it ( 'on LoadEntriesByTimeRangeSuccess, the entriesForReport is populated with the payload info from the action' , ( ) => {
301- const payload = entryList ;
232+ const payload = entriesList ;
302233 const action = new actions . LoadEntriesByTimeRangeSuccess ( payload ) ;
303234
304235 const state = entryReducer ( initialState , action ) ;
0 commit comments