@coorpacademy/app-review 0.1.15 → 0.1.16

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 (212) hide show
  1. package/es/actions/api/fetch-skills.d.ts +4 -6
  2. package/es/actions/api/fetch-skills.js +7 -4
  3. package/es/actions/api/fetch-slide.d.ts +14 -7
  4. package/es/actions/api/fetch-slide.js +22 -19
  5. package/es/actions/api/post-progression.d.ts +4 -6
  6. package/es/actions/api/post-progression.js +13 -8
  7. package/es/actions/api/test/create-test-store.d.ts +5 -0
  8. package/es/actions/api/test/create-test-store.js +16 -0
  9. package/es/actions/api/test/fetch-skills.test.js +54 -0
  10. package/es/actions/api/test/fetch-slide.test.js +61 -0
  11. package/es/actions/api/test/post-progression.test.d.ts +1 -0
  12. package/es/actions/api/test/post-progression.test.js +102 -0
  13. package/es/actions/ui/answers.d.ts +7 -0
  14. package/es/actions/ui/answers.js +7 -0
  15. package/es/fixtures/temp-fixture.d.ts +1 -1
  16. package/es/index.js +10 -16
  17. package/es/reducers/data/index.d.ts +1 -1
  18. package/es/reducers/data/slides.d.ts +2 -2
  19. package/es/reducers/data/slides.js +5 -1
  20. package/es/reducers/data/test/progression.test.d.ts +1 -0
  21. package/es/reducers/data/test/progression.test.js +38 -0
  22. package/es/reducers/data/test/skills.test.d.ts +1 -0
  23. package/es/reducers/data/test/skills.test.js +12 -0
  24. package/es/reducers/data/test/slides.test.d.ts +1 -0
  25. package/es/reducers/data/test/slides.test.js +20 -0
  26. package/es/reducers/data/test/token.test.d.ts +1 -0
  27. package/es/reducers/data/test/token.test.js +11 -0
  28. package/es/reducers/index.d.ts +2 -2
  29. package/es/reducers/ui/answers.d.ts +4 -0
  30. package/es/reducers/ui/answers.js +13 -0
  31. package/es/reducers/ui/index.d.ts +4 -4
  32. package/es/reducers/ui/index.js +2 -2
  33. package/es/reducers/ui/test/answers.test.d.ts +1 -0
  34. package/es/reducers/ui/test/answers.test.js +11 -0
  35. package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  36. package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
  37. package/es/reducers/ui/test/navigation.test.d.ts +1 -0
  38. package/es/reducers/ui/test/navigation.test.js +15 -0
  39. package/es/services/fetch-slide.js +1 -1
  40. package/es/services/index.js +3 -1
  41. package/es/services/post-answer.d.ts +2 -0
  42. package/es/services/post-answer.js +18 -0
  43. package/es/services/test/fetch-slide.test.d.ts +1 -0
  44. package/es/services/test/fetch-slide.test.js +22 -0
  45. package/es/services/test/post-answer.test.d.ts +1 -0
  46. package/es/services/test/post-answer.test.js +57 -0
  47. package/es/services/test/post-progression.test.js +9 -1
  48. package/es/test/util/services.mock.js +37 -7
  49. package/es/types/common.d.ts +22 -8
  50. package/es/views/slides/index.d.ts +78 -2
  51. package/es/views/slides/index.js +70 -4
  52. package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
  53. package/es/views/slides/map-api-slide-to-ui.js +172 -0
  54. package/{lib/helpers → es/views/slides}/test/fixtures/free-text.d.ts +1 -1
  55. package/es/views/slides/test/fixtures/free-text.js +38 -0
  56. package/es/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +1 -1
  57. package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
  58. package/es/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +1 -1
  59. package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
  60. package/es/{helpers → views/slides}/test/fixtures/qcm.d.ts +1 -1
  61. package/es/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
  62. package/es/{helpers → views/slides}/test/fixtures/select-template.d.ts +1 -1
  63. package/es/views/slides/test/fixtures/select-template.js +92 -0
  64. package/es/{helpers → views/slides}/test/fixtures/slider.d.ts +1 -1
  65. package/es/views/slides/test/fixtures/slider.js +36 -0
  66. package/es/{helpers → views/slides}/test/fixtures/text-template.d.ts +1 -1
  67. package/es/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
  68. package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  69. package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  70. package/lib/actions/api/fetch-skills.d.ts +4 -6
  71. package/lib/actions/api/fetch-skills.js +55 -7
  72. package/lib/actions/api/fetch-slide.d.ts +14 -7
  73. package/lib/actions/api/fetch-slide.js +70 -20
  74. package/lib/actions/api/post-progression.d.ts +4 -6
  75. package/lib/actions/api/post-progression.js +63 -9
  76. package/lib/actions/api/test/create-test-store.d.ts +5 -0
  77. package/lib/actions/api/test/create-test-store.js +18 -0
  78. package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
  79. package/lib/actions/api/test/fetch-skills.test.js +113 -0
  80. package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
  81. package/lib/actions/api/test/fetch-slide.test.js +120 -0
  82. package/lib/actions/api/test/post-progression.test.d.ts +1 -0
  83. package/lib/actions/api/test/post-progression.test.js +160 -0
  84. package/lib/actions/ui/answers.d.ts +7 -0
  85. package/lib/actions/ui/answers.js +9 -0
  86. package/lib/fixtures/temp-fixture.d.ts +1 -1
  87. package/lib/index.js +21 -18
  88. package/lib/reducers/data/index.d.ts +1 -1
  89. package/lib/reducers/data/slides.d.ts +2 -2
  90. package/lib/reducers/data/slides.js +5 -1
  91. package/lib/reducers/data/test/progression.test.d.ts +1 -0
  92. package/lib/reducers/data/test/progression.test.js +38 -0
  93. package/lib/reducers/data/test/skills.test.d.ts +1 -0
  94. package/lib/reducers/data/test/skills.test.js +12 -0
  95. package/lib/reducers/data/test/slides.test.d.ts +1 -0
  96. package/lib/reducers/data/test/slides.test.js +20 -0
  97. package/lib/reducers/data/test/token.test.d.ts +1 -0
  98. package/lib/reducers/data/test/token.test.js +11 -0
  99. package/lib/reducers/index.d.ts +2 -2
  100. package/lib/reducers/ui/answers.d.ts +4 -0
  101. package/lib/reducers/ui/answers.js +14 -0
  102. package/lib/reducers/ui/index.d.ts +4 -4
  103. package/lib/reducers/ui/index.js +2 -2
  104. package/lib/reducers/ui/test/answers.test.d.ts +1 -0
  105. package/lib/reducers/ui/test/answers.test.js +11 -0
  106. package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  107. package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
  108. package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
  109. package/lib/reducers/ui/test/navigation.test.js +15 -0
  110. package/lib/services/fetch-slide.js +1 -1
  111. package/lib/services/index.js +3 -1
  112. package/lib/services/post-answer.d.ts +2 -0
  113. package/lib/services/post-answer.js +62 -0
  114. package/lib/services/test/fetch-slide.test.d.ts +1 -0
  115. package/lib/services/test/fetch-slide.test.js +76 -0
  116. package/lib/services/test/post-answer.test.d.ts +1 -0
  117. package/lib/services/test/post-answer.test.js +111 -0
  118. package/lib/services/test/post-progression.test.js +9 -1
  119. package/lib/test/util/services.mock.js +37 -7
  120. package/lib/types/common.d.ts +22 -8
  121. package/lib/views/slides/index.d.ts +78 -2
  122. package/lib/views/slides/index.js +70 -4
  123. package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
  124. package/lib/views/slides/map-api-slide-to-ui.js +178 -0
  125. package/{es/helpers → lib/views/slides}/test/fixtures/free-text.d.ts +1 -1
  126. package/lib/views/slides/test/fixtures/free-text.js +38 -0
  127. package/lib/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +1 -1
  128. package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
  129. package/lib/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +1 -1
  130. package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
  131. package/lib/{helpers → views/slides}/test/fixtures/qcm.d.ts +1 -1
  132. package/lib/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
  133. package/lib/{helpers → views/slides}/test/fixtures/select-template.d.ts +1 -1
  134. package/lib/views/slides/test/fixtures/select-template.js +92 -0
  135. package/lib/{helpers → views/slides}/test/fixtures/slider.d.ts +1 -1
  136. package/lib/views/slides/test/fixtures/slider.js +36 -0
  137. package/lib/{helpers → views/slides}/test/fixtures/text-template.d.ts +1 -1
  138. package/lib/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
  139. package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  140. package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  141. package/package.json +3 -3
  142. package/src/actions/api/fetch-skills.ts +12 -12
  143. package/src/actions/api/fetch-slide.ts +33 -29
  144. package/src/actions/api/post-progression.ts +18 -21
  145. package/src/actions/api/test/create-test-store.ts +25 -0
  146. package/src/actions/api/test/fetch-skills.test.ts +70 -0
  147. package/src/actions/api/test/fetch-slide.test.ts +77 -0
  148. package/src/actions/api/test/post-progression.test.ts +119 -0
  149. package/src/actions/ui/answers.ts +16 -0
  150. package/src/fixtures/temp-fixture.ts +1 -1
  151. package/src/index.tsx +14 -29
  152. package/src/reducers/data/index.ts +1 -1
  153. package/src/reducers/data/slides.ts +11 -2
  154. package/src/reducers/data/test/progression.test.ts +42 -0
  155. package/src/reducers/data/test/skills.test.ts +14 -0
  156. package/src/reducers/data/test/slides.test.ts +26 -0
  157. package/src/reducers/data/test/token.test.ts +13 -0
  158. package/src/reducers/ui/answers.ts +19 -0
  159. package/src/reducers/ui/index.ts +3 -3
  160. package/src/reducers/ui/test/answers.test.ts +13 -0
  161. package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
  162. package/src/reducers/ui/test/navigation.test.ts +19 -0
  163. package/src/services/fetch-slide.ts +1 -1
  164. package/src/services/index.ts +3 -1
  165. package/src/services/post-answer.ts +27 -0
  166. package/src/services/test/fetch-slide.test.ts +30 -0
  167. package/src/services/test/post-answer.test.ts +68 -0
  168. package/src/services/test/post-progression.test.ts +9 -1
  169. package/src/test/util/services.mock.ts +37 -7
  170. package/src/types/common.ts +34 -14
  171. package/src/views/slides/index.ts +164 -5
  172. package/src/views/slides/map-api-slide-to-ui.ts +251 -0
  173. package/src/views/slides/test/fixtures/free-text.ts +43 -0
  174. package/src/views/slides/test/fixtures/qcm-drag.ts +111 -0
  175. package/src/views/slides/test/fixtures/qcm-graphic.ts +94 -0
  176. package/src/{helpers → views/slides}/test/fixtures/qcm.ts +6 -2
  177. package/src/views/slides/test/fixtures/select-template.ts +98 -0
  178. package/src/views/slides/test/fixtures/slider.ts +41 -0
  179. package/src/{helpers → views/slides}/test/fixtures/text-template.ts +6 -2
  180. package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +21 -10
  181. package/es/helpers/map-api-slide-to-ui.d.ts +0 -11
  182. package/es/helpers/map-api-slide-to-ui.js +0 -193
  183. package/es/helpers/test/fixtures/free-text.js +0 -30
  184. package/es/helpers/test/fixtures/qcm-drag.js +0 -112
  185. package/es/helpers/test/fixtures/qcm-graphic.js +0 -76
  186. package/es/helpers/test/fixtures/select-template.js +0 -94
  187. package/es/helpers/test/fixtures/slider.js +0 -33
  188. package/es/reducers/ui/slides.d.ts +0 -9
  189. package/es/reducers/ui/slides.js +0 -42
  190. package/es/types/views/slides.d.ts +0 -74
  191. package/es/types/views/slides.js +0 -6
  192. package/lib/helpers/map-api-slide-to-ui.d.ts +0 -11
  193. package/lib/helpers/map-api-slide-to-ui.js +0 -201
  194. package/lib/helpers/test/fixtures/free-text.js +0 -30
  195. package/lib/helpers/test/fixtures/qcm-drag.js +0 -112
  196. package/lib/helpers/test/fixtures/qcm-graphic.js +0 -76
  197. package/lib/helpers/test/fixtures/select-template.js +0 -94
  198. package/lib/helpers/test/fixtures/slider.js +0 -33
  199. package/lib/reducers/ui/slides.d.ts +0 -9
  200. package/lib/reducers/ui/slides.js +0 -43
  201. package/lib/types/views/slides.d.ts +0 -74
  202. package/lib/types/views/slides.js +0 -6
  203. package/src/helpers/map-api-slide-to-ui.ts +0 -279
  204. package/src/helpers/test/fixtures/free-text.ts +0 -33
  205. package/src/helpers/test/fixtures/qcm-drag.ts +0 -115
  206. package/src/helpers/test/fixtures/qcm-graphic.ts +0 -79
  207. package/src/helpers/test/fixtures/select-template.ts +0 -97
  208. package/src/helpers/test/fixtures/slider.ts +0 -36
  209. package/src/reducers/ui/slides.ts +0 -58
  210. package/src/types/views/slides.ts +0 -90
  211. /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
  212. /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/actions/api/test/fetch-slide.test.d.ts} +0 -0
