@coorpacademy/app-review 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/es/actions/api/fetch-skills.d.ts +3 -3
  2. package/es/actions/api/fetch-skills.js +7 -2
  3. package/es/actions/api/fetch-slide.d.ts +1 -1
  4. package/es/actions/api/fetch-slide.js +3 -1
  5. package/es/actions/api/post-answer.d.ts +10 -0
  6. package/es/actions/api/post-answer.js +25 -0
  7. package/es/actions/api/post-progression.d.ts +3 -3
  8. package/es/actions/api/post-progression.js +5 -2
  9. package/es/actions/api/test/fetch-skills.test.js +7 -4
  10. package/es/actions/api/test/fetch-slide.test.js +7 -4
  11. package/es/actions/api/test/post-answer.test.d.ts +1 -0
  12. package/es/actions/api/test/post-answer.test.js +82 -0
  13. package/es/actions/api/test/post-progression.test.js +7 -4
  14. package/es/actions/data/test/token.test.d.ts +1 -0
  15. package/es/actions/data/test/token.test.js +25 -0
  16. package/es/actions/index.d.ts +1 -8
  17. package/es/actions/{api/test → test}/create-test-store.d.ts +2 -2
  18. package/es/actions/{api/test → test}/create-test-store.js +1 -1
  19. package/es/actions/ui/answers.d.ts +17 -3
  20. package/es/actions/ui/answers.js +39 -3
  21. package/es/actions/ui/slides.d.ts +0 -5
  22. package/es/actions/ui/slides.js +0 -4
  23. package/es/actions/ui/test/answers.test.d.ts +1 -0
  24. package/es/actions/ui/test/answers.test.js +90 -0
  25. package/es/actions/ui/test/slides.test.d.ts +1 -0
  26. package/es/actions/ui/test/slides.test.js +26 -0
  27. package/es/common/index.d.ts +0 -3
  28. package/es/common/index.js +0 -4
  29. package/es/index.js +1 -3
  30. package/es/reducers/data/index.d.ts +1 -1
  31. package/es/reducers/data/progression.d.ts +2 -3
  32. package/es/reducers/data/progression.js +0 -5
  33. package/es/reducers/data/slides.d.ts +2 -3
  34. package/es/reducers/data/test/progression.test.js +1 -1
  35. package/es/reducers/index.d.ts +2 -1
  36. package/es/reducers/ui/answers.d.ts +2 -2
  37. package/es/reducers/ui/answers.js +4 -8
  38. package/es/reducers/ui/index.d.ts +4 -1
  39. package/es/reducers/ui/index.js +3 -1
  40. package/es/reducers/ui/slide.d.ts +8 -0
  41. package/es/reducers/ui/slide.js +26 -0
  42. package/es/reducers/ui/test/answers.test.js +19 -3
  43. package/es/reducers/ui/test/current-slide-ref.test.js +1 -1
  44. package/es/reducers/ui/test/navigation.test.js +5 -5
  45. package/es/reducers/ui/test/slide.test.d.ts +1 -0
  46. package/es/reducers/ui/test/slide.test.js +12 -0
  47. package/es/test/util/services.mock.d.ts +2 -1
  48. package/es/test/util/services.mock.js +86 -72
  49. package/es/types/common.d.ts +0 -25
  50. package/es/views/skills/index.d.ts +1 -1
  51. package/es/views/skills/index.js +0 -3
  52. package/es/views/skills/test/skills.test.d.ts +1 -0
  53. package/es/views/skills/test/skills.test.js +94 -0
  54. package/es/views/slides/index.d.ts +13 -2
  55. package/es/views/slides/index.js +18 -14
  56. package/es/views/slides/map-api-slide-to-ui.js +44 -51
  57. package/es/views/slides/test/fixtures/free-text.d.ts +2 -1
  58. package/es/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  59. package/es/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  60. package/es/views/slides/test/fixtures/qcm.d.ts +2 -1
  61. package/es/views/slides/test/fixtures/select-template.d.ts +2 -1
  62. package/es/views/slides/test/fixtures/slider.d.ts +2 -1
  63. package/es/views/slides/test/fixtures/text-template.d.ts +2 -1
  64. package/es/views/slides/test/index.test.d.ts +1 -0
  65. package/es/views/slides/test/index.test.js +234 -0
  66. package/lib/actions/api/fetch-skills.d.ts +3 -3
  67. package/lib/actions/api/fetch-skills.js +22 -19
  68. package/lib/actions/api/fetch-slide.d.ts +1 -1
  69. package/lib/actions/api/fetch-slide.js +3 -1
  70. package/lib/actions/api/post-answer.d.ts +10 -0
  71. package/lib/actions/api/post-answer.js +75 -0
  72. package/lib/actions/api/post-progression.d.ts +3 -3
  73. package/lib/actions/api/post-progression.js +6 -3
  74. package/lib/actions/api/test/fetch-skills.test.js +7 -4
  75. package/lib/actions/api/test/fetch-slide.test.js +7 -4
  76. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  77. package/lib/actions/api/test/post-answer.test.js +145 -0
  78. package/lib/actions/api/test/post-progression.test.js +7 -4
  79. package/lib/actions/data/test/token.test.d.ts +1 -0
  80. package/lib/actions/data/test/token.test.js +70 -0
  81. package/lib/actions/index.d.ts +1 -8
  82. package/lib/actions/{api/test → test}/create-test-store.d.ts +2 -2
  83. package/lib/actions/{api/test → test}/create-test-store.js +1 -1
  84. package/lib/actions/ui/answers.d.ts +17 -3
  85. package/lib/actions/ui/answers.js +48 -3
  86. package/lib/actions/ui/slides.d.ts +0 -5
  87. package/lib/actions/ui/slides.js +0 -4
  88. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  89. package/lib/actions/ui/test/answers.test.js +171 -0
  90. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  91. package/lib/actions/ui/test/slides.test.js +71 -0
  92. package/lib/common/index.d.ts +0 -3
  93. package/lib/common/index.js +0 -4
  94. package/lib/index.js +1 -3
  95. package/lib/reducers/data/index.d.ts +1 -1
  96. package/lib/reducers/data/progression.d.ts +2 -3
  97. package/lib/reducers/data/progression.js +0 -5
  98. package/lib/reducers/data/slides.d.ts +2 -3
  99. package/lib/reducers/data/test/progression.test.js +1 -1
  100. package/lib/reducers/index.d.ts +2 -1
  101. package/lib/reducers/ui/answers.d.ts +2 -2
  102. package/lib/reducers/ui/answers.js +4 -8
  103. package/lib/reducers/ui/index.d.ts +4 -1
  104. package/lib/reducers/ui/index.js +3 -1
  105. package/lib/reducers/ui/slide.d.ts +8 -0
  106. package/lib/reducers/ui/slide.js +27 -0
  107. package/lib/reducers/ui/test/answers.test.js +19 -3
  108. package/lib/reducers/ui/test/current-slide-ref.test.js +1 -1
  109. package/lib/reducers/ui/test/navigation.test.js +5 -5
  110. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  111. package/lib/reducers/ui/test/slide.test.js +12 -0
  112. package/lib/test/util/services.mock.d.ts +2 -1
  113. package/lib/test/util/services.mock.js +86 -72
  114. package/lib/types/common.d.ts +0 -25
  115. package/lib/views/skills/index.d.ts +1 -1
  116. package/lib/views/skills/index.js +0 -3
  117. package/lib/views/skills/test/skills.test.d.ts +1 -0
  118. package/lib/views/skills/test/skills.test.js +94 -0
  119. package/lib/views/slides/index.d.ts +13 -2
  120. package/lib/views/slides/index.js +18 -14
  121. package/lib/views/slides/map-api-slide-to-ui.js +77 -76
  122. package/lib/views/slides/test/fixtures/free-text.d.ts +2 -1
  123. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  124. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  125. package/lib/views/slides/test/fixtures/qcm.d.ts +2 -1
  126. package/lib/views/slides/test/fixtures/select-template.d.ts +2 -1
  127. package/lib/views/slides/test/fixtures/slider.d.ts +2 -1
  128. package/lib/views/slides/test/fixtures/text-template.d.ts +2 -1
  129. package/lib/views/slides/test/index.test.d.ts +1 -0
  130. package/lib/views/slides/test/index.test.js +234 -0
  131. package/package.json +6 -5
  132. package/src/actions/api/fetch-skills.ts +18 -11
  133. package/src/actions/api/fetch-slide.ts +3 -1
  134. package/src/actions/api/post-answer.ts +39 -0
  135. package/src/actions/api/post-progression.ts +7 -4
  136. package/src/actions/api/test/fetch-skills.test.ts +9 -6
  137. package/src/actions/api/test/fetch-slide.test.ts +9 -6
  138. package/src/actions/api/test/post-answer.test.ts +101 -0
  139. package/src/actions/api/test/post-progression.test.ts +9 -6
  140. package/src/actions/data/test/token.test.ts +29 -0
  141. package/src/actions/index.ts +1 -17
  142. package/src/actions/{api/test → test}/create-test-store.ts +2 -2
  143. package/src/actions/ui/answers.ts +52 -5
  144. package/src/actions/ui/slides.ts +1 -8
  145. package/src/actions/ui/test/answers.test.ts +103 -0
  146. package/src/actions/ui/test/slides.test.ts +30 -0
  147. package/src/common/index.ts +0 -7
  148. package/src/index.tsx +1 -3
  149. package/src/reducers/data/progression.ts +2 -7
  150. package/src/reducers/data/slides.ts +2 -3
  151. package/src/reducers/data/test/progression.test.ts +3 -3
  152. package/src/reducers/ui/answers.ts +5 -9
  153. package/src/reducers/ui/index.ts +4 -1
  154. package/src/reducers/ui/slide.ts +43 -0
  155. package/src/reducers/ui/test/answers.test.ts +24 -4
  156. package/src/reducers/ui/test/current-slide-ref.test.ts +1 -1
  157. package/src/reducers/ui/test/navigation.test.ts +5 -5
  158. package/src/reducers/ui/test/slide.test.ts +15 -0
  159. package/src/test/util/services.mock.ts +91 -73
  160. package/src/types/common.ts +0 -30
  161. package/src/views/skills/index.ts +1 -5
  162. package/src/views/skills/test/skills.test.ts +101 -0
  163. package/src/views/slides/index.ts +37 -22
  164. package/src/views/slides/map-api-slide-to-ui.ts +89 -89
  165. package/src/views/slides/test/fixtures/free-text.ts +2 -1
  166. package/src/views/slides/test/fixtures/qcm-drag.ts +2 -1
  167. package/src/views/slides/test/fixtures/qcm-graphic.ts +2 -1
  168. package/src/views/slides/test/fixtures/qcm.ts +2 -1
  169. package/src/views/slides/test/fixtures/select-template.ts +2 -1
  170. package/src/views/slides/test/fixtures/slider.ts +2 -1
  171. package/src/views/slides/test/fixtures/text-template.ts +2 -1
  172. package/src/views/slides/test/index.test.ts +240 -0
  173. package/src/views/slides/test/map-api-slide-to-ui.test.ts +2 -1
  174. package/es/fixtures/qcm-slide.d.ts +0 -2
  175. package/es/fixtures/qcm-slide.js +0 -33
  176. package/es/fixtures/temp-fixture.d.ts +0 -3
  177. package/es/fixtures/temp-fixture.js +0 -84
  178. package/lib/fixtures/qcm-slide.d.ts +0 -2
  179. package/lib/fixtures/qcm-slide.js +0 -33
  180. package/lib/fixtures/temp-fixture.d.ts +0 -3
  181. package/lib/fixtures/temp-fixture.js +0 -84
  182. package/src/fixtures/qcm-slide.ts +0 -35
  183. package/src/fixtures/temp-fixture.ts +0 -94
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const selectTemplateSlide: SlideFromAPI;
3
4
  export declare const selectTemplateUISlide: Partial<UISlide>;
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const sliderSlide: SlideFromAPI;
3
4
  export declare const sliderUISlide: Partial<UISlide>;
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const textTemplateSlide: SlideFromAPI;
3
4
  export declare const textTemplateUISlide: Partial<UISlide>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,234 @@
