/
app.component.spec.ts
48 lines (40 loc) · 1.62 KB
/
app.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
import { AppComponent } from './app.component';
import { BasePage, renderComponent, getMock } from 'ng-vacuum';
import { AppModule } from './app.module';
import { when } from 'omnimock';
import { AuthService } from './auth/auth.service';
import { fakeAsync } from '@angular/core/testing';
import { FancyButtonComponent } from './fancy-button.component';
import { CONSOLE } from './auth/app.providers';
describe('AppComponent', () => {
let isAuthenticated: boolean;
function createPage() {
isAuthenticated = false;
when(getMock(AuthService).isAuthenticated()).useGetter(() => isAuthenticated);
page = new Page(renderComponent(AppComponent, AppModule));
}
it('lets user log in when not authenticated', fakeAsync(() => {
const page = createPage();
when(getMock(AuthService).setAuthenticated(true)).return().once();
page.detectChanges();
page.loginButton.click();
expect().nothing();
}));
it('presents a fancy button when authenticated', fakeAsync(() => {
const page = createPage();
isAuthenticated = true;
page.detectChanges();
expect(page.fancyButton.confirmLabel).toBe('Got it');
expect(page.fancyButton.cancelLabel).toBe('Nooo');
when(getMock(CONSOLE).log('confirm')).return().once();
page.fancyButton.clicked.emit('confirm');
}));
});
class Page extends BasePage<AppComponent> {
get loginButton(): HTMLElement {
return this.rendering.find('[test-id=login-button]').nativeElement;
}
get fancyButton() {
return this.rendering.findComponent(FancyButtonComponent);
}
}