@@ -76,11 +76,6 @@ describe('DetailsFieldsComponent', () => {
76
76
description : '' ,
77
77
technology : '' ,
78
78
} ;
79
- const dateTest = moment ( ) . format ( 'YYYY-MM-DD' ) ;
80
- const endHourTest = moment ( ) . format ( 'HH:mm:ss' ) ;
81
- const endDateTest = new Date ( `${ dateTest } T${ endHourTest . trim ( ) } ` ) ;
82
- const startHourTest = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
83
- const startDateTest = new Date ( `${ dateTest } T${ startHourTest . trim ( ) } ` ) ;
84
79
85
80
beforeEach ( waitForAsync ( ( ) => {
86
81
TestBed . configureTestingModule ( {
@@ -106,8 +101,8 @@ describe('DetailsFieldsComponent', () => {
106
101
project_id : 'id' ,
107
102
activity_id : '' ,
108
103
uri : 'ticketUri' ,
109
- start_date : startDateTest ,
110
- end_date : endDateTest ,
104
+ start_date : null ,
105
+ end_date : null ,
111
106
description : '' ,
112
107
technologies : [ ] ,
113
108
id : 'xyz'
@@ -218,6 +213,7 @@ describe('DetailsFieldsComponent', () => {
218
213
219
214
it ( 'should emit saveEntry event' , ( ) => {
220
215
spyOn ( component . saveEntry , 'emit' ) ;
216
+ component . entryToEdit = { ...entryToEdit } ;
221
217
component . entryForm . setValue ( {
222
218
project_id : 'p1' ,
223
219
project_name : 'p-name' ,
@@ -299,6 +295,7 @@ describe('DetailsFieldsComponent', () => {
299
295
component . goingToWorkOnThis = true ;
300
296
spyOn ( component . saveEntry , 'emit' ) ;
301
297
298
+ component . entryToEdit = { ...entryToEdit } ;
302
299
component . entryForm . setValue ( { ...formValues , start_date : '2020-06-11' , end_date : '2020-06-11' } ) ;
303
300
304
301
component . onSubmit ( ) ;
@@ -315,26 +312,71 @@ describe('DetailsFieldsComponent', () => {
315
312
} ,
316
313
shouldRestartEntry : false
317
314
} ;
318
-
319
315
expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
320
316
} ) ;
321
317
322
- it ( 'onSubmit an entry without change hours, should not modify the start_date and end_date ' , ( ) => {
323
- component . entryToEdit = { ...entryToEdit , description : 'test' , } ;
318
+ it ( 'should not modify the start_date when start_hour has not been modified' , ( ) => {
319
+ const dateTest = moment ( ) . format ( 'YYYY-MM-DD' ) ;
320
+ const startHourTest = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
321
+ const expectedStartDate = new Date ( `${ dateTest } T${ startHourTest . trim ( ) } ` ) ;
322
+
323
+ component . entryToEdit = { ...entryToEdit , start_date : expectedStartDate } ;
324
324
fixture . componentInstance . ngOnChanges ( ) ;
325
325
326
- const startHourValue = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm' ) ;
327
- const endHourValue = moment ( ) . format ( 'HH:mm' ) ;
326
+ component . entryForm . patchValue ( { description : 'test' } ) ;
328
327
329
- component . onSubmit ( ) ;
328
+ expect ( component . startDateToSubmit ( ) ) . toEqual ( expectedStartDate ) ;
329
+ } ) ;
330
+
331
+ it ( 'should modify the start_date when start_hour has been modified' , ( ) => {
332
+ const dateTest = moment ( ) . format ( 'YYYY-MM-DD' ) ;
333
+ const startHourTest = moment ( ) . format ( 'HH:mm:ss' ) ;
334
+ const startDate = new Date ( `${ dateTest } T${ startHourTest . trim ( ) } ` ) ;
335
+
336
+ component . entryToEdit = { ...entryToEdit , start_date : startDate } ;
337
+ fixture . componentInstance . ngOnChanges ( ) ;
338
+
339
+ const updatedStartDate = moment ( ) . subtract ( 1 , 'hours' ) ;
340
+ const updatedStartHour = updatedStartDate . format ( 'HH:mm' ) ;
341
+ component . entryForm . patchValue ( { start_hour : updatedStartHour } ) ;
342
+
343
+ const expectedStartDate = moment ( updatedStartDate ) . seconds ( 0 ) . millisecond ( 0 ) . toISOString ( ) ;
344
+ expect ( component . startDateToSubmit ( ) ) . toEqual ( expectedStartDate ) ;
345
+ } ) ;
330
346
331
- expect ( component . starDateValue ) . toEqual ( startHourValue ) ;
332
- expect ( component . endDateValue ) . toEqual ( endHourValue ) ;
347
+ it ( 'should not modify the end_date when end_hour has not been modified' , ( ) => {
348
+ const dateTest = moment ( ) . format ( 'YYYY-MM-DD' ) ;
349
+ const endtHourTest = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
350
+ const expectedEndDate = new Date ( `${ dateTest } T${ endtHourTest . trim ( ) } ` ) ;
351
+
352
+ component . entryToEdit = { ...entryToEdit , end_date : expectedEndDate } ;
353
+ fixture . componentInstance . ngOnChanges ( ) ;
354
+
355
+ component . entryForm . patchValue ( { description : 'test' } ) ;
356
+
357
+ expect ( component . endDateToSubmit ( ) ) . toEqual ( expectedEndDate ) ;
333
358
} ) ;
334
359
360
+ it ( 'should modify the end_date when end_hour has been modified' , ( ) => {
361
+ const dateTest = moment ( ) . format ( 'YYYY-MM-DD' ) ;
362
+ const endHourTest = moment ( ) . format ( 'HH:mm:ss' ) ;
363
+ const endDate = new Date ( `${ dateTest } T${ endHourTest . trim ( ) } ` ) ;
364
+
365
+ component . entryToEdit = { ...entryToEdit , end_date : endDate } ;
366
+ fixture . componentInstance . ngOnChanges ( ) ;
367
+
368
+ const updatedEndDate = moment ( ) . subtract ( 1 , 'hours' ) ;
369
+ const updatedEndHour = updatedEndDate . format ( 'HH:mm' ) ;
370
+ component . entryForm . patchValue ( { end_hour : updatedEndHour } ) ;
371
+
372
+ const expectedEndDate = moment ( updatedEndDate ) . seconds ( 0 ) . millisecond ( 0 ) . toISOString ( ) ;
373
+ expect ( component . endDateToSubmit ( ) ) . toEqual ( expectedEndDate ) ;
374
+ } ) ;
375
+
335
376
it ( 'displays error message when the date selected is in the future' , ( ) => {
336
377
spyOn ( toastrServiceStub , 'error' ) ;
337
378
379
+ component . entryToEdit = { ...entryToEdit } ;
338
380
const futureDate = moment ( ) . add ( 1 , 'days' ) . format ( DATE_FORMAT_YEAR ) ;
339
381
component . entryForm . setValue ( { ...formValues , start_date : futureDate , end_date : futureDate } ) ;
340
382
component . onSubmit ( ) ;
@@ -345,6 +387,7 @@ describe('DetailsFieldsComponent', () => {
345
387
it ( 'when start_date is in the future and end_date is OK then throws an error' , ( ) => {
346
388
spyOn ( toastrServiceStub , 'error' ) ;
347
389
390
+ component . entryToEdit = { ...entryToEdit } ;
348
391
const futureDate = moment ( ) . add ( 1 , 'days' ) . format ( DATE_FORMAT_YEAR ) ;
349
392
const currentDate = moment ( ) . format ( DATE_FORMAT_YEAR ) ;
350
393
component . entryForm . setValue ( { ...formValues , start_date : futureDate , end_date : currentDate } ) ;
@@ -356,6 +399,7 @@ describe('DetailsFieldsComponent', () => {
356
399
it ( 'when start_date is OK and end_date is in the future then throws an error future' , ( ) => {
357
400
spyOn ( toastrServiceStub , 'error' ) ;
358
401
402
+ component . entryToEdit = { ...entryToEdit } ;
359
403
const futureDate = moment ( ) . add ( 1 , 'days' ) . format ( DATE_FORMAT_YEAR ) ;
360
404
const currentDate = moment ( ) . format ( DATE_FORMAT_YEAR ) ;
361
405
component . entryForm . setValue ( { ...formValues , start_date : currentDate , end_date : futureDate } ) ;
0 commit comments