@coorpacademy/app-review 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/es/actions/api/fetch-skills.d.ts +3 -3
  2. package/es/actions/api/fetch-skills.js +7 -2
  3. package/es/actions/api/fetch-slide.d.ts +1 -1
  4. package/es/actions/api/fetch-slide.js +3 -1
  5. package/es/actions/api/post-answer.d.ts +10 -0
  6. package/es/actions/api/post-answer.js +25 -0
  7. package/es/actions/api/post-progression.d.ts +3 -3
  8. package/es/actions/api/post-progression.js +5 -2
  9. package/es/actions/api/test/fetch-skills.test.js +7 -4
  10. package/es/actions/api/test/fetch-slide.test.js +7 -4
  11. package/es/actions/api/test/post-answer.test.d.ts +1 -0
  12. package/es/actions/api/test/post-answer.test.js +82 -0
  13. package/es/actions/api/test/post-progression.test.js +7 -4
  14. package/es/actions/data/test/token.test.d.ts +1 -0
  15. package/es/actions/data/test/token.test.js +25 -0
  16. package/es/actions/index.d.ts +1 -8
  17. package/es/actions/{api/test → test}/create-test-store.d.ts +2 -2
  18. package/es/actions/{api/test → test}/create-test-store.js +1 -1
  19. package/es/actions/ui/answers.d.ts +17 -3
  20. package/es/actions/ui/answers.js +39 -3
  21. package/es/actions/ui/slides.d.ts +0 -5
  22. package/es/actions/ui/slides.js +0 -4
  23. package/es/actions/ui/test/answers.test.d.ts +1 -0
  24. package/es/actions/ui/test/answers.test.js +90 -0
  25. package/es/actions/ui/test/slides.test.d.ts +1 -0
  26. package/es/actions/ui/test/slides.test.js +26 -0
  27. package/es/common/index.d.ts +0 -3
  28. package/es/common/index.js +0 -4
  29. package/es/index.js +1 -3
  30. package/es/reducers/data/index.d.ts +1 -1
  31. package/es/reducers/data/progression.d.ts +2 -3
  32. package/es/reducers/data/progression.js +0 -5
  33. package/es/reducers/data/slides.d.ts +2 -3
  34. package/es/reducers/data/test/progression.test.js +1 -1
  35. package/es/reducers/index.d.ts +2 -1
  36. package/es/reducers/ui/answers.d.ts +2 -2
  37. package/es/reducers/ui/answers.js +4 -8
  38. package/es/reducers/ui/index.d.ts +4 -1
  39. package/es/reducers/ui/index.js +3 -1
  40. package/es/reducers/ui/slide.d.ts +8 -0
  41. package/es/reducers/ui/slide.js +26 -0
  42. package/es/reducers/ui/test/answers.test.js +19 -3
  43. package/es/reducers/ui/test/current-slide-ref.test.js +1 -1
  44. package/es/reducers/ui/test/navigation.test.js +5 -5
  45. package/es/reducers/ui/test/slide.test.d.ts +1 -0
  46. package/es/reducers/ui/test/slide.test.js +12 -0
  47. package/es/test/util/services.mock.d.ts +2 -1
  48. package/es/test/util/services.mock.js +86 -72
  49. package/es/types/common.d.ts +0 -25
  50. package/es/views/skills/index.d.ts +1 -1
  51. package/es/views/skills/index.js +0 -3
  52. package/es/views/skills/test/skills.test.d.ts +1 -0
  53. package/es/views/skills/test/skills.test.js +94 -0
  54. package/es/views/slides/index.d.ts +13 -2
  55. package/es/views/slides/index.js +18 -14
  56. package/es/views/slides/map-api-slide-to-ui.js +44 -51
  57. package/es/views/slides/test/fixtures/free-text.d.ts +2 -1
  58. package/es/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  59. package/es/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  60. package/es/views/slides/test/fixtures/qcm.d.ts +2 -1
  61. package/es/views/slides/test/fixtures/select-template.d.ts +2 -1
  62. package/es/views/slides/test/fixtures/slider.d.ts +2 -1
  63. package/es/views/slides/test/fixtures/text-template.d.ts +2 -1
  64. package/es/views/slides/test/index.test.d.ts +1 -0
  65. package/es/views/slides/test/index.test.js +234 -0
  66. package/lib/actions/api/fetch-skills.d.ts +3 -3
  67. package/lib/actions/api/fetch-skills.js +22 -19
  68. package/lib/actions/api/fetch-slide.d.ts +1 -1
  69. package/lib/actions/api/fetch-slide.js +3 -1
  70. package/lib/actions/api/post-answer.d.ts +10 -0
  71. package/lib/actions/api/post-answer.js +75 -0
  72. package/lib/actions/api/post-progression.d.ts +3 -3
  73. package/lib/actions/api/post-progression.js +6 -3
  74. package/lib/actions/api/test/fetch-skills.test.js +7 -4
  75. package/lib/actions/api/test/fetch-slide.test.js +7 -4
  76. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  77. package/lib/actions/api/test/post-answer.test.js +145 -0
  78. package/lib/actions/api/test/post-progression.test.js +7 -4
  79. package/lib/actions/data/test/token.test.d.ts +1 -0
  80. package/lib/actions/data/test/token.test.js +70 -0
  81. package/lib/actions/index.d.ts +1 -8
  82. package/lib/actions/{api/test → test}/create-test-store.d.ts +2 -2
  83. package/lib/actions/{api/test → test}/create-test-store.js +1 -1
  84. package/lib/actions/ui/answers.d.ts +17 -3
  85. package/lib/actions/ui/answers.js +48 -3
  86. package/lib/actions/ui/slides.d.ts +0 -5
  87. package/lib/actions/ui/slides.js +0 -4
  88. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  89. package/lib/actions/ui/test/answers.test.js +171 -0
  90. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  91. package/lib/actions/ui/test/slides.test.js +71 -0
  92. package/lib/common/index.d.ts +0 -3
  93. package/lib/common/index.js +0 -4
  94. package/lib/index.js +1 -3
  95. package/lib/reducers/data/index.d.ts +1 -1
  96. package/lib/reducers/data/progression.d.ts +2 -3
  97. package/lib/reducers/data/progression.js +0 -5
  98. package/lib/reducers/data/slides.d.ts +2 -3
  99. package/lib/reducers/data/test/progression.test.js +1 -1
  100. package/lib/reducers/index.d.ts +2 -1
  101. package/lib/reducers/ui/answers.d.ts +2 -2
  102. package/lib/reducers/ui/answers.js +4 -8
  103. package/lib/reducers/ui/index.d.ts +4 -1
  104. package/lib/reducers/ui/index.js +3 -1
  105. package/lib/reducers/ui/slide.d.ts +8 -0
  106. package/lib/reducers/ui/slide.js +27 -0
  107. package/lib/reducers/ui/test/answers.test.js +19 -3
  108. package/lib/reducers/ui/test/current-slide-ref.test.js +1 -1
  109. package/lib/reducers/ui/test/navigation.test.js +5 -5
  110. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  111. package/lib/reducers/ui/test/slide.test.js +12 -0
  112. package/lib/test/util/services.mock.d.ts +2 -1
  113. package/lib/test/util/services.mock.js +86 -72
  114. package/lib/types/common.d.ts +0 -25
  115. package/lib/views/skills/index.d.ts +1 -1
  116. package/lib/views/skills/index.js +0 -3
  117. package/lib/views/skills/test/skills.test.d.ts +1 -0
  118. package/lib/views/skills/test/skills.test.js +94 -0
  119. package/lib/views/slides/index.d.ts +13 -2
  120. package/lib/views/slides/index.js +18 -14
  121. package/lib/views/slides/map-api-slide-to-ui.js +77 -76
  122. package/lib/views/slides/test/fixtures/free-text.d.ts +2 -1
  123. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  124. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  125. package/lib/views/slides/test/fixtures/qcm.d.ts +2 -1
  126. package/lib/views/slides/test/fixtures/select-template.d.ts +2 -1
  127. package/lib/views/slides/test/fixtures/slider.d.ts +2 -1
  128. package/lib/views/slides/test/fixtures/text-template.d.ts +2 -1
  129. package/lib/views/slides/test/index.test.d.ts +1 -0
  130. package/lib/views/slides/test/index.test.js +234 -0
  131. package/package.json +6 -5
  132. package/src/actions/api/fetch-skills.ts +18 -11
  133. package/src/actions/api/fetch-slide.ts +3 -1
  134. package/src/actions/api/post-answer.ts +39 -0
  135. package/src/actions/api/post-progression.ts +7 -4
  136. package/src/actions/api/test/fetch-skills.test.ts +9 -6
  137. package/src/actions/api/test/fetch-slide.test.ts +9 -6
  138. package/src/actions/api/test/post-answer.test.ts +101 -0
  139. package/src/actions/api/test/post-progression.test.ts +9 -6
  140. package/src/actions/data/test/token.test.ts +29 -0
  141. package/src/actions/index.ts +1 -17
  142. package/src/actions/{api/test → test}/create-test-store.ts +2 -2
  143. package/src/actions/ui/answers.ts +52 -5
  144. package/src/actions/ui/slides.ts +1 -8
  145. package/src/actions/ui/test/answers.test.ts +103 -0
  146. package/src/actions/ui/test/slides.test.ts +30 -0
  147. package/src/common/index.ts +0 -7
  148. package/src/index.tsx +1 -3
  149. package/src/reducers/data/progression.ts +2 -7
  150. package/src/reducers/data/slides.ts +2 -3
  151. package/src/reducers/data/test/progression.test.ts +3 -3
  152. package/src/reducers/ui/answers.ts +5 -9
  153. package/src/reducers/ui/index.ts +4 -1
  154. package/src/reducers/ui/slide.ts +43 -0
  155. package/src/reducers/ui/test/answers.test.ts +24 -4
  156. package/src/reducers/ui/test/current-slide-ref.test.ts +1 -1
  157. package/src/reducers/ui/test/navigation.test.ts +5 -5
  158. package/src/reducers/ui/test/slide.test.ts +15 -0
  159. package/src/test/util/services.mock.ts +91 -73
  160. package/src/types/common.ts +0 -30
  161. package/src/views/skills/index.ts +1 -5
  162. package/src/views/skills/test/skills.test.ts +101 -0
  163. package/src/views/slides/index.ts +37 -22
  164. package/src/views/slides/map-api-slide-to-ui.ts +89 -89
  165. package/src/views/slides/test/fixtures/free-text.ts +2 -1
  166. package/src/views/slides/test/fixtures/qcm-drag.ts +2 -1
  167. package/src/views/slides/test/fixtures/qcm-graphic.ts +2 -1
  168. package/src/views/slides/test/fixtures/qcm.ts +2 -1
  169. package/src/views/slides/test/fixtures/select-template.ts +2 -1
  170. package/src/views/slides/test/fixtures/slider.ts +2 -1
  171. package/src/views/slides/test/fixtures/text-template.ts +2 -1
  172. package/src/views/slides/test/index.test.ts +240 -0
  173. package/src/views/slides/test/map-api-slide-to-ui.test.ts +2 -1
  174. package/es/fixtures/qcm-slide.d.ts +0 -2
  175. package/es/fixtures/qcm-slide.js +0 -33
  176. package/es/fixtures/temp-fixture.d.ts +0 -3
  177. package/es/fixtures/temp-fixture.js +0 -84
  178. package/lib/fixtures/qcm-slide.d.ts +0 -2
  179. package/lib/fixtures/qcm-slide.js +0 -33
  180. package/lib/fixtures/temp-fixture.d.ts +0 -3
  181. package/lib/fixtures/temp-fixture.js +0 -84
  182. package/src/fixtures/qcm-slide.ts +0 -35
  183. package/src/fixtures/temp-fixture.ts +0 -94
