1
1
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
- import { of } from 'rxjs' ;
3
2
import { ActivatedRoute , Router } from '@angular/router' ;
4
3
import { MockNgbModalService } from '../../helpers/mocks/service/mock-ngb-modal.service' ;
5
4
import { MockTranslateService } from '../../helpers/mocks/service/mock-translate.service' ;
@@ -9,45 +8,42 @@ import { UserSettingsContainerComponent } from 'app/shared/user-settings/user-se
9
8
import { MockRouter } from '../../helpers/mocks/mock-router' ;
10
9
import { AccountService } from 'app/core/auth/account.service' ;
11
10
import { MockActivatedRoute } from '../../helpers/mocks/activated-route/mock-activated-route' ;
11
+ import { MockAccountService } from '../../helpers/mocks/service/mock-account.service' ;
12
12
13
13
describe ( 'UserSettingsContainerComponent' , ( ) => {
14
14
let fixture : ComponentFixture < UserSettingsContainerComponent > ;
15
15
let comp : UserSettingsContainerComponent ;
16
16
17
- let accountServiceMock : { getAuthenticationState : jest . Mock ; isAtLeastTutor : jest . Mock } ;
18
-
19
17
let translateService : TranslateService ;
18
+ let accountService : AccountService ;
20
19
21
20
const router = new MockRouter ( ) ;
22
21
router . setUrl ( '' ) ;
23
22
24
23
beforeEach ( async ( ) => {
25
- accountServiceMock = {
26
- getAuthenticationState : jest . fn ( ( ) => of ( { id : 13 } as any ) ) ,
27
- isAtLeastTutor : jest . fn ( ( ) => true ) ,
28
- } ;
29
-
30
24
await TestBed . configureTestingModule ( {
31
25
imports : [ UserSettingsContainerComponent ] ,
32
26
providers : [
33
27
{ provide : TranslateService , useClass : MockTranslateService } ,
34
28
{ provide : NgbModal , useClass : MockNgbModalService } ,
35
29
{ provide : Router , useValue : router } ,
36
30
{ provide : ActivatedRoute , useValue : new MockActivatedRoute ( ) } ,
37
- { provide : AccountService , useValue : accountServiceMock } ,
31
+ { provide : AccountService , useClass : MockAccountService } ,
38
32
] ,
39
33
} ) . compileComponents ( ) ;
40
34
41
35
fixture = TestBed . createComponent ( UserSettingsContainerComponent ) ;
42
36
comp = fixture . componentInstance ;
43
37
translateService = TestBed . inject ( TranslateService ) ;
38
+ accountService = TestBed . inject ( AccountService ) ;
44
39
translateService . currentLang = 'en' ;
45
40
} ) ;
46
41
47
42
it ( 'should initialize with loaded user' , ( ) => {
43
+ const getAuthenticationSpy = jest . spyOn ( accountService , 'getAuthenticationState' ) ;
48
44
fixture . detectChanges ( ) ;
49
- expect ( accountServiceMock . getAuthenticationState ) . toHaveBeenCalled ( ) ;
50
- expect ( comp . currentUser ?. id ) . toEqual ( 13 ) ;
51
- expect ( comp . isAtLeastTutor ) . toEqual ( true ) ;
45
+ expect ( getAuthenticationSpy ) . toHaveBeenCalled ( ) ;
46
+ expect ( comp . currentUser ?. id ) . toEqual ( 99 ) ;
47
+ expect ( comp . isAtLeastTutor ) . toEqual ( false ) ;
52
48
} ) ;
53
49
} ) ;
0 commit comments