forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreducers.test.js
More file actions
155 lines (138 loc) · 2.93 KB
/
reducers.test.js
File metadata and controls
155 lines (138 loc) · 2.93 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import reducer from '../../src/reducers';
import {
SUBMIT,
TOGGLE,
TOGGLE_JS,
TOGGLE_MODE,
START,
RESTART
} from '../../src/static/constants/actions';
const answers = [
{
name: 'Template',
type: 'behavioral',
answered: true,
correct: true,
answerId: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947',
uuid: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947'
},
{
name: 'Visitor',
type: 'behavioral',
answered: false,
correct: null,
answerId: null,
uuid: 'eb9427c5-0167-4d65-a99b-a5ffadf5fd46'
},
{
name: 'Singleton',
type: 'creational',
answered: false,
correct: null,
answerId: null,
uuid: 'slearknbqarlnbqasOLdnv'
}
];
const initialState = {
js: 'es5',
mode: 'dark',
patterns: answers,
intro: true,
progress: {
answers: [],
remaining: answers,
current: answers[0]
}
};
describe('Reducers', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(undefined);
});
it('should return unchanged state on toggle', () => {
const action = {
type: TOGGLE,
payload: null
};
expect(reducer(initialState, action)).toEqual({
...initialState
});
});
it('should toggle JS', () => {
const action = {
type: TOGGLE_JS,
payload: 'es6'
};
expect(reducer(initialState, action)).toEqual({
...initialState,
js: 'es6'
});
});
it('should toggle MODE', () => {
const action = {
type: TOGGLE_MODE,
payload: 'light'
};
expect(reducer(initialState, action)).toEqual({
...initialState,
mode: 'light'
});
});
it('should toggle INTRO', () => {
const action = {
type: START
};
expect(reducer(initialState, action)).toEqual({
...initialState,
intro: false
});
});
it('should handle SUBMIT', () => {
const action = {
type: SUBMIT,
payload: {
currentIndex: 1,
remainingPatterns: [answers[1], answers[2]],
recentlyAnswered: answers[0]
}
};
expect(reducer(initialState, action)).toMatchObject({
...initialState,
progress: {
remaining: [answers[1], answers[2]],
answers: [answers[0]],
current: answers[2]
}
});
});
it('should handle the _last_ SUBMIT', () => {
const action = {
type: SUBMIT,
payload: {
currentIndex: null,
remainingPatterns: [],
recentlyAnswered: answers[2]
}
};
expect(reducer(initialState, action)).toMatchObject({
...initialState,
progress: {
remaining: [],
answers: [answers[2]],
current: null
}
});
});
it('should handle RESTART', () => {
const action = {
type: RESTART,
payload: null
};
expect(reducer(initialState, action)).toMatchObject({
...initialState,
progress: {
remaining: answers,
answers: []
}
});
});
});