1
+ import test from 'ava';
2
+ import identity from 'lodash/fp/identity';
3
+ import omit from 'lodash/fp/omit';
4
+ import { mapStateToSlidesProps } from '..';
5
+ import { freeTextSlide } from './fixtures/free-text';
6
+ test('should create initial props when fetched slide is still not received', function (t) {
7
+ var state = {
8
+ data: {
9
+ progression: {
10
+ _id: '62b1d1087aa12f00253f40ee',
11
+ content: {
12
+ ref: '_skillref',
13
+ type: 'skill'
14
+ },
15
+ engine: {
16
+ ref: 'review'
17
+ },
18
+ state: {
19
+ allAnswers: [],
20
+ isCorrect: true,
21
+ nextContent: {
22
+ ref: 'sli_N1XACJobn',
23
+ type: 'slide'
24
+ },
25
+ pendingSlides: [],
26
+ slides: [],
27
+ step: {
28
+ current: 1
29
+ },
30
+ stars: 0
31
+ }
32
+ },
33
+ skills: [],
34
+ slides: {
35
+ sli_N1XACJobn: null
36
+ },
37
+ token: '1234'
38
+ },
39
+ ui: {
40
+ currentSlideRef: '',
41
+ navigation: ['loader', 'slides'],
42
+ answers: [],
43
+ slide: {
44
+ validateButton: false
45
+ }
46
+ }
47
+ };
48
+ var props = mapStateToSlidesProps(state, identity);
49
+ t.is(props.congratsProps, undefined);
50
+ t.deepEqual(omit(['onQuitClick'], props.header), {
51
+ 'aria-label': 'aria-header-wrapper',
52
+ closeButtonAriaLabel: 'aria-close-button',
53
+ mode: '__revision_mode',
54
+ skillName: '__agility',
55
+ steps: [
56
+ {
57
+ current: true,
58
+ icon: 'no-answer',
59
+ value: '1'
60
+ },
61
+ {
62
+ current: false,
63
+ icon: 'no-answer',
64
+ value: '2'
65
+ },
66
+ {
67
+ current: false,
68
+ icon: 'no-answer',
69
+ value: '3'
70
+ },
71
+ {
72
+ current: false,
73
+ icon: 'no-answer',
74
+ value: '4'
75
+ },
76
+ {
77
+ current: false,
78
+ icon: 'no-answer',
79
+ value: '5'
80
+ }
81
+ ]
82
+ });
83
+ t.deepEqual(omit(['validateButton'], props.stack), {
84
+ correctionPopinProps: undefined,
85
+ endReview: false,
86
+ slides: {
87
+ '0': {
88
+ hidden: false,
89
+ position: 0,
90
+ loading: true
91
+ },
92
+ '1': {
93
+ hidden: false,
94
+ position: 1,
95
+ loading: true
96
+ },
97
+ '2': {
98
+ hidden: false,
99
+ position: 2,
100
+ loading: true
101
+ },
102
+ '3': {
103
+ hidden: false,
104
+ position: 3,
105
+ loading: true
106
+ },
107
+ '4': {
108
+ hidden: false,
109
+ position: 4,
110
+ loading: true
111
+ }
112
+ }
113
+ });
114
+ });
115
+ test('should create initial props when the slide is on the state', function (t) {
116
+ var state = {
117
+ data: {
118
+ progression: {
119
+ _id: '62b1d1087aa12f00253f40ee',
120
+ content: {
121
+ ref: '_skillref',
122
+ type: 'skill'
123
+ },
124
+ engine: {
125
+ ref: 'review'
126
+ },
127
+ state: {
128
+ allAnswers: [],
129
+ isCorrect: true,
130
+ nextContent: {
131
+ ref: 'sli_N1XACJobn',
132
+ type: 'slide'
133
+ },
134
+ pendingSlides: [],
135
+ slides: [],
136
+ step: {
137
+ current: 1
138
+ },
139
+ stars: 0
140
+ }
141
+ },
142
+ skills: [],
143
+ slides: {
144
+ sli_N1XACJobn: freeTextSlide
145
+ },
146
+ token: '1234'
147
+ },
148
+ ui: {
149
+ currentSlideRef: 'sli_N1XACJobn',
150
+ navigation: ['loader', 'slides'],
151
+ answers: ['My value'],
152
+ slide: {
153
+ validateButton: true
154
+ }
155
+ }
156
+ };
157
+ var props = mapStateToSlidesProps(state, identity);
158
+ t.is(props.congratsProps, undefined);
159
+ t.deepEqual(omit(['onQuitClick'], props.header), {
160
+ 'aria-label': 'aria-header-wrapper',
161
+ closeButtonAriaLabel: 'aria-close-button',
162
+ mode: '__revision_mode',
163
+ skillName: '__agility',
164
+ steps: [
165
+ {
166
+ current: true,
167
+ icon: 'no-answer',
168
+ value: '1'
169
+ },
170
+ {
171
+ current: false,
172
+ icon: 'no-answer',
173
+ value: '2'
174
+ },
175
+ {
176
+ current: false,
177
+ icon: 'no-answer',
178
+ value: '3'
179
+ },
180
+ {
181
+ current: false,
182
+ icon: 'no-answer',
183
+ value: '4'
184
+ },
185
+ {
186
+ current: false,
187
+ icon: 'no-answer',
188
+ value: '5'
189
+ }
190
+ ]
191
+ });
192
+ t.deepEqual(omit(['validateButton', 'slides'], props.stack), {
193
+ correctionPopinProps: undefined,
194
+ endReview: false
195
+ });
196
+ t.false(props.stack.validateButton.disabled);
197
+ t.deepEqual(omit('answerUI', props.stack.slides['0']), {
198
+ hidden: false,
199
+ position: 0,
200
+ loading: false,
201
+ parentContentTitle: 'From "Developing the review app" course',
202
+ questionText: 'Which term is used to describe the act of asking what the usual salary is for the position you are applying for?'
203
+ });
204
+ t.deepEqual(omit('model.onChange', props.stack.slides['0'].answerUI), {
205
+ help: 'Type your answer.',
206
+ model: {
207
+ placeholder: 'Type here',
208
+ type: 'freeText',
209
+ value: 'My value'
210
+ }
211
+ });
212
+ t.deepEqual(omit(['0'], props.stack.slides), {
213
+ '1': {
214
+ hidden: false,
215
+ position: 1,
216
+ loading: true
217
+ },
218
+ '2': {
219
+ hidden: false,
220
+ position: 2,
221
+ loading: true
222
+ },
223
+ '3': {
224
+ hidden: false,
225
+ position: 3,
226
+ loading: true
227
+ },
228
+ '4': {
229
+ hidden: false,
230
+ position: 4,
231
+ loading: true
232
+ }
233
+ });
234
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -18,7 +18,8 @@
18
18
  "clean:es": "rm -rf es",
19
19
  "clean": "concurrently \"npm run clean:commonjs\" \"npm run clean:es\"",
20
20
  "typecheck": "tsc --noEmit",
21
- "test:unit": "ava",
21
+ "ava": "ava",
22
+ "test:unit": "nyc npm run ava",
22
23
  "lint": "eslint '**/*' --cache --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json",
23
24
  "lint:fix": "npm run lint -- --fix",
24
25
  "test": "npm run lint && npm run typecheck && npm run test:unit"
@@ -40,7 +41,7 @@
40
41
  "./package.json": "./package.json"
41
42
  },
42
43
  "dependencies": {
43
- "@coorpacademy/components": "10.22.10",
44
+ "@coorpacademy/components": "10.22.11",
44
45
  "@coorpacademy/redux-task": "^1.1.5",
45
46
  "cross-fetch": "^3.1.5",
46
47
  "jwt-decode": "^3.1.2",
@@ -74,8 +75,8 @@
74
75
  "nock": "^13.2.9",
75
76
  "postcss-modules-values-replace": "^3.4.0",
76
77
  "react-dom": "^17.0.2",
77
- "ts-node": "^10.8.1",
78
+ "ts-node": "^10.9.1",
78
79
  "typescript": "^4.7.4"
79
80
  },
80
- "gitHead": "508e3fdb30d727840bd9b13e9402c2970eb17731"
81
+ "gitHead": "7191ac405f4eebce61c459722595014ea973818c"
81
82
  }
