@coorpacademy/app-review 0.1.16 → 0.1.18

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 (196) 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 +14 -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 +41 -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 +100 -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 +3 -3
  32. package/es/reducers/data/progression.js +2 -5
  33. package/es/reducers/data/slides.d.ts +2 -3
  34. package/es/reducers/data/test/progression.test.js +12 -27
  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 +23 -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 +3 -1
  48. package/es/test/util/services.mock.js +89 -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 +19 -15
  56. package/es/views/slides/map-api-slide-to-ui.js +65 -68
  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/slider.d.ts +2 -1
  62. package/es/views/slides/test/fixtures/template.d.ts +4 -0
  63. package/{lib/views/slides/test/fixtures/select-template.js → es/views/slides/test/fixtures/template.js} +82 -4
  64. package/es/views/slides/test/index.test.d.ts +1 -0
  65. package/es/views/slides/test/index.test.js +473 -0
  66. package/es/views/slides/test/map-api-slide-to-ui.test.js +4 -10
  67. package/es/views/slides/test/slide.template.on-change.test.d.ts +1 -0
  68. package/es/views/slides/test/slide.template.on-change.test.js +79 -0
  69. package/lib/actions/api/fetch-skills.d.ts +3 -3
  70. package/lib/actions/api/fetch-skills.js +22 -19
  71. package/lib/actions/api/fetch-slide.d.ts +1 -1
  72. package/lib/actions/api/fetch-slide.js +3 -1
  73. package/lib/actions/api/post-answer.d.ts +14 -0
  74. package/lib/actions/api/post-answer.js +75 -0
  75. package/lib/actions/api/post-progression.d.ts +3 -3
  76. package/lib/actions/api/post-progression.js +6 -3
  77. package/lib/actions/api/test/fetch-skills.test.js +7 -4
  78. package/lib/actions/api/test/fetch-slide.test.js +7 -4
  79. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  80. package/lib/actions/api/test/post-answer.test.js +145 -0
  81. package/lib/actions/api/test/post-progression.test.js +7 -4
  82. package/lib/actions/data/test/token.test.d.ts +1 -0
  83. package/lib/actions/data/test/token.test.js +70 -0
  84. package/lib/actions/index.d.ts +1 -8
  85. package/lib/actions/{api/test → test}/create-test-store.d.ts +2 -2
  86. package/lib/actions/{api/test → test}/create-test-store.js +1 -1
  87. package/lib/actions/ui/answers.d.ts +17 -3
  88. package/lib/actions/ui/answers.js +50 -3
  89. package/lib/actions/ui/slides.d.ts +0 -5
  90. package/lib/actions/ui/slides.js +0 -4
  91. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  92. package/lib/actions/ui/test/answers.test.js +190 -0
  93. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  94. package/lib/actions/ui/test/slides.test.js +71 -0
  95. package/lib/common/index.d.ts +0 -3
  96. package/lib/common/index.js +0 -4
  97. package/lib/index.js +1 -3
  98. package/lib/reducers/data/index.d.ts +1 -1
  99. package/lib/reducers/data/progression.d.ts +3 -3
  100. package/lib/reducers/data/progression.js +2 -5
  101. package/lib/reducers/data/slides.d.ts +2 -3
  102. package/lib/reducers/data/test/progression.test.js +12 -27
  103. package/lib/reducers/index.d.ts +2 -1
  104. package/lib/reducers/ui/answers.d.ts +2 -2
  105. package/lib/reducers/ui/answers.js +4 -8
  106. package/lib/reducers/ui/index.d.ts +4 -1
  107. package/lib/reducers/ui/index.js +3 -1
  108. package/lib/reducers/ui/slide.d.ts +8 -0
  109. package/lib/reducers/ui/slide.js +27 -0
  110. package/lib/reducers/ui/test/answers.test.js +23 -3
  111. package/lib/reducers/ui/test/current-slide-ref.test.js +1 -1
  112. package/lib/reducers/ui/test/navigation.test.js +5 -5
  113. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  114. package/lib/reducers/ui/test/slide.test.js +12 -0
  115. package/lib/test/util/services.mock.d.ts +3 -1
  116. package/lib/test/util/services.mock.js +89 -72
  117. package/lib/types/common.d.ts +0 -25
  118. package/lib/views/skills/index.d.ts +1 -1
  119. package/lib/views/skills/index.js +0 -3
  120. package/lib/views/skills/test/skills.test.d.ts +1 -0
  121. package/lib/views/skills/test/skills.test.js +94 -0
  122. package/lib/views/slides/index.d.ts +13 -2
  123. package/lib/views/slides/index.js +19 -15
  124. package/lib/views/slides/map-api-slide-to-ui.js +106 -99
  125. package/lib/views/slides/test/fixtures/free-text.d.ts +2 -1
  126. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  127. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  128. package/lib/views/slides/test/fixtures/qcm.d.ts +2 -1
  129. package/lib/views/slides/test/fixtures/slider.d.ts +2 -1
  130. package/lib/views/slides/test/fixtures/template.d.ts +4 -0
  131. package/{es/views/slides/test/fixtures/select-template.js → lib/views/slides/test/fixtures/template.js} +82 -4
  132. package/lib/views/slides/test/index.test.d.ts +1 -0
  133. package/lib/views/slides/test/index.test.js +473 -0
  134. package/lib/views/slides/test/map-api-slide-to-ui.test.js +4 -10
  135. package/lib/views/slides/test/slide.template.on-change.test.d.ts +1 -0
  136. package/lib/views/slides/test/slide.template.on-change.test.js +82 -0
  137. package/package.json +6 -5
  138. package/src/actions/api/fetch-skills.ts +18 -11
  139. package/src/actions/api/fetch-slide.ts +3 -1
  140. package/src/actions/api/post-answer.ts +44 -0
  141. package/src/actions/api/post-progression.ts +7 -4
  142. package/src/actions/api/test/fetch-skills.test.ts +9 -6
  143. package/src/actions/api/test/fetch-slide.test.ts +9 -6
  144. package/src/actions/api/test/post-answer.test.ts +101 -0
  145. package/src/actions/api/test/post-progression.test.ts +9 -6
  146. package/src/actions/data/test/token.test.ts +29 -0
  147. package/src/actions/index.ts +1 -17
  148. package/src/actions/{api/test → test}/create-test-store.ts +2 -2
  149. package/src/actions/ui/answers.ts +55 -6
  150. package/src/actions/ui/slides.ts +1 -8
  151. package/src/actions/ui/test/answers.test.ts +115 -0
  152. package/src/actions/ui/test/slides.test.ts +30 -0
  153. package/src/common/index.ts +0 -7
  154. package/src/index.tsx +1 -3
  155. package/src/reducers/data/progression.ts +4 -7
  156. package/src/reducers/data/slides.ts +2 -3
  157. package/src/reducers/data/test/progression.test.ts +15 -31
  158. package/src/reducers/ui/answers.ts +5 -9
  159. package/src/reducers/ui/index.ts +4 -1
  160. package/src/reducers/ui/slide.ts +43 -0
  161. package/src/reducers/ui/test/answers.test.ts +29 -4
  162. package/src/reducers/ui/test/current-slide-ref.test.ts +1 -1
  163. package/src/reducers/ui/test/navigation.test.ts +5 -5
  164. package/src/reducers/ui/test/slide.test.ts +15 -0
  165. package/src/test/util/services.mock.ts +94 -73
  166. package/src/types/common.ts +0 -30
  167. package/src/views/skills/index.ts +1 -5
  168. package/src/views/skills/test/skills.test.ts +101 -0
  169. package/src/views/slides/index.ts +38 -23
  170. package/src/views/slides/map-api-slide-to-ui.ts +146 -113
  171. package/src/views/slides/test/fixtures/free-text.ts +2 -1
  172. package/src/views/slides/test/fixtures/qcm-drag.ts +2 -1
  173. package/src/views/slides/test/fixtures/qcm-graphic.ts +2 -1
  174. package/src/views/slides/test/fixtures/qcm.ts +2 -1
  175. package/src/views/slides/test/fixtures/slider.ts +2 -1
  176. package/src/views/slides/test/fixtures/{select-template.ts → template.ts} +84 -5
  177. package/src/views/slides/test/index.test.ts +493 -0
  178. package/src/views/slides/test/map-api-slide-to-ui.test.ts +6 -11
  179. package/src/views/slides/test/slide.template.on-change.test.ts +92 -0
  180. package/es/fixtures/qcm-slide.d.ts +0 -2
  181. package/es/fixtures/qcm-slide.js +0 -33
  182. package/es/fixtures/temp-fixture.d.ts +0 -3
  183. package/es/fixtures/temp-fixture.js +0 -84
  184. package/es/views/slides/test/fixtures/select-template.d.ts +0 -3
  185. package/es/views/slides/test/fixtures/text-template.d.ts +0 -3
  186. package/es/views/slides/test/fixtures/text-template.js +0 -58
  187. package/lib/fixtures/qcm-slide.d.ts +0 -2
  188. package/lib/fixtures/qcm-slide.js +0 -33
  189. package/lib/fixtures/temp-fixture.d.ts +0 -3
  190. package/lib/fixtures/temp-fixture.js +0 -84
  191. package/lib/views/slides/test/fixtures/select-template.d.ts +0 -3
  192. package/lib/views/slides/test/fixtures/text-template.d.ts +0 -3
  193. package/lib/views/slides/test/fixtures/text-template.js +0 -58
  194. package/src/fixtures/qcm-slide.ts +0 -35
  195. package/src/fixtures/temp-fixture.ts +0 -94
  196. package/src/views/slides/test/fixtures/text-template.ts +0 -61
