@@ -245,19 +245,25 @@ describe('DetailsFieldsComponent', () => {
245245 expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
246246 } ) ;
247247
248- it ( 'when the current entry is not running, then the end hour input should be rendered' , ( ) => {
248+ it ( 'when the current entry is not running, then the end date and end hour inputs should be rendered' , ( ) => {
249249 component . goingToWorkOnThis = false ;
250250 fixture . detectChanges ( ) ;
251251
252+ const endDateInput = fixture . debugElement . nativeElement . querySelector ( '#end_date' ) ;
252253 const endHourInput = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
254+
255+ expect ( endDateInput ) . toBeDefined ( ) ;
253256 expect ( endHourInput ) . toBeDefined ( ) ;
254257 } ) ;
255258
256- it ( 'when the current entry is running, then the end hour input should not be rendered' , ( ) => {
259+ it ( 'when the current entry is running, then the end date and end hour inputs should not be rendered' , ( ) => {
257260 component . goingToWorkOnThis = true ;
258261 fixture . detectChanges ( ) ;
259262
263+ const endDateInput = fixture . debugElement . nativeElement . querySelector ( '#end_date' ) ;
260264 const endHourInput = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
265+
266+ expect ( endDateInput ) . toBeNull ( ) ;
261267 expect ( endHourInput ) . toBeNull ( ) ;
262268 } ) ;
263269
@@ -316,22 +322,22 @@ describe('DetailsFieldsComponent', () => {
316322 } ) ;
317323
318324 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 ( ) } ` ) ;
325+ const currentDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
326+ const startHour = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
327+ const expectedStartDate = new Date ( `${ currentDate } T${ startHour . trim ( ) } ` ) ;
322328
323329 component . entryToEdit = { ...entryToEdit , start_date : expectedStartDate } ;
324330 fixture . componentInstance . ngOnChanges ( ) ;
325331
326332 component . entryForm . patchValue ( { description : 'test' } ) ;
327333
328- expect ( component . startDateToSubmit ( ) ) . toEqual ( expectedStartDate ) ;
334+ expect ( component . dateToSubmit ( 'start_date' , 'start_hour' ) ) . toEqual ( expectedStartDate ) ;
329335 } ) ;
330336
331337 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 ( ) } ` ) ;
338+ const currentDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
339+ const startHour = moment ( ) . format ( 'HH:mm:ss' ) ;
340+ const startDate = new Date ( `${ currentDate } T${ startHour . trim ( ) } ` ) ;
335341
336342 component . entryToEdit = { ...entryToEdit , start_date : startDate } ;
337343 fixture . componentInstance . ngOnChanges ( ) ;
@@ -341,26 +347,26 @@ describe('DetailsFieldsComponent', () => {
341347 component . entryForm . patchValue ( { start_hour : updatedStartHour } ) ;
342348
343349 const expectedStartDate = moment ( updatedStartDate ) . seconds ( 0 ) . millisecond ( 0 ) . toISOString ( ) ;
344- expect ( component . startDateToSubmit ( ) ) . toEqual ( expectedStartDate ) ;
350+ expect ( component . dateToSubmit ( 'start_date' , 'start_hour' ) ) . toEqual ( expectedStartDate ) ;
345351 } ) ;
346352
347353 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 ( ) } ` ) ;
354+ const currentDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
355+ const endHour = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
356+ const expectedEndDate = new Date ( `${ currentDate } T${ endHour . trim ( ) } ` ) ;
351357
352358 component . entryToEdit = { ...entryToEdit , end_date : expectedEndDate } ;
353359 fixture . componentInstance . ngOnChanges ( ) ;
354360
355361 component . entryForm . patchValue ( { description : 'test' } ) ;
356362
357- expect ( component . endDateToSubmit ( ) ) . toEqual ( expectedEndDate ) ;
363+ expect ( component . dateToSubmit ( 'end_date' , 'end_hour' ) ) . toEqual ( expectedEndDate ) ;
358364 } ) ;
359365
360366 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 ( ) } ` ) ;
367+ const currentDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
368+ const endHour = moment ( ) . format ( 'HH:mm:ss' ) ;
369+ const endDate = new Date ( `${ currentDate } T${ endHour . trim ( ) } ` ) ;
364370
365371 component . entryToEdit = { ...entryToEdit , end_date : endDate } ;
366372 fixture . componentInstance . ngOnChanges ( ) ;
@@ -370,7 +376,7 @@ describe('DetailsFieldsComponent', () => {
370376 component . entryForm . patchValue ( { end_hour : updatedEndHour } ) ;
371377
372378 const expectedEndDate = moment ( updatedEndDate ) . seconds ( 0 ) . millisecond ( 0 ) . toISOString ( ) ;
373- expect ( component . endDateToSubmit ( ) ) . toEqual ( expectedEndDate ) ;
379+ expect ( component . dateToSubmit ( 'end_date' , 'end_hour' ) ) . toEqual ( expectedEndDate ) ;
374380 } ) ;
375381
376382 it ( 'displays error message when the date selected is in the future' , ( ) => {
0 commit comments