@@ -1,7 +1,8 @@
1
1
  import buildTask from '@coorpacademy/redux-task';
2
- import {Dispatch} from 'redux';
2
+ import get from 'lodash/fp/get';
3
+ import type {Dispatch} from 'redux';
3
4
  import type {StoreState} from '../../reducers';
4
- import {Options, Skill} from '../../types/common';
5
+ import type {Options, Skill} from '../../types/common';
5
6
 
6
7
  export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST' as const;
7
8
  export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS' as const;
@@ -12,13 +13,19 @@ export type ReceivedSkills = {
12
13
  payload: Skill[];
13
14
  };
14
15
 
15
- export const fetchSkills =
16
- (token: string) =>
17
- async (dispatch: Dispatch, getState: () => StoreState, {services}: Options): Promise<void> => {
18
- const action = buildTask({
19
- types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
20
- task: () => services.fetchSkills(token)
21
- });
16
+ export const fetchSkills = async (
17
+ dispatch: Dispatch,
18
+ getState: () => StoreState,
19
+ {services}: Options
20
+ ): Promise<void> => {
21
+ const action = buildTask({
22
+ types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
23
+ task: () => {
24
+ const state = getState();
25
+ const token = get('data.token', state);
26
+ return services.fetchSkills(token);
27
+ }
28
+ });
22
29
 
23
- await dispatch(action);
24
- };
30
+ await dispatch(action);
31
+ };
@@ -23,7 +23,7 @@ export type ReceivedSlide = {
23
23
  };
