@@ -27,6 +27,11 @@ describe('EntryFieldsComponent', () => {
27
27
error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
28
28
warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
29
29
} ;
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 ( ) ;
30
35
31
36
const state = {
32
37
projects : {
@@ -57,6 +62,28 @@ describe('EntryFieldsComponent', () => {
57
62
} ,
58
63
entryList : [ ] ,
59
64
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
+ ] }
60
87
} ,
61
88
} ;
62
89
@@ -134,6 +161,37 @@ describe('EntryFieldsComponent', () => {
134
161
expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
135
162
} ) ;
136
163
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
+
137
195
it ( 'If start hour is in the future, reset to initial start_date in form' , ( ) => {
138
196
component . newData = entry ;
139
197
component . activeEntry = entry ;
@@ -155,12 +213,37 @@ describe('EntryFieldsComponent', () => {
155
213
it ( 'when a start hour is updated, then dispatch UpdateActiveEntry' , ( ) => {
156
214
component . activeEntry = entry ;
157
215
component . setDataToUpdate ( entry ) ;
216
+ const newHour = moment ( ) . format ( 'HH:mm:ss' ) ;
217
+ component . entryForm . patchValue ( { start_hour : newHour } ) ;
158
218
spyOn ( store , 'dispatch' ) ;
159
219
160
220
component . onUpdateStartHour ( ) ;
161
221
expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
162
222
} ) ;
163
223
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
+
164
247
it ( 'when a technology is added, then dispatch UpdateActiveEntry' , ( ) => {
165
248
const addedTechnologies = [ 'react' ] ;
166
249
spyOn ( store , 'dispatch' ) ;
0 commit comments