-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhome.component.spec.ts
More file actions
62 lines (49 loc) · 1.81 KB
/
home.component.spec.ts
File metadata and controls
62 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { HomeComponent } from './home.component'
import { AccountService } from '../account'
import { of } from 'rxjs'
describe('HomeComponent', () => {
let component: HomeComponent
let fixture: ComponentFixture<HomeComponent>
let accountServiceSpy: jasmine.SpyObj<AccountService>
beforeEach(() => {
accountServiceSpy = jasmine.createSpyObj('AccountService', ['getAccountData'])
TestBed.configureTestingModule({
declarations: [HomeComponent],
providers: [{ provide: AccountService, useValue: accountServiceSpy }],
})
fixture = TestBed.createComponent(HomeComponent)
component = fixture.componentInstance
accountServiceSpy = TestBed.inject(AccountService) as jasmine.SpyObj<AccountService>
})
it('should call getAccountData but not getMemberData', () => {
accountServiceSpy.getAccountData.and.returnValue(of(null))
expect(component).toBeTruthy()
component.ngOnInit()
expect(accountServiceSpy.getAccountData).toHaveBeenCalled()
expect(component.loggedInMessage).toBeUndefined()
})
it('should call getMemberData if account data is not null', () => {
accountServiceSpy.getAccountData.and.returnValue(
of({
id: 'id',
activated: true,
authorities: ['test', 'test'],
email: 'email@email.com',
firstName: 'name',
langKey: 'en',
lastName: 'surname',
imageUrl: 'url',
salesforceId: 'sfid',
loggedAs: false,
loginAs: 'sfid',
mainContact: false,
mfaEnabled: false,
})
)
expect(component).toBeTruthy()
component.ngOnInit()
expect(accountServiceSpy.getAccountData).toHaveBeenCalled()
expect(component.loggedInMessage).toEqual('You are logged in as user email@email.com')
})
})