@@ -18,6 +18,7 @@ import { TimeEntriesComponent } from './time-entries.component';
1818import { ActionsSubject } from '@ngrx/store' ;
1919import { EntryActionTypes } from './../../time-clock/store/entry.actions' ;
2020import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker' ;
21+ import { DebugElement } from '@angular/core' ;
2122
2223describe ( 'TimeEntriesComponent' , ( ) => {
2324 type Merged = TechnologyState & ProjectState & EntryState ;
@@ -57,6 +58,7 @@ describe('TimeEntriesComponent', () => {
5758 project_name : 'Time-tracker' ,
5859 start_date : new Date ( '2020-02-05T15:36:15.887Z' ) ,
5960 end_date : new Date ( '2020-02-05T18:36:15.887Z' ) ,
61+ customer_name : 'ioet Inc.' ,
6062 activity_id : 'development' ,
6163 technologies : [ 'Angular' , 'TypeScript' ] ,
6264 description : 'No comments' ,
@@ -375,19 +377,54 @@ describe('TimeEntriesComponent', () => {
375377 component . entry = null ;
376378 component . entryId = null ;
377379 const lastEntry = {
378- description : 'testing is fun' ,
379- technologies : [ ] ,
380- uri : 'http://testing.is.fun' ,
381- activity_id : 'sss' ,
382- project_id : 'id' ,
383- start_date : new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ,
384- end_date : new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) )
380+ description : 'testing is fun' ,
381+ technologies : [ ] ,
382+ uri : 'http://testing.is.fun' ,
383+ activity_id : 'sss' ,
384+ project_id : 'id' ,
385+ start_date : new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ,
386+ end_date : new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) )
385387 } ;
386- state . timeEntriesDataSource . data = [ lastEntry ] ;
388+ state . timeEntriesDataSource . data = [ lastEntry ] ;
387389 mockEntriesSelector = store . overrideSelector ( getTimeEntriesDataSource , state . timeEntriesDataSource ) ;
388390
389- component . projectSelected ( { projectId : 'id' } ) ;
391+ component . projectSelected ( { projectId : 'id' } ) ;
390392 expect ( component . entry ) . toEqual ( lastEntry ) ;
391393 } ) ) ;
392394
395+ it ( 'when the data source is loaded, the table should to show the appropriated column titles' , waitForAsync ( ( ) => {
396+ component . timeEntriesDataSource$ . subscribe ( ( ) => {
397+
398+ fixture . detectChanges ( ) ;
399+
400+ const expectedColumnTitles = [
401+ 'Date' ,
402+ 'Time in - out' ,
403+ 'Duration' ,
404+ 'Customer' ,
405+ 'Project' ,
406+ 'Activity' ,
407+ '' ,
408+ ] ;
409+
410+ const columnTitles : string [ ] = [ ] ;
411+
412+ const HTMLTimeEntriesDebugElement : DebugElement = fixture . debugElement ;
413+ const HTMLTimeEntriesElement : HTMLElement = HTMLTimeEntriesDebugElement . nativeElement ;
414+ const HTMLTimeEntriesTable = HTMLTimeEntriesElement . querySelector ( '.table' ) as HTMLTableElement ;
415+ const HTMLTableHead = HTMLTimeEntriesTable . rows [ 0 ] ;
416+
417+ Array . from ( HTMLTableHead . cells ) . forEach ( columnTitle => {
418+ columnTitles . push ( columnTitle . innerText ) ;
419+ } ) ;
420+ expect ( expectedColumnTitles ) . toEqual ( columnTitles ) ;
421+ } ) ;
422+ } ) ) ;
423+
424+ it ( 'when the data source is loaded, the entry should to have customer_name field' , waitForAsync ( ( ) => {
425+ component . timeEntriesDataSource$ . subscribe ( dataSource => {
426+ const entryData = dataSource . data [ 0 ] ;
427+ expect ( entryData . customer_name ) . toContain ( 'ioet Inc.' ) ;
428+ } ) ;
429+ } ) ) ;
393430} ) ;
0 commit comments