-
Notifications
You must be signed in to change notification settings - Fork 4
/
quotes.ts
38 lines (29 loc) · 1.34 KB
/
quotes.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
import { IQuote } from 'interfaces/IQuote';
import {
QuotesActionTypes,
quoteFetchAllSuccess,
quoteCreateSuccess,
quoteFetchOneSuccess
} from '../../actions/quotes';
import { QuotesState } from '../../states/quotes';
import { quotesReducer } from '../quotes';
describe('Reducer for quotes', () => {
const state: QuotesState = [];
const quote: IQuote = {id: 2, text: 'ccc', author: 'ddd'};
it(`${QuotesActionTypes.FETCH_ALL_SUCCESS} must replace quotes list in store`, () => {
const newState = quotesReducer(state, quoteFetchAllSuccess([quote]));
expect(newState).toEqual([quote]);
});
it(`${QuotesActionTypes.CREATED_SUCCESS} must append quote to the list in store`, () => {
const newState = quotesReducer(state, quoteCreateSuccess(quote));
expect(newState).toEqual([quote]);
});
it(`${QuotesActionTypes.FETCH_ONE_SUCCESS} must append quote to the list in store, if quote is not exist in list`, () => {
const newState = quotesReducer(state, quoteFetchOneSuccess(quote));
expect(newState).toEqual([quote]);
});
it(`${QuotesActionTypes.FETCH_ONE_SUCCESS} must do not append quote to the list in store, if quote is exist in list`, () => {
const newState = quotesReducer([quote], quoteFetchOneSuccess(quote));
expect(newState).toEqual([quote]);
});
});