@@ -0,0 +1,29 @@
1
+ import test from 'ava';
2
+ import {createTestStore} from '../../test/create-test-store';
3
+ import {services} from '../../../test/util/services.mock';
4
+ import {StoreState} from '../../../reducers';
5
+ import {storeToken, STORE_TOKEN} from '../token';
6
+
7
+ const initialState: StoreState = {
8
+ data: {
9
+ progression: null,
10
+ slides: {},
11
+ skills: [],
12
+ token: '1234'
13
+ },
14
+ ui: {
15
+ currentSlideRef: '',
16
+ navigation: [],
17
+ answers: [],
18
+ slide: {
19
+ validateButton: false
20
+ }
21
+ }
22
+ };
23
+
24
+ test('should dispatch STORE_TOKEN action when storeToken is called', async t => {
25
+ const expectedActions = [{type: STORE_TOKEN, payload: 'JWT.token'}];
26
+
27
+ const {dispatch} = createTestStore(t, initialState, services, expectedActions);
28
+ await dispatch(storeToken('JWT.token'));
29
+ });
@@ -1,22 +1,6 @@
1
- import {StoreToken} from './data/token';
2
-
3
- import {navigateBack, navigateTo, NavigateBack, NavigateTo, StartApp} from './ui/navigation';
4
- import {ReceivedSlide} from './api/fetch-slide';
5
- import {ReceiveProgression} from './api/post-progression';
6
- import {ReceivedSkills} from './api/fetch-skills';
7
- import {validateSlide} from './ui/slides';
8
-
9
- export type Action =
10
- | NavigateBack
11
- | NavigateTo
12
- | ReceivedSkills
13
- | StartApp
14
- | ReceivedSlide
15
- | StoreToken
16
- | ReceiveProgression;
1
+ import {navigateBack, navigateTo} from './ui/navigation';
17
2
 
