|
1
|
|
|
import postsReducer from '../reducers' |
|
2
|
|
|
import { |
|
3
|
|
|
CHANGE_PAGE, |
|
4
|
|
|
CHANGE_ROW_PER_PAGE, |
|
5
|
|
|
SET_ORDER, |
|
6
|
|
|
SET_ORDER_COLUMN, |
|
7
|
|
|
SET_SELECTED_POST, |
|
8
|
|
|
SELECT_ALL_POSTS, |
|
9
|
|
|
CLEAR_SELECTED, |
|
10
|
|
|
FETCH_POSTS |
|
11
|
|
|
} from 'core/state/actionType' |
|
12
|
|
|
import { toSuccess, toError } from 'core/state/utils' |
|
13
|
|
|
|
|
14
|
|
|
describe('Posts Reducer ', () => { |
|
15
|
|
|
describe('default', () => { |
|
16
|
|
|
it('should work corectly', function() { |
|
17
|
|
|
const action = { |
|
18
|
|
|
type: 'default' |
|
19
|
|
|
} |
|
20
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
21
|
|
|
expect(() => { |
|
22
|
|
|
postsReducer() |
|
23
|
|
|
}).toThrow(TypeError) |
|
24
|
|
|
}) |
|
25
|
|
|
}) |
|
26
|
|
|
describe('CHANGE_PAGE', () => { |
|
27
|
|
|
it('should work corectly', function() { |
|
28
|
|
|
const action = { |
|
29
|
|
|
type: CHANGE_PAGE, |
|
30
|
|
|
payload: 1 |
|
31
|
|
|
} |
|
32
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
33
|
|
|
}) |
|
34
|
|
|
}) |
|
35
|
|
|
describe('CHANGE_ROW_PER_PAGE', () => { |
|
36
|
|
|
it('should work corectly', function() { |
|
37
|
|
|
const action = { |
|
38
|
|
|
type: CHANGE_ROW_PER_PAGE, |
|
39
|
|
|
payload: 10 |
|
40
|
|
|
} |
|
41
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
42
|
|
|
}) |
|
43
|
|
|
}) |
|
44
|
|
|
describe('SET_ORDER', () => { |
|
45
|
|
|
it('should work corectly', function() { |
|
46
|
|
|
const action = { |
|
47
|
|
|
type: SET_ORDER, |
|
48
|
|
|
payload: 'asc' |
|
49
|
|
|
} |
|
50
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
51
|
|
|
}) |
|
52
|
|
|
}) |
|
53
|
|
|
describe('SET_ORDER_COLUMN', () => { |
|
54
|
|
|
it('should work corectly', function() { |
|
55
|
|
|
const action = { |
|
56
|
|
|
type: SET_ORDER_COLUMN, |
|
57
|
|
|
payload: 'author' |
|
58
|
|
|
} |
|
59
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
60
|
|
|
}) |
|
61
|
|
|
}) |
|
62
|
|
|
|
|
63
|
|
|
describe('SELECT_ALL_POSTS', () => { |
|
64
|
|
|
it('should work corectly', function() { |
|
65
|
|
|
const posts = [{ slug: 'a' }, { slug: 'b' }] |
|
66
|
|
|
const action = { |
|
67
|
|
|
type: SELECT_ALL_POSTS |
|
68
|
|
|
} |
|
69
|
|
|
expect(postsReducer({ posts }, action)).toMatchSnapshot() |
|
70
|
|
|
}) |
|
71
|
|
|
}) |
|
72
|
|
|
|
|
73
|
|
|
describe('CLEAR_SELECTED', () => { |
|
74
|
|
|
it('should work corectly', function() { |
|
75
|
|
|
const action = { |
|
76
|
|
|
type: CLEAR_SELECTED |
|
77
|
|
|
} |
|
78
|
|
|
const selectedPosts = [{ slug: 'a' }, { slug: 'b' }] |
|
79
|
|
|
expect(postsReducer({ selectedPosts }, action)).toMatchSnapshot() |
|
80
|
|
|
}) |
|
81
|
|
|
}) |
|
82
|
|
|
|
|
83
|
|
|
describe('FETCH_POSTS', () => { |
|
84
|
|
|
it('success', function() { |
|
85
|
|
|
const action = { |
|
86
|
|
|
type: toSuccess(FETCH_POSTS), |
|
87
|
|
|
payload: 'success payload' |
|
88
|
|
|
} |
|
89
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
90
|
|
|
}) |
|
91
|
|
|
|
|
92
|
|
|
it('error', function() { |
|
93
|
|
|
const action = { |
|
94
|
|
|
type: toError(FETCH_POSTS), |
|
95
|
|
|
payload: 'faild payload' |
|
96
|
|
|
} |
|
97
|
|
|
expect(postsReducer({}, action)).toMatchSnapshot() |
|
98
|
|
|
}) |
|
99
|
|
|
}) |
|
100
|
|
|
|
|
101
|
|
|
describe('SET_SELECTED_POST', () => { |
|
102
|
|
|
it('add new selected post', function() { |
|
103
|
|
|
const selectedPosts = ['a', 'b', 'c', 'd'] |
|
104
|
|
|
const action = { |
|
105
|
|
|
type: SET_SELECTED_POST, |
|
106
|
|
|
payload: 'e' |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
expect(postsReducer({ selectedPosts }, action)).toMatchSnapshot() |
|
110
|
|
|
}) |
|
111
|
|
|
|
|
112
|
|
|
it('remove a selected post at the beginning', function() { |
|
113
|
|
|
const selectedPosts = ['a', 'b', 'c', 'd'] |
|
114
|
|
|
const action = { |
|
115
|
|
|
type: SET_SELECTED_POST, |
|
116
|
|
|
payload: 'a' |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
expect(postsReducer({ selectedPosts }, action)).toMatchSnapshot() |
|
120
|
|
|
}) |
|
121
|
|
|
|
|
122
|
|
|
it('remove a selected post at the middle', function() { |
|
123
|
|
|
const selectedPosts = ['a', 'b', 'c', 'd'] |
|
124
|
|
|
const action = { |
|
125
|
|
|
type: SET_SELECTED_POST, |
|
126
|
|
|
payload: 'b' |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
expect(postsReducer({ selectedPosts }, action)).toMatchSnapshot() |
|
130
|
|
|
}) |
|
131
|
|
|
|
|
132
|
|
|
it('remove a selected post at the end', function() { |
|
133
|
|
|
const selectedPosts = ['a', 'b', 'c', 'd'] |
|
134
|
|
|
const action = { |
|
135
|
|
|
type: SET_SELECTED_POST, |
|
136
|
|
|
payload: 'd' |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
expect(postsReducer({ selectedPosts }, action)).toMatchSnapshot() |
|
140
|
|
|
}) |
|
141
|
|
|
}) |
|
142
|
|
|
}) |
|
143
|
|
|
|