11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2- import { Router , NavigationEnd , RouterModule } from '@angular/router' ;
2+ import { Router , NavigationEnd , provideRouter } from '@angular/router' ;
33import { of } from 'rxjs' ;
44import { IntacctComponent } from './intacct.component' ;
55import { HelperService } from 'src/app/core/services/common/helper.service' ;
@@ -8,9 +8,11 @@ import { WindowService } from 'src/app/core/services/common/window.service';
88import { AppcuesService } from 'src/app/core/services/integration/appcues.service' ;
99import { UserService } from 'src/app/core/services/misc/user.service' ;
1010import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service' ;
11- import { AppName , AppUrl , IntacctOnboardingState } from 'src/app/core/models/enum/enum.model' ;
11+ import { AppUrl , IntacctOnboardingState } from 'src/app/core/models/enum/enum.model' ;
1212import { mockUser , testOnboardingState , workspaceResponse } from './intacct.fixture' ;
1313import { IntacctWorkspace } from 'src/app/core/models/intacct/db/workspaces.model' ;
14+ import { SharedModule } from 'src/app/shared/shared.module' ;
15+ import { HttpClientTestingModule } from '@angular/common/http/testing' ;
1416
1517describe ( 'IntacctComponent' , ( ) => {
1618 let component : IntacctComponent ;
@@ -19,16 +21,15 @@ describe('IntacctComponent', () => {
1921 let workspaceServiceSpy : jasmine . SpyObj < SiWorkspaceService > ;
2022 let helperServiceSpy : jasmine . SpyObj < HelperService > ;
2123 let storageServiceSpy : jasmine . SpyObj < StorageService > ;
22- let routerSpy : jasmine . SpyObj < Router > ;
2324 let windowServiceMock : Partial < WindowService > ;
2425 let appcuesServiceSpy : jasmine . SpyObj < AppcuesService > ;
26+ let router : Router ;
2527
2628 beforeEach ( async ( ) => {
2729 const userSpy = jasmine . createSpyObj ( 'UserService' , [ 'getUserProfile' ] ) ;
2830 const workspaceSpy = jasmine . createSpyObj ( 'SiWorkspaceService' , [ 'getWorkspace' , 'postWorkspace' , 'syncFyleDimensions' , 'syncIntacctDimensions' ] ) ;
2931 const helperSpy = jasmine . createSpyObj ( 'HelperService' , [ 'setBaseApiURL' ] ) ;
3032 const storageSpy = jasmine . createSpyObj ( 'StorageService' , [ 'set' ] ) ;
31- const routerSpyObj = jasmine . createSpyObj ( 'Router' , [ 'navigateByUrl' , 'events' ] ) ;
3233 const appcuesSpy = jasmine . createSpyObj ( 'AppcuesService' , [ 'initialiseAppcues' ] ) ;
3334
3435 windowServiceMock = {
@@ -42,27 +43,28 @@ describe('IntacctComponent', () => {
4243 } ;
4344
4445 await TestBed . configureTestingModule ( {
45- declarations : [ IntacctComponent ] ,
46- imports : [ RouterModule ] ,
46+ declarations : [ IntacctComponent ] ,
47+ imports : [ SharedModule , HttpClientTestingModule ] ,
4748 providers : [
4849 { provide : HelperService , useValue : helperSpy } ,
4950 { provide : AppcuesService , useValue : appcuesSpy } ,
50- { provide : Router , useValue : routerSpyObj } ,
5151 { provide : StorageService , useValue : storageSpy } ,
5252 { provide : UserService , useValue : userSpy } ,
5353 { provide : SiWorkspaceService , useValue : workspaceSpy } ,
54- { provide : WindowService , useValue : windowServiceMock }
54+ { provide : WindowService , useValue : windowServiceMock } ,
55+ provideRouter ( [ ] )
5556 ]
5657 } ) . compileComponents ( ) ;
5758
5859 userServiceSpy = TestBed . inject ( UserService ) as jasmine . SpyObj < UserService > ;
5960 workspaceServiceSpy = TestBed . inject ( SiWorkspaceService ) as jasmine . SpyObj < SiWorkspaceService > ;
6061 helperServiceSpy = TestBed . inject ( HelperService ) as jasmine . SpyObj < HelperService > ;
6162 storageServiceSpy = TestBed . inject ( StorageService ) as jasmine . SpyObj < StorageService > ;
62- routerSpy = TestBed . inject ( Router ) as jasmine . SpyObj < Router > ;
63- ( routerSpy . events as any ) = of ( new NavigationEnd ( 0 , '' , '' ) ) ;
63+ router = TestBed . inject ( Router ) ;
6464 appcuesServiceSpy = TestBed . inject ( AppcuesService ) as jasmine . SpyObj < AppcuesService > ;
6565
66+ spyOn ( router , 'navigateByUrl' ) ;
67+ spyOnProperty ( router , 'events' ) . and . returnValue ( of ( new NavigationEnd ( 0 , '' , '' ) ) ) ;
6668 userServiceSpy . getUserProfile . and . returnValue ( mockUser ) ;
6769 workspaceServiceSpy . getWorkspace . and . returnValue ( of ( workspaceResponse ) ) ;
6870 workspaceServiceSpy . syncFyleDimensions . and . returnValue ( of ( ) ) ;
@@ -85,7 +87,7 @@ describe('IntacctComponent', () => {
8587 expect ( storageServiceSpy . set ) . toHaveBeenCalledWith ( 'onboarding-state' , IntacctOnboardingState . CONNECTION ) ;
8688 expect ( workspaceServiceSpy . syncFyleDimensions ) . toHaveBeenCalled ( ) ;
8789 expect ( workspaceServiceSpy . syncIntacctDimensions ) . toHaveBeenCalled ( ) ;
88- expect ( routerSpy . navigateByUrl ) . toHaveBeenCalledWith ( '/integrations/intacct/onboarding/landing' ) ;
90+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/integrations/intacct/onboarding/landing' ) ;
8991 } ) ;
9092
9193 it ( 'should create a new workspace if none exists' , ( ) => {
@@ -97,18 +99,17 @@ describe('IntacctComponent', () => {
9799 expect ( workspaceServiceSpy . postWorkspace ) . toHaveBeenCalled ( ) ;
98100 expect ( storageServiceSpy . set ) . toHaveBeenCalledWith ( 'workspaceId' , 1 ) ;
99101 expect ( storageServiceSpy . set ) . toHaveBeenCalledWith ( 'onboarding-state' , IntacctOnboardingState . CONNECTION ) ;
100- expect ( routerSpy . navigateByUrl ) . toHaveBeenCalledWith ( '/integrations/intacct/onboarding/landing' ) ;
102+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/integrations/intacct/onboarding/landing' ) ;
101103 } ) ;
102104
103105 it ( 'should navigate to correct route based on onboarding state' , ( ) => {
104- Object . entries ( testOnboardingState ) . forEach ( ( [ state , route ] ) => {
105- routerSpy . navigateByUrl . calls . reset ( ) ;
106+ Object . entries ( testOnboardingState ) . forEach ( ( [ state , route ] ) => {
106107 const testWorkspace : IntacctWorkspace = { ...workspaceResponse [ 0 ] , onboarding_state : state as IntacctOnboardingState } ;
107108 workspaceServiceSpy . getWorkspace . and . returnValue ( of ( [ testWorkspace ] ) ) ;
108109
109110 fixture . detectChanges ( ) ;
110111
111- expect ( routerSpy . navigateByUrl ) . toHaveBeenCalledWith ( route ) ;
112+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( route ) ;
112113
113114 fixture = TestBed . createComponent ( IntacctComponent ) ;
114115 component = fixture . componentInstance ;
@@ -119,7 +120,7 @@ describe('IntacctComponent', () => {
119120 component . windowReference . location . pathname = '/some/other/path' ;
120121 fixture . detectChanges ( ) ;
121122
122- expect ( routerSpy . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
123+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
123124 } ) ;
124125
125126 it ( 'should initialise Appcues' , ( ) => {
0 commit comments