/
account-user-info.component.spec.ts
83 lines (67 loc) · 2.85 KB
/
account-user-info.component.spec.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EMPTY, of } from 'rxjs';
import { instance, mock, when } from 'ts-mockito';
import { AccountFacade } from 'ish-core/facades/account.facade';
import { Customer } from 'ish-core/models/customer/customer.model';
import { User } from 'ish-core/models/user/user.model';
import { AccountUserInfoComponent } from './account-user-info.component';
describe('Account User Info Component', () => {
let component: AccountUserInfoComponent;
let fixture: ComponentFixture<AccountUserInfoComponent>;
let element: HTMLElement;
let accountFacade: AccountFacade;
beforeEach(async () => {
accountFacade = mock(AccountFacade);
when(accountFacade.customer$).thenReturn(EMPTY);
when(accountFacade.roles$).thenReturn(EMPTY);
await TestBed.configureTestingModule({
declarations: [AccountUserInfoComponent],
providers: [{ provide: AccountFacade, useFactory: () => instance(accountFacade) }],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(AccountUserInfoComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
});
it('should be created', () => {
expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
});
it('should not render when user is private customer', () => {
when(accountFacade.customer$).thenReturn(of({ isBusinessCustomer: false } as Customer));
fixture.detectChanges();
expect(element).toMatchInlineSnapshot(`N/A`);
});
it('should render when user is business customer', () => {
when(accountFacade.customer$).thenReturn(of({ isBusinessCustomer: true, companyName: 'Foods Inc.' } as Customer));
when(accountFacade.user$).thenReturn(of({ firstName: 'Max', lastName: 'Mustermann' } as User));
when(accountFacade.roles$).thenReturn(
of([
{ displayName: 'Approver', roleId: 'APP_B2B_APPROVER' },
{ displayName: 'Buyer', roleId: 'APP_B2B_BUYER' },
])
);
fixture.detectChanges();
expect(element).toMatchInlineSnapshot(`
<li role="presentation" class="account-welcome">
<h4>Mustermann, Max</h4>
<div>Foods Inc.</div>
<div>Approver, Buyer</div>
</li>
`);
});
it('should display email when user has no name', () => {
when(accountFacade.customer$).thenReturn(of({ isBusinessCustomer: true, companyName: 'Foods Inc.' } as Customer));
when(accountFacade.user$).thenReturn(of({ login: 'max.mustermann@test.intershop.de' } as User));
when(accountFacade.roles$).thenReturn(EMPTY);
fixture.detectChanges();
expect(element).toMatchInlineSnapshot(`
<li role="presentation" class="account-welcome">
<h4 class="ellipsis">max.mustermann@test.intershop.de</h4>
<div>Foods Inc.</div>
</li>
`);
});
});