@@ -15,6 +15,18 @@ 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+ logout ( ) {
26+ return true ;
27+ }
28+ } ;
29+
1830 const userInfoServiceStub = {
1931 isAdmin : ( ) => of ( true ) ,
2032 } ;
@@ -24,7 +36,7 @@ describe('SidebarComponent', () => {
2436 TestBed . configureTestingModule ( {
2537 declarations : [ SidebarComponent ] ,
2638 providers : [
27- AzureAdB2CService ,
39+ { provide : AzureAdB2CService , useValue : azureAdB2CServiceStub } ,
2840 { provide : UserInfoService , useValue : userInfoServiceStub } ,
2941 ] ,
3042 imports : [ RouterTestingModule . withRoutes ( routes ) ] ,
@@ -41,19 +53,19 @@ describe('SidebarComponent', () => {
4153 fixture . detectChanges ( ) ;
4254 } ) ;
4355
44- it ( 'should be created' , ( ) => {
56+ it ( 'component should be created' , ( ) => {
4557 spyOn ( azureAdB2CServiceStubInjected , 'isAdmin' ) . and . returnValue ( false ) ;
4658 expect ( component ) . toBeTruthy ( ) ;
4759 } ) ;
4860
49- it ( 'admin users have six menu items' , ( ) => {
61+ it ( 'admin users should have six menu items' , ( ) => {
5062 component . getSidebarItems ( ) . subscribe ( ( ) => {
5163 const menuItems = component . itemsSidebar ;
5264 expect ( menuItems . length ) . toBe ( 6 ) ;
5365 } ) ;
5466 } ) ;
5567
56- it ( 'non admin users have two menu items' , ( ) => {
68+ it ( 'non admin users should have two menu items' , ( ) => {
5769 spyOn ( userInfoServiceStub , 'isAdmin' ) . and . returnValue ( of ( false ) ) ;
5870
5971 component . getSidebarItems ( ) . subscribe ( ( ) => {
@@ -62,7 +74,7 @@ describe('SidebarComponent', () => {
6274 } ) ;
6375 } ) ;
6476
65- it ( 'when item is selected is should be set as active and the others as inactive' , ( ) => {
77+ it ( 'when item is selected should be set as active and the others as inactive' , ( ) => {
6678 const route = 'time-clock' ;
6779 router . navigate ( [ route ] ) ;
6880
@@ -74,30 +86,6 @@ describe('SidebarComponent', () => {
7486 } ) ;
7587 } ) ;
7688
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-
10189 it ( 'should use the Azure service on logout' , ( ) => {
10290 spyOn ( azureAdB2CServiceStubInjected , 'logout' ) ;
10391 component . logout ( ) ;
0 commit comments