-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.js
76 lines (69 loc) · 2.03 KB
/
test.js
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
import Immutable from 'seamless-immutable';
import createReducer from '../../creators/createReducer';
import onSuccess from '.';
const initialState = {
target: null,
targetLoading: true,
targetError: 'Some error'
};
const initialPollingState = {
target: null,
targetLoading: true,
targetError: 'Some error',
targetIsRetrying: true,
targetRetryCount: 3,
targetTimeoutID: 3
};
const setUp = {
state: null,
pollingState: null
};
beforeEach(() => {
setUp.state = Immutable(initialState);
setUp.pollingState = Immutable(initialPollingState);
});
describe('onSuccess', () => {
it('Sets correctly target with error and loading', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onSuccess()
});
const newState = reducer(setUp.state, { type: '@@ACTION/TYPE', target: 'target', payload: 'Success Payload' });
expect(newState).toEqual({
target: 'Success Payload',
targetLoading: false,
targetError: null
});
});
it('Sets conditionally target content based on payload', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onSuccess((action, state) => action.payload + (state[action.target] || 0))
});
const incrementAction = { type: '@@ACTION/TYPE', target: 'target', payload: 1 };
setUp.state = reducer(setUp.state, incrementAction);
setUp.state = reducer(setUp.state, incrementAction);
expect(setUp.state).toEqual({
target: 2,
targetLoading: false,
targetError: null
});
});
it('Sets polling target', () => {
const reducer = createReducer(setUp.pollingState, {
'@@ACTION/TYPE_SUCCESS': onSuccess()
});
const newState = reducer(setUp.pollingState, {
type: '@@ACTION/TYPE_SUCCESS',
target: 'target',
payload: 'Success Payload',
isPolling: true
});
expect(newState).toEqual({
target: 'Success Payload',
targetLoading: false,
targetError: null,
targetIsRetrying: false,
targetRetryCount: 0,
targetTimeoutID: 3
});
});
});