@@ -1,6 +1,6 @@
1
- import { Dispatch } from 'redux';
1
+ import type { Dispatch } from 'redux';
2
2
  import type { StoreState } from '../../reducers';
3
- import { Options, Skill } from '../../types/common';
3
+ import type { Options, Skill } from '../../types/common';
4
4
  export declare const SKILLS_FETCH_REQUEST: "@@skills/FETCH_REQUEST";
5
5
  export declare const SKILLS_FETCH_SUCCESS: "@@skills/FETCH_SUCCESS";
6
6
  export declare const SKILLS_FETCH_FAILURE: "@@skills/FETCH_FAILURE";
@@ -8,4 +8,4 @@ export declare type ReceivedSkills = {
8
8
  type: '@@skills/FETCH_SUCCESS';
9
9
  payload: Skill[];
10
10
  };
11
- export declare const fetchSkills: (token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
11
+ export declare const fetchSkills: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -1,11 +1,16 @@
1
1
  import buildTask from '@coorpacademy/redux-task';
2
+ import get from 'lodash/fp/get';
2
3
  export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST';
3
4
  export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS';
4
5
  export const SKILLS_FETCH_FAILURE = '@@skills/FETCH_FAILURE';
5
- export const fetchSkills = (token) => async (dispatch, getState, { services }) => {
6
+ export const fetchSkills = async (dispatch, getState, { services }) => {
6
7
  const action = buildTask({
7
8
  types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
8
- task: () => services.fetchSkills(token)
9
+ task: () => {
10
+ const state = getState();
11
+ const token = get('data.token', state);
12
+ return services.fetchSkills(token);
13
+ }
9
14
  });
10
15
  await dispatch(action);
11
16
  };
@@ -17,4 +17,4 @@ export declare type ReceivedSlide = {
17
17
  slideRef: string;
18
18
  };
19
19
  };
20
- export declare const fetchSlide: (slideRef: string, token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
20
+ export declare const fetchSlide: (slideRef: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -6,13 +6,15 @@ 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 = (slideRef, token) => async (dispatch, getState, { services }) => {
9
+ export const fetchSlide = (slideRef) => async (dispatch, getState, { services }) => {
10
10
  const action = buildTask({
11
11
  types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
12
12
  bailout: (state) => {
13
13
  return has(`data.slide.${slideRef}`, state);
14
14
  },
15
15
  task: () => {
16
+ const state = getState();
17
+ const token = get('data.token', state);
16
18
  return services.fetchSlide(slideRef, token);
17
19
  },
18
20
  meta: { slideRef }
@@ -0,0 +1,14 @@
1
+ import type { Dispatch } from 'redux';
2
+ import type { Options, ProgressionFromAPI } from '../../types/common';
3
+ import type { StoreState } from '../../reducers';
4
+ export declare const POST_ANSWER_REQUEST: "@@answer/POST_REQUEST";
5
+ export declare const POST_ANSWER_SUCCESS: "@@answer/POST_SUCCESS";
6
+ export declare const POST_ANSWER_FAILURE: "@@answer/POST_FAILURE";
7
+ export declare type PostAnswerRequestAction = {
8
+ type: typeof POST_ANSWER_REQUEST;
9
+ };
10
+ export declare type PostAnswerSuccessAction = {
11
+ type: typeof POST_ANSWER_SUCCESS;
12
+ payload: ProgressionFromAPI;
13
+ };
14
+ export declare const postAnswer: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ import buildTask from '@coorpacademy/redux-task';
2
+ import get from 'lodash/fp/get';
3
+ import { fetchSlide } from './fetch-slide';
4
+ export const POST_ANSWER_REQUEST = '@@answer/POST_REQUEST';
5
+ export const POST_ANSWER_SUCCESS = '@@answer/POST_SUCCESS';
6
+ export const POST_ANSWER_FAILURE = '@@answer/POST_FAILURE';
7
+ export const postAnswer = async (dispatch, getState, { services }) => {
8
+ const action = buildTask({
9
+ types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
10
+ task: () => {
11
+ const state = getState();
12
+ const token = get('data.token', state);
13
+ const answer = get('ui.answers', state);
14
+ const progressionId = get('data.progression._id', state);
15
+ const skillRef = get('data.progression.content.ref', state);
16
+ return services.postAnswer(skillRef, token, progressionId, answer);
17
+ }
18
+ });
19
+ const response = await dispatch(action);
20
+ if (response.type === POST_ANSWER_SUCCESS) {
21
+ const progression = response.payload;
22
+ const slideRef = progression.state.nextContent.ref;
23
+ await dispatch(fetchSlide(slideRef));
24
+ }
25
+ };
@@ -1,11 +1,11 @@
1
1
  import type { Dispatch } from 'redux';
2
- import { Options, ProgressionFromAPI } from '../../types/common';
2
+ import type { Options, ProgressionFromAPI } from '../../types/common';
3
3
  import type { StoreState } from '../../reducers';
4
4
  export declare const POST_PROGRESSION_REQUEST: "@@progression/POST_REQUEST";
5
5
  export declare const POST_PROGRESSION_SUCCESS: "@@progression/POST_SUCCESS";
6
6
  export declare const POST_PROGRESSION_FAILURE: "@@progression/POST_FAILURE";
7
- export declare type ReceiveProgression = {
7
+ export declare type ReceivedProgression = {
8
8
  type: typeof POST_PROGRESSION_SUCCESS;
9
9
  payload: ProgressionFromAPI;
10
10
  };
11
- export declare const postProgression: (skillRef: string, token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
11
+ export declare const postProgression: (skillRef: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -1,9 +1,12 @@
1
1
  import buildTask from '@coorpacademy/redux-task';
2
+ import get from 'lodash/fp/get';
2
3
  import { fetchSlide } from './fetch-slide';
3
4
  export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST';
4
5
  export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS';
5
6
  export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE';
6
- export const postProgression = (skillRef, token) => async (dispatch, getState, { services }) => {
7
+ export const postProgression = (skillRef) => async (dispatch, getState, { services }) => {
8
+ const state = getState();
9
+ const token = get('data.token', state);
7
10
  const action = buildTask({
8
11
  types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
9
12
  task: () => {
@@ -14,6 +17,6 @@ export const postProgression = (skillRef, token) => async (dispatch, getState, {
14
17
  if (response.type === POST_PROGRESSION_SUCCESS) {
15
18
  const progression = response.payload;
16
19
  const slideRef = progression.state.nextContent.ref;
17
- await dispatch(fetchSlide(slideRef, token));
20
+ await dispatch(fetchSlide(slideRef));
18
21
  }
19
22
  };
@@ -1,7 +1,7 @@
1
1
  import test from 'ava';
2
2
  import { fetchSkills, SKILLS_FETCH_FAILURE, SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS } from '../fetch-skills';
3
3
  import { services as mockedServices } from '../../../test/util/services.mock';
4
- import { createTestStore } from './create-test-store';
4
+ import { createTestStore } from '../../test/create-test-store';
5
5
  const initialState = {
6
6
  data: {
7
7
  progression: null,
@@ -12,7 +12,10 @@ const initialState = {
12
12
  ui: {
13
13
  currentSlideRef: '',
14
14
  navigation: [],
15
- answers: []
15
+ answers: [],
16
+ slide: {
17
+ validateButton: false
18
+ }
16
19
  }
17
20
  };
18
21
  test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a list of skills', async (t) => {
@@ -31,7 +34,7 @@ test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a lis
31
34
  }
32
35
  ];
33
36
  const { dispatch } = createTestStore(t, initialState, services, expectedActions);
34
- await dispatch(fetchSkills('1234'));
37
+ await dispatch(fetchSkills);
35
38
  });
36
39
  test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', async (t) => {
37
40
  const services = {
@@ -50,5 +53,5 @@ test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', async
50
53
  }
51
54
  ];
52
55
  const { dispatch } = createTestStore(t, initialState, services, expectedActions);
53
- await dispatch(fetchSkills('1234'));
56
+ await dispatch(fetchSkills);
54
57
  });
@@ -3,7 +3,7 @@ import { fetchSlide, SLIDE_FETCH_FAILURE, SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCE
3
3
  import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
4
4
  import { services as mockedServices } from '../../../test/util/services.mock';
5
5
  import { SET_CURRENT_SLIDE } from '../../ui/slides';
6
- import { createTestStore } from './create-test-store';
6
+ import { createTestStore } from '../../test/create-test-store';
7
7
  const initialState = {
8
8
  data: {
9
9
  progression: null,
@@ -14,7 +14,10 @@ const initialState = {
14
14
  ui: {
15
15
  currentSlideRef: '',
16
16
  navigation: [],
17
- answers: []
17
+ answers: [],
18
+ slide: {
19
+ validateButton: false
20
+ }
18
21
  }
19
22
  };
20
23
  test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlide return a slide', async (t) => {
@@ -36,7 +39,7 @@ test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlid
36
39
  { type: SET_CURRENT_SLIDE, payload: freeTextSlide }
37
40
  ];
38
41
  const { dispatch } = createTestStore(t, initialState, services, expectedActions);
39
- await dispatch(fetchSlide('sli_VJYjJnJhg', '1234'));
42
+ await dispatch(fetchSlide('sli_VJYjJnJhg'));
40
43
  });
41
44
  test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', async (t) => {
42
45
  const services = {
@@ -57,5 +60,5 @@ test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', async (
57
60
  }
58
61
  ];
59
62
  const { dispatch } = createTestStore(t, initialState, services, expectedActions);
60
- await dispatch(fetchSlide('slide_ref', '1234'));
63
+ await dispatch(fetchSlide('slide_ref'));
61
64
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
1
+ import test from 'ava';
2
+ import { createTestStore } from '../../test/create-test-store';
3
+ import { postAnswerResponse, services } from '../../../test/util/services.mock';
4
+ import { postAnswer, POST_ANSWER_FAILURE, POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS } from '../post-answer';
5
+ import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
6
+ import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
7
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
8
+ import { SET_CURRENT_SLIDE } from '../../ui/slides';
9
+ const progressionId = '123456789123';
10
+ const skillRef = '_skill-ref';
11
+ const answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
12
+ const initialState = {
13
+ data: {
14
+ progression: {
15
+ _id: progressionId,
16
+ content: { type: 'skill', ref: skillRef },
17
+ engine: {
18
+ ref: 'review'
19
+ },
20
+ state: {
21
+ allAnswers: [],
22
+ isCorrect: true,
23
+ nextContent: {
24
+ ref: 'sli_VJYjJnJhg',
25
+ type: 'slide'
26
+ },
27
+ pendingSlides: [],
28
+ slides: [],
29
+ step: {
30
+ current: 1
31
+ },
32
+ stars: 0
33
+ }
34
+ },
35
+ slides: {
36
+ [freeTextSlide.id]: freeTextSlide
37
+ },
38
+ skills: [{ skillRef, custom: false, name: skillRef, slidesToReview: 5 }],
39
+ token: '1234'
40
+ },
41
+ ui: {
42
+ currentSlideRef: 'sli_VJYjJnJhg',
43
+ navigation: ['skills', 'slides'],
44
+ answers: answer,
45
+ slide: {
46
+ validateButton: false
47
+ }
48
+ }
49
+ };
50
+ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_SUCCESS when the updated progression is returned', async (t) => {
51
+ const expectedActions = [
52
+ { type: POST_ANSWER_REQUEST },
53
+ {
54
+ type: POST_ANSWER_SUCCESS,
55
+ payload: postAnswerResponse
56
+ },
57
+ { type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'sli_VkSQroQnx' } },
58
+ {
59
+ type: SLIDE_FETCH_SUCCESS,
60
+ meta: { slideRef: 'sli_VkSQroQnx' },
61
+ payload: qcmGraphicSlide
62
+ },
63
+ { type: SET_CURRENT_SLIDE, payload: qcmGraphicSlide }
64
+ ];
65
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
66
+ await dispatch(postAnswer);
67
+ });
68
+ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_FAILURE on error', async (t) => {
69
+ const expectedActions = [
70
+ { type: POST_ANSWER_REQUEST },
71
+ {
72
+ type: POST_ANSWER_FAILURE,
73
+ payload: new Error('unexpected'),
74
+ error: true
75
+ }
76
+ ];
77
+ const { dispatch } = createTestStore(t, initialState, {
78
+ ...services,
79
+ postAnswer: () => Promise.reject(new Error('unexpected'))
80
+ }, expectedActions);
81
+ await dispatch(postAnswer);
82
+ });
@@ -4,7 +4,7 @@ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
4
4
  import { services as mockedServices } from '../../../test/util/services.mock';
5
5
  import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
6
6
  import { SET_CURRENT_SLIDE } from '../../ui/slides';
7
- import { createTestStore } from './create-test-store';
7
+ import { createTestStore } from '../../test/create-test-store';
8
8
  const initialState = {
9
9
  data: {
10
10
  progression: null,
@@ -15,7 +15,10 @@ const initialState = {
15
15
  ui: {
16
16
  currentSlideRef: '',
17
17
  navigation: [],
18
- answers: []
18
+ answers: [],
19
+ slide: {
20
+ validateButton: false
21
+ }
19
22
  }
20
23
  };
21
24
  test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions when postProgression return a progression', async (t) => {
@@ -78,7 +81,7 @@ test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions w
78
81
  { type: SET_CURRENT_SLIDE, payload: freeTextSlide }
79
82
  ];
80
83
  const { dispatch } = createTestStore(t, initialState, services, expectedActions);
81
- await dispatch(postProgression('skill_12345', '1234'));
84
+ await dispatch(postProgression('skill_12345'));
82
85
  });
83
86
  test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails', async (t) => {
84
87
  const services = {
@@ -98,5 +101,5 @@ test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails
98
101
  }
99
102
  ];
100
103
  const { dispatch } = createTestStore(t, initialState, services, expectedActions);
101
- await dispatch(postProgression('skill_12345', '1234'));
104
+ await dispatch(postProgression('skill_12345'));
102
105
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import test from 'ava';
2
+ import { createTestStore } from '../../test/create-test-store';
3
+ import { services } from '../../../test/util/services.mock';
4
+ import { storeToken, STORE_TOKEN } from '../token';
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
+ slide: {
17
+ validateButton: false
18
+ }
19
+ }
20
+ };
21
+ test('should dispatch STORE_TOKEN action when storeToken is called', async (t) => {
22
+ const expectedActions = [{ type: STORE_TOKEN, payload: 'JWT.token' }];
23
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
24
+ await dispatch(storeToken('JWT.token'));
25
+ });
@@ -1,12 +1,5 @@
1
- import { StoreToken } from './data/token';
2
- import { navigateBack, navigateTo, NavigateBack, NavigateTo, StartApp } from './ui/navigation';
3
- import { ReceivedSlide } from './api/fetch-slide';
4
- import { ReceiveProgression } from './api/post-progression';
5
- import { ReceivedSkills } from './api/fetch-skills';
6
- import { validateSlide } from './ui/slides';
7
- export declare type Action = NavigateBack | NavigateTo | ReceivedSkills | StartApp | ReceivedSlide | StoreToken | ReceiveProgression;
1
+ import { navigateBack, navigateTo } from './ui/navigation';
8
2
  export declare type Dispatchers = {
9
3
  navigateTo: typeof navigateTo;
10
4
  navigateBack: typeof navigateBack;
11
- validateSlide: typeof validateSlide;
12
5
  };
@@ -1,5 +1,5 @@
1
1
  import type { ExecutionContext } from 'ava';
2
2
  import { AnyAction, Store } from 'redux';
3
- import { StoreState } from '../../../reducers';
4
- import { Services } from '../../../types/common';
3
+ import { StoreState } from '../../reducers';
4
+ import { Services } from '../../types/common';
5
5
  export declare const createTestStore: (t: ExecutionContext, initialState: StoreState, services: Services, actions: AnyAction[]) => Store;
@@ -1,7 +1,7 @@
1
1
  import constant from 'lodash/fp/constant';
2
2
  import { applyMiddleware, compose, createStore } from 'redux';
3
3
  import thunk from 'redux-thunk';
4
- import rootReducer from '../../../reducers';
4
+ import rootReducer from '../../reducers';
5
5
  const assertActionsMiddleware = (t, ACTIONS) => constant((next) => (action) => {
6
6
  const expectedAction = ACTIONS.shift();
7
7
  if (!expectedAction)
@@ -1,7 +1,21 @@
1
1
  import { Dispatch } from 'redux';
2
+ import type { StoreState } from '../../reducers';
3
+ export declare const EDIT_QCM: "@@answer/EDIT_QCM";
4
+ export declare const EDIT_QCM_GRAPHIC: "@@answer/EDIT_QCM_GRAPHIC";
5
+ export declare const EDIT_QCM_DRAG: "@@answer/EDIT_QCM_DRAG";
6
+ export declare const EDIT_TEMPLATE: "@@answer/EDIT_TEMPLATE";
2
7
  export declare const EDIT_BASIC: "@@answer/EDIT_BASIC";
3
- export declare type EditBasicAction = {
4
- type: typeof EDIT_BASIC;
8
+ export declare const EDIT_SLIDER: "@@answer/EDIT_SLIDER";
9
+ export declare const ANSWER_EDIT: {
10
+ readonly qcm: "@@answer/EDIT_QCM";
11
+ readonly qcmGraphic: "@@answer/EDIT_QCM_GRAPHIC";
12
+ readonly qcmDrag: "@@answer/EDIT_QCM_DRAG";
13
+ readonly template: "@@answer/EDIT_TEMPLATE";
14
+ readonly basic: "@@answer/EDIT_BASIC";
15
+ readonly slider: "@@answer/EDIT_SLIDER";
16
+ };
17
+ export declare type EditAnswerAction = {
18
+ type: typeof EDIT_QCM | typeof EDIT_QCM_GRAPHIC | typeof EDIT_QCM_DRAG | typeof EDIT_TEMPLATE | typeof EDIT_BASIC | typeof EDIT_SLIDER;
5
19
  payload: string[];
6
20
  };
7
- export declare const editAnswer: (answer: string) => (dispatch: Dispatch) => EditBasicAction;
21
+ export declare const editAnswer: (answer: string[]) => (dispatch: Dispatch, getState: () => StoreState) => EditAnswerAction;
@@ -1,7 +1,45 @@
1
+ import { flatten, get, includes, pull } from 'lodash/fp';
2
+ export const EDIT_QCM = '@@answer/EDIT_QCM';
3
+ export const EDIT_QCM_GRAPHIC = '@@answer/EDIT_QCM_GRAPHIC';
4
+ export const EDIT_QCM_DRAG = '@@answer/EDIT_QCM_DRAG';
5
+ export const EDIT_TEMPLATE = '@@answer/EDIT_TEMPLATE';
1
6
  export const EDIT_BASIC = '@@answer/EDIT_BASIC';
2
- export const editAnswer = (answer) => (dispatch) => {
7
+ export const EDIT_SLIDER = '@@answer/EDIT_SLIDER';
8
+ export const ANSWER_EDIT = {
9
+ qcm: EDIT_QCM,
10
+ qcmGraphic: EDIT_QCM_GRAPHIC,
11
+ qcmDrag: EDIT_QCM_DRAG,
12
+ template: EDIT_TEMPLATE,
13
+ basic: EDIT_BASIC,
14
+ slider: EDIT_SLIDER
15
+ };
16
+ const buildAnswer = (userAnswers, questionType, newValue) => {
17
+ switch (questionType) {
18
+ case 'qcm':
19
+ case 'qcmGraphic':
20
+ case 'qcmDrag': {
21
+ const firstValue = newValue[0];
22
+ return includes(firstValue, userAnswers)
23
+ ? pull(firstValue, userAnswers)
24
+ : flatten([...userAnswers, firstValue]);
25
+ }
26
+ case 'basic':
27
+ case 'slider':
28
+ case 'template':
29
+ return newValue;
30
+ default:
31
+ return [];
32
+ }
33
+ };
34
+ export const editAnswer = (answer) => (dispatch, getState) => {
35
+ const state = getState();
36
+ const currentSlideRef = get(['ui', 'currentSlideRef'])(state);
37
+ const userAnswers = get(['ui', 'answers'])(state);
38
+ const slide = get(['data', 'slides', currentSlideRef])(state);
39
+ const questionType = get(['question', 'type'])(slide);
40
+ const type = get(questionType, ANSWER_EDIT);
3
41
  return dispatch({
4
- type: EDIT_BASIC,
5
- payload: [answer]
42
+ type,
43
+ payload: buildAnswer(userAnswers, questionType, answer)
6
44
  });
7
45
  };
@@ -17,10 +17,5 @@ export declare type SetCurrentSlide = {
17
17
  payload: SlideFromAPI;
18
18
  };
19
19
  export declare const setCurrentSlide: (payload: SlideFromAPI) => SetCurrentSlide;
20
- export declare const VALIDATE_SLIDE = "@@slide/VALIDATE";
21
- export declare type ValidateSlide = {
22
- type: typeof VALIDATE_SLIDE;
23
- };
24
- export declare const validateSlide: () => ValidateSlide;
25
20
  export declare type UISlidesAction = SetCurrentSlide;
26
21
  export {};
@@ -3,7 +3,3 @@ export const setCurrentSlide = (payload) => ({
3
3
  type: SET_CURRENT_SLIDE,
4
4
  payload
5
5
  });
6
- export const VALIDATE_SLIDE = '@@slide/VALIDATE';
7
- export const validateSlide = () => ({
8
- type: VALIDATE_SLIDE
9
- });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,100 @@
1
+ import test from 'ava';
2
+ import pipe from 'lodash/fp/pipe';
3
+ import set from 'lodash/fp/set';
4
+ import { createTestStore } from '../../test/create-test-store';
5
+ import { services } from '../../../test/util/services.mock';
6
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
7
+ import { qcmDragSlide } from '../../../views/slides/test/fixtures/qcm-drag';
8
+ import { qcmSlide } from '../../../views/slides/test/fixtures/qcm';
9
+ import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
10
+ import { sliderSlide } from '../../../views/slides/test/fixtures/slider';
11
+ import { templateSlide } from '../../../views/slides/test/fixtures/template';
12
+ import { editAnswer, ANSWER_EDIT } from '../answers';
13
+ const initialState = {
14
+ data: {
15
+ progression: {
16
+ _id: '62b1d1087aa12f00253f40ee',
17
+ content: {
18
+ ref: '_skill-ref',
19
+ type: 'skill'
20
+ },
21
+ engine: {
22
+ ref: 'review'
23
+ },
24
+ state: {
25
+ allAnswers: [],
26
+ isCorrect: true,
27
+ nextContent: {
28
+ ref: '',
29
+ type: 'slide'
30
+ },
31
+ pendingSlides: [],
32
+ slides: [],
33
+ step: {
34
+ current: 1
35
+ },
36
+ stars: 0
37
+ }
38
+ },
39
+ slides: {},
40
+ skills: [],
41
+ token: '1234'
42
+ },
43
+ ui: {
44
+ currentSlideRef: '',
45
+ navigation: [],
46
+ answers: [],
47
+ slide: {
48
+ validateButton: false
49
+ }
50
+ }
51
+ };
52
+ const buildInitialState = (state, question) => {
53
+ return pipe(set(['data', 'progression', 'state', 'nextContent', 'ref'], question.id), set(['data', 'slides', question.id], question), set(['ui', 'currentSlideRef'], question.id))(state);
54
+ };
55
+ test('should dispatch EDIT_BASIC action when editAnswer is called', async (t) => {
56
+ const state = buildInitialState(initialState, freeTextSlide);
57
+ const expectedActions = [{ type: ANSWER_EDIT.basic, payload: ['My Answer'] }];
58
+ const { dispatch } = createTestStore(t, state, services, expectedActions);
59
+ await dispatch(editAnswer(['My Answer']));
60
+ });
61
+ test('should dispatch EDIT_QCM action when editAnswer is called', async (t) => {
62
+ let state = buildInitialState(initialState, qcmSlide);
63
+ state = set(['ui', 'answers'], ['My First Answer', 'My Second Answer'], state);
64
+ const expectedActions = [{ type: ANSWER_EDIT.qcm, payload: ['My First Answer'] }];
65
+ const { dispatch } = createTestStore(t, state, services, expectedActions);
66
+ await dispatch(editAnswer(['My Second Answer']));
67
+ });
68
+ test('should dispatch EDIT_QCM_GRAPHIC action when editAnswer is called', async (t) => {
69
+ let state = buildInitialState(initialState, qcmGraphicSlide);
70
+ state = set(['ui', 'answers'], ['My First Answer', 'My Second Answer', 'My Third Answer'], state);
71
+ const expectedActions = [
72
+ { type: ANSWER_EDIT.qcmGraphic, payload: ['My First Answer', 'My Third Answer'] }
73
+ ];
74
+ const { dispatch } = createTestStore(t, state, services, expectedActions);
75
+ await dispatch(editAnswer(['My Second Answer']));
76
+ });
77
+ test('should dispatch EDIT_QCM_DRAG action when editAnswer is called', async (t) => {
78
+ let state = buildInitialState(initialState, qcmDragSlide);
79
+ state = set(['ui', 'answers'], ['My First Answer', 'My Second Answer'], state);
80
+ const expectedActions = [
81
+ { type: ANSWER_EDIT.qcmDrag, payload: ['My First Answer', 'My Second Answer', 'My Third Answer'] }
82
+ ];
83
+ const { dispatch } = createTestStore(t, state, services, expectedActions);
84
+ await dispatch(editAnswer(['My Third Answer']));
85
+ });
86
+ test('should dispatch EDIT_SLIDER action when editAnswer is called', async (t) => {
87
+ const state = buildInitialState(initialState, sliderSlide);
88
+ const expectedActions = [{ type: ANSWER_EDIT.slider, payload: ['5'] }];
89
+ const { dispatch } = createTestStore(t, state, services, expectedActions);
90
+ await dispatch(editAnswer(['5']));
91
+ });
92
+ test('should dispatch EDIT_TEMPLATE action when editAnswer is called', async (t) => {
93
+ let state = buildInitialState(initialState, templateSlide);
94
+ state = set(['ui', 'answers'], ['Catalogue', '', 'étoiles'], state);
95
+ const expectedActions = [
96
+ { type: ANSWER_EDIT.template, payload: ['Catalogue', 'My Answer', 'étoiles'] }
97
+ ];
98
+ const { dispatch } = createTestStore(t, state, services, expectedActions);
99
+ await dispatch(editAnswer(['Catalogue', 'My Answer', 'étoiles']));
100
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import test from 'ava';
2
+ import { createTestStore } from '../../test/create-test-store';
3
+ import { services } from '../../../test/util/services.mock';
4
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
5
+ import { setCurrentSlide, SET_CURRENT_SLIDE } from '../slides';
6
+ const initialState = {
7
+ data: {
8
+ progression: null,
9
+ slides: {},
10
+ skills: [],
11
+ token: '1234'
12
+ },
13
+ ui: {
14
+ currentSlideRef: '',
15
+ navigation: [],
16
+ answers: [],
17
+ slide: {
18
+ validateButton: false
19
+ }
20
+ }
21
+ };
22
+ test('should dispatch SET_CURRENT_SLIDE action when setCurrentSlide is called', async (t) => {
23
+ const expectedActions = [{ type: SET_CURRENT_SLIDE, payload: freeTextSlide }];
24
+ const { dispatch } = createTestStore(t, initialState, services, expectedActions);
25
+ await dispatch(setCurrentSlide(freeTextSlide));
26
+ });
@@ -1,5 +1,3 @@
1
- export declare const TOTAL_SLIDES_STACK = 5;
2
- export declare const HIGHEST_INDEX: number;
3
1
  export declare const VIEWS: {
4
2
  readonly skills: 'skills';
5
3
  readonly onboarding: 'onboarding';
@@ -7,4 +5,3 @@ export declare const VIEWS: {
7
5
  };
8
6
  export declare const slideIndexes: readonly ["0", "1", "2", "3", "4"];
9
7
  export declare type SlideIndexes = typeof slideIndexes[number];
10
- export declare const indexToString: (index: number) => SlideIndexes;