1
1
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
- import { Router , NavigationEnd , RouterModule } from '@angular/router' ;
2
+ import { Router , NavigationEnd , provideRouter } from '@angular/router' ;
3
3
import { of } from 'rxjs' ;
4
4
import { IntacctComponent } from './intacct.component' ;
5
5
import { HelperService } from 'src/app/core/services/common/helper.service' ;
@@ -8,9 +8,11 @@ import { WindowService } from 'src/app/core/services/common/window.service';
8
8
import { AppcuesService } from 'src/app/core/services/integration/appcues.service' ;
9
9
import { UserService } from 'src/app/core/services/misc/user.service' ;
10
10
import { 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' ;
12
12
import { mockUser , testOnboardingState , workspaceResponse } from './intacct.fixture' ;
13
13
import { 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' ;
14
16
15
17
describe ( 'IntacctComponent' , ( ) => {
16
18
let component : IntacctComponent ;
@@ -19,16 +21,15 @@ describe('IntacctComponent', () => {
19
21
let workspaceServiceSpy : jasmine . SpyObj < SiWorkspaceService > ;
20
22
let helperServiceSpy : jasmine . SpyObj < HelperService > ;
21
23
let storageServiceSpy : jasmine . SpyObj < StorageService > ;
22
- let routerSpy : jasmine . SpyObj < Router > ;
23
24
let windowServiceMock : Partial < WindowService > ;
24
25
let appcuesServiceSpy : jasmine . SpyObj < AppcuesService > ;
26
+ let router : Router ;
25
27
26
28
beforeEach ( async ( ) => {
27
29
const userSpy = jasmine . createSpyObj ( 'UserService' , [ 'getUserProfile' ] ) ;
28
30
const workspaceSpy = jasmine . createSpyObj ( 'SiWorkspaceService' , [ 'getWorkspace' , 'postWorkspace' , 'syncFyleDimensions' , 'syncIntacctDimensions' ] ) ;
29
31
const helperSpy = jasmine . createSpyObj ( 'HelperService' , [ 'setBaseApiURL' ] ) ;
30
32
const storageSpy = jasmine . createSpyObj ( 'StorageService' , [ 'set' ] ) ;
31
- const routerSpyObj = jasmine . createSpyObj ( 'Router' , [ 'navigateByUrl' , 'events' ] ) ;
32
33
const appcuesSpy = jasmine . createSpyObj ( 'AppcuesService' , [ 'initialiseAppcues' ] ) ;
33
34
34
35
windowServiceMock = {
@@ -42,27 +43,28 @@ describe('IntacctComponent', () => {
42
43
} ;
43
44
44
45
await TestBed . configureTestingModule ( {
45
- declarations : [ IntacctComponent ] ,
46
- imports : [ RouterModule ] ,
46
+ declarations : [ IntacctComponent ] ,
47
+ imports : [ SharedModule , HttpClientTestingModule ] ,
47
48
providers : [
48
49
{ provide : HelperService , useValue : helperSpy } ,
49
50
{ provide : AppcuesService , useValue : appcuesSpy } ,
50
- { provide : Router , useValue : routerSpyObj } ,
51
51
{ provide : StorageService , useValue : storageSpy } ,
52
52
{ provide : UserService , useValue : userSpy } ,
53
53
{ provide : SiWorkspaceService , useValue : workspaceSpy } ,
54
- { provide : WindowService , useValue : windowServiceMock }
54
+ { provide : WindowService , useValue : windowServiceMock } ,
55
+ provideRouter ( [ ] )
55
56
]
56
57
} ) . compileComponents ( ) ;
57
58
58
59
userServiceSpy = TestBed . inject ( UserService ) as jasmine . SpyObj < UserService > ;
59
60
workspaceServiceSpy = TestBed . inject ( SiWorkspaceService ) as jasmine . SpyObj < SiWorkspaceService > ;
60
61
helperServiceSpy = TestBed . inject ( HelperService ) as jasmine . SpyObj < HelperService > ;
61
62
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 ) ;
64
64
appcuesServiceSpy = TestBed . inject ( AppcuesService ) as jasmine . SpyObj < AppcuesService > ;
65
65
66
+ spyOn ( router , 'navigateByUrl' ) ;
67
+ spyOnProperty ( router , 'events' ) . and . returnValue ( of ( new NavigationEnd ( 0 , '' , '' ) ) ) ;
66
68
userServiceSpy . getUserProfile . and . returnValue ( mockUser ) ;
67
69
workspaceServiceSpy . getWorkspace . and . returnValue ( of ( workspaceResponse ) ) ;
68
70
workspaceServiceSpy . syncFyleDimensions . and . returnValue ( of ( ) ) ;
@@ -85,7 +87,7 @@ describe('IntacctComponent', () => {
85
87
expect ( storageServiceSpy . set ) . toHaveBeenCalledWith ( 'onboarding-state' , IntacctOnboardingState . CONNECTION ) ;
86
88
expect ( workspaceServiceSpy . syncFyleDimensions ) . toHaveBeenCalled ( ) ;
87
89
expect ( workspaceServiceSpy . syncIntacctDimensions ) . toHaveBeenCalled ( ) ;
88
- expect ( routerSpy . navigateByUrl ) . toHaveBeenCalledWith ( '/integrations/intacct/onboarding/landing' ) ;
90
+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/integrations/intacct/onboarding/landing' ) ;
89
91
} ) ;
90
92
91
93
it ( 'should create a new workspace if none exists' , ( ) => {
@@ -97,18 +99,17 @@ describe('IntacctComponent', () => {
97
99
expect ( workspaceServiceSpy . postWorkspace ) . toHaveBeenCalled ( ) ;
98
100
expect ( storageServiceSpy . set ) . toHaveBeenCalledWith ( 'workspaceId' , 1 ) ;
99
101
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' ) ;
101
103
} ) ;
102
104
103
105
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 ] ) => {
106
107
const testWorkspace : IntacctWorkspace = { ...workspaceResponse [ 0 ] , onboarding_state : state as IntacctOnboardingState } ;
107
108
workspaceServiceSpy . getWorkspace . and . returnValue ( of ( [ testWorkspace ] ) ) ;
108
109
109
110
fixture . detectChanges ( ) ;
110
111
111
- expect ( routerSpy . navigateByUrl ) . toHaveBeenCalledWith ( route ) ;
112
+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( route ) ;
112
113
113
114
fixture = TestBed . createComponent ( IntacctComponent ) ;
114
115
component = fixture . componentInstance ;
@@ -119,7 +120,7 @@ describe('IntacctComponent', () => {
119
120
component . windowReference . location . pathname = '/some/other/path' ;
120
121
fixture . detectChanges ( ) ;
121
122
122
- expect ( routerSpy . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
123
+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
123
124
} ) ;
124
125
125
126
it ( 'should initialise Appcues' , ( ) => {
0 commit comments