-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathpage.spec.ts
119 lines (101 loc) · 3.43 KB
/
page.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
MockNgRedux,
NgReduxTestingModule,
} from '@angular-redux/store/testing';
import { TestBed } from '@angular/core/testing';
import { Component, Input } from '@angular/core';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/toArray';
import { Observable } from 'rxjs/Observable';
import { AnimalAPIActions } from '../animals/api/actions';
import { ANIMAL_TYPES } from '../animals/model';
import { ElephantPageComponent } from './page';
@Component({
selector: 'zoo-animal-list',
template: 'Mock Animal List',
})
class MockAnimalListComponent {
@Input() animalsName: string;
@Input() animals: Observable<any>;
@Input() loading: Observable<boolean>;
@Input() error: Observable<any>;
}
xdescribe('Elephant Page Container', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ElephantPageComponent, MockAnimalListComponent],
imports: [NgReduxTestingModule],
providers: [AnimalAPIActions],
}).compileComponents();
MockNgRedux.reset();
});
it('should select some elephants from the Redux store', done => {
const fixture = TestBed.createComponent(ElephantPageComponent);
const elephantPage = fixture.debugElement.componentInstance;
const mockStoreSequence = [
{ elephant1: { name: 'I am an Elephant!', id: 'elephant1' } },
{
elephant1: { name: 'I am an Elephant!', id: 'elephant1' },
elephant2: { name: 'I am a second Elephant!', id: 'elephant2' },
},
];
const expectedSequence = [
[{ name: 'I am an Elephant!', id: 'elephant1' }],
[
// Alphanumeric sort by name.
{ name: 'I am a second Elephant!', id: 'elephant2' },
{ name: 'I am an Elephant!', id: 'elephant1' },
],
];
const elephantItemStub = MockNgRedux.getSelectorStub(['elephant', 'items']);
mockStoreSequence.forEach(value => elephantItemStub.next(value));
elephantItemStub.complete();
elephantPage.animals$
.toArray()
.subscribe(
actualSequence => expect(actualSequence).toEqual(expectedSequence),
null,
done,
);
});
it('should know when the animals are loading', done => {
const fixture = TestBed.createComponent(ElephantPageComponent);
const elephantPage = fixture.debugElement.componentInstance;
const stub = MockNgRedux.getSelectorStub(['elephant', 'loading']);
stub.next(false);
stub.next(true);
stub.complete();
elephantPage.loading$
.toArray()
.subscribe(
actualSequence => expect(actualSequence).toEqual([false, true]),
null,
done,
);
});
it("should know when there's an error", done => {
const fixture = TestBed.createComponent(ElephantPageComponent);
const elephantPage = fixture.debugElement.componentInstance;
const stub = MockNgRedux.getSelectorStub(['elephant', 'error']);
stub.next(false);
stub.next(true);
stub.complete();
elephantPage.error$
.toArray()
.subscribe(
actualSequence => expect(actualSequence).toEqual([false, true]),
null,
done,
);
});
it('should load elephants on creation', () => {
const spy = spyOn(MockNgRedux.mockInstance, 'dispatch');
const fixture = TestBed.createComponent(ElephantPageComponent);
expect(spy).toHaveBeenCalledWith({
type: AnimalAPIActions.LOAD_ANIMALS,
meta: { animalType: ANIMAL_TYPES.ELEPHANT },
payload: null,
});
});
});