@@ -27,6 +27,11 @@ describe('EntryFieldsComponent', () => {
2727 error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
2828 warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
2929 } ;
30+ const lastDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
31+ const startHourTest = moment ( ) . add ( - 5 , 'hours' ) . format ( 'HH:mm:ss' ) ;
32+ const endHourTest = moment ( ) . add ( - 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
33+ const lastStartHourEntryEntered = new Date ( `${ lastDate } T${ startHourTest . trim ( ) } ` ) . toISOString ( ) ;
34+ const lastEndHourEntryEntered = new Date ( `${ lastDate } T${ endHourTest . trim ( ) } ` ) . toISOString ( ) ;
3035
3136 const state = {
3237 projects : {
@@ -57,6 +62,28 @@ describe('EntryFieldsComponent', () => {
5762 } ,
5863 entryList : [ ] ,
5964 message : '' ,
65+ timeEntriesDataSource : { data : [
66+ {
67+ activity_id : 'xyz' ,
68+ activity_name : 'abc' ,
69+ id : 'id-15' ,
70+ project_id : 'project-id-15' ,
71+ description : 'description for an entry' ,
72+ uri : 'abc' ,
73+ start_date : moment ( ) . toISOString ( ) ,
74+ end_date : moment ( ) . toISOString ( ) ,
75+ } ,
76+ {
77+ activity_id : 'xyz' ,
78+ activity_name : 'abc' ,
79+ id : 'id-15' ,
80+ project_id : 'project-id-15' ,
81+ description : 'description for an entry' ,
82+ uri : 'abc' ,
83+ start_date : lastStartHourEntryEntered ,
84+ end_date : lastEndHourEntryEntered ,
85+ }
86+ ] }
6087 } ,
6188 } ;
6289
@@ -134,6 +161,37 @@ describe('EntryFieldsComponent', () => {
134161 expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
135162 } ) ;
136163
164+ it ( 'displays error message when new hour entered is in the past of other entry' , ( ) => {
165+ component . newData = entry ;
166+ component . activeEntry = entry ;
167+ component . setDataToUpdate ( entry ) ;
168+ spyOn ( toastrServiceStub , 'error' ) ;
169+
170+ const hourInTheFuture = moment ( ) . add ( - 6 , 'hour' ) . format ( 'HH:mm:ss' ) ;
171+ component . entryForm . patchValue ( { start_hour : hourInTheFuture } ) ;
172+ component . onUpdateStartHour ( ) ;
173+
174+ expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
175+ } ) ;
176+
177+ it ( 'If start hour is in the past of other entry, reset to initial start_date in form' , ( ) => {
178+ component . newData = entry ;
179+ component . activeEntry = entry ;
180+ component . setDataToUpdate ( entry ) ;
181+
182+ const newHour = moment ( ) . add ( - 6 , 'hours' ) . format ( 'HH:mm:ss' ) ;
183+ component . entryForm . patchValue ( { start_hour : newHour } ) ;
184+
185+ spyOn ( component . entryForm , 'patchValue' ) ;
186+ component . onUpdateStartHour ( ) ;
187+
188+ expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith (
189+ {
190+ start_hour : component . newData . start_hour
191+ }
192+ ) ;
193+ } ) ;
194+
137195 it ( 'If start hour is in the future, reset to initial start_date in form' , ( ) => {
138196 component . newData = entry ;
139197 component . activeEntry = entry ;
@@ -155,12 +213,37 @@ describe('EntryFieldsComponent', () => {
155213 it ( 'when a start hour is updated, then dispatch UpdateActiveEntry' , ( ) => {
156214 component . activeEntry = entry ;
157215 component . setDataToUpdate ( entry ) ;
216+ const newHour = moment ( ) . format ( 'HH:mm:ss' ) ;
217+ component . entryForm . patchValue ( { start_hour : newHour } ) ;
158218 spyOn ( store , 'dispatch' ) ;
159219
160220 component . onUpdateStartHour ( ) ;
161221 expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
162222 } ) ;
163223
224+ it ( 'when a start hour is update, then select the last time entry' , async ( ( ) => {
225+ component . activeEntry = entry ;
226+ component . setDataToUpdate ( entry ) ;
227+ const newHour = moment ( ) . format ( 'HH:mm:ss' ) ;
228+
229+ component . entryForm . patchValue ( { start_hour : newHour } ) ;
230+ component . onUpdateStartHour ( ) ;
231+
232+ expect ( component . lastEntry ) . toBe ( state . entries . timeEntriesDataSource . data [ 1 ] ) ;
233+ } ) ) ;
234+
235+ it ( 'when a start hour is updated in other time entry, then dispatch UpdateEntry and UpdateEntryRunning' , ( ) => {
236+ component . activeEntry = entry ;
237+ component . setDataToUpdate ( entry ) ;
238+
239+ const newHour = moment ( ) . add ( - 4 , 'hours' ) . format ( 'HH:mm:ss' ) ;
240+ component . entryForm . patchValue ( { start_hour : newHour } ) ;
241+ spyOn ( store , 'dispatch' ) ;
242+
243+ component . onUpdateStartHour ( ) ;
244+ expect ( store . dispatch ) . toHaveBeenCalledTimes ( 2 ) ;
245+ } ) ;
246+
164247 it ( 'when a technology is added, then dispatch UpdateActiveEntry' , ( ) => {
165248 const addedTechnologies = [ 'react' ] ;
166249 spyOn ( store , 'dispatch' ) ;
0 commit comments