@@ -15,15 +15,6 @@ describe('SidebarComponent', () => {
1515 let router ;
1616 const routes : Routes = [ { path : 'time-clock' , component : TimeClockComponent } ] ;
1717
18- const azureAdB2CServiceStub = {
19- isLogin ( ) {
20- return true ;
21- } ,
22- isAdmin ( ) {
23- return true ;
24- } ,
25- } ;
26-
2718 const userInfoServiceStub = {
2819 isAdmin : ( ) => of ( true ) ,
2920 } ;
@@ -83,10 +74,33 @@ describe('SidebarComponent', () => {
8374 } ) ;
8475 } ) ;
8576
86- it ( 'uses the Azure service on logout' , ( ) => {
77+ it ( 'onInit checks if isLogin is true and gets the name, email and sets the tenantid in the Storage' , ( ) => {
78+ spyOn ( azureAdB2CServiceStubInjected , 'isLogin' ) . and . returnValue ( true ) ;
79+ spyOn ( azureAdB2CServiceStubInjected , 'getName' ) . and . returnValue ( 'Name' ) ;
80+ spyOn ( azureAdB2CServiceStubInjected , 'getUserEmail' ) . and . returnValue ( 'Email' ) ;
81+ spyOn ( azureAdB2CServiceStubInjected , 'setTenantId' ) ;
82+ component . ngOnInit ( ) ;
83+ expect ( azureAdB2CServiceStubInjected . isLogin ) . toHaveBeenCalled ( ) ;
84+ expect ( azureAdB2CServiceStubInjected . getName ) . toHaveBeenCalled ( ) ;
85+ expect ( azureAdB2CServiceStubInjected . getUserEmail ) . toHaveBeenCalled ( ) ;
86+ expect ( azureAdB2CServiceStubInjected . setTenantId ) . toHaveBeenCalled ( ) ;
87+ } ) ;
88+
89+ it ( 'onInit does not get the name and the email if isLogin is false' , ( ) => {
90+ spyOn ( azureAdB2CServiceStubInjected , 'isLogin' ) . and . returnValue ( false ) ;
91+ spyOn ( azureAdB2CServiceStubInjected , 'getName' ) . and . returnValue ( 'Name' ) ;
92+ spyOn ( azureAdB2CServiceStubInjected , 'getUserEmail' ) . and . returnValue ( 'Email' ) ;
93+ spyOn ( azureAdB2CServiceStubInjected , 'setTenantId' ) ;
94+ component . ngOnInit ( ) ;
95+ expect ( azureAdB2CServiceStubInjected . isLogin ) . toHaveBeenCalled ( ) ;
96+ expect ( azureAdB2CServiceStubInjected . getName ) . toHaveBeenCalledTimes ( 0 ) ;
97+ expect ( azureAdB2CServiceStubInjected . getUserEmail ) . toHaveBeenCalledTimes ( 0 ) ;
98+ expect ( azureAdB2CServiceStubInjected . setTenantId ) . not . toHaveBeenCalled ( ) ;
99+ } ) ;
100+
101+ it ( 'should use the Azure service on logout' , ( ) => {
87102 spyOn ( azureAdB2CServiceStubInjected , 'logout' ) ;
88103 component . logout ( ) ;
89104 expect ( azureAdB2CServiceStubInjected . logout ) . toHaveBeenCalled ( ) ;
90105 } ) ;
91-
92106} ) ;
0 commit comments