@@ -1,13 +1,11 @@
1
- import type { ThunkAction } from 'redux-thunk';
2
- import { AnyAction } from 'redux';
1
+ import { Dispatch } from 'redux';
3
2
  import type { StoreState } from '../../reducers';
4
3
  import { Options, Skill } from '../../types/common';
5
4
  export declare const SKILLS_FETCH_REQUEST: "@@skills/FETCH_REQUEST";
6
5
  export declare const SKILLS_FETCH_SUCCESS: "@@skills/FETCH_SUCCESS";
7
6
  export declare const SKILLS_FETCH_FAILURE: "@@skills/FETCH_FAILURE";
8
- export interface ReceivedSkills extends AnyAction {
7
+ export declare type ReceivedSkills = {
9
8
  type: '@@skills/FETCH_SUCCESS';
10
9
  payload: Skill[];
11
- }
12
- export declare type FetchSkillsAction = ThunkAction<Promise<void>, StoreState, Options, AnyAction>;
13
- export declare const fetchSkills: (token: string) => FetchSkillsAction;
10
+ };
11
+ export declare const fetchSkills: (token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -2,7 +2,10 @@ import buildTask from '@coorpacademy/redux-task';
2
2
  export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST';
3
3
  export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS';
4
4
  export const SKILLS_FETCH_FAILURE = '@@skills/FETCH_FAILURE';
5
- export const fetchSkills = (token) => buildTask({
6
- types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
7
- task: (dispatch, getState, { services }) => services.fetchSkills(token)
8
- });
5
+ export const fetchSkills = (token) => async (dispatch, getState, { services }) => {
6
+ const action = buildTask({
7
+ types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
8
+ task: () => services.fetchSkills(token)
9
+ });
10
+ await dispatch(action);
11
+ };
@@ -1,13 +1,20 @@
1
- import type { AnyAction } from 'redux';
2
- import type { ThunkAction } from 'redux-thunk';
1
+ import type { Dispatch } from 'redux';
3
2
  import type { StoreState } from '../../reducers';
4
- import type { Options, ProgressionFromAPI, SlideFromAPI } from '../../types/common';
3
+ import type { Options, SlideFromAPI } from '../../types/common';
5
4
  export declare const SLIDE_FETCH_REQUEST: "@@slides/FETCH_REQUEST";
6
5
  export declare const SLIDE_FETCH_SUCCESS: "@@slides/FETCH_SUCCESS";
7
6
  export declare const SLIDE_FETCH_FAILURE: "@@slides/FETCH_FAILURE";
8
- export interface ReceivedSlide extends AnyAction {
7
+ export declare type FetchSlide = {
8
+ type: typeof SLIDE_FETCH_REQUEST;
9
+ meta: {
10
+ slideRef: string;
11
+ };
12
+ };
13
+ export declare type ReceivedSlide = {
9
14
  type: typeof SLIDE_FETCH_SUCCESS;
10
15
  payload: SlideFromAPI;
11
- }
12
- export declare type FetchSlideAction = ThunkAction<Promise<SlideFromAPI>, StoreState, Options, AnyAction>;
13
- export declare const fetchSlide: (progressionFromAPI: ProgressionFromAPI, token: string) => FetchSlideAction;
16
+ meta: {
17
+ slideRef: string;
18
+ };
19
+ };
20
+ export declare const fetchSlide: (slideRef: string, token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -6,23 +6,26 @@ import { setCurrentSlide } from '../ui/slides';
6
6
  export const SLIDE_FETCH_REQUEST = '@@slides/FETCH_REQUEST';
7
7
  export const SLIDE_FETCH_SUCCESS = '@@slides/FETCH_SUCCESS';
8
8
  export const SLIDE_FETCH_FAILURE = '@@slides/FETCH_FAILURE';
9
- export const fetchSlide = (progressionFromAPI, token) => buildTask({
10
- types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
11
- bailout: (state) => {
12
- const { ref: slideRef } = get('state.nextContent', progressionFromAPI);
13
- return has(`data.slide.${slideRef}`, state);
14
- },
15
- task: (dispatch, getState, { services }) => {
16
- const { ref: slideRef } = get('state.nextContent', progressionFromAPI);
17
- return services.fetchSlide(slideRef, token).then((slideFromAPI) => {
18
- if (!slideFromAPI)
19
- throw new Error('Slide not found');
20
- const state = getState();
21
- const slides = get('data.progression.state.slides', state);
22
- if (isEmpty(slides)) {
23
- dispatch(setCurrentSlide(slideFromAPI));
24
- }
25
- return slideFromAPI;
26
- });
9
+ export const fetchSlide = (slideRef, token) => async (dispatch, getState, { services }) => {
10
+ const action = buildTask({
11
+ types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
12
+ bailout: (state) => {
13
+ return has(`data.slide.${slideRef}`, state);
14
+ },
15
+ task: () => {
16
+ return services.fetchSlide(slideRef, token);
17
+ },
18
+ meta: { slideRef }
19
+ });
20
+ const response = await dispatch(action);
21
+ if (response.type === SLIDE_FETCH_SUCCESS) {
22
+ const slideFromAPI = response.payload;
23
+ if (!slideFromAPI)
24
+ throw new Error('Slide not found');
25
+ const state = getState();
26
+ const slides = get('data.progression.state.slides', state);
27
+ if (isEmpty(slides)) {
28
+ dispatch(setCurrentSlide(slideFromAPI));
29
+ }
27
30
  }
28
- });
31
+ };
@@ -1,13 +1,11 @@
1
- import type { AnyAction } from 'redux';
2
- import type { ThunkAction } from 'redux-thunk';
1
+ import type { Dispatch } from 'redux';
3
2
  import { Options, ProgressionFromAPI } from '../../types/common';
4
3
  import type { StoreState } from '../../reducers';
5
4
  export declare const POST_PROGRESSION_REQUEST: "@@progression/POST_REQUEST";
6
5
  export declare const POST_PROGRESSION_SUCCESS: "@@progression/POST_SUCCESS";
7
6
  export declare const POST_PROGRESSION_FAILURE: "@@progression/POST_FAILURE";
8
- export interface ReceiveProgression extends AnyAction {
7
+ export declare type ReceiveProgression = {
9
8
  type: typeof POST_PROGRESSION_SUCCESS;
10
9
  payload: ProgressionFromAPI;
11
- }
12
- export declare type PostProgressionAction = ThunkAction<Promise<ProgressionFromAPI>, StoreState, Options, AnyAction>;
13
- export declare const postProgression: (skillRef: string, token: string) => PostProgressionAction;
10
+ };
11
+ export declare const postProgression: (skillRef: string, token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -3,12 +3,17 @@ import { fetchSlide } from './fetch-slide';
3
3
  export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST';
4
4
  export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS';
5
5
  export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE';
6
- export const postProgression = (skillRef, token) => buildTask({
7
- types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
8
- task: (dispatch, getState, { services }) => {
9
- return services.postProgression(skillRef, token).then((progression) => {
10
- dispatch(fetchSlide(progression, token));
11
- return progression;
12
- });
6
+ export const postProgression = (skillRef, token) => async (dispatch, getState, { services }) => {
7
+ const action = buildTask({
8
+ types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
9
+ task: () => {
10
+ return services.postProgression(skillRef, token);
11
+ }
12
+ });
13
+ const response = await dispatch(action);
14
+ if (response.type === POST_PROGRESSION_SUCCESS) {
15
+ const progression = response.payload;
16
+ const slideRef = progression.state.nextContent.ref;
17
+ await dispatch(fetchSlide(slideRef, token));
13
18
  }
14
- });
19
+ };
@@ -0,0 +1,5 @@
1
+ import type { ExecutionContext } from 'ava';
2
+ import { AnyAction, Store } from 'redux';
3
+ import { StoreState } from '../../../reducers';
4
+ import { Services } from '../../../types/common';
5
+ export declare const createTestStore: (t: ExecutionContext, initialState: StoreState, services: Services, actions: AnyAction[]) => Store;
@@ -0,0 +1,16 @@
1
+ import constant from 'lodash/fp/constant';
2
+ import { applyMiddleware, compose, createStore } from 'redux';
3
+ import thunk from 'redux-thunk';
4
+ import rootReducer from '../../../reducers';
5
+ const assertActionsMiddleware = (t, ACTIONS) => constant((next) => (action) => {
6
+ const expectedAction = ACTIONS.shift();
7
+ if (!expectedAction)
8
+ throw new Error(`Missing {type: "${action.type}"} action`);
9
+ t.deepEqual(action, expectedAction);
10
+ return next(action);
11
+ });
12
+ export const createTestStore = (t, initialState, services, actions) => {
13
+ const thunkMiddleware = thunk.withExtraArgument({ services });
14
+ const enhancer = compose(applyMiddleware(thunkMiddleware, assertActionsMiddleware(t, actions)));
15
+ return createStore(rootReducer, initialState, enhancer);
16
+ };
@@ -0,0 +1,54 @@
1
+ import test from 'ava';
2
+ import { fetchSkills, SKILLS_FETCH_FAILURE, SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS } from '../fetch-skills';
3
+ import { services as mockedServices } from '../../../test/util/services.mock';
4
+ import { createTestStore } from './create-test-store';
5
+ const initialState = {
6
+ data: {
7
+ progression: null,
8
+ slides: {},
9
+ skills: [],
10
+ token: '1234'
11
+ },
12
+ ui: {
13
+ currentSlideRef: '',
14
+ navigation: [],
15
+ answers: []
16
+ }
17
+ };
18
+ test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a list of skills', async (t) => {
19
+ const services = {
20
+ ...mockedServices,
21
+ fetchSkills: token => {
22
+ t.is(token, '1234');
23
+ return Promise.resolve([]);
24
+ }
25
+ };
26
+ const expectedActions = [
27
+ { type: SKILLS_FETCH_REQUEST },
28
+ {
29
+ type: SKILLS_FETCH_SUCCESS,
30
+ payload: []
31
+ }
32
+ ];
33
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
34
+ await dispatch(fetchSkills('1234'));
35
+ });
36
+ test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', async (t) => {
37
+ const services = {
38
+ ...mockedServices,
39
+ fetchSkills: token => {
40
+ t.is(token, '1234');
41
+ return Promise.reject(new Error('unexpected'));
42
+ }
43
+ };
44
+ const expectedActions = [
45
+ { type: SKILLS_FETCH_REQUEST },
46
+ {
47
+ type: SKILLS_FETCH_FAILURE,
48
+ payload: new Error('unexpected'),
49
+ error: true
50
+ }
51
+ ];
52
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
53
+ await dispatch(fetchSkills('1234'));
54
+ });
@@ -0,0 +1,61 @@
1
+ import test from 'ava';
2
+ import { fetchSlide, SLIDE_FETCH_FAILURE, SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
3
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
4
+ import { services as mockedServices } from '../../../test/util/services.mock';
5
+ import { SET_CURRENT_SLIDE } from '../../ui/slides';
6
+ import { createTestStore } from './create-test-store';
7
+ const initialState = {
8
+ data: {
9
+ progression: null,
10
+ slides: {},
11
+ skills: [],
12
+ token: '1234'
13
+ },
14
+ ui: {
15
+ currentSlideRef: '',
16
+ navigation: [],
17
+ answers: []
18
+ }
19
+ };
20
+ test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlide return a slide', async (t) => {
21
+ const services = {
22
+ ...mockedServices,
23
+ fetchSlide: (slideRef, token) => {
24
+ t.is(token, '1234');
25
+ t.is(slideRef, 'sli_VJYjJnJhg');
26
+ return Promise.resolve(freeTextSlide);
27
+ }
28
+ };
29
+ const expectedActions = [
30
+ { type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'sli_VJYjJnJhg' } },
31
+ {
32
+ type: SLIDE_FETCH_SUCCESS,
33
+ meta: { slideRef: 'sli_VJYjJnJhg' },
34
+ payload: freeTextSlide
35
+ },
36
+ { type: SET_CURRENT_SLIDE, payload: freeTextSlide }
37
+ ];
38
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
39
+ await dispatch(fetchSlide('sli_VJYjJnJhg', '1234'));
40
+ });
41
+ test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', async (t) => {
42
+ const services = {
43
+ ...mockedServices,
44
+ fetchSlide: (slideRef, token) => {
45
+ t.is(token, '1234');
46
+ t.is(slideRef, 'slide_ref');
47
+ return Promise.reject(new Error('error'));
48
+ }
49
+ };
50
+ const expectedActions = [
51
+ { type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'slide_ref' } },
52
+ {
53
+ type: SLIDE_FETCH_FAILURE,
54
+ meta: { slideRef: 'slide_ref' },
55
+ payload: new Error('error'),
56
+ error: true
57
+ }
58
+ ];
59
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
60
+ await dispatch(fetchSlide('slide_ref', '1234'));
61
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,102 @@
1
+ import test from 'ava';
2
+ import { postProgression, POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE } from '../post-progression';
3
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
4
+ import { services as mockedServices } from '../../../test/util/services.mock';
5
+ import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
6
+ import { SET_CURRENT_SLIDE } from '../../ui/slides';
7
+ import { createTestStore } from './create-test-store';
8
+ const initialState = {
9
+ data: {
10
+ progression: null,
11
+ slides: {},
12
+ skills: [],
13
+ token: '1234'
14
+ },
15
+ ui: {
16
+ currentSlideRef: '',
17
+ navigation: [],
18
+ answers: []
19
+ }
20
+ };
21
+ test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions when postProgression return a progression', async (t) => {
22
+ const progression = {
23
+ _id: '62b1d1087aa12f00253f40ee',
24
+ content: {
25
+ ref: '_skill-ref',
26
+ type: 'skill'
27
+ },
28
+ engine: {
29
+ ref: 'review'
30
+ },
31
+ state: {
32
+ allAnswers: [],
33
+ isCorrect: true,
34
+ nextContent: {
35
+ ref: 'sli_VJYjJnJhg',
36
+ type: 'slide'
37
+ },
38
+ pendingSlides: [],
39
+ slides: [],
40
+ step: {
41
+ current: 1
42
+ },
43
+ stars: 0
44
+ }
45
+ };
46
+ const services = {
47
+ ...mockedServices,
48
+ postProgression: (skillRef, token) => {
49
+ t.is(token, '1234');
50
+ t.is(skillRef, 'skill_12345');
51
+ return Promise.resolve(progression);
52
+ },
53
+ fetchSlide: (slideRef, token) => {
54
+ t.is(token, '1234');
55
+ t.is(slideRef, 'sli_VJYjJnJhg');
56
+ return Promise.resolve(freeTextSlide);
57
+ }
58
+ };
59
+ const expectedActions = [
60
+ { type: POST_PROGRESSION_REQUEST },
61
+ {
62
+ type: POST_PROGRESSION_SUCCESS,
63
+ payload: progression
64
+ },
65
+ {
66
+ type: SLIDE_FETCH_REQUEST,
67
+ meta: {
68
+ slideRef: 'sli_VJYjJnJhg'
69
+ }
70
+ },
71
+ {
72
+ type: SLIDE_FETCH_SUCCESS,
73
+ meta: {
74
+ slideRef: 'sli_VJYjJnJhg'
75
+ },
76
+ payload: freeTextSlide
77
+ },
78
+ { type: SET_CURRENT_SLIDE, payload: freeTextSlide }
79
+ ];
80
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
81
+ await dispatch(postProgression('skill_12345', '1234'));
82
+ });
83
+ test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails', async (t) => {
84
+ const services = {
85
+ ...mockedServices,
86
+ postProgression: (skillRef, token) => {
87
+ t.is(token, '1234');
88
+ t.is(skillRef, 'skill_12345');
89
+ return Promise.reject(new Error('error'));
90
+ }
91
+ };
92
+ const expectedActions = [
93
+ { type: POST_PROGRESSION_REQUEST },
94
+ {
95
+ type: POST_PROGRESSION_FAILURE,
96
+ payload: new Error('error'),
97
+ error: true
98
+ }
99
+ ];
100
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
101
+ await dispatch(postProgression('skill_12345', '1234'));
102
+ });
@@ -0,0 +1,7 @@
1
+ import { Dispatch } from 'redux';
2
+ export declare const EDIT_BASIC: "@@answer/EDIT_BASIC";
3
+ export declare type EditBasicAction = {
4
+ type: typeof EDIT_BASIC;
5
+ payload: string[];
6
+ };
7
+ export declare const editAnswer: (answer: string) => (dispatch: Dispatch) => EditBasicAction;
@@ -0,0 +1,7 @@
1
+ export const EDIT_BASIC = '@@answer/EDIT_BASIC';
2
+ export const editAnswer = (answer) => (dispatch) => {
3
+ return dispatch({
4
+ type: EDIT_BASIC,
5
+ payload: [answer]
6
+ });
7
+ };
@@ -1,3 +1,3 @@
1
- import { SlidesViewProps, CorrectionPopinProps } from '../types/views/slides';
1
+ import { SlidesViewProps, CorrectionPopinProps } from '../views/slides';
2
2
  export declare const correctionPopinProps: CorrectionPopinProps;