24
24
 
25
25
  export const fetchSlide =
26
- (slideRef: string, token: string) =>
26
+ (slideRef: string) =>
27
27
  async (dispatch: Dispatch, getState: () => StoreState, {services}: Options): Promise<void> => {
28
28
  const action = buildTask({
29
29
  types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
@@ -31,6 +31,8 @@ export const fetchSlide =
31
31
  return has(`data.slide.${slideRef}`, state);
32
32
  },
33
33
  task: () => {
34
+ const state = getState();
35
+ const token = get('data.token', state);
34
36
  return services.fetchSlide(slideRef, token);
35
37
  },
36
38
  meta: {slideRef}
@@ -0,0 +1,39 @@
1
+ import type {Dispatch} from 'redux';
2
+ import buildTask from '@coorpacademy/redux-task';
3
+ import get from 'lodash/fp/get';
4
+ import type {Options} from '../../types/common';
5
+ import type {StoreState} from '../../reducers';
6
+ import {fetchSlide} from './fetch-slide';
7
+
8
+ export const POST_ANSWER_REQUEST = '@@answer/POST_REQUEST' as const;
9
+ export const POST_ANSWER_SUCCESS = '@@answer/POST_SUCCESS' as const;
10
+ export const POST_ANSWER_FAILURE = '@@answer/POST_FAILURE' as const;
11
+
12
+ export type PostAnswerRequestAction = {
13
+ type: typeof POST_ANSWER_REQUEST;
14
+ };
15
+
16
+ export const postAnswer = async (
17
+ dispatch: Dispatch,
18
+ getState: () => StoreState,
19
+ {services}: Options
20
+ ): Promise<void> => {
21
+ const action = buildTask({
22
+ types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
23
+ task: () => {
24
+ const state = getState();
25
+ const token = get('data.token', state);
26
+ const answer = get('ui.answers', state);
27
+ const progressionId = get('data.progression._id', state);
28
+ const skillRef = get('data.progression.content.ref', state);
29
+ return services.postAnswer(skillRef, token, progressionId, answer);
30
+ }
31
+ });
32
+ const response = await dispatch(action);
33
+
34
+ if (response.type === POST_ANSWER_SUCCESS) {
35
+ const progression = response.payload;
36
+ const slideRef = progression.state.nextContent.ref;
37
+ await dispatch(fetchSlide(slideRef));
38
+ }
39
+ };
@@ -1,6 +1,7 @@
1
1
  import type {Dispatch} from 'redux';
2
2
  import buildTask from '@coorpacademy/redux-task';
3
- import {Options, ProgressionFromAPI} from '../../types/common';
3
+ import get from 'lodash/fp/get';
4
+ import type {Options, ProgressionFromAPI} from '../../types/common';
4
5
  import type {StoreState} from '../../reducers';
5
6
  import {fetchSlide} from './fetch-slide';
6
7
 
@@ -8,14 +9,16 @@ export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST' as const;
8
9
  export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS' as const;
9
10
  export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE' as const;
10
11
 
11
- export type ReceiveProgression = {
12
+ export type ReceivedProgression = {
12
13
  type: typeof POST_PROGRESSION_SUCCESS;
13
14
  payload: ProgressionFromAPI;
14
15
  };
15
16
 
16
17
  export const postProgression =
17
- (skillRef: string, token: string) =>
18
+ (skillRef: string) =>
18
19
  async (dispatch: Dispatch, getState: () => StoreState, {services}: Options): Promise<void> => {
20
+ const state = getState();
21
+ const token = get('data.token', state);
19
22
  const action = buildTask({
20
23
  types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
21
24
  task: () => {
@@ -27,6 +30,6 @@ export const postProgression =
27
30
  if (response.type === POST_PROGRESSION_SUCCESS) {
28
31
  const progression = response.payload;
29
32
  const slideRef = progression.state.nextContent.ref;
30
- await dispatch(fetchSlide(slideRef, token));
33
+ await dispatch(fetchSlide(slideRef));
31
34
  }
32
35
  };
@@ -1,5 +1,6 @@
1
1
  import test from 'ava';
2
- import {Services} from '../../../types/common';
2
+ import type {Services} from '../../../types/common';
3
+ import type {StoreState} from '../../../reducers';
3
4
  import {
4
5
  fetchSkills,
5
6
  SKILLS_FETCH_FAILURE,
@@ -7,8 +8,7 @@ import {
7
8
  SKILLS_FETCH_SUCCESS
8
9
  } from '../fetch-skills';
9
10
  import {services as mockedServices} from '../../../test/util/services.mock';
10
- import {StoreState} from '../../../reducers';
11
- import {createTestStore} from './create-test-store';
11
+ import {createTestStore} from '../../test/create-test-store';
12
12
 
13
13
  const initialState: StoreState = {
14
14
  data: {
@@ -20,7 +20,10 @@ const initialState: StoreState = {
20
20
  ui: {
21
21
  currentSlideRef: '',
22
22
  navigation: [],
23
- answers: []
23
+ answers: [],
24
+ slide: {
25
+ validateButton: false
26
+ }
24
27
  }
25
28
  };
26
29
 
@@ -43,7 +46,7 @@ test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a lis
43
46
 
44
47
  const {dispatch} = createTestStore(t, initialState, services, expectedActions);
45
48
 
46
- await dispatch(fetchSkills('1234'));
49
+ await dispatch(fetchSkills);
47
50
  });
48
51
 
49
52
  test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', async t => {
@@ -66,5 +69,5 @@ test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', async
66
69
 
67
70
  const {dispatch} = createTestStore(t, initialState, services, expectedActions);
68
71
 
69
- await dispatch(fetchSkills('1234'));
72
+ await dispatch(fetchSkills);
70
73
  });
@@ -1,5 +1,5 @@
1
1
  import test from 'ava';
2
- import {Services} from '../../../types/common';
2
+ import type {Services} from '../../../types/common';
3
3
  import {
4
4
  fetchSlide,
5
5
  SLIDE_FETCH_FAILURE,
@@ -8,9 +8,9 @@ import {
8
8
  } from '../fetch-slide';
9
9
  import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
10
10
  import {services as mockedServices} from '../../../test/util/services.mock';
11
- import {StoreState} from '../../../reducers';
11
+ import type {StoreState} from '../../../reducers';
12
12
  import {SET_CURRENT_SLIDE} from '../../ui/slides';
13
- import {createTestStore} from './create-test-store';
13
+ import {createTestStore} from '../../test/create-test-store';
14
14
 
15
15
  const initialState: StoreState = {
16
16
  data: {
@@ -22,7 +22,10 @@ const initialState: StoreState = {
22
22
  ui: {
23
23
  currentSlideRef: '',
24
24
  navigation: [],
25
- answers: []
25
+ answers: [],
26
+ slide: {
27
+ validateButton: false
28
+ }
26
29
  }
27
30
  };
28
31
 
@@ -48,7 +51,7 @@ test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlid
48
51
 
49
52
  const {dispatch} = createTestStore(t, initialState, services, expectedActions);
50
53
 
51
- await dispatch(fetchSlide('sli_VJYjJnJhg', '1234'));
54
+ await dispatch(fetchSlide('sli_VJYjJnJhg'));
52
55
  });
53
56
 
54
57
  test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', async t => {
@@ -73,5 +76,5 @@ test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', async t
73
76
 
74
77
  const {dispatch} = createTestStore(t, initialState, services, expectedActions);
75
78
 
76
- await dispatch(fetchSlide('slide_ref', '1234'));
79
+ await dispatch(fetchSlide('slide_ref'));
77
80
  });
@@ -0,0 +1,101 @@
1
+ import test from 'ava';
2
+ import {createTestStore} from '../../test/create-test-store';
3
+ import {postAnswerResponse, services} from '../../../test/util/services.mock';
4
+ import {
5
+ postAnswer,
6
+ POST_ANSWER_FAILURE,
7
+ POST_ANSWER_REQUEST,
8
+ POST_ANSWER_SUCCESS
9
+ } from '../post-answer';
10
+ import type {StoreState} from '../../../reducers';
11
+ import {SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS} from '../fetch-slide';
12
+ import {qcmGraphicSlide} from '../../../views/slides/test/fixtures/qcm-graphic';
13
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
14
+ import {SET_CURRENT_SLIDE} from '../../ui/slides';
15
+
16
+ const progressionId = '123456789123';
17
+ const skillRef = '_skill-ref';
18
+ const answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
19
+
20
+ const initialState: StoreState = {
21
+ data: {
22
+ progression: {
23
+ _id: progressionId,
24
+ content: {type: 'skill', ref: skillRef},
25
+ engine: {
26
+ ref: 'review'
27
+ },
28
+ state: {
29
+ allAnswers: [],
30
+ isCorrect: true,
31
+ nextContent: {
32
+ ref: 'sli_VJYjJnJhg',
33
+ type: 'slide'
34
+ },
35
+ pendingSlides: [],
36
+ slides: [],
37
+ step: {
38
+ current: 1
39
+ },
40
+ stars: 0
41
+ }
42
+ },
43
+ slides: {
44
+ [freeTextSlide.id]: freeTextSlide
45
+ },
46
+ skills: [{skillRef, custom: false, name: skillRef, slidesToReview: 5}],
47
+ token: '1234'
48
+ },
49
+ ui: {
50
+ currentSlideRef: 'sli_VJYjJnJhg',
51
+ navigation: ['skills', 'slides'],
52
+ answers: answer,
53
+ slide: {
54
+ validateButton: false
55
+ }
56
+ }
57
+ };
58
+
59
+ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_SUCCESS when the updated progression is returned', async t => {
60
+ const expectedActions = [
61
+ {type: POST_ANSWER_REQUEST},
62
+ {
63
+ type: POST_ANSWER_SUCCESS,
64
+ payload: postAnswerResponse
65
+ },
66
+ {type: SLIDE_FETCH_REQUEST, meta: {slideRef: 'sli_VkSQroQnx'}},
67
+ {
68
+ type: SLIDE_FETCH_SUCCESS,
69
+ meta: {slideRef: 'sli_VkSQroQnx'},
70
+ payload: qcmGraphicSlide
71
+ },
72
+ {type: SET_CURRENT_SLIDE, payload: qcmGraphicSlide}
73
+ ];
74
+
75
+ const {dispatch} = createTestStore(t, initialState, services, expectedActions);
76
+
77
+ await dispatch(postAnswer);
78
+ });
79
+
80
+ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_FAILURE on error', async t => {
81
+ const expectedActions = [
82
+ {type: POST_ANSWER_REQUEST},
83
+ {
84
+ type: POST_ANSWER_FAILURE,
85
+ payload: new Error('unexpected'),
86
+ error: true
87
+ }
88
+ ];
89
+
90
+ const {dispatch} = createTestStore(
91
+ t,
92
+ initialState,
93
+ {
94
+ ...services,
95
+ postAnswer: () => Promise.reject(new Error('unexpected'))
96
+ },
97
+ expectedActions
98
+ );
99
+
100
+ await dispatch(postAnswer);
101
+ });
@@ -1,5 +1,5 @@
1
1
  import test from 'ava';
