@@ -25,7 +25,7 @@ describe('HomeComponent', () => {
2525 currentLang : 'en'
2626 }
2727 } ,
28- { provide : OauthService , useValue : { logout : jest . fn ( ) } }
28+ { provide : OauthService , useValue : { logout : jest . fn ( ) , isAuthenticated$ : of ( false ) } }
2929 ] ,
3030 schemas : [ NO_ERRORS_SCHEMA ] ,
3131 declarations : [ HomeComponent ]
@@ -73,7 +73,7 @@ describe('HomeComponent', () => {
7373 } ) ;
7474 } ) ;
7575
76- describe ( 'logout access' , ( ) => {
76+ describe ( 'logout access while authenticated ' , ( ) => {
7777 beforeEach ( async ( ( ) => {
7878 TestBed . configureTestingModule ( {
7979 imports : [ ObliqueTestingModule ] ,
@@ -85,7 +85,7 @@ describe('HomeComponent', () => {
8585 currentLang : 'en'
8686 }
8787 } ,
88- { provide : OauthService , useValue : { logout : jest . fn ( ) } } ,
88+ { provide : OauthService , useValue : { logout : jest . fn ( ) , isAuthenticated$ : of ( true ) } } ,
8989 { provide : ActivatedRoute , useValue : { data : of ( { logout : true } ) } }
9090 ] ,
9191 schemas : [ NO_ERRORS_SCHEMA ] ,
@@ -103,9 +103,45 @@ describe('HomeComponent', () => {
103103 expect ( component ) . toBeTruthy ( ) ;
104104 } ) ;
105105
106- it ( 'should logout' , ( ) => {
106+ it ( 'should not logout' , ( ) => {
107107 const oauth = TestBed . inject ( OauthService ) ;
108108 expect ( oauth . logout ) . toHaveBeenCalled ( ) ;
109109 } ) ;
110110 } ) ;
111+
112+ describe ( 'logout access while not authenticated' , ( ) => {
113+ beforeEach ( async ( ( ) => {
114+ TestBed . configureTestingModule ( {
115+ imports : [ ObliqueTestingModule ] ,
116+ providers : [
117+ {
118+ provide : TranslateService ,
119+ useValue : {
120+ onLangChange : new EventEmitter < LangChangeEvent > ( ) ,
121+ currentLang : 'en'
122+ }
123+ } ,
124+ { provide : OauthService , useValue : { logout : jest . fn ( ) , isAuthenticated$ : of ( false ) } } ,
125+ { provide : ActivatedRoute , useValue : { data : of ( { logout : true } ) } }
126+ ] ,
127+ schemas : [ NO_ERRORS_SCHEMA ] ,
128+ declarations : [ HomeComponent ]
129+ } ) . compileComponents ( ) ;
130+ } ) ) ;
131+
132+ beforeEach ( ( ) => {
133+ fixture = TestBed . createComponent ( HomeComponent ) ;
134+ component = fixture . componentInstance ;
135+ fixture . detectChanges ( ) ;
136+ } ) ;
137+
138+ it ( 'should create' , ( ) => {
139+ expect ( component ) . toBeTruthy ( ) ;
140+ } ) ;
141+
142+ it ( 'should logout' , ( ) => {
143+ const oauth = TestBed . inject ( OauthService ) ;
144+ expect ( oauth . logout ) . not . toHaveBeenCalled ( ) ;
145+ } ) ;
146+ } ) ;
111147} ) ;
0 commit comments