3
3
  export declare const congratsProps: SlidesViewProps['congratsProps'];
package/es/index.js CHANGED
@@ -1,32 +1,26 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { connect, Provider } from 'react-redux';
2
+ import { useSelector, useDispatch, Provider } from 'react-redux';
3
3
  import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
4
4
  import { TemplateContext } from '@coorpacademy/components/es/template/app-review/template-context';
5
5
  import isEmpty from 'lodash/fp/isEmpty';
6
6
  import get from 'lodash/fp/get';
7
7
  import configureStore from './configure-store';
8
- import { validateSlide } from './actions/ui/slides';
9
- import { navigateTo, navigateBack } from './actions/ui/navigation';
8
+ import { navigateTo } from './actions/ui/navigation';
10
9
  import { storeToken } from './actions/data/token';
11
10
  import { fetchSkills } from './actions/api/fetch-skills';
12
11
  import { postProgression } from './actions/api/post-progression';
13
12
  import { VIEWS } from './common';
14
13
  import { mapStateToSlidesProps } from './views/slides';
15
14
  import { mapStateToSkillsProps } from './views/skills';
16
- const mapDispatchToProps = {
17
- navigateTo,
18
- navigateBack,
19
- validateSlide
20
- };
21
- const getCurrentViewName = (storeState) => storeState.ui.navigation[storeState.ui.navigation.length - 1];
22
- const mapStateToProps = (state) => {
23
- return {
24
- viewName: getCurrentViewName(state),
25
- slides: mapStateToSlidesProps(state),
26
- skills: mapStateToSkillsProps(state)
15
+ const ConnectedApp = () => {
16
+ const dispatch = useDispatch();
17
+ const props = {
18
+ viewName: useSelector((state) => state.ui.navigation[state.ui.navigation.length - 1]),
19
+ slides: useSelector((state) => mapStateToSlidesProps(state, dispatch)),
20
+ skills: useSelector((state) => mapStateToSkillsProps(state))
27
21
  };
22
+ return React.createElement(AppReviewTemplate, { ...props });
28
23
  };
29
- const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
30
24
  const AppReview = ({ options }) => {
31
25
  const [store, setStore] = useState(null);
32
26
  const [isProgressionCreated, setIsProgressionCreated] = useState(false);
@@ -77,6 +71,6 @@ const AppReview = ({ options }) => {
77
71
  const { templateContext: values } = options;
78
72
  return (React.createElement(Provider, { store: store },
79
73
  React.createElement(TemplateContext, { values: values },
80
- React.createElement(App, null))));
74
+ React.createElement(ConnectedApp, null))));
81
75
  };