18
3
  export type Dispatchers = {
19
4
  navigateTo: typeof navigateTo;
20
5
  navigateBack: typeof navigateBack;
21
- validateSlide: typeof validateSlide;
22
6
  };
@@ -2,8 +2,8 @@ import type {ExecutionContext} from 'ava';
2
2
  import constant from 'lodash/fp/constant';
3
3
  import {AnyAction, applyMiddleware, compose, createStore, Dispatch, Middleware, Store} from 'redux';
4
4
  import thunk from 'redux-thunk';
5
- import rootReducer, {StoreState} from '../../../reducers';
6
- import {Services} from '../../../types/common';
5
+ import rootReducer, {StoreState} from '../../reducers';
6
+ import {Services} from '../../types/common';
7
7
 
8
8
  const assertActionsMiddleware = (t: ExecutionContext, ACTIONS: AnyAction[]): Middleware =>
9
9
  constant((next: Dispatch) => (action: AnyAction): unknown => {
@@ -1,16 +1,63 @@
1
1
  import {Dispatch} from 'redux';
2
+ import {flatten, get, includes, pull} from 'lodash/fp';
3
+ import type {StoreState} from '../../reducers';
2
4
 
5
+ export const EDIT_QCM = '@@answer/EDIT_QCM' as const;
6
+ export const EDIT_QCM_GRAPHIC = '@@answer/EDIT_QCM_GRAPHIC' as const;
7
+ export const EDIT_QCM_DRAG = '@@answer/EDIT_QCM_DRAG' as const;
8
+ export const EDIT_TEMPLATE = '@@answer/EDIT_TEMPLATE' as const;
3
9
  export const EDIT_BASIC = '@@answer/EDIT_BASIC' as const;
4
- export type EditBasicAction = {
5
- type: typeof EDIT_BASIC;
10
+ export const EDIT_SLIDER = '@@answer/EDIT_SLIDER' as const;
11
+
12
+ export const ANSWER_EDIT = {
13
+ qcm: EDIT_QCM,
14
+ qcmGraphic: EDIT_QCM_GRAPHIC,
15
+ qcmDrag: EDIT_QCM_DRAG,
16
+ template: EDIT_TEMPLATE,
17
+ basic: EDIT_BASIC,
18
+ slider: EDIT_SLIDER
19
+ } as const;
20
+
21
+ export type EditAnswerAction = {
22
+ type:
23
+ | typeof EDIT_QCM
24
+ | typeof EDIT_QCM_GRAPHIC
25
+ | typeof EDIT_QCM_DRAG
26
+ | typeof EDIT_TEMPLATE
27
+ | typeof EDIT_BASIC
28
+ | typeof EDIT_SLIDER;
6
29
  payload: string[];
7
30
  };
8
31
 
32
+ const buildAnswer = (userAnswers: string[], questionType: string, newValue: string): string[] => {
33
+ switch (questionType) {
34
+ case 'qcm':
35
+ case 'qcmGraphic':
36
+ case 'qcmDrag': {
37
+ return includes(newValue, userAnswers)
38
+ ? pull(newValue, userAnswers)
39
+ : flatten([...userAnswers, newValue]);
40
+ }
41
+ case 'basic':
42
+ case 'slider':
43
+ return [newValue];
44
+ default:
45
+ return [];
46
+ }
47
+ };
48
+
9
49
  export const editAnswer =
10
50
  (answer: string) =>
11
- (dispatch: Dispatch): EditBasicAction => {
51
+ (dispatch: Dispatch, getState: () => StoreState): EditAnswerAction => {
52
+ const state = getState();
53
+ const currentSlideRef = get(['ui', 'currentSlideRef'])(state);
54
+ const userAnswers = get(['ui', 'answers'])(state);
55
+ const slide = get(['data', 'slides', currentSlideRef])(state);
56
+ const questionType = get(['question', 'type'])(slide);
57
+ const type = get(questionType, ANSWER_EDIT);
58
+
12
59
  return dispatch({
13
- type: EDIT_BASIC,
14
- payload: [answer]
60
+ type,
61
+ payload: buildAnswer(userAnswers, questionType, answer)
15
62
  });
16
63
  };
@@ -15,6 +15,7 @@ export type Slide = {
15
15
  };
16
16
 
17
17
  export const SET_CURRENT_SLIDE = '@@slide/SET_CURRENT_SLIDE' as const;
18
+
18
19
  export type SetCurrentSlide = {
19
20
  type: typeof SET_CURRENT_SLIDE;
20
21
  payload: SlideFromAPI;
@@ -24,12 +25,4 @@ export const setCurrentSlide = (payload: SlideFromAPI): SetCurrentSlide => ({
24
25
  payload
25
26
  });
26
27
 
27
- export const VALIDATE_SLIDE = '@@slide/VALIDATE';
28
- export type ValidateSlide = {
29
- type: typeof VALIDATE_SLIDE;
30
- };
31
- export const validateSlide = (): ValidateSlide => ({
32
- type: VALIDATE_SLIDE
33
- });
34
-
35
28
  export type UISlidesAction = SetCurrentSlide;
@@ -0,0 +1,103 @@
1
+ import test from 'ava';
2
+ import pipe from 'lodash/fp/pipe';
3
+ import set from 'lodash/fp/set';
4
+ import {SlideFromAPI} from '../../../types/common';
5
+ import {createTestStore} from '../../test/create-test-store';
6
+ import {services} from '../../../test/util/services.mock';
7
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
8
+ import {qcmDragSlide} from '../../../views/slides/test/fixtures/qcm-drag';
9
+ import {qcmSlide} from '../../../views/slides/test/fixtures/qcm';
10
+ import {qcmGraphicSlide} from '../../../views/slides/test/fixtures/qcm-graphic';
11
+ import {sliderSlide} from '../../../views/slides/test/fixtures/slider';
12
+ import {StoreState} from '../../../reducers';
13
+ import {editAnswer, ANSWER_EDIT} from '../answers';
14
+
15
+ const initialState: StoreState = {
16
+ data: {
17
+ progression: {
18
+ _id: '62b1d1087aa12f00253f40ee',
19
+ content: {
20
+ ref: '_skill-ref',
21
+ type: 'skill'
22
+ },
23
+ engine: {
24
+ ref: 'review'
25
+ },
26
+ state: {
27
+ allAnswers: [],
28
+ isCorrect: true,
29
+ nextContent: {
30
+ ref: '',
31
+ type: 'slide'
32
+ },
33
+ pendingSlides: [],
34
+ slides: [],
35
+ step: {
36
+ current: 1
37
+ },
38
+ stars: 0
39
+ }
40
+ },
41
+ slides: {},
42
+ skills: [],
43
+ token: '1234'
44
+ },
45
+ ui: {
46
+ currentSlideRef: '',
47
+ navigation: [],
48
+ answers: [],
49
+ slide: {
50
+ validateButton: false
51
+ }
52
+ }
53
+ };
54
+
55
+ const buildInitialState = (state: StoreState, question: SlideFromAPI): StoreState => {
56
+ return pipe(
57
+ set(['data', 'progression', 'state', 'nextContent', 'ref'], question.id),
58
+ set(['data', 'slides', question.id], question),
59
+ set(['ui', 'currentSlideRef'], question.id)
60
+ )(state);
61
+ };
62
+
63
+ test('should dispatch EDIT_BASIC action when editAnswer is called', async t => {
64
+ const state = buildInitialState(initialState, freeTextSlide);
65
+ const expectedActions = [{type: ANSWER_EDIT.basic, payload: ['My Answer']}];
66
+ const {dispatch} = createTestStore(t, state, services, expectedActions);
67
+ await dispatch(editAnswer('My Answer'));
68
+ });
69
+
70
+ test('should dispatch EDIT_QCM action when editAnswer is called', async t => {
71
+ let state = buildInitialState(initialState, qcmSlide);
72
+ state = set(['ui', 'answers'], ['My First Answer', 'My Second Answer'], state);
73
+ const expectedActions = [{type: ANSWER_EDIT.qcm, payload: ['My First Answer']}];
74
+ const {dispatch} = createTestStore(t, state, services, expectedActions);
75
+ await dispatch(editAnswer('My Second Answer'));
76
+ });
77
+
78
+ test('should dispatch EDIT_QCM_GRAPHIC action when editAnswer is called', async t => {
79
+ let state = buildInitialState(initialState, qcmGraphicSlide);
80
+ state = set(['ui', 'answers'], ['My First Answer', 'My Second Answer', 'My Third Answer'], state);
81
+ const expectedActions = [
82
+ {type: ANSWER_EDIT.qcmGraphic, payload: ['My First Answer', 'My Third Answer']}
83
+ ];
84
+ const {dispatch} = createTestStore(t, state, services, expectedActions);
85
+ await dispatch(editAnswer('My Second Answer'));
86
+ });
87
+
88
+ test('should dispatch EDIT_QCM_DRAG action when editAnswer is called', async t => {
89
+ let state = buildInitialState(initialState, qcmDragSlide);
90
+ state = set(['ui', 'answers'], ['My First Answer', 'My Second Answer'], state);
91
+ const expectedActions = [
92
+ {type: ANSWER_EDIT.qcmDrag, payload: ['My First Answer', 'My Second Answer', 'My Third Answer']}
93
+ ];
94
+ const {dispatch} = createTestStore(t, state, services, expectedActions);
95
+ await dispatch(editAnswer('My Third Answer'));
96
+ });
97
+
98
+ test('should dispatch EDIT_SLIDER action when editAnswer is called', async t => {
99
+ const state = buildInitialState(initialState, sliderSlide);
100
+ const expectedActions = [{type: ANSWER_EDIT.slider, payload: ['5']}];
101
+ const {dispatch} = createTestStore(t, state, services, expectedActions);
102
+ await dispatch(editAnswer('5'));
103
+ });
@@ -0,0 +1,30 @@
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 {StoreState} from '../../../reducers';
6
+ import {setCurrentSlide, SET_CURRENT_SLIDE} from '../slides';
7
+
8
+ const initialState: StoreState = {
9
+ data: {
10
+ progression: null,
11
+ slides: {},
12
+ skills: [],
13
+ token: '1234'
14
+ },
15
+ ui: {
16
+ currentSlideRef: '',
17
+ navigation: [],
18
+ answers: [],
19
+ slide: {
20
+ validateButton: false
21
+ }
22
+ }
23
+ };
24
+
25
+ test('should dispatch SET_CURRENT_SLIDE action when setCurrentSlide is called', async t => {
26
+ const expectedActions = [{type: SET_CURRENT_SLIDE, payload: freeTextSlide}];
27
+
28
+ const {dispatch} = createTestStore(t, initialState, services, expectedActions);
29
+ await dispatch(setCurrentSlide(freeTextSlide));
30
+ });
@@ -1,8 +1,3 @@
1
- import _toString from 'lodash/fp/toString';
2
-
3
- export const TOTAL_SLIDES_STACK = 5;
4
- export const HIGHEST_INDEX = TOTAL_SLIDES_STACK - 1;
5
-
6
1
  export const VIEWS: {
7
2
  readonly skills: 'skills';
8
3
  readonly onboarding: 'onboarding';
@@ -16,5 +11,3 @@ export const VIEWS: {
16
11
  export const slideIndexes = ['0', '1', '2', '3', '4'] as const;
17
12
 
18
13
  export type SlideIndexes = typeof slideIndexes[number];
19
-
20
- export const indexToString = (index: number): SlideIndexes => _toString(index) as SlideIndexes;
package/src/index.tsx CHANGED
@@ -68,9 +68,7 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
68
68
 
69
69
  /* ThunkAction is not assignable to parameter of type 'AnyAction'
70
70
  ts problem is described here = https://github.com/reduxjs/redux-thunk/issues/333 */
71
- skillRef
72
- ? store.dispatch(postProgression(skillRef, token))
73
- : store.dispatch(fetchSkills(token));
71
+ skillRef ? store.dispatch(postProgression(skillRef)) : store.dispatch(fetchSkills);
74
72
  }, [options, store]);
75
73
 
76
74
  useEffect(() => {
@@ -1,5 +1,4 @@
1
- import {ValidateSlide, VALIDATE_SLIDE} from '../../actions/ui/slides';
2
- import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../actions/api/post-progression';
1
+ import {POST_PROGRESSION_SUCCESS, ReceivedProgression} from '../../actions/api/post-progression';
3
2
  import {ProgressionFromAPI} from '../../types/common';
4
3
 
5
4
  export type ProgressionState = ProgressionFromAPI | null;
@@ -7,13 +6,9 @@ export type ProgressionState = ProgressionFromAPI | null;
7
6
  const reducer = (
8
7
  // eslint-disable-next-line default-param-last
9
8
  state: ProgressionState = null,
10
- action: ValidateSlide | ReceiveProgression
9
+ action: ReceivedProgression
11
10
  ): ProgressionState => {
12
11
  switch (action.type) {
13
- case VALIDATE_SLIDE: {
14
- // TODO: fix on VALIDATE ticket -> launch a POST PROGRESSION
15
- return state;
16
- }
17
12
  case POST_PROGRESSION_SUCCESS: {
18
13
  const progression = action.payload;
19
14
  return progression;
@@ -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,10 +1,10 @@
1
1
  import test from 'ava';
2
2
  import reducer from '../progression';
3
- import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../../actions/api/post-progression';
3
+ import {POST_PROGRESSION_SUCCESS, ReceivedProgression} from '../../../actions/api/post-progression';
4
4
  import {ProgressionFromAPI} from '../../../types/common';
5
5
 
6
- test('should have inital value', t => {
7
- const state = reducer(undefined, {} as ReceiveProgression);
6
+ test('should have initial value', t => {
7
+ const state = reducer(undefined, {} as ReceivedProgression);
8
8
  t.is(state, null);
9
9
  });
10
10
 
@@ -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,33 @@
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
+ });
@@ -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
+ });