@@ -9,13 +9,15 @@ import { ProjectState } from '../../project-management/store/project.reducer';
99import { ProjectListHoverComponent } from '../components' ;
1010import { ProjectService } from '../../project-management/services/project.service' ;
1111import { FilterProjectPipe } from '../../shared/pipes' ;
12+ import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service' ;
1213
1314describe ( 'TimeClockComponent' , ( ) => {
1415 let component : TimeClockComponent ;
1516 let fixture : ComponentFixture < TimeClockComponent > ;
1617 let de : DebugElement ;
1718 let store : MockStore < ProjectState > ;
1819 let projectService : ProjectService ;
20+ let azureAdB2CService : AzureAdB2CService ;
1921 const state = {
2022 projects : {
2123 projectList : [ { id : 'id' , name : 'name' , description : 'description' } ] ,
@@ -32,7 +34,7 @@ describe('TimeClockComponent', () => {
3234 TestBed . configureTestingModule ( {
3335 imports : [ HttpClientTestingModule ] ,
3436 declarations : [ TimeClockComponent , ProjectListHoverComponent , FilterProjectPipe ] ,
35- providers : [ ProjectService , provideMockStore ( { initialState : state } ) ] ,
37+ providers : [ ProjectService , AzureAdB2CService , provideMockStore ( { initialState : state } ) ] ,
3638 } ) . compileComponents ( ) ;
3739 store = TestBed . inject ( MockStore ) ;
3840 } ) ) ;
@@ -43,12 +45,29 @@ describe('TimeClockComponent', () => {
4345 de = fixture . debugElement ;
4446 fixture . detectChanges ( ) ;
4547 projectService = TestBed . inject ( ProjectService ) ;
48+ azureAdB2CService = TestBed . inject ( AzureAdB2CService ) ;
4649 } ) ;
4750
4851 it ( 'should be created' , ( ) => {
4952 expect ( component ) . toBeTruthy ( ) ;
5053 } ) ;
5154
55+ it ( 'onInit checks if isLogin and gets the userName' , ( ) => {
56+ spyOn ( azureAdB2CService , 'isLogin' ) . and . returnValue ( true ) ;
57+ spyOn ( azureAdB2CService , 'getName' ) . and . returnValue ( 'Name' ) ;
58+ component . ngOnInit ( ) ;
59+ expect ( azureAdB2CService . isLogin ) . toHaveBeenCalled ( ) ;
60+ expect ( azureAdB2CService . getName ) . toHaveBeenCalled ( ) ;
61+ } ) ;
62+
63+ it ( 'onInit does not get the name if isLogin false' , ( ) => {
64+ spyOn ( azureAdB2CService , 'isLogin' ) . and . returnValue ( false ) ;
65+ spyOn ( azureAdB2CService , 'getName' ) . and . returnValue ( 'Name' ) ;
66+ component . ngOnInit ( ) ;
67+ expect ( azureAdB2CService . isLogin ) . toHaveBeenCalled ( ) ;
68+ expect ( azureAdB2CService . getName ) . toHaveBeenCalledTimes ( 0 ) ;
69+ } ) ;
70+
5271 it ( 'Service injected via inject(...) and TestBed.get(...) should be the same instance' , inject (
5372 [ ProjectService ] ,
5473 ( injectService : ProjectService ) => {
0 commit comments