@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,5 +1,4 @@
1
1
  import set from 'lodash/fp/set';
2
- import {ValidateSlide} from '../../actions/ui/slides';
3
2
  import {
4
3
  ReceivedSlide,
5
4
  FetchSlide,
@@ -8,9 +7,9 @@ import {
8
7
  } from '../../actions/api/fetch-slide';
9
8
  import {SlideFromAPI} from '../../types/common';
10
9
 
11
- export type SlidesAction = FetchSlide | ReceivedSlide | ValidateSlide;
10
+ export type SlidesAction = FetchSlide | ReceivedSlide;
12
11
 
13
- export type SlidesState = Record<string, SlideFromAPI>;
12
+ export type SlidesState = Record<string, SlideFromAPI | null>;
14
13
  export const initialState: SlidesState = {};
15
14
 
16
15
  // eslint-disable-next-line default-param-last
@@ -1,42 +1,26 @@
1
1
  import test from 'ava';
2
2
  import reducer from '../progression';
3
- import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../../actions/api/post-progression';
4
- import {ProgressionFromAPI} from '../../../types/common';
3
+ import {POST_PROGRESSION_SUCCESS, ReceivedProgression} from '../../../actions/api/post-progression';
4
+ import {POST_ANSWER_SUCCESS} from '../../../actions/api/post-answer';
5
+ import {postAnswerResponse, postProgressionResponse} from '../../../test/util/services.mock';
5
6
 
6
- test('should have inital value', t => {
7
- const state = reducer(undefined, {} as ReceiveProgression);
7
+ test('should have initial value', t => {
8
+ const state = reducer(undefined, {} as ReceivedProgression);
8
9
  t.is(state, null);
9
10
  });
10
11
 
11
12
  test('should set the value of POST_PROGRESSION_SUCCESS action', t => {
12
- const progression: ProgressionFromAPI = {
13
- _id: '62b1d1087aa12f00253f40ee',
14
- content: {
15
- ref: '_skill-ref',
16
- type: 'skill'
17
- },
18
- engine: {
19
- ref: 'review'
20
- },
21
- state: {
22
- allAnswers: [],
23
- isCorrect: true,
24
- nextContent: {
25
- ref: 'sli_N1XACJobn',
26
- type: 'slide'
27
- },
28
- pendingSlides: [],
29
- slides: [],
30
- step: {
31
- current: 1
32
- },
33
- stars: 0
34
- }
35
- };
36
-
37
13
  const state = reducer(null, {
38
14
  type: POST_PROGRESSION_SUCCESS,
39
- payload: progression
15
+ payload: postProgressionResponse
16
+ });
17
+ t.deepEqual(state, postProgressionResponse);
18
+ });
19
+
20
+ test('should set the value of POST_ANSWER_SUCCESS action', t => {
21
+ const state = reducer(null, {
22
+ type: POST_ANSWER_SUCCESS,
23
+ payload: postAnswerResponse
40
24
  });
41
- t.deepEqual(state, progression);
25
+ t.deepEqual(state, postAnswerResponse);
42
26
  });
@@ -1,19 +1,15 @@
1
- import {EditBasicAction, EDIT_BASIC} from '../../actions/ui/answers';
1
+ import {includes, values} from 'lodash/fp';
2
+ import {EditAnswerAction, ANSWER_EDIT} from '../../actions/ui/answers';
2
3
 
3
4
  export type AnswerState = string[];
5
+ const ANSWER_EDIT_ACTIONS = values(ANSWER_EDIT);
4
6
 
5
7
  const reducer = (
6
8
  // eslint-disable-next-line default-param-last
7
9
  state: AnswerState = [],
8
- action: EditBasicAction
10
+ action: EditAnswerAction
9
11
  ): AnswerState => {
10
- switch (action.type) {
11
- case EDIT_BASIC: {
12
- return action.payload;
13
- }
14
- default:
15
- return state;
16
- }
12
+ return includes(action.type, ANSWER_EDIT_ACTIONS) ? action.payload : state;
17
13
  };
18
14
 
19
15
  export default reducer;
@@ -3,15 +3,18 @@ import {combineReducers} from 'redux';
3
3
  import currentSlideRef, {CurrentSlideRefState} from './current-slide-ref';
4
4
  import navigation, {NavigationState} from './navigation';
5
5
  import answers, {AnswerState} from './answers';
6
+ import slide, {UISlideState} from './slide';
6
7
 
7
8
  export type UIState = {
8
9
  currentSlideRef: CurrentSlideRefState;
9
10
  navigation: NavigationState;
10
11
  answers: AnswerState;
12
+ slide: UISlideState;
11
13
  };
12
14
 
13
15
  export default combineReducers({
14
16
  currentSlideRef,
15
17
  navigation,
16
- answers
18
+ answers,
19
+ slide
17
20
  });
@@ -0,0 +1,43 @@
1
+ import compact from 'lodash/fp/compact';
2
+ import isEmpty from 'lodash/fp/isEmpty';
3
+ import pipe from 'lodash/fp/pipe';
4
+ import {
5
+ EditAnswerAction,
6
+ EDIT_BASIC,
7
+ EDIT_QCM,
8
+ EDIT_QCM_DRAG,
9
+ EDIT_QCM_GRAPHIC,
10
+ EDIT_SLIDER,
11
+ EDIT_TEMPLATE
12
+ } from '../../actions/ui/answers';
13
+ import {PostAnswerRequestAction, POST_ANSWER_REQUEST} from '../../actions/api/post-answer';
14
+
15
+ export type UISlideState = {
16
+ validateButton: boolean;
17
+ };
18
+
19
+ export const initialState: UISlideState = {validateButton: false};
20
+
21
+ const reducer = (
22
+ // eslint-disable-next-line default-param-last
23
+ state: UISlideState = initialState,
24
+ action: PostAnswerRequestAction | EditAnswerAction
25
+ ): UISlideState => {
26
+ switch (action.type) {
27
+ case EDIT_QCM:
28
+ case EDIT_QCM_GRAPHIC:
29
+ case EDIT_QCM_DRAG:
30
+ case EDIT_TEMPLATE:
31
+ case EDIT_BASIC:
32
+ case EDIT_SLIDER: {
33
+ return pipe(compact, isEmpty)(action.payload) ? initialState : {validateButton: true};
34
+ }
35
+ case POST_ANSWER_REQUEST: {
36
+ return initialState;
37
+ }
38
+ default:
39
+ return state;
40
+ }
41
+ };
42
+
43
+ export default reducer;
@@ -1,13 +1,38 @@
1
1
  import test from 'ava';
2
2
  import reducer from '../answers';
3
- import {EditBasicAction, EDIT_BASIC} from '../../../actions/ui/answers';
3
+ import {EditAnswerAction, ANSWER_EDIT} from '../../../actions/ui/answers';
4
4
 
5
- test('should have inital value', t => {
6
- const state = reducer(undefined, {} as EditBasicAction);
5
+ test('should have initial value', t => {
6
+ const state = reducer(undefined, {} as EditAnswerAction);
7
7
  t.deepEqual(state, []);
8
8
  });
9
9
 
10
10
  test('should set the value of EDIT_BASIC action', t => {
11
- const state = reducer([], {type: EDIT_BASIC, payload: ['value']});
11
+ const state = reducer([], {type: ANSWER_EDIT.basic, payload: ['value']});
12
12
  t.deepEqual(state, ['value']);
13
13
  });
14
+
15
+ test('should set the value of EDIT_QCM action', t => {
16
+ const state = reducer([], {type: ANSWER_EDIT.qcm, payload: ['value1', 'value2']});
17
+ t.deepEqual(state, ['value1', 'value2']);
18
+ });
19
+
20
+ test('should set the value of EDIT_QCM_GRAPHIC action', t => {
21
+ const state = reducer([], {type: ANSWER_EDIT.qcmGraphic, payload: ['True', 'False']});
22
+ t.deepEqual(state, ['True', 'False']);
23
+ });
24
+
25
+ test('should set the value of EDIT_QCM_DRAG action', t => {
26
+ const state = reducer([], {type: ANSWER_EDIT.qcmDrag, payload: ['value1', 'value2']});
27
+ t.deepEqual(state, ['value1', 'value2']);
28
+ });
29
+
30
+ test('should set the value of EDIT_SLIDER action', t => {
31
+ const state = reducer([], {type: ANSWER_EDIT.slider, payload: ['5']});
32
+ t.deepEqual(state, ['5']);
33
+ });
34
+
35
+ test('should set the value of EDIT_TEMPLATE action', t => {
36
+ const state = reducer([], {type: ANSWER_EDIT.template, payload: ['value1', 'value2']});
37
+ t.deepEqual(state, ['value1', 'value2']);
38
+ });
@@ -3,7 +3,7 @@ import reducer from '../current-slide-ref';
3
3
  import {SetCurrentSlide, SET_CURRENT_SLIDE} from '../../../actions/ui/slides';
4
4
  import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
5
5
 
6
- test('should have inital value', t => {
6
+ test('should have initial value', t => {
7
7
  const state = reducer(undefined, {} as SetCurrentSlide);
8
8
  t.is(state, '');
9
9
  });
@@ -1,19 +1,19 @@
1
1
  import test from 'ava';
2
2
  import reducer from '../navigation';
3
- import {NavigateTo, NAVIGATE_TO, NAVIGATE_BACK} from '../../../actions/ui/navigation';
3
+ import {NavigateTo, navigateBack, navigateTo} from '../../../actions/ui/navigation';
4
4
 
5
- test('should have inital value', t => {
5
+ test('should have initial value', t => {
6
6
  const state = reducer(undefined, {} as NavigateTo);
7
7
  t.deepEqual(state, []);
8
8
  });
9
9
 
10
10
  test('should set the value of NAVIGATE_TO and NAVIGATE_BACK action', t => {
11
- const state = reducer([], {type: NAVIGATE_TO, payload: 'loader'});
11
+ const state = reducer([], navigateTo('loader'));
12
12
  t.deepEqual(state, ['loader']);
13
13
 
14
- const updatedState = reducer(state, {type: NAVIGATE_TO, payload: 'skills'});
14
+ const updatedState = reducer(state, navigateTo('skills'));
15
15
  t.deepEqual(updatedState, ['loader', 'skills']);
16
16
 
17
- const _updatedState = reducer(updatedState, {type: NAVIGATE_BACK});
17
+ const _updatedState = reducer(updatedState, navigateBack());
18
18
  t.deepEqual(_updatedState, ['loader']);
19
19
  });
@@ -0,0 +1,15 @@
1
+ import test from 'ava';
2
+ import reducer, {initialState} from '../slide';
3
+ import {EDIT_BASIC} from '../../../actions/ui/answers';
4
+ import {PostAnswerRequestAction} from '../../../actions/api/post-answer';
5
+
6
+ test('should use initial state if no answers are found when an EditAnswerAction is received', t => {
7
+ const state = reducer(undefined, {type: EDIT_BASIC, payload: ['']});
8
+ t.truthy(state);
9
+ t.false(state.validateButton);
10
+ });
11
+
12
+ test('should return state directly when there is no corresponding action handler + have an initial state', t => {
13
+ const state = reducer(undefined, {type: 'NOPE'} as unknown as PostAnswerRequestAction);
14
+ t.deepEqual(state, initialState);
15
+ });
@@ -1,82 +1,103 @@
1
+ import {qcmSlide} from '../../views/slides/test/fixtures/qcm';
2
+ import {qcmGraphicSlide} from '../../views/slides/test/fixtures/qcm-graphic';
1
3
  import {freeTextSlide} from '../../views/slides/test/fixtures/free-text';
2
- import {Services} from '../../types/common';
4
+ import {sliderSlide} from '../../views/slides/test/fixtures/slider';
5
+ import {templateSlide} from '../../views/slides/test/fixtures/template';
6
+ import {ProgressionFromAPI, Services, SlideFromAPI} from '../../types/common';
3
7
 
4
- export const services: Services = {
5
- fetchSkills: () => {
6
- return Promise.resolve([
7
- {
8
- skillRef: '_skill-ref',
9
- slidesToReview: 2,
10
- name: 'skill-test',
11
- custom: false
12
- },
13
- {
14
- skillRef: '_skill-ref-2',
15
- slidesToReview: 2,
16
- name: 'skill-test-2',
17
- custom: true
18
- }
19
- ]);
8
+ const getSlideFixture = (ref: string): SlideFromAPI => {
9
+ switch (ref) {
10
+ case qcmSlide.universalRef:
11
+ return qcmSlide;
12
+ case qcmGraphicSlide.universalRef:
13
+ return qcmGraphicSlide;
14
+ case freeTextSlide.universalRef:
15
+ return freeTextSlide;
16
+ case templateSlide.universalRef:
17
+ return templateSlide;
18
+ default:
19
+ return sliderSlide;
20
+ }
21
+ };
22
+
23
+ const fetchSkillsResponse = [
24
+ {
25
+ skillRef: '_skill-ref',
26
+ slidesToReview: 2,
27
+ name: 'skill-test',
28
+ custom: false
20
29
  },
21
- fetchSlide: ref => {
22
- return Promise.resolve({...freeTextSlide, universalRef: ref, id: ref});
30
+ {
31
+ skillRef: '_skill-ref-2',
32
+ slidesToReview: 2,
33
+ name: 'skill-test-2',
34
+ custom: true
35
+ }
36
+ ];
37
+
38
+ export const postProgressionResponse: ProgressionFromAPI = {
39
+ _id: '62b1d1087aa12f00253f40ee',
40
+ content: {
41
+ ref: '_skill-ref',
42
+ type: 'skill'
23
43
  },
24
- postProgression: () => {
25
- return Promise.resolve({
26
- _id: '62b1d1087aa12f00253f40ee',
27
- content: {
28
- ref: '_skill-ref',
29
- type: 'skill'
30
- },
31
- engine: {
32
- ref: 'review'
33
- },
34
- state: {
35
- allAnswers: [],
36
- isCorrect: true,
37
- nextContent: {
38
- ref: 'sli_N1XACJobn',
39
- type: 'slide'
40
- },
41
- pendingSlides: [],
42
- slides: [],
43
- step: {
44
- current: 1
45
- },
46
- stars: 0
47
- }
48
- });
44
+ engine: {
45
+ ref: 'review'
46
+ },
47
+ state: {
48
+ allAnswers: [],
49
+ isCorrect: true,
50
+ nextContent: {
51
+ ref: 'sli_VJYjJnJhg',
52
+ type: 'slide'
53
+ },
54
+ pendingSlides: [],
55
+ slides: [],
56
+ step: {
57
+ current: 1
58
+ },
59
+ stars: 0
60
+ }
61
+ };
62
+
63
+ export const postAnswerResponse: ProgressionFromAPI = {
64
+ _id: '62b1d1087aa12f00253f40ee',
65
+ content: {
66
+ ref: '_skill-ref',
67
+ type: 'skill'
49
68
  },
50
- postAnswer: () => {
51
- return Promise.resolve({
52
- _id: '62b1d1087aa12f00253f40ee',
53
- content: {
54
- ref: '_skill-ref',
55
- type: 'skill'
56
- },
57
- engine: {
58
- ref: 'review'
59
- },
60
- state: {
61
- allAnswers: [
62
- {
63
- slideRef: 'sli_N1XACJobn',
64
- isCorrect: true,
65
- answer: ['Le créateur peut fixer un pourcentage pour chaque transaction future']
66
- }
67
- ],
69
+ engine: {
70
+ ref: 'review'
71
+ },
72
+ state: {
73
+ allAnswers: [
74
+ {
75
+ slideRef: 'sli_VJYjJnJhg',
68
76
  isCorrect: true,
69
- nextContent: {
70
- ref: 'sli_VkSQroQnx',
71
- type: 'slide'
72
- },
73
- pendingSlides: [],
74
- slides: ['sli_N1XACJobn'],
75
- step: {
76
- current: 2
77
- },
78
- stars: 4
77
+ answer: ['Benchmark']
79
78
  }
80
- });
79
+ ],
80
+ isCorrect: true,
81
+ nextContent: {
82
+ ref: 'sli_VkSQroQnx',
83
+ type: 'slide'
84
+ },
85
+ content: {
86
+ ref: 'sli_VJYjJnJhg',
87
+ type: 'slide'
88
+ },
89
+ pendingSlides: [],
90
+ slides: ['sli_VJYjJnJhg'],
91
+ step: {
92
+ current: 2
93
+ },
94
+ stars: 4
81
95
  }
82
96
  };
97
+
98
+ export const services: Services = {
99
+ fetchSkills: () => Promise.resolve(fetchSkillsResponse),
100
+ fetchSlide: ref => Promise.resolve({...getSlideFixture(ref), universalRef: ref, id: ref}),
101
+ postProgression: () => Promise.resolve(postProgressionResponse),
102
+ postAnswer: () => Promise.resolve(postAnswerResponse)
103
+ };
@@ -1,6 +1,3 @@
1
- import {SlideIndexes} from '../common';
2
- import {AnswerUI} from './slides';
3
-
4
1
  // TODO use type from components
5
2
  type TemplateContextValues = {
6
3
  brandTheme?: unknown;
@@ -172,33 +169,6 @@ export type JWT = {
172
169
  host: string;
173
170
  };
174
171
 
175
- type SlideUIAnimations = 'unstack' | 'restack';
176
-
177
- export type NextUISlide = {
178
- questionText?: string;
179
- answerUI?: AnswerUI;
180
- hidden?: boolean;
181
- position?: number;
182
- animationType?: SlideUIAnimations;
183
- isCorrect?: boolean;
184
- endReview?: boolean;
185
- };
186
-
187
- export type UISlide = {
188
- questionText?: string;
189
- answerUI?: AnswerUI;
190
- hidden?: boolean;
191
- position: number;
192
- animationType?: SlideUIAnimations;
193
- isCorrect?: boolean;
194
- endReview?: boolean;
195
- nextContent?: NextUISlide;
196
- };
197
-
198
- export type FinishedSlides = {
199
- [key in SlideIndexes]?: true;
200
- };
201
-
202
172
  export type WithRequired<T, K extends keyof T> = T & {
203
173
  // the "-" is a Mapping Modifier, removes optionality from a prop
204
174
  [P in K]-?: T[P];
@@ -28,11 +28,7 @@ type SkillsProps = NoSkillsProps & {
28
28
 
29
29
  export {SkillsProps};
30
30
 
31
- export const mapStateToSkillsProps = (state: StoreState): SkillsProps | null => {
32
- if (!state.data.skills) {
33
- return null;
34
- }
35
-
31
+ export const mapStateToSkillsProps = (state: StoreState): SkillsProps => {
36
32
  return {
37
33
  title: '@todo title',
38
34
  titleNoSkills: '@todo titleNoSkills',
@@ -0,0 +1,101 @@
1
+ import test from 'ava';
2
+ import map from 'lodash/fp/map';
3
+ import omit from 'lodash/fp/omit';
4
+ import {StoreState} from '../../../reducers';
5
+ import {mapStateToSkillsProps} from '..';
6
+
7
+ test('should create initial props when there are no skills on the state', t => {
8
+ const state: StoreState = {
9
+ data: {
10
+ progression: null,
11
+ skills: [],
12
+ slides: {},
13
+ token: '1234'
14
+ },
15
+ ui: {
16
+ currentSlideRef: '',
17
+ navigation: ['loader', 'skills'],
18
+ answers: [],
19
+ slide: {
20
+ validateButton: false
21
+ }
22
+ }
23
+ };
24
+
25
+ const props = mapStateToSkillsProps(state);
26
+
27
+ t.deepEqual(props, {
28
+ title: '@todo title',
29
+ titleNoSkills: '@todo titleNoSkills',
30
+ textNoSkills: '@todo textNoSkills',
31
+ iconSkillAriaLabel: '@todo iconSkillAriaLabel',
32
+ isLoading: false,
33
+ isLoadingAriaLabel: '@todo loading',
34
+ listSkills: []
35
+ });
36
+ });
37
+
38
+ test('should create initial props when skills on the state', t => {
39
+ const state: StoreState = {
40
+ data: {
41
+ progression: null,
42
+ skills: [
43
+ {
44
+ skillRef: '_skill-ref',
45
+ slidesToReview: 2,
46
+ name: 'skill-test',
47
+ custom: false
48
+ },
49
+ {
50
+ skillRef: '_skill-ref-2',
51
+ slidesToReview: 5,
52
+ name: 'skill-test-2',
53
+ custom: true
54
+ }
55
+ ],
56
+ slides: {},
57
+ token: '1234'
58
+ },
59
+ ui: {
60
+ currentSlideRef: '',
61
+ navigation: ['loader', 'skills'],
62
+ answers: [],
63
+ slide: {
64
+ validateButton: false
65
+ }
66
+ }
67
+ };
68
+
69
+ const props = mapStateToSkillsProps(state);
70
+
71
+ t.deepEqual(omit('listSkills', props), {
72
+ title: '@todo title',
73
+ titleNoSkills: '@todo titleNoSkills',
74
+ textNoSkills: '@todo textNoSkills',
75
+ iconSkillAriaLabel: '@todo iconSkillAriaLabel',
76
+ isLoading: false,
77
+ isLoadingAriaLabel: '@todo loading'
78
+ });
79
+ t.deepEqual(map(omit('onClick'), props.listSkills), [
80
+ {
81
+ 'aria-label': '',
82
+ isCustom: false,
83
+ skillTitle: 'skill-test',
84
+ skillAriaLabel: '@todo skill aria label',
85
+ buttonLabel: '@todo button',
86
+ buttonAriaLabel: '@todo button aria label',
87
+ reviseLabel: '@todo revise',
88
+ reviseAriaLabel: '@todo revise aria label'
89
+ },
90
+ {
91
+ 'aria-label': '',
92
+ isCustom: true,
93
+ skillTitle: 'skill-test-2',
94
+ skillAriaLabel: '@todo skill aria label',
95
+ buttonLabel: '@todo button',
96
+ buttonAriaLabel: '@todo button aria label',
97
+ reviseLabel: '@todo revise',
98
+ reviseAriaLabel: '@todo revise aria label'
99
+ }
100
+ ]);
101
+ });