82
76
  export default AppReview;
@@ -4,7 +4,7 @@ import { SlidesState } from './slides';
4
4
  import { TokenState } from './token';
5
5
  export declare type DataState = {
6
6
  isFetching?: boolean;
7
- progression?: ProgressionState;
7
+ progression: ProgressionState;
8
8
  skills: SkillsState;
9
9
  slides: SlidesState;
10
10
  token?: TokenState;
@@ -1,7 +1,7 @@
1
1
  import { ValidateSlide } from '../../actions/ui/slides';
2
- import { ReceivedSlide } from '../../actions/api/fetch-slide';
2
+ import { ReceivedSlide, FetchSlide } from '../../actions/api/fetch-slide';
3
3
  import { SlideFromAPI } from '../../types/common';
4
- export declare type SlidesAction = ReceivedSlide | ValidateSlide;
4
+ export declare type SlidesAction = FetchSlide | ReceivedSlide | ValidateSlide;
5
5
  export declare type SlidesState = Record<string, SlideFromAPI>;
6
6
  export declare const initialState: SlidesState;
7
7
  declare const reducer: (state: SlidesState | undefined, action: SlidesAction) => SlidesState;
@@ -1,9 +1,13 @@
1
1
  import set from 'lodash/fp/set';
2
- import { SLIDE_FETCH_SUCCESS } from '../../actions/api/fetch-slide';
2
+ import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../../actions/api/fetch-slide';
3
3
  export const initialState = {};
4
4
  // eslint-disable-next-line default-param-last
5
5
  const reducer = (state = initialState, action) => {
6
6
  switch (action.type) {
7
+ case SLIDE_FETCH_REQUEST: {
8
+ const { meta } = action;
9
+ return set(meta.slideRef, null, state);
10
+ }
7
11
  case SLIDE_FETCH_SUCCESS: {
8
12
  const slide = action.payload;
9
13
  return set(slide.id, slide, state);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ import test from 'ava';
2
+ import reducer from '../progression';
3
+ import { POST_PROGRESSION_SUCCESS } from '../../../actions/api/post-progression';
4
+ test('should have inital value', t => {
5
+ const state = reducer(undefined, {});
6
+ t.is(state, null);
7
+ });
8
+ test('should set the value of POST_PROGRESSION_SUCCESS action', t => {
9
+ const progression = {
10
+ _id: '62b1d1087aa12f00253f40ee',
11
+ content: {
12
+ ref: '_skill-ref',
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
+ const state = reducer(null, {
34
+ type: POST_PROGRESSION_SUCCESS,
35
+ payload: progression
36
+ });
37
+ t.deepEqual(state, progression);
38
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import test from 'ava';
2
+ import reducer from '../skills';
3
+ import { SKILLS_FETCH_SUCCESS } from '../../../actions/api/fetch-skills';
4
+ test('should have inital value', t => {
5
+ const state = reducer(undefined, {});
6
+ t.deepEqual(state, []);
7
+ });
8
+ test('should set the value of SKILLS_FETCH_SUCCESS action', t => {
9
+ const skills = [{ skillRef: 'skill', name: 'skill name', slidesToReview: 5, custom: false }];
10
+ const state = reducer([], { type: SKILLS_FETCH_SUCCESS, payload: skills });
11
+ t.deepEqual(state, skills);
12
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import test from 'ava';
2
+ import reducer from '../slides';
3
+ import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../../../actions/api/fetch-slide';
4
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {});
7
+ t.deepEqual(state, {});
8
+ });
9
+ test('should set the value of SLIDE_FETCH_REQUEST action', t => {
10
+ const state = reducer({}, { type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'slideRef' } });
11
+ t.deepEqual(state, {
12
+ slideRef: null
13
+ });
14
+ });
15
+ test('should set the value of SLIDE_FETCH_SUCCESS action', t => {
16
+ const state = reducer({}, { type: SLIDE_FETCH_SUCCESS, payload: freeTextSlide, meta: { slideRef: 'sli_VJYjJnJhg' } });
17
+ t.deepEqual(state, {
18
+ sli_VJYjJnJhg: freeTextSlide
19
+ });
20
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import test from 'ava';
2
+ import reducer from '../token';
3
+ import { STORE_TOKEN } from '../../../actions/data/token';
4
+ test('should have inital value', t => {
5
+ const state = reducer(undefined, {});
6
+ t.is(state, null);
7
+ });
8
+ test('should set the value of STORE_TOKEN action', t => {
9
+ const state = reducer(null, { type: STORE_TOKEN, payload: 'token' });
10
+ t.is(state, 'token');
11
+ });
@@ -14,7 +14,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
14
14
  ui: import("redux").CombinedState<{
15
15
  currentSlideRef: string;
16
16
  navigation: import("./ui/navigation").NavigationState;
17
- slides: import("./ui/slides").UISlidesState;
17
+ answers: import("./ui/answers").AnswerState;
18
18
  }>;
19
- }>, import("../actions/ui/slides").SetCurrentSlide | import("../actions/api/post-progression").ReceiveProgression | import("../actions/api/fetch-skills").ReceivedSkills | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/ui/navigation").NavigateTo | import("../actions/ui/navigation").NavigateBack>;
19
+ }>, import("../actions/ui/slides").SetCurrentSlide | import("../actions/api/post-progression").ReceiveProgression | import("../actions/api/fetch-skills").ReceivedSkills | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/ui/navigation").NavigateTo | import("../actions/ui/navigation").NavigateBack | import("../actions/ui/answers").EditBasicAction>;
20
20
  export default _default;
@@ -0,0 +1,4 @@
1
+ import { EditBasicAction } from '../../actions/ui/answers';
2
+ export declare type AnswerState = string[];
3
+ declare const reducer: (state: AnswerState | undefined, action: EditBasicAction) => AnswerState;
4
+ export default reducer;
@@ -0,0 +1,13 @@
1
+ import { EDIT_BASIC } from '../../actions/ui/answers';
2
+ const reducer = (
3
+ // eslint-disable-next-line default-param-last
4
+ state = [], action) => {
5
+ switch (action.type) {
6
+ case EDIT_BASIC: {
7
+ return action.payload;
8
+ }
9
+ default:
10
+ return state;
11
+ }
12
+ };
13
+ export default reducer;