Newer
Older
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
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Component, Input } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import * as fromLogin from '../../login/store/login.reducer';
import * as loginActions from '../../login/store/login.action';
import { LoginToken } from "../../login/store/model";
describe('[Search] Container: AppComponent', () => {
@Component({ selector: 'app-nav', template: '' })
class NavStubComponent {
@Input() isAuthenticated: boolean;
@Input() loginToken: LoginToken;
}
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let store: MockStore;
const initialState = {
login: { ...fromLogin.initialState }
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [
AppComponent,
NavStubComponent
],
providers: [
provideMockStore({ initialState })
]
});
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should execute ngOnInit lifecycle', () => {
const loginLocalStorageAction = new loginActions.LoginLocalStorageAction();
const spy = spyOn(store, 'dispatch');
component.ngOnInit();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(loginLocalStorageAction);
});
it('#logout() should dispatch LogoutAction', () => {
const logoutAction = new loginActions.LogoutAction();
const spy = spyOn(store, 'dispatch');
component.logout();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(logoutAction);
});
});