2
- import {ProgressionFromAPI, Services} from '../../../types/common';
2
+ import type {ProgressionFromAPI, Services} from '../../../types/common';
3
3
  import {
4
4
  postProgression,
5
5
  POST_PROGRESSION_REQUEST,
@@ -8,10 +8,10 @@ import {
8
8
  } from '../post-progression';
9
9
  import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
10
10
  import {services as mockedServices} from '../../../test/util/services.mock';
11
- import {StoreState} from '../../../reducers';
11
+ import type {StoreState} from '../../../reducers';
12
12
  import {SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS} from '../fetch-slide';
13
13
  import {SET_CURRENT_SLIDE} from '../../ui/slides';
14
- import {createTestStore} from './create-test-store';
14
+ import {createTestStore} from '../../test/create-test-store';
15
15
 
16
16
  const initialState: StoreState = {
17
17
  data: {
@@ -23,7 +23,10 @@ const initialState: StoreState = {
23
23
  ui: {
24
24
  currentSlideRef: '',
25
25
  navigation: [],
26
- answers: []
26
+ answers: [],
27
+ slide: {
28
+ validateButton: false
29
+ }
27
30
  }
28
31
  };
29
32
 
@@ -91,7 +94,7 @@ test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions w
91
94
 
92
95
  const {dispatch} = createTestStore(t, initialState, services, expectedActions);
93
96
 
94
- await dispatch(postProgression('skill_12345', '1234'));
97
+ await dispatch(postProgression('skill_12345'));
95
98
  });
96
99
 
97
100
  test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails', async t => {
@@ -115,5 +118,5 @@ test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails
115
118
 
116
119
  const {dispatch} = createTestStore(t, initialState, services, expectedActions);
117
120
 
118
- await dispatch(postProgression('skill_12345', '1234'));
121
+ await dispatch(postProgression('skill_12345'));
119
122
  });