@@ -21,7 +21,7 @@ describe('Reports Page', () => {
2121 description : 'any comment' ,
2222 uri : 'custom uri' ,
2323 project_id : '123' ,
24- project_name : 'Time-Tracker'
24+ project_name : 'Time-Tracker' ,
2525 } ;
2626
2727 const state : EntryState = {
@@ -33,38 +33,41 @@ describe('Reports Page', () => {
3333 timeEntriesSummary : null ,
3434 timeEntriesDataSource : {
3535 data : [ timeEntry ] ,
36- isLoading : false
36+ isLoading : false ,
3737 } ,
3838 reportDataSource : {
3939 data : [ timeEntry ] ,
40- isLoading : false
41- }
40+ isLoading : false ,
41+ } ,
4242 } ;
4343
44- beforeEach ( waitForAsync ( ( ) => {
45- TestBed . configureTestingModule ( {
46- imports : [ ] ,
47- declarations : [ TimeEntriesTableComponent , SubstractDatePipe ] ,
48- providers : [ provideMockStore ( { initialState : state } ) ] ,
49- } ) . compileComponents ( ) ;
50- store = TestBed . inject ( MockStore ) ;
51-
52- } ) ) ;
44+ beforeEach (
45+ waitForAsync ( ( ) => {
46+ TestBed . configureTestingModule ( {
47+ imports : [ ] ,
48+ declarations : [ TimeEntriesTableComponent , SubstractDatePipe ] ,
49+ providers : [ provideMockStore ( { initialState : state } ) ] ,
50+ } ) . compileComponents ( ) ;
51+ store = TestBed . inject ( MockStore ) ;
52+ } )
53+ ) ;
5354
54- beforeEach ( waitForAsync ( ( ) => {
55- fixture = TestBed . createComponent ( TimeEntriesTableComponent ) ;
56- component = fixture . componentInstance ;
57- store . setState ( state ) ;
58- getReportDataSourceSelectorMock = store . overrideSelector ( getReportDataSource , state . reportDataSource ) ;
59- fixture . detectChanges ( ) ;
60- } ) ) ;
55+ beforeEach (
56+ waitForAsync ( ( ) => {
57+ fixture = TestBed . createComponent ( TimeEntriesTableComponent ) ;
58+ component = fixture . componentInstance ;
59+ store . setState ( state ) ;
60+ getReportDataSourceSelectorMock = store . overrideSelector ( getReportDataSource , state . reportDataSource ) ;
61+ fixture . detectChanges ( ) ;
62+ } )
63+ ) ;
6164
6265 it ( 'component should be created' , async ( ) => {
6366 expect ( component ) . toBeTruthy ( ) ;
6467 } ) ;
6568
6669 it ( 'on success load time entries, the report should be populated' , ( ) => {
67- component . reportDataSource$ . subscribe ( ds => {
70+ component . reportDataSource$ . subscribe ( ( ds ) => {
6871 expect ( ds . data ) . toEqual ( state . reportDataSource . data ) ;
6972 } ) ;
7073 } ) ;
@@ -78,16 +81,20 @@ describe('Reports Page', () => {
7881
7982 fit ( 'when the uri starts with http or https it should return true and open the url in a new tab' , ( ) => {
8083 const uriExpected = 'http://customuri.com' ;
84+ spyOn ( component , 'isValidUri' ) . and . returnValue ( true ) ;
8185 spyOn ( window , 'open' ) ;
82- const isValidUri = uriExpected . startsWith ( 'http' || 'https' ) ;
83- expect ( isValidUri ) . toBeTrue ( ) ;
84- expect ( window . open ) . toHaveBeenCalled ( ) ;
86+
87+ expect ( component . isLinkExternal ( uriExpected ) ) . not . toEqual ( '' ) ;
88+ expect ( window . open ) . toHaveBeenCalledWith ( uriExpected , '_blank' ) ;
89+ expect ( component . isValidUri ) . toHaveBeenCalled ( ) ;
8590 } ) ;
8691
8792 it ( 'when the uri starts without http or https it should return false and not navigate or open a new tab' , ( ) => {
8893 const uriExpected = timeEntry . uri ;
89- const isValidUri = uriExpected . startsWith ( 'http' || 'https' ) ;
90- expect ( isValidUri ) . toBeFalse ( ) ;
94+ spyOn ( component , 'isValidUri' ) . and . returnValue ( false ) ;
95+
96+ expect ( component . isLinkExternal ( uriExpected ) ) . toEqual ( '' ) ;
97+ expect ( component . isValidUri ) . toHaveBeenCalled ( ) ;
9198 } ) ;
9299
93100 afterEach ( ( ) => {
0 commit comments