@@ -29,9 +29,10 @@ describe('EntryFieldsComponent', () => {
29
29
error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
30
30
warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
31
31
} ;
32
- const lastDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
33
- const startHourTest = moment ( ) . subtract ( 5 , 'hours' ) . format ( 'HH:mm:ss' ) ;
34
- const endHourTest = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
32
+ const mockDate = '2020-12-01T12:00:00' ;
33
+ const lastDate = moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ;
34
+ const startHourTest = moment ( mockDate ) . subtract ( 5 , 'hours' ) . format ( 'HH:mm:ss' ) ;
35
+ const endHourTest = moment ( mockDate ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
35
36
const lastStartHourEntryEntered = new Date ( `${ lastDate } T${ startHourTest . trim ( ) } ` ) . toISOString ( ) ;
36
37
const lastEndHourEntryEntered = new Date ( `${ lastDate } T${ endHourTest . trim ( ) } ` ) . toISOString ( ) ;
37
38
@@ -95,8 +96,8 @@ describe('EntryFieldsComponent', () => {
95
96
project_id : 'project-id-15' ,
96
97
description : 'description for active entry' ,
97
98
uri : 'abc' ,
98
- start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
99
- start_hour : moment ( ) . format ( 'HH:mm' ) ,
99
+ start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
100
+ start_hour : moment ( mockDate ) . format ( 'HH:mm' ) ,
100
101
} ;
101
102
102
103
beforeEach ( waitForAsync ( ( ) => {
@@ -144,16 +145,20 @@ describe('EntryFieldsComponent', () => {
144
145
uri : entryDataForm . uri ,
145
146
activity_id : entryDataForm . activity_id ,
146
147
start_hour : formatDate ( entry . start_date , 'HH:mm' , 'en' ) ,
147
- start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
148
+ start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
148
149
}
149
150
) ;
150
151
expect ( component . selectedTechnologies ) . toEqual ( [ ] ) ;
151
152
} ) ;
152
153
153
154
it ( 'displays error message when the date selected is in the future' , ( ) => {
154
- component . newData = entry ;
155
- component . activeEntry = entry ;
156
- component . setDataToUpdate ( entry ) ;
155
+ const mockEntry = { ...entry ,
156
+ start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
157
+ start_hour : moment ( ) . format ( 'HH:mm' )
158
+ } ;
159
+ component . newData = mockEntry ;
160
+ component . activeEntry = mockEntry ;
161
+ component . setDataToUpdate ( mockEntry ) ;
157
162
spyOn ( toastrServiceStub , 'error' ) ;
158
163
159
164
const hourInTheFuture = moment ( ) . add ( 1 , 'hours' ) . format ( 'HH:mm' ) ;
@@ -170,7 +175,7 @@ describe('EntryFieldsComponent', () => {
170
175
component . setDataToUpdate ( entry ) ;
171
176
spyOn ( toastrServiceStub , 'error' ) ;
172
177
173
- const hourInThePast = moment ( ) . subtract ( 6 , 'hour' ) . format ( 'HH:mm' ) ;
178
+ const hourInThePast = moment ( mockDate ) . subtract ( 6 , 'hour' ) . format ( 'HH:mm' ) ;
174
179
component . entryForm . patchValue ( { start_hour : hourInThePast } ) ;
175
180
component . onUpdateStartHour ( ) ;
176
181
@@ -188,7 +193,7 @@ describe('EntryFieldsComponent', () => {
188
193
component . newData = entry ;
189
194
component . activeEntry = entry ;
190
195
component . setDataToUpdate ( entry ) ;
191
- const updatedTime = moment ( ) . format ( 'HH:mm' ) ;
196
+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
192
197
component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
193
198
spyOn ( component . entryForm , 'patchValue' ) ;
194
199
component . cancelTimeInUpdate ( ) ;
@@ -206,7 +211,7 @@ describe('EntryFieldsComponent', () => {
206
211
component . activeEntry = entry ;
207
212
component . setDataToUpdate ( entry ) ;
208
213
209
- const updatedTime = moment ( ) . subtract ( 6 , 'hours' ) . format ( 'HH:mm' ) ;
214
+ const updatedTime = moment ( mockDate ) . subtract ( 6 , 'hours' ) . format ( 'HH:mm' ) ;
210
215
component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
211
216
212
217
spyOn ( component . entryForm , 'patchValue' ) ;
@@ -221,9 +226,13 @@ describe('EntryFieldsComponent', () => {
221
226
} ) ;
222
227
223
228
it ( 'If start hour is in the future, reset to initial start_date in form' , ( ) => {
224
- component . newData = entry ;
225
- component . activeEntry = entry ;
226
- component . setDataToUpdate ( entry ) ;
229
+ const mockEntry = { ...entry ,
230
+ start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
231
+ start_hour : moment ( ) . format ( 'HH:mm' )
232
+ } ;
233
+ component . newData = mockEntry ;
234
+ component . activeEntry = mockEntry ;
235
+ component . setDataToUpdate ( mockEntry ) ;
227
236
228
237
const hourInTheFuture = moment ( ) . add ( 1 , 'hours' ) . format ( 'HH:mm' ) ;
229
238
component . entryForm . patchValue ( { start_hour : hourInTheFuture } ) ;
@@ -240,9 +249,10 @@ describe('EntryFieldsComponent', () => {
240
249
} ) ;
241
250
242
251
it ( 'when a start hour is updated, then dispatch UpdateActiveEntry' , ( ) => {
243
- component . activeEntry = entry ;
252
+ component . activeEntry = entry ;
244
253
component . setDataToUpdate ( entry ) ;
245
- const updatedTime = moment ( ) . format ( 'HH:mm' ) ;
254
+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
255
+
246
256
component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
247
257
spyOn ( store , 'dispatch' ) ;
248
258
@@ -252,9 +262,9 @@ describe('EntryFieldsComponent', () => {
252
262
} ) ;
253
263
254
264
it ( 'When start_time is updated, component.last_entry is equal to time entry in the position 1' , waitForAsync ( ( ) => {
255
- component . activeEntry = entry ;
265
+ component . activeEntry = entry ;
256
266
component . setDataToUpdate ( entry ) ;
257
- const updatedTime = moment ( ) . format ( 'HH:mm' ) ;
267
+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
258
268
259
269
component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
260
270
component . onUpdateStartHour ( ) ;
@@ -263,9 +273,9 @@ describe('EntryFieldsComponent', () => {
263
273
} ) ) ;
264
274
265
275
it ( 'When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched' , ( ) => {
266
- component . activeEntry = entry ;
276
+ component . activeEntry = entry ;
267
277
component . setDataToUpdate ( entry ) ;
268
- const updatedTime = moment ( ) . subtract ( 4 , 'hours' ) . format ( 'HH:mm' ) ;
278
+ const updatedTime = moment ( mockDate ) . subtract ( 4 , 'hours' ) . format ( 'HH:mm' ) ;
269
279
component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
270
280
spyOn ( store , 'dispatch' ) ;
271
281
0 commit comments