@coorpacademy/app-review 0.2.10-alpha.5 → 0.2.10

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 (60) hide show
  1. package/es/actions/ui/next-slide.d.ts +14 -0
  2. package/es/actions/ui/next-slide.js +15 -0
  3. package/es/actions/ui/test/next-slide.test.d.ts +1 -0
  4. package/es/actions/ui/test/next-slide.test.js +63 -0
  5. package/es/index.js +3 -6
  6. package/es/test/index.test.js +1 -8
  7. package/es/types/common.d.ts +0 -9
  8. package/es/types/slides.d.ts +2 -1
  9. package/es/views/slides/index.d.ts +1 -1
  10. package/es/views/slides/index.js +3 -2
  11. package/es/views/slides/map-api-slide-to-ui.js +5 -0
  12. package/es/views/slides/test/fixtures/slider.js +2 -1
  13. package/es/views/slides/test/index.test.js +11 -11
  14. package/es/views/slides/test/slide.free-text.on-change.test.js +1 -2
  15. package/es/views/slides/test/slide.qcm-drag.on-click.test.js +1 -2
  16. package/es/views/slides/test/slide.qcm-graphic.on-click.test.js +1 -2
  17. package/es/views/slides/test/slide.qcm.on-click.test.js +1 -2
  18. package/es/views/slides/test/slide.slider.on-change.test.js +1 -2
  19. package/es/views/slides/test/slide.slider.on-slider-change.test.d.ts +1 -0
  20. package/es/views/slides/test/slide.slider.on-slider-change.test.js +63 -0
  21. package/es/views/slides/test/slide.template.on-change.test.js +2 -3
  22. package/lib/actions/ui/next-slide.d.ts +14 -0
  23. package/lib/actions/ui/next-slide.js +16 -0
  24. package/lib/actions/ui/test/next-slide.test.d.ts +1 -0
  25. package/lib/actions/ui/test/next-slide.test.js +64 -0
  26. package/lib/index.js +3 -7
  27. package/lib/test/index.test.js +1 -8
  28. package/lib/types/common.d.ts +0 -9
  29. package/lib/types/slides.d.ts +2 -1
  30. package/lib/views/slides/index.d.ts +1 -1
  31. package/lib/views/slides/index.js +3 -2
  32. package/lib/views/slides/map-api-slide-to-ui.js +5 -0
  33. package/lib/views/slides/test/fixtures/slider.js +2 -1
  34. package/lib/views/slides/test/index.test.js +11 -11
  35. package/lib/views/slides/test/slide.free-text.on-change.test.js +1 -2
  36. package/lib/views/slides/test/slide.qcm-drag.on-click.test.js +1 -2
  37. package/lib/views/slides/test/slide.qcm-graphic.on-click.test.js +1 -2
  38. package/lib/views/slides/test/slide.qcm.on-click.test.js +1 -2
  39. package/lib/views/slides/test/slide.slider.on-change.test.js +1 -2
  40. package/lib/views/slides/test/slide.slider.on-slider-change.test.d.ts +1 -0
  41. package/lib/views/slides/test/slide.slider.on-slider-change.test.js +65 -0
  42. package/lib/views/slides/test/slide.template.on-change.test.js +2 -3
  43. package/package.json +4 -4
  44. package/src/actions/ui/next-slide.ts +31 -0
  45. package/src/actions/ui/test/next-slide.test.ts +75 -0
  46. package/src/index.tsx +4 -7
  47. package/src/test/index.test.tsx +1 -8
  48. package/src/types/common.ts +0 -11
  49. package/src/types/slides.ts +2 -1
  50. package/src/views/slides/index.ts +3 -6
  51. package/src/views/slides/map-api-slide-to-ui.ts +5 -0
  52. package/src/views/slides/test/fixtures/slider.ts +2 -1
  53. package/src/views/slides/test/index.test.ts +11 -11
  54. package/src/views/slides/test/slide.free-text.on-change.test.ts +1 -2
  55. package/src/views/slides/test/slide.qcm-drag.on-click.test.ts +1 -2
  56. package/src/views/slides/test/slide.qcm-graphic.on-click.test.ts +1 -2
  57. package/src/views/slides/test/slide.qcm.on-click.test.ts +1 -2
  58. package/src/views/slides/test/slide.slider.on-change.test.ts +1 -2
  59. package/src/views/slides/test/slide.slider.on-slider-change.test.ts +71 -0
  60. package/src/views/slides/test/slide.template.on-change.test.ts +2 -3
