-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquotes.reducer.spec.ts
60 lines (52 loc) · 1.85 KB
/
quotes.reducer.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
import {QuotesFetchedAll, QuotesFetchedOne} from '@store/actions/quotes.action';
import {quotesReducer} from '@store/reducers/quotes.reducer';
import {IQuotesState} from '@store/states/quotes.state';
import {quotesMock} from '@mocks/qoutes.mock';
import {IQuote} from '@models/qoute.model';
describe('Reducer for quotes', () => {
it('QuotesFetchedAll must replace quotes list in store', () => {
const state: IQuotesState = {quotes: []};
const newState = quotesReducer(state, new QuotesFetchedAll(quotesMock));
expect(newState).toEqual({quotes: quotesMock});
});
it('QuotesFetchedOne must append quote to the list in store', () => {
const quote: IQuote = {
id: 6,
text: 'Test me pls',
author: 'you'
};
const state: IQuotesState = {quotes: []};
const newState = quotesReducer(state, new QuotesFetchedOne(quote));
expect(newState).toEqual({quotes: [quote]});
});
it('QuotesFetchedOne must do not append quote to the list in store, if quote is exist in list', () => {
const quote: IQuote = {
id: 6,
text: 'Test me pls',
author: 'you'
};
const state: IQuotesState = {quotes: [quote]};
const newState = quotesReducer(state, new QuotesFetchedOne(quote));
expect(newState).toBe(state);
});
it('QuotesFetchedOne must append quote to the list in store, if quote is not exist in list', () => {
const quote1: IQuote = {
id: 1,
text: 'Test me pls 1',
author: 'you'
};
const quote2: IQuote = {
id: 2,
text: 'Test me pls 2',
author: 'you'
};
const quote3: IQuote = {
id: 3,
text: 'Test me pls 3',
author: 'you'
};
const state: IQuotesState = {quotes: [quote3, quote2]};
const newState = quotesReducer(state, new QuotesFetchedOne(quote1));
expect(newState).toEqual({quotes: [quote1, quote2, quote3]});
});
});