|
1 | 1 | import reducer from '../../src/reducers';
|
2 |
| -import { SUBMIT, TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../../src/static/constants/actions'; |
| 2 | +import { |
| 3 | + SUBMIT, |
| 4 | + TOGGLE, |
| 5 | + TOGGLE_JS, |
| 6 | + TOGGLE_MODE, |
| 7 | + RESTART |
| 8 | +} from '../../src/static/constants/actions'; |
3 | 9 |
|
4 | 10 | const answers = [
|
5 | 11 | {
|
6 | 12 | name: 'Template',
|
7 | 13 | type: 'behavioral',
|
8 |
| - codeES5: 'Code ES5', |
9 |
| - codeES6: 'Code ES6', |
10 |
| - answered: false, |
11 |
| - correct: null, |
12 |
| - answerId: null, |
| 14 | + answered: true, |
| 15 | + correct: true, |
| 16 | + answerId: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947', |
13 | 17 | uuid: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947'
|
14 | 18 | },
|
15 | 19 | {
|
16 | 20 | name: 'Visitor',
|
17 | 21 | type: 'behavioral',
|
18 |
| - codeES5: 'Code ES5', |
19 |
| - codeES6: 'Code ES6', |
20 | 22 | answered: false,
|
21 | 23 | correct: null,
|
22 | 24 | answerId: null,
|
23 | 25 | uuid: 'eb9427c5-0167-4d65-a99b-a5ffadf5fd46'
|
| 26 | + }, |
| 27 | + { |
| 28 | + name: 'Singleton', |
| 29 | + type: 'creational', |
| 30 | + answered: false, |
| 31 | + correct: null, |
| 32 | + answerId: null, |
| 33 | + uuid: 'slearknbqarlnbqasOLdnv' |
24 | 34 | }
|
25 | 35 | ];
|
26 | 36 |
|
@@ -75,22 +85,57 @@ describe('Reducers', () => {
|
75 | 85 | });
|
76 | 86 | });
|
77 | 87 |
|
78 |
| - xit('should handle SUBMIT', () => { |
| 88 | + it('should handle SUBMIT', () => { |
79 | 89 | const action = {
|
80 | 90 | type: SUBMIT,
|
81 | 91 | payload: {
|
82 |
| - currentIndex: 0, |
83 |
| - remainingPatterns: answers[1], |
| 92 | + currentIndex: 1, |
| 93 | + remainingPatterns: [answers[1], answers[2]], |
84 | 94 | recentlyAnswered: answers[0]
|
85 | 95 | }
|
86 | 96 | };
|
87 | 97 |
|
88 | 98 | expect(reducer(initialState, action)).toMatchObject({
|
89 | 99 | ...initialState,
|
90 | 100 | progress: {
|
91 |
| - remaining: [answers[1]], |
| 101 | + remaining: [answers[1], answers[2]], |
92 | 102 | answers: [answers[0]],
|
93 |
| - current: answers[1] |
| 103 | + current: answers[2] |
| 104 | + } |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should handle the _last_ SUBMIT', () => { |
| 109 | + const action = { |
| 110 | + type: SUBMIT, |
| 111 | + payload: { |
| 112 | + currentIndex: null, |
| 113 | + remainingPatterns: [], |
| 114 | + recentlyAnswered: answers[2] |
| 115 | + } |
| 116 | + }; |
| 117 | + |
| 118 | + expect(reducer(initialState, action)).toMatchObject({ |
| 119 | + ...initialState, |
| 120 | + progress: { |
| 121 | + remaining: [], |
| 122 | + answers: [answers[2]], |
| 123 | + current: null |
| 124 | + } |
| 125 | + }); |
| 126 | + }); |
| 127 | + |
| 128 | + it('should handle RESTART', () => { |
| 129 | + const action = { |
| 130 | + type: RESTART, |
| 131 | + payload: null |
| 132 | + }; |
| 133 | + |
| 134 | + expect(reducer(initialState, action)).toMatchObject({ |
| 135 | + ...initialState, |
| 136 | + progress: { |
| 137 | + remaining: answers, |
| 138 | + answers: [] |
94 | 139 | }
|
95 | 140 | });
|
96 | 141 | });
|
|
0 commit comments