@@ -132,15 +132,8 @@ var clickAllSlides = function (t, container, accumulator) {
132
132
  };
133
133
  var appOptions = {
134
134
  token: process.env.API_TEST_TOKEN || '',
135
- templateContext: {
136
- theme: { color: { primary: '#123' } }
137
- },
138
135
  skillRef: 'skill_NJC0jFKoH',
139
- services: services,
140
- onQuitClick: function () {
141
- // eslint-disable-next-line no-console
142
- console.log('onQuitClick - options');
143
- }
136
+ services: services
144
137
  };
145
138
  test('should show the loader while the app is fetching the data', function (t) { return __awaiter(void 0, void 0, void 0, function () {
146
139
  var container, loader;
@@ -1,8 +1,3 @@
1
- declare type TemplateContextValues = {
2
- brandTheme?: unknown;
3
- theme?: unknown;
4
- translations?: unknown;
5
- };
6
1
  export declare type ChoiceFromAPI = {
7
2
  _id: string;
8
3
  id?: string;
@@ -140,12 +135,8 @@ export declare type Options = {
140
135
  };
141
136
  export declare type AppOptions = {
142
137
  token: string;
143
- theme?: unknown;
144
- translations?: unknown;
145
- templateContext?: TemplateContextValues;
146
138
  skillRef?: string;
147
139
  services: Services;
148
- onQuitClick: Function;
149
140
  };
150
141
  export declare type JWT = {
151
142
  exp: number;
@@ -44,8 +44,9 @@ export declare type DropDown = {
44
44
  export declare type QuestionRange = {
45
45
  type: 'slider';
46
46
  placeholder?: string;
47
- onChange?: Function;
47
+ onChange?: (value: number) => void;
48
48
  onChangeEnd?: Function;
49
+ onSliderChange?: (value: number) => void;
49
50
  multi?: boolean;
50
51
  value: number | number[];
51
52
  title: string;
@@ -89,5 +89,5 @@ export declare type SlidesViewProps = {
89
89
  };
90
90
  export declare const initialState: SlidesStack;
91
91
  export declare const buildStepItems: (state: StoreState) => StepItem[];
92
- export declare const mapStateToSlidesProps: (state: StoreState, dispatch: Dispatch, onQuitClick: Function) => SlidesViewProps;
92
+ export declare const mapStateToSlidesProps: (state: StoreState, dispatch: Dispatch) => SlidesViewProps;
93
93
  export {};
@@ -167,7 +167,7 @@ var getCorrectionPopinProps = function (isCorrect, correctAnswer, klf) { return
167
167
  },
168
168
  type: isCorrect ? 'right' : 'wrong'
169
169
  }); };
170
- export var mapStateToSlidesProps = function (state, dispatch, onQuitClick) {
170
+ export var mapStateToSlidesProps = function (state, dispatch) {
171
171
  var currentSlideRef = get(['ui', 'currentSlideRef'], state);
172
172
  var correction = get(['data', 'corrections', currentSlideRef], state);
173
173
  var isCorrect = get(['data', 'progression', 'state', 'isCorrect'], state);
@@ -177,7 +177,8 @@ export var mapStateToSlidesProps = function (state, dispatch, onQuitClick) {
177
177
  mode: '__revision_mode',
178
178
  skillName: '__agility',
179
179
  onQuitClick: function () {
180
- onQuitClick();
180
+ // eslint-disable-next-line no-console
181
+ console.log('onQuitClick');
181
182
  },
182
183
  'aria-label': 'aria-header-wrapper',
183
184
  closeButtonAriaLabel: 'aria-close-button',
@@ -145,8 +145,13 @@ var sliderProps = function (dispatch) {
145
145
  title: "".concat(currentValue, " ").concat(question.content.unitLabel),
146
146
  value: sliderPosition,
147
147
  onChange: function (position) {
148
+ // atom/range handler
148
149
  var newValue = pipe(multiply(maxValue), round, get(__, values), _toString)(position);
149
150
  dispatch(editAnswer([newValue]));
151
+ },
152
+ onSliderChange: function (newValue) {
153
+ // mobile/slider handler
154
+ dispatch(editAnswer(["".concat(newValue)]));
150
155
  }
151
156
  };
152
157
  };
@@ -30,7 +30,8 @@ export var sliderUISlide = {
30
30
  maxLabel: '15 an(s)',
31
31
  title: '1 an(s)',
32
32
  value: 0,
33
- onChange: noop
33
+ onChange: noop,
34
+ onSliderChange: noop
34
35
  }
35
36
  }
36
37
  };
@@ -62,7 +62,7 @@ test('should create initial props when fetched slide is not still received', fun
62
62
  }
63
63
  }
64
64
  };
65
- var props = mapStateToSlidesProps(state, identity, identity);
65
+ var props = mapStateToSlidesProps(state, identity);
66
66
  t.is(props.congratsProps, undefined);
67
67
  t.deepEqual(omit(['onQuitClick'], props.header), {
68
68
  'aria-label': 'aria-header-wrapper',
@@ -151,7 +151,7 @@ test('should create props when first slide is on the state', function (t) {
151
151
  }
152
152
  }
153
153
  };
154
- var props = mapStateToSlidesProps(state, identity, identity);
154
+ var props = mapStateToSlidesProps(state, identity);
155
155
  t.is(props.congratsProps, undefined);
156
156
  t.deepEqual(omit(['onQuitClick'], props.header), {
157
157
  'aria-label': 'aria-header-wrapper',
@@ -253,7 +253,7 @@ test('should create props when slide is on the state and user has selected answe
253
253
  }
254
254
  }
255
255
  };
256
- var props = mapStateToSlidesProps(state, identity, identity);
256
+ var props = mapStateToSlidesProps(state, identity);
257
257
  t.is(props.congratsProps, undefined);
258
258
  t.deepEqual(omit(['onQuitClick'], props.header), {
259
259
  'aria-label': 'aria-header-wrapper',
@@ -356,7 +356,7 @@ test('should verify props when first slide was answered correctly and next slide
356
356
  }
357
357
  }
358
358
  };
359
- var props = mapStateToSlidesProps(state, identity, identity);
359
+ var props = mapStateToSlidesProps(state, identity);
360
360
  t.is(props.congratsProps, undefined);
361
361
  t.deepEqual(omit(['onQuitClick'], props.header), {
362
362
  'aria-label': 'aria-header-wrapper',
@@ -459,7 +459,7 @@ test('should verify props when first slide was answered with error and next slid
459
459
  }
460
460
  }
461
461
  };
462
- var props = mapStateToSlidesProps(state, identity, identity);
462
+ var props = mapStateToSlidesProps(state, identity);
463
463
  t.is(props.congratsProps, undefined);
464
464
  t.deepEqual(omit(['onQuitClick'], props.header), {
465
465
  'aria-label': 'aria-header-wrapper',
@@ -523,7 +523,7 @@ test('should verify props when first slide was answered, next slide is fetched &
523
523
  }
524
524
  }
525
525
  };
526
- var props = mapStateToSlidesProps(state, identity, identity);
526
+ var props = mapStateToSlidesProps(state, identity);
527
527
  t.is(props.congratsProps, undefined);
528
528
  t.deepEqual(omit(['onQuitClick'], props.header), {
529
529
  'aria-label': 'aria-header-wrapper',
@@ -635,7 +635,7 @@ test('should verify props when first slide was answered incorrectly, next slide
635
635
  }
636
636
  }
637
637
  };
638
- var props = mapStateToSlidesProps(state, identity, identity);
638
+ var props = mapStateToSlidesProps(state, identity);
639
639
  t.is(props.congratsProps, undefined);
640
640
  t.deepEqual(omit(['onQuitClick'], props.header), {
641
641
  'aria-label': 'aria-header-wrapper',
@@ -745,7 +745,7 @@ test('should verify props when currentSlideRef has changed to nextContent of pro
745
745
  }
746
746
  }
747
747
  };
748
- var props = mapStateToSlidesProps(state, identity, identity);
748
+ var props = mapStateToSlidesProps(state, identity);
749
749
  t.is(props.congratsProps, undefined);
750
750
  t.deepEqual(omit(['onQuitClick'], props.header), {
751
751
  'aria-label': 'aria-header-wrapper',
@@ -815,7 +815,7 @@ test('should verify props when progression is in success', function (t) {
815
815
  }
816
816
  }
817
817
  };
818
- var props = mapStateToSlidesProps(state, identity, identity);
818
+ var props = mapStateToSlidesProps(state, identity);
819
819
  t.is(props.congratsProps, undefined);
820
820
  t.deepEqual(omit(['onQuitClick'], props.header), {
821
821
  'aria-label': 'aria-header-wrapper',
@@ -885,7 +885,7 @@ test('should verify props when progression has answered a current pendingSlide',
885
885
  }
886
886
  }
887
887
  };
888
- var props = mapStateToSlidesProps(state, identity, identity);
888
+ var props = mapStateToSlidesProps(state, identity);
889
889
  t.deepEqual(omit(['onQuitClick'], props.header), {
890
890
  'aria-label': 'aria-header-wrapper',
891
891
  closeButtonAriaLabel: 'aria-close-button',
@@ -953,7 +953,7 @@ test('should verify props when progression still has a pendingSlide', function (
953
953
  }
954
954
  }
955
955
  };
956
- var props = mapStateToSlidesProps(state, identity, identity);
956
+ var props = mapStateToSlidesProps(state, identity);
957
957
  t.deepEqual(omit(['onQuitClick'], props.header), {
958
958
  'aria-label': 'aria-header-wrapper',
959
959
  closeButtonAriaLabel: 'aria-close-button',
@@ -2,7 +2,6 @@ var _a;
2
2
  import test from 'ava';
3
3
  import omit from 'lodash/fp/omit';
4
4
  import get from 'lodash/fp/get';
5
- import identity from 'lodash/fp/identity';
6
5
  import { mapStateToSlidesProps } from '..';
7
6
  import { services } from '../../../test/util/services.mock';
8
7
  import { createTestStore } from '../../../actions/test/create-test-store';
@@ -59,7 +58,7 @@ test('should dispatch EDIT_BASIC action via the property onChange of a Free Text
59
58
  }
60
59
  ];
61
60
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
62
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
61
+ var props = mapStateToSlidesProps(getState(), dispatch);
63
62
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
64
63
  animateCorrectionPopin: false,
65
64
  showCorrectionPopin: false,
@@ -2,7 +2,6 @@ var _a;
2
2
  import test from 'ava';
3
3
  import omit from 'lodash/fp/omit';
4
4
  import get from 'lodash/fp/get';
5
- import identity from 'lodash/fp/identity';
6
5
  import { mapStateToSlidesProps } from '..';
7
6
  import { services } from '../../../test/util/services.mock';
8
7
  import { createTestStore } from '../../../actions/test/create-test-store';
@@ -59,7 +58,7 @@ test('should dispatch EDIT_QCM_DRAG action via the property onClick of a QCM Dra
59
58
  }
60
59
  ];
61
60
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
62
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
61
+ var props = mapStateToSlidesProps(getState(), dispatch);
63
62
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
64
63
  animateCorrectionPopin: false,
65
64
  showCorrectionPopin: false,
@@ -2,7 +2,6 @@ var _a;
2
2
  import test from 'ava';
3
3
  import omit from 'lodash/fp/omit';
4
4
  import get from 'lodash/fp/get';
5
- import identity from 'lodash/fp/identity';
6
5
  import { mapStateToSlidesProps } from '..';
7
6
  import { services } from '../../../test/util/services.mock';
8
7
  import { createTestStore } from '../../../actions/test/create-test-store';
@@ -59,7 +58,7 @@ test('should dispatch EDIT_QCM_GRAPHIC action via the property onClick of a QCM
59
58
  }
60
59
  ];
61
60
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
62
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
61
+ var props = mapStateToSlidesProps(getState(), dispatch);
63
62
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
64
63
  animateCorrectionPopin: false,
65
64
  showCorrectionPopin: false,
@@ -2,7 +2,6 @@ var _a;
2
2
  import test from 'ava';
3
3
  import omit from 'lodash/fp/omit';
4
4
  import get from 'lodash/fp/get';
5
- import identity from 'lodash/fp/identity';
6
5
  import { mapStateToSlidesProps } from '..';
7
6
  import { services } from '../../../test/util/services.mock';
8
7
  import { createTestStore } from '../../../actions/test/create-test-store';
@@ -61,7 +60,7 @@ test('should dispatch EDIT_QCM action via the property onClick of a QCM slide',
61
60
  }
62
61
  ];
63
62
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
64
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
63
+ var props = mapStateToSlidesProps(getState(), dispatch);
65
64
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
66
65
  animateCorrectionPopin: false,
67
66
  showCorrectionPopin: false,
@@ -2,7 +2,6 @@ var _a;
2
2
  import test from 'ava';
3
3
  import omit from 'lodash/fp/omit';
4
4
  import get from 'lodash/fp/get';
5
- import identity from 'lodash/fp/identity';
6
5
  import { mapStateToSlidesProps } from '..';
7
6
  import { services } from '../../../test/util/services.mock';
8
7
  import { createTestStore } from '../../../actions/test/create-test-store';
@@ -59,7 +58,7 @@ test('should dispatch EDIT_SLIDER action via the property onChange of a Slider s
59
58
  }
60
59
  ];
61
60
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
62
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
61
+ var props = mapStateToSlidesProps(getState(), dispatch);
63
62
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
64
63
  animateCorrectionPopin: false,
65
64
  showCorrectionPopin: false,
@@ -0,0 +1,65 @@
1
+ var _a;
2
+ import test from 'ava';
3
+ import get from 'lodash/fp/get';
4
+ import { mapStateToSlidesProps } from '..';
5
+ import { services } from '../../../test/util/services.mock';
6
+ import { createTestStore } from '../../../actions/test/create-test-store';
7
+ import { EDIT_SLIDER } from '../../../actions/ui/answers';
8
+ import { sliderSlide } from './fixtures/slider';
9
+ var progression = {
10
+ _id: '123456789123',
11
+ content: { type: 'skill', ref: '_skill-ref' },
12
+ engine: {
13
+ ref: 'review'
14
+ },
15
+ state: {
16
+ allAnswers: [],
17
+ isCorrect: true,
18
+ nextContent: {
19
+ ref: sliderSlide._id,
20
+ type: 'slide'
21
+ },
22
+ pendingSlides: [],
23
+ slides: [],
24
+ step: {
25
+ current: 1
26
+ },
27
+ stars: 0
28
+ }
29
+ };
30
+ var initialState = {
31
+ data: {
32
+ progression: progression,
33
+ slides: (_a = {},
34
+ _a[sliderSlide._id] = sliderSlide,
35
+ _a),
36
+ skills: [],
37
+ token: '1234',
38
+ corrections: {},
39
+ rank: {}
40
+ },
41
+ ui: {
42
+ currentSlideRef: sliderSlide._id,
43
+ navigation: ['skills', 'slides'],
44
+ answers: [],
45
+ slide: {
46
+ validateButton: false
47
+ }
48
+ }
49
+ };
50
+ test('should dispatch EDIT_SLIDER action via the property onSliderChange of a Slider slide', function (t) {
51
+ var _a;
52
+ t.plan(1);
53
+ var expectedActions = [
54
+ {
55
+ type: EDIT_SLIDER,
56
+ payload: ['111']
57
+ }
58
+ ];
59
+ var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
60
+ var props = mapStateToSlidesProps(getState(), dispatch);
61
+ var SlideProps = (_a = props.stack.slides['0'].answerUI) === null || _a === void 0 ? void 0 : _a.model;
62
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
+ var onSliderChange = get('onSliderChange', SlideProps);
64
+ onSliderChange(111);
65
+ });
@@ -2,7 +2,6 @@ var _a;
2
2
  import test from 'ava';
3
3
  import omit from 'lodash/fp/omit';
4
4
  import get from 'lodash/fp/get';
5
- import identity from 'lodash/fp/identity';
6
5
  import { mapStateToSlidesProps } from '..';
7
6
  import { services } from '../../../test/util/services.mock';
8
7
  import { createTestStore } from '../../../actions/test/create-test-store';
@@ -54,7 +53,7 @@ test('should dispatch EDIT_TEMPLATE action via the property onChange of a Templa
54
53
  t.plan(2);
55
54
  var expectedActions = [{ type: EDIT_TEMPLATE, payload: ['', 'test', ''] }];
56
55
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
57
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
56
+ var props = mapStateToSlidesProps(getState(), dispatch);
58
57
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
59
58
  animateCorrectionPopin: false,
60
59
  showCorrectionPopin: false,
@@ -73,7 +72,7 @@ test('should dispatch EDIT_TEMPLATE action via the property onChange of a Templa
73
72
  t.plan(2);
74
73
  var expectedActions = [{ type: EDIT_TEMPLATE, payload: ['Catalogue', '', ''] }];
75
74
  var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
76
- var props = mapStateToSlidesProps(getState(), dispatch, identity);
75
+ var props = mapStateToSlidesProps(getState(), dispatch);
77
76
  t.deepEqual(omit('answerUI', props.stack.slides['0']), {
78
77
  animateCorrectionPopin: false,
79
78
  showCorrectionPopin: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.2.10-alpha.5+b5f45c65b",
3
+ "version": "0.2.10",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -41,8 +41,8 @@
41
41
  "./package.json": "./package.json"
42
42
  },
43
43
  "dependencies": {
44
- "@coorpacademy/components": "10.22.24",
45
- "@coorpacademy/redux-task": "1.1.5",
44
+ "@coorpacademy/components": "10.22.25",
45
+ "@coorpacademy/redux-task": "^1.1.5",
46
46
  "cross-fetch": "^3.1.5",
47
47
  "jwt-decode": "^3.1.2",
48
48
  "react-redux": "^8.0.1",
@@ -78,5 +78,5 @@
78
78
  "ts-node": "^10.9.1",
79
79
  "typescript": "^4.7.4"
80
80
  },
81
- "gitHead": "b5f45c65ba35d615bc2a74df5c9ff7afe25a35bb"
81
+ "gitHead": "6e9facb9c3b9b962abe565d779b5a8035e531fa2"
82
82
  }
@@ -0,0 +1,31 @@
1
+ import type {Dispatch} from 'redux';
2
+ import get from 'lodash/fp/get';
3
+ import type {StoreState} from '../../reducers';
4
+
5
+ export const NEXT_SLIDE = '@@slide/NEXT_SLIDE' as const;
6
+
7
+ type NextSlidePayload = {
8
+ currentSlideRef: string;
9
+ nextSlideRef: string;
10
+ animationType: string;
11
+ };
12
+
13
+ export type NextSlide = {
14
+ type: typeof NEXT_SLIDE;
15
+ payload: NextSlidePayload;
16
+ };
17
+
18
+ export const nextSlide = (dispatch: Dispatch, getState: () => StoreState): NextSlide => {
19
+ const state = getState();
20
+ const payload = {
21
+ currentSlideRef: get(['ui', 'currentSlideRef'], state),
22
+ nextSlideRef: get(['data', 'progression', 'state', 'nextContent', 'ref'], state),
23
+ animationType: state.data.progression?.state.isCorrect ? 'unstack' : 'restack'
24
+ };
25
+ const action = {
26
+ type: NEXT_SLIDE,
27
+ payload
28
+ };
29
+
30
+ return dispatch(action);
31
+ };
@@ -0,0 +1,75 @@
1
+ import test from 'ava';
2
+ import pipe from 'lodash/fp/pipe';
3
+ import set from 'lodash/fp/set';
4
+ import {StoreState} from '../../../reducers';
5
+ import {nextSlide, NEXT_SLIDE} from '../next-slide';
6
+ import {createTestStore} from '../../test/create-test-store';
7
+ import {
8
+ getChoicesCorrection,
9
+ postAnswerResponses,
10
+ services
11
+ } from '../../../test/util/services.mock';
12
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
13
+ import {qcmGraphicSlide} from '../../../views/slides/test/fixtures/qcm-graphic';
14
+
15
+ const progression = postAnswerResponses[freeTextSlide.universalRef];
16
+ const skillRef = '_skill-ref';
17
+ const answer = ['Vous isoler dans un lieu calme'];
18
+
19
+ const state: StoreState = {
20
+ data: {
21
+ progression,
22
+ slides: {
23
+ [freeTextSlide.universalRef]: freeTextSlide,
24
+ [qcmGraphicSlide.universalRef]: qcmGraphicSlide
25
+ },
26
+ skills: [{skillRef, custom: false, name: skillRef, slidesToReview: 5}],
27
+ token: '1234',
28
+ corrections: {[freeTextSlide.universalRef]: getChoicesCorrection(freeTextSlide.universalRef)},
29
+ rank: {start: 93}
30
+ },
31
+ ui: {
32
+ currentSlideRef: freeTextSlide._id,
33
+ navigation: ['loader', 'slides'],
34
+ answers: answer,
35
+ slide: {
36
+ validateButton: false,
37
+ animateCorrectionPopin: true,
38
+ showCorrectionPopin: true
39
+ }
40
+ }
41
+ };
42
+ test('should dispatch NEXT_SLIDE action when nextSlide is called and the progression state is correct', t => {
43
+ const expectedActions = [
44
+ {
45
+ type: NEXT_SLIDE,
46
+ payload: {
47
+ currentSlideRef: freeTextSlide.universalRef,
48
+ nextSlideRef: qcmGraphicSlide.universalRef,
49
+ animationType: 'unstack'
50
+ }
51
+ }
52
+ ];
53
+ const {dispatch} = createTestStore(t, state, services, expectedActions);
54
+ dispatch(nextSlide);
55
+ });
56
+
57
+ test('should dispatch NEXT_SLIDE action when nextSlide is called and the progression state is not correct', t => {
58
+ const stateWithWrongAnswer = pipe(
59
+ set(['data', 'progression', 'state', 'isCorrect'], false),
60
+ set(['data', 'progression', 'state', 'allAnswers', 0, 'isCorrect'], false)
61
+ )(state);
62
+
63
+ const expectedActions = [
64
+ {
65
+ type: NEXT_SLIDE,
66
+ payload: {
67
+ currentSlideRef: freeTextSlide.universalRef,
68
+ nextSlideRef: qcmGraphicSlide.universalRef,
69
+ animationType: 'restack'
70
+ }
71
+ }
72
+ ];
73
+ const {dispatch} = createTestStore(t, stateWithWrongAnswer, services, expectedActions);
74
+ dispatch(nextSlide);
75
+ });
package/src/index.tsx CHANGED
@@ -19,18 +19,17 @@ import {VIEWS} from './common';
19
19
  import {mapStateToSlidesProps} from './views/slides';
20
20
  import {mapStateToSkillsProps} from './views/skills';
21
21
 
22
- const ConnectedApp = ({onQuitClick}: {onQuitClick: Function}): JSX.Element => {
22
+ const ConnectedApp = (): JSX.Element => {
23
23
  const dispatch = useDispatch();
24
24
 
25
25
  const props = {
26
26
  viewName: useSelector(
27
27
  (state: StoreState) => state.ui.navigation[state.ui.navigation.length - 1]
28
28
  ),
29
- slides: useSelector((state: StoreState) => mapStateToSlidesProps(state, dispatch, onQuitClick)),
29
+ slides: useSelector((state: StoreState) => mapStateToSlidesProps(state, dispatch)),
30
30
  skills: useSelector((state: StoreState) => mapStateToSkillsProps(state))
31
31
  };
32
- // eslint-disable-next-line no-console
33
- console.log(props);
32
+
34
33
  return <AppReviewTemplate {...props} />;
35
34
  };
36
35
 
@@ -38,8 +37,6 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
38
37
  const [store, setStore] = useState<Store<StoreState, AnyAction> | null>(null);
39
38
  const [isProgressionCreated, setIsProgressionCreated] = useState(false);
40
39
 
41
- const onQuitClick = get('onQuitClick', options);
42
-
43
40
  useEffect(() => {
44
41
  if (store) return;
45
42
 
@@ -91,7 +88,7 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
91
88
 
92
89
  return (
93
90
  <Provider store={store}>
94
- <ConnectedApp onQuitClick={onQuitClick} />
91
+ <ConnectedApp />
95
92
  </Provider>
96
93
  );
97
94
  };
@@ -58,15 +58,8 @@ const clickAllSlides = async (
58
58
 
59
59
  const appOptions: AppOptions = {
60
60
  token: process.env.API_TEST_TOKEN || '',
61
- templateContext: {
62
- theme: {color: {primary: '#123'}}
63
- },
64
61
  skillRef: 'skill_NJC0jFKoH',
65
- services,
66
- onQuitClick: (): void => {
67
- // eslint-disable-next-line no-console
68
- console.log('onQuitClick - options');
69
- }
62
+ services
70
63
  };
71
64
 
72
65
  test('should show the loader while the app is fetching the data', async t => {
@@ -1,10 +1,3 @@
1
- // TODO use type from components
2
- type TemplateContextValues = {
3
- brandTheme?: unknown;
4
- theme?: unknown; // TODO type Theme
5
- translations?: unknown; // TODO type Translations
6
- };
7
-
8
1
  // TODO: EDIT_CHOICES -> specify typing
9
2
  export type ChoiceFromAPI = {
10
3
  _id: string;
@@ -176,12 +169,8 @@ export type Options = {
176
169
 
177
170
  export type AppOptions = {
178
171
  token: string;
179
- theme?: unknown;
180
- translations?: unknown;
181
- templateContext?: TemplateContextValues;
182
172
  skillRef?: string;
183
173
  services: Services;
184
- onQuitClick: Function;
185
174
  };
186
175
 
187
176
  export type JWT = {
@@ -59,8 +59,9 @@ export type DropDown = {
59
59
  export type QuestionRange = {
60
60
  type: 'slider';
61
61
  placeholder?: string;
62
- onChange?: Function;
62
+ onChange?: (value: number) => void;
63
63
  onChangeEnd?: Function;
64
+ onSliderChange?: (value: number) => void;
64
65
  multi?: boolean;
65
66
  value: number | number[];
66
67
  title: string;
@@ -298,11 +298,7 @@ const getCorrectionPopinProps = (
298
298
  type: isCorrect ? 'right' : 'wrong'
299
299
  });
300
300
 
301
- export const mapStateToSlidesProps = (
302
- state: StoreState,
303
- dispatch: Dispatch,
304
- onQuitClick: Function
305
- ): SlidesViewProps => {
301
+ export const mapStateToSlidesProps = (state: StoreState, dispatch: Dispatch): SlidesViewProps => {
306
302
  const currentSlideRef = get(['ui', 'currentSlideRef'], state);
307
303
  const correction = get(['data', 'corrections', currentSlideRef], state);
308
304
  const isCorrect = get(['data', 'progression', 'state', 'isCorrect'], state);
@@ -313,7 +309,8 @@ export const mapStateToSlidesProps = (
313
309
  mode: '__revision_mode',
314
310
  skillName: '__agility',
315
311
  onQuitClick: (): void => {
316
- onQuitClick();
312
+ // eslint-disable-next-line no-console
313
+ console.log('onQuitClick');
317
314
  },
318
315
  'aria-label': 'aria-header-wrapper',
319
316
  closeButtonAriaLabel: 'aria-close-button',
@@ -225,6 +225,7 @@ const sliderProps =
225
225
  title: `${currentValue} ${question.content.unitLabel}`,
226
226
  value: sliderPosition,
227
227
  onChange: (position: number): void => {
228
+ // atom/range handler
228
229
  const newValue: string = pipe(
229
230
  multiply(maxValue),
230
231
  round,
@@ -232,6 +233,10 @@ const sliderProps =
232
233
  _toString
233
234
  )(position);
234
235
  dispatch(editAnswer([newValue]));
236
+ },
237
+ onSliderChange: (newValue: number): void => {
238
+ // mobile/slider handler
239
+ dispatch(editAnswer([`${newValue}`]));
235
240
  }
236
241
  };
237
242
  };