-
Notifications
You must be signed in to change notification settings - Fork 1
/
quote.resolver.spec.ts
91 lines (72 loc) · 2.33 KB
/
quote.resolver.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
import {QuoteResolver} from '@router/resolvers/quote.resolver';
import {Store, StoreModule} from '@ngrx/store';
import {IQuote} from '@models/qoute.model';
import {TestBed} from '@angular/core/testing';
import {reducersProvider, reducersToken} from '@store/reducers';
import {QuotesFetchedOne, QuotesFetchOne} from '@store/actions/quotes.action';
import {ActivatedRouteSnapshot} from '@angular/router';
import {quotesMock} from '@mocks/qoutes.mock';
describe('QuoteResolver - resolves data for quote page', () => {
const expectedQuote: IQuote = quotesMock[2];
const route = new ActivatedRouteSnapshot();
const state = null;
route.params = {id: expectedQuote.id};
let quoteResolver: QuoteResolver;
let store: Store<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot(reducersToken)
],
providers: [
QuoteResolver,
reducersProvider
]
});
quoteResolver = TestBed.get(QuoteResolver);
store = TestBed.get(Store);
});
it('Creates QuotesFetchOne action, for loading data from server', () => {
const storeDispatchSpy = spyOn(store, 'dispatch').and.callThrough();
const expectedAction = new QuotesFetchOne(expectedQuote.id);
quoteResolver.resolve(route, state);
const [action] = storeDispatchSpy.calls.mostRecent().args;
expect(action).toEqual(
expectedAction,
'QuotesFetchOne action is not created'
);
});
it('Gives quote from store by id from router', () => {
let quote: IQuote = null;
store.dispatch(new QuotesFetchedOne(expectedQuote));
quoteResolver.resolve(route, state)
.subscribe(q => {
quote = q;
});
expect(quote).toEqual(
expectedQuote,
'Given quote is not expected'
);
});
it('If the store does not have the expected quote, then it expects its appearance (filter)', () => {
let quote: IQuote = null;
store.dispatch(new QuotesFetchedOne({
id: 0,
text: '',
author: ''
}));
quoteResolver.resolve(route, state)
.subscribe(q => {
quote = q;
});
expect(quote).toBe(
null,
'Quote must be null, when its not exist in store'
);
store.dispatch(new QuotesFetchedOne(expectedQuote));
expect(quote).toEqual(
expectedQuote,
'Given quote is not expected'
);
});
});