@@ -18,6 +18,7 @@ import { TimeEntriesComponent } from './time-entries.component';
18
18
import { ActionsSubject } from '@ngrx/store' ;
19
19
import { EntryActionTypes } from './../../time-clock/store/entry.actions' ;
20
20
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker' ;
21
+ import { DebugElement } from '@angular/core' ;
21
22
22
23
describe ( 'TimeEntriesComponent' , ( ) => {
23
24
type Merged = TechnologyState & ProjectState & EntryState ;
@@ -57,6 +58,7 @@ describe('TimeEntriesComponent', () => {
57
58
project_name : 'Time-tracker' ,
58
59
start_date : new Date ( '2020-02-05T15:36:15.887Z' ) ,
59
60
end_date : new Date ( '2020-02-05T18:36:15.887Z' ) ,
61
+ customer_name : 'ioet Inc.' ,
60
62
activity_id : 'development' ,
61
63
technologies : [ 'Angular' , 'TypeScript' ] ,
62
64
description : 'No comments' ,
@@ -375,19 +377,59 @@ describe('TimeEntriesComponent', () => {
375
377
component . entry = null ;
376
378
component . entryId = null ;
377
379
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 ) )
385
387
} ;
386
- state . timeEntriesDataSource . data = [ lastEntry ] ;
388
+ state . timeEntriesDataSource . data = [ lastEntry ] ;
387
389
mockEntriesSelector = store . overrideSelector ( getTimeEntriesDataSource , state . timeEntriesDataSource ) ;
388
390
389
- component . projectSelected ( { projectId : 'id' } ) ;
391
+ component . projectSelected ( { projectId : 'id' } ) ;
390
392
expect ( component . entry ) . toEqual ( lastEntry ) ;
391
393
} ) ) ;
392
394
395
+ it ( 'when the data source is loaded, the entry should to have customer_name field' , 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
+
421
+ expect ( expectedColumnTitles ) . toEqual ( columnTitles ) ;
422
+
423
+ } ) ;
424
+ } ) ) ;
425
+
426
+ it ( 'on success times entries data source charged, the entry should to have customer_name field' , waitForAsync ( ( ) => {
427
+ component . timeEntriesDataSource$ . subscribe ( dataSource => {
428
+ const entryData = dataSource . data [ 0 ] ;
429
+
430
+ expect ( entryData . customer_name ) . toContain ( 'ioet Inc.' ) ;
431
+
432
+ } ) ;
433
+ } ) ) ;
434
+
393
435
} ) ;
0 commit comments