@coorpacademy/app-review 0.4.5 → 0.5.0

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 (72) hide show
  1. package/es/actions/ui/next-slide.d.ts +4 -2
  2. package/es/actions/ui/next-slide.js +7 -4
  3. package/es/actions/ui/slides.d.ts +2 -3
  4. package/es/common/index.d.ts +2 -0
  5. package/es/common/index.js +9 -0
  6. package/es/reducers/index.d.ts +2 -1
  7. package/es/reducers/ui/answers.d.ts +2 -2
  8. package/es/reducers/ui/current-slide-ref.d.ts +3 -2
  9. package/es/reducers/ui/current-slide-ref.js +3 -0
  10. package/es/reducers/ui/index.d.ts +4 -1
  11. package/es/reducers/ui/index.js +3 -1
  12. package/es/reducers/ui/positions.d.ts +5 -0
  13. package/es/reducers/ui/positions.js +25 -0
  14. package/es/reducers/ui/slide.d.ts +2 -2
  15. package/es/views/slides/index.d.ts +1 -2
  16. package/es/views/slides/index.js +15 -23
  17. package/lib/actions/ui/next-slide.d.ts +4 -2
  18. package/lib/actions/ui/next-slide.js +7 -4
  19. package/lib/actions/ui/slides.d.ts +2 -3
  20. package/lib/common/index.d.ts +2 -0
  21. package/lib/common/index.js +9 -0
  22. package/lib/reducers/index.d.ts +2 -1
  23. package/lib/reducers/ui/answers.d.ts +2 -2
  24. package/lib/reducers/ui/current-slide-ref.d.ts +3 -2
  25. package/lib/reducers/ui/current-slide-ref.js +3 -0
  26. package/lib/reducers/ui/index.d.ts +4 -1
  27. package/lib/reducers/ui/index.js +3 -1
  28. package/lib/reducers/ui/positions.d.ts +5 -0
  29. package/lib/reducers/ui/positions.js +26 -0
  30. package/lib/reducers/ui/slide.d.ts +2 -2
  31. package/lib/views/slides/index.d.ts +1 -2
  32. package/lib/views/slides/index.js +15 -24
  33. package/package.json +3 -3
  34. package/src/actions/api/test/fetch-correction.test.ts +1 -0
  35. package/src/actions/api/test/fetch-rank.test.ts +1 -0
  36. package/src/actions/api/test/fetch-skills.test.ts +1 -0
  37. package/src/actions/api/test/fetch-slide.test.ts +1 -0
  38. package/src/actions/api/test/post-answer.test.ts +2 -0
  39. package/src/actions/api/test/post-progression.test.ts +1 -0
  40. package/src/actions/data/test/token.test.ts +1 -0
  41. package/src/actions/ui/next-slide.ts +15 -9
  42. package/src/actions/ui/slides.ts +2 -4
  43. package/src/actions/ui/test/answers.test.ts +1 -0
  44. package/src/actions/ui/test/next-slide.test.ts +7 -2
  45. package/src/actions/ui/test/slides.test.ts +1 -0
  46. package/src/common/index.ts +12 -0
  47. package/src/reducers/ui/answers.ts +2 -2
  48. package/src/reducers/ui/current-slide-ref.ts +5 -2
  49. package/src/reducers/ui/index.ts +4 -1
  50. package/src/reducers/ui/positions.ts +32 -0
  51. package/src/reducers/ui/slide.ts +7 -2
  52. package/src/reducers/ui/test/answers.test.ts +3 -1
  53. package/src/reducers/ui/test/current-slide-ref.test.ts +2 -2
  54. package/src/reducers/ui/test/positions.test.ts +68 -0
  55. package/src/reducers/ui/test/slide.test.ts +3 -1
  56. package/src/types/common.ts +0 -1
  57. package/src/views/skills/test/skills.test.ts +2 -0
  58. package/src/views/slides/index.ts +18 -29
  59. package/src/views/slides/test/index.test.ts +37 -31
  60. package/src/views/slides/test/slide.free-text.on-change.test.ts +1 -1
  61. package/src/views/slides/test/slide.next-slide.on-click.test.ts +8 -1
  62. package/src/views/slides/test/slide.qcm-drag.on-click.test.ts +1 -1
  63. package/src/views/slides/test/slide.qcm-graphic.on-click.test.ts +1 -1
  64. package/src/views/slides/test/slide.qcm.on-click.test.ts +1 -1
  65. package/src/views/slides/test/slide.slider.on-change.test.ts +1 -1
  66. package/src/views/slides/test/slide.slider.on-slider-change.test.ts +15 -3
  67. package/src/views/slides/test/slide.template.on-change.test.ts +9 -10
  68. package/es/actions/ui/is-fetching.d.ts +0 -10
  69. package/es/actions/ui/is-fetching.js +0 -4
  70. package/lib/actions/ui/is-fetching.d.ts +0 -10
  71. package/lib/actions/ui/is-fetching.js +0 -4
  72. package/src/actions/ui/is-fetching.ts +0 -13
@@ -9,16 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import concat from 'lodash/fp/concat';
13
12
  import findLast from 'lodash/fp/findLast';
14
13
  import get from 'lodash/fp/get';
15
14
  import getOr from 'lodash/fp/getOr';
16
15
  import last from 'lodash/fp/last';
17
16
  import reduce from 'lodash/fp/reduce';
18
17
  import set from 'lodash/fp/set';
19
- import slice from 'lodash/fp/slice';
20
18
  import toInteger from 'lodash/fp/toInteger';
21
19
  import join from 'lodash/fp/join';
20
+ import { getProgressionSlidesRefs } from '../../common';
22
21
  import { postAnswer } from '../../actions/api/post-answer';
23
22
  import { nextSlide } from '../../actions/ui/next-slide';
24
23
  import { mapApiSlideToUi } from './map-api-slide-to-ui';
@@ -27,40 +26,29 @@ var ICON_VALUES = {
27
26
  wrong: 'wrong',
28
27
  'no-answer': 'no-answer'
29
28
  };
29
+ // TODO replace this, position no more needed
30
30
  export var initialState = {
31
31
  '0': {
32
- hidden: false,
33
32
  position: 0,
34
33
  loading: true
35
34
  },
36
35
  '1': {
37
- hidden: false,
38
36
  position: 1,
39
37
  loading: true
40
38
  },
41
39
  '2': {
42
- hidden: false,
43
40
  position: 2,
44
41
  loading: true
45
42
  },
46
43
  '3': {
47
- hidden: false,
48
44
  position: 3,
49
45
  loading: true
50
46
  },
51
47
  '4': {
52
- hidden: false,
53
48
  position: 4,
54
49
  loading: true
55
50
  }
56
51
  };
57
- var getProgressionSlidesRefs = function (progression) {
58
- if (progression.state.step.current < 5) {
59
- var slideRef = progression.state.nextContent.ref;
60
- return concat(progression.state.slides, [slideRef]);
61
- }
62
- return slice(0, 5, progression.state.slides);
63
- };
64
52
  var buildStackSlides = function (state, dispatch) {
65
53
  var currentSlideRef = state.ui.currentSlideRef;
66
54
  var progression = state.data.progression;
@@ -68,22 +56,25 @@ var buildStackSlides = function (state, dispatch) {
68
56
  return initialState;
69
57
  var slideRefs = getProgressionSlidesRefs(progression);
70
58
  // @ts-expect-error typescript does not support capped versions of lodash functions
71
- var stack = reduce.convert({ cap: false })(function (acc, uiSlide, index) {
72
- var slideRef = slideRefs[toInteger(index)];
59
+ var stack = reduce.convert({ cap: false })(function (acc, uiSlide, _index) {
60
+ var index = toInteger(_index);
61
+ var positions = state.ui.positions;
62
+ var position = positions[index];
63
+ var slideRef = slideRefs[index];
73
64
  if (!slideRef)
74
- return set(index, uiSlide, acc);
65
+ return set(index, __assign(__assign({}, uiSlide), { position: position }), acc);
75
66
  var slideFromAPI = get(slideRef, state.data.slides);
76
67
  if (!slideFromAPI)
77
- return set(index, uiSlide, acc);
68
+ return set(index, __assign(__assign({}, uiSlide), { position: position }), acc);
78
69
  var answers = getOr([], ['ui', 'answers', slideRef], state);
79
70
  var _a = mapApiSlideToUi(dispatch)(slideFromAPI, answers), questionText = _a.questionText, answerUI = _a.answerUI;
80
- var parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
81
- var parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
71
+ var _b = slideFromAPI.parentContentTitle, parentContentTitle = _b.title, parentContentType = _b.type;
82
72
  var isCurrentSlideRef = currentSlideRef === slideRef;
83
- var animateCorrectionPopin = isCurrentSlideRef && get(['ui', 'slide', slideRef, 'animateCorrectionPopin'], state);
84
- var showCorrectionPopin = isCurrentSlideRef && get(['ui', 'slide', slideRef, 'showCorrectionPopin'], state);
85
- var animationType = get(['ui', 'slide', slideRef, 'animationType'], state);
86
- var updatedUiSlide = __assign(__assign({}, uiSlide), { showCorrectionPopin: showCorrectionPopin, animateCorrectionPopin: animateCorrectionPopin, loading: false, questionText: questionText, answerUI: answerUI, parentContentTitle: "From \"".concat(parentContentTitle, "\" ").concat(parentContentType), animationType: animationType });
73
+ var slideUI = get(['ui', 'slide', slideRef], state);
74
+ var animateCorrectionPopin = isCurrentSlideRef && slideUI.animateCorrectionPopin;
75
+ var showCorrectionPopin = isCurrentSlideRef && slideUI.showCorrectionPopin;
76
+ var animationType = slideUI.animationType;
77
+ var updatedUiSlide = __assign(__assign({}, uiSlide), { position: position, showCorrectionPopin: showCorrectionPopin, animateCorrectionPopin: animateCorrectionPopin, loading: false, questionText: questionText, answerUI: answerUI, parentContentTitle: "From \"".concat(parentContentTitle, "\" ").concat(parentContentType), animationType: animationType });
87
78
  return set(index, updatedUiSlide, acc);
88
79
  }, initialState, initialState);
89
80
  return stack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -43,7 +43,7 @@
43
43
  "./package.json": "./package.json"
44
44
  },
45
45
  "dependencies": {
46
- "@coorpacademy/components": "10.23.7",
46
+ "@coorpacademy/components": "10.23.8",
47
47
  "@coorpacademy/redux-task": "^1.1.5",
48
48
  "cross-fetch": "^3.1.5",
49
49
  "jwt-decode": "^3.1.2",
@@ -78,5 +78,5 @@
78
78
  "webpack-cli": "^3.3.11",
79
79
  "webpack-dev-server": "^3.11.0"
80
80
  },
81
- "gitHead": "0a46c83d80845f4c08a35cc278b7a11ccb4d8d0e"
81
+ "gitHead": "ef2f2340a0169672d5880e8fb9900cd7c7ebf12c"
82
82
  }
@@ -36,6 +36,7 @@ const initialState: StoreState = {
36
36
  currentSlideRef: freeTextSlide._id,
37
37
  navigation: ['skills', 'slides'],
38
38
  answers: {[freeTextSlide.universalRef]: answer},
39
+ positions: [0, 1, 2, 3, 4],
39
40
  slide: {
40
41
  [freeTextSlide.universalRef]: {
41
42
  validateButton: false,
@@ -24,6 +24,7 @@ const initialState: StoreState = {
24
24
  rank: {}
25
25
  },
26
26
  ui: {
27
+ positions: [0, 1, 2, 3, 4],
27
28
  currentSlideRef: '',
28
29
  navigation: [],
29
30
  answers: {},
@@ -20,6 +20,7 @@ const initialState: StoreState = {
20
20
  rank: {}
21
21
  },
22
22
  ui: {
23
+ positions: [0, 1, 2, 3, 4],
23
24
  currentSlideRef: '',
24
25
  navigation: [],
25
26
  answers: {},
@@ -22,6 +22,7 @@ const initialState: StoreState = {
22
22
  rank: {}
23
23
  },
24
24
  ui: {
25
+ positions: [0, 1, 2, 3, 4],
25
26
  currentSlideRef: '',
26
27
  navigation: [],
27
28
  answers: {},
@@ -65,6 +65,7 @@ const initialState: StoreState = {
65
65
  ui: {
66
66
  currentSlideRef: freeTextSlide._id,
67
67
  navigation: ['skills', 'slides'],
68
+ positions: [0, 1, 2, 3, 4],
68
69
  answers: {
69
70
  [freeTextSlide._id]: answer
70
71
  },
@@ -148,6 +149,7 @@ test('should dispatch post-answer, fetch-correction and fetch-end-rank actions w
148
149
  ui: {
149
150
  currentSlideRef: templateSlide._id,
150
151
  navigation: ['skills', 'slides'],
152
+ positions: [-1, -1, -1, -1, 0],
151
153
  answers: {
152
154
  [freeTextSlide._id]: answer,
153
155
  [qcmGraphicSlide._id]: ['qcm-graphic answer'],
@@ -23,6 +23,7 @@ const initialState: StoreState = {
23
23
  rank: {}
24
24
  },
25
25
  ui: {
26
+ positions: [0, 1, 2, 3, 4],
26
27
  currentSlideRef: '',
27
28
  navigation: [],
28
29
  answers: {},
@@ -14,6 +14,7 @@ const initialState: StoreState = {
14
14
  rank: {}
15
15
  },
16
16
  ui: {
17
+ positions: [0, 1, 2, 3, 4],
17
18
  currentSlideRef: '',
18
19
  navigation: [],
19
20
  answers: {},
@@ -1,8 +1,8 @@
1
1
  import type {Dispatch} from 'redux';
2
+ import filter from 'lodash/fp/filter';
2
3
  import get from 'lodash/fp/get';
3
- import getOr from 'lodash/fp/getOr';
4
4
  import type {StoreState} from '../../reducers';
5
- import {ProgressionFromAPI} from '../../types/common';
5
+ import {ProgressionFromAPI, ProgressionAnswerItem} from '../../types/common';
6
6
 
7
7
  export const NEXT_SLIDE = '@@slide/NEXT_SLIDE' as const;
8
8
 
@@ -10,26 +10,32 @@ type NextSlidePayload = {
10
10
  currentSlideRef: string;
11
11
  nextSlideRef: string;
12
12
  animationType: string;
13
+ totalCorrectAnswers: number;
14
+ answeredSlides: string[];
13
15
  };
14
16
 
15
- export type NextSlide = {
17
+ export type NextSlideAction = {
16
18
  type: typeof NEXT_SLIDE;
17
19
  payload: NextSlidePayload;
18
20
  };
19
21
 
20
- export const nextSlide = (dispatch: Dispatch, getState: () => StoreState): NextSlide => {
22
+ export const nextSlide = (dispatch: Dispatch, getState: () => StoreState): NextSlideAction => {
21
23
  const state = getState();
22
- const payload = {
24
+ const progression = state.data.progression as ProgressionFromAPI;
25
+ const {isCorrect, allAnswers, slides} = progression.state;
26
+ const correctAnswers = filter((answer: ProgressionAnswerItem) => answer.isCorrect, allAnswers);
27
+
28
+ const payload: NextSlidePayload = {
23
29
  currentSlideRef: get(['ui', 'currentSlideRef'], state),
24
30
  nextSlideRef: get(
25
31
  ['state', 'nextContent', 'ref'],
26
32
  state.data.progression as ProgressionFromAPI
27
33
  ),
28
- animationType: getOr(false, ['state', 'isCorrect'], state.data.progression)
29
- ? 'unstack'
30
- : 'restack'
34
+ animationType: isCorrect ? 'unstack' : 'restack',
35
+ totalCorrectAnswers: correctAnswers.length,
36
+ answeredSlides: slides
31
37
  };
32
- const action = {
38
+ const action: NextSlideAction = {
33
39
  type: NEXT_SLIDE,
34
40
  payload
35
41
  };
@@ -16,13 +16,11 @@ export type Slide = {
16
16
 
17
17
  export const SET_CURRENT_SLIDE = '@@slide/SET_CURRENT_SLIDE' as const;
18
18
 
19
- export type SetCurrentSlide = {
19
+ export type SetCurrentSlideAction = {
20
20
  type: typeof SET_CURRENT_SLIDE;
21
21
  payload: SlideFromAPI;
22
22
  };
23
- export const setCurrentSlide = (payload: SlideFromAPI): SetCurrentSlide => ({
23
+ export const setCurrentSlide = (payload: SlideFromAPI): SetCurrentSlideAction => ({
24
24
  type: SET_CURRENT_SLIDE,
25
25
  payload
26
26
  });
27
-
28
- export type UISlidesAction = SetCurrentSlide;
@@ -49,6 +49,7 @@ const initialState: StoreState = {
49
49
  rank: {}
50
50
  },
51
51
  ui: {
52
+ positions: [0, 1, 2, 3, 4],
52
53
  currentSlideRef: '',
53
54
  navigation: [],
54
55
  answers: {},
@@ -31,6 +31,7 @@ const state: StoreState = {
31
31
  ui: {
32
32
  currentSlideRef: freeTextSlide._id,
33
33
  navigation: ['loader', 'slides'],
34
+ positions: [0, 1, 2, 3, 4],
34
35
  answers: {
35
36
  [freeTextSlide._id]: answer
36
37
  },
@@ -50,7 +51,9 @@ test('should dispatch NEXT_SLIDE action when nextSlide is called and the progres
50
51
  payload: {
51
52
  currentSlideRef: freeTextSlide.universalRef,
52
53
  nextSlideRef: qcmGraphicSlide.universalRef,
53
- animationType: 'unstack'
54
+ animationType: 'unstack',
55
+ totalCorrectAnswers: 1,
56
+ answeredSlides: [freeTextSlide.universalRef]
54
57
  }
55
58
  }
56
59
  ];
@@ -70,7 +73,9 @@ test('should dispatch NEXT_SLIDE action when nextSlide is called and the progres
70
73
  payload: {
71
74
  currentSlideRef: freeTextSlide.universalRef,
72
75
  nextSlideRef: qcmGraphicSlide.universalRef,
73
- animationType: 'restack'
76
+ animationType: 'restack',
77
+ totalCorrectAnswers: 0,
78
+ answeredSlides: [freeTextSlide.universalRef]
74
79
  }
75
80
  }
76
81
  ];
@@ -17,6 +17,7 @@ const initialState: StoreState = {
17
17
  ui: {
18
18
  currentSlideRef: '',
19
19
  navigation: [],
20
+ positions: [0, 1, 2, 3, 4],
20
21
  answers: {},
21
22
  slide: {}
22
23
  }
@@ -1,3 +1,7 @@
1
+ import concat from 'lodash/fp/concat';
2
+ import slice from 'lodash/fp/slice';
3
+ import type {ProgressionFromAPI} from '../types/common';
4
+
1
5
  export const VIEWS: {
2
6
  readonly skills: 'skills';
3
7
  readonly onboarding: 'onboarding';
@@ -11,3 +15,11 @@ export const VIEWS: {
11
15
  export const slideIndexes = ['0', '1', '2', '3', '4'] as const;
12
16
 
13
17
  export type SlideIndexes = typeof slideIndexes[number];
18
+
19
+ export const getProgressionSlidesRefs = (progression: ProgressionFromAPI): string[] => {
20
+ if (progression.state.step.current < 5) {
21
+ const slideRef = progression.state.nextContent.ref;
22
+ return concat(progression.state.slides, [slideRef]);
23
+ }
24
+ return slice(0, 5, progression.state.slides);
25
+ };
@@ -8,7 +8,7 @@ import {
8
8
  EDIT_SLIDER,
9
9
  EDIT_TEMPLATE
10
10
  } from '../../actions/ui/answers';
11
- import {NextSlide, NEXT_SLIDE} from '../../actions/ui/next-slide';
11
+ import {NextSlideAction, NEXT_SLIDE} from '../../actions/ui/next-slide';
12
12
 
13
13
  export type UISlideAnswer = string[];
14
14
 
@@ -19,7 +19,7 @@ export const initialState: UIAnswerState = {};
19
19
  const reducer = (
20
20
  // eslint-disable-next-line default-param-last
21
21
  state: UIAnswerState = initialState,
22
- action: EditAnswerAction | NextSlide
22
+ action: EditAnswerAction | NextSlideAction
23
23
  ): UIAnswerState => {
24
24
  switch (action.type) {
25
25
  case EDIT_QCM:
@@ -1,13 +1,16 @@
1
- import {SET_CURRENT_SLIDE, UISlidesAction} from '../../actions/ui/slides';
1
+ import {NEXT_SLIDE, NextSlideAction} from '../../actions/ui/next-slide';
2
+ import {SET_CURRENT_SLIDE, SetCurrentSlideAction} from '../../actions/ui/slides';
2
3
 
3
4
  export type CurrentSlideRefState = string;
4
5
 
5
6
  const reducer = (
6
7
  // eslint-disable-next-line default-param-last
7
8
  state: CurrentSlideRefState = '',
8
- action: UISlidesAction
9
+ action: SetCurrentSlideAction | NextSlideAction
9
10
  ): CurrentSlideRefState => {
10
11
  switch (action.type) {
12
+ case NEXT_SLIDE:
13
+ return action.payload.nextSlideRef;
11
14
  case SET_CURRENT_SLIDE: {
12
15
  return action.payload._id;
13
16
  }
@@ -3,6 +3,7 @@ import {combineReducers} from 'redux';
3
3
  import currentSlideRef, {CurrentSlideRefState} from './current-slide-ref';
4
4
  import navigation, {NavigationState} from './navigation';
5
5
  import answers, {UIAnswerState} from './answers';
6
+ import positions, {UIPositionState} from './positions';
6
7
  import slide, {UISlideState} from './slide';
7
8
 
8
9
  export type UIState = {
@@ -10,11 +11,13 @@ export type UIState = {
10
11
  navigation: NavigationState;
11
12
  answers: UIAnswerState;
12
13
  slide: UISlideState;
14
+ positions: UIPositionState;
13
15
  };
14
16
 
15
17
  export default combineReducers({
16
18
  currentSlideRef,
17
19
  navigation,
18
20
  answers,
19
- slide
21
+ slide,
22
+ positions
20
23
  });
@@ -0,0 +1,32 @@
1
+ import findIndex from 'lodash/fp/findIndex';
2
+ import map from 'lodash/fp/map';
3
+ import set from 'lodash/fp/set';
4
+ import {ReceivedProgression, POST_PROGRESSION_SUCCESS} from '../../actions/api/post-progression';
5
+ import {NextSlideAction, NEXT_SLIDE} from '../../actions/ui/next-slide';
6
+
7
+ export type UIPositionState = number[];
8
+ const initialState: UIPositionState = [0, 1, 2, 3, 4];
9
+
10
+ const reducer = (
11
+ // eslint-disable-next-line default-param-last
12
+ state: UIPositionState = initialState,
13
+ action: NextSlideAction | ReceivedProgression
14
+ ): UIPositionState => {
15
+ switch (action.type) {
16
+ case POST_PROGRESSION_SUCCESS: {
17
+ return initialState;
18
+ }
19
+ case NEXT_SLIDE: {
20
+ const {totalCorrectAnswers, answeredSlides, currentSlideRef, animationType} = action.payload;
21
+
22
+ const nextCurrentSlidePosition = animationType === 'unstack' ? -1 : 4 - totalCorrectAnswers;
23
+ const currentSlideIndex = findIndex(ref => ref === currentSlideRef, answeredSlides);
24
+ const newState = map(position => (position === -1 ? position : position - 1), state);
25
+ return set([`${currentSlideIndex}`], nextCurrentSlidePosition)(newState);
26
+ }
27
+ default:
28
+ return state;
29
+ }
30
+ };
31
+
32
+ export default reducer;
@@ -15,7 +15,7 @@ import {
15
15
  import {PostAnswerRequestAction, POST_ANSWER_REQUEST} from '../../actions/api/post-answer';
16
16
  import {ReceivedCorrection, CORRECTION_FETCH_SUCCESS} from '../../actions/api/fetch-correction';
17
17
  import {FetchSlide, SLIDE_FETCH_REQUEST} from '../../actions/api/fetch-slide';
18
- import {NextSlide, NEXT_SLIDE} from '../../actions/ui/next-slide';
18
+ import {NextSlideAction, NEXT_SLIDE} from '../../actions/ui/next-slide';
19
19
  import {SlideUIAnimations} from '../../types/slides';
20
20
 
21
21
  export type UISlide = {
@@ -32,7 +32,12 @@ export const initialState: UISlideState = {};
32
32
  const reducer = (
33
33
  // eslint-disable-next-line default-param-last
34
34
  state: UISlideState = initialState,
35
- action: FetchSlide | PostAnswerRequestAction | EditAnswerAction | ReceivedCorrection | NextSlide
35
+ action:
36
+ | FetchSlide
37
+ | PostAnswerRequestAction
38
+ | EditAnswerAction
39
+ | ReceivedCorrection
40
+ | NextSlideAction
36
41
  ): UISlideState => {
37
42
  switch (action.type) {
38
43
  case SLIDE_FETCH_REQUEST: {
@@ -94,7 +94,9 @@ test('should set the next slide ref with an empty array if NEXT_SLIDE action is
94
94
  payload: {
95
95
  currentSlideRef: '1234',
96
96
  nextSlideRef: '5678',
97
- animationType: 'unstack'
97
+ animationType: 'unstack',
98
+ totalCorrectAnswers: 1,
99
+ answeredSlides: ['1234']
98
100
  }
99
101
  }
100
102
  );
@@ -1,10 +1,10 @@
1
1
  import test from 'ava';
2
2
  import reducer from '../current-slide-ref';
3
- import {SetCurrentSlide, SET_CURRENT_SLIDE} from '../../../actions/ui/slides';
3
+ import {SetCurrentSlideAction, SET_CURRENT_SLIDE} from '../../../actions/ui/slides';
4
4
  import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
5
5
 
6
6
  test('should have initial value', t => {
7
- const state = reducer(undefined, {} as SetCurrentSlide);
7
+ const state = reducer(undefined, {} as SetCurrentSlideAction);
8
8
  t.is(state, '');
9
9
  });
10
10
 
@@ -0,0 +1,68 @@
1
+ import test from 'ava';
2
+ import reducer from '../positions';
3
+ import {POST_PROGRESSION_SUCCESS, ReceivedProgression} from '../../../actions/api/post-progression';
4
+ import {NEXT_SLIDE} from '../../../actions/ui/next-slide';
5
+
6
+ test('should have initial value', t => {
7
+ const state = reducer(undefined, {} as ReceivedProgression);
8
+ t.deepEqual(state, [0, 1, 2, 3, 4]);
9
+ });
10
+
11
+ test('should reset state to initial value when POST_PROGRESSION_SUCCESS action', t => {
12
+ const state = reducer([-1, -1, -1, -1, -1], {
13
+ type: POST_PROGRESSION_SUCCESS
14
+ } as ReceivedProgression);
15
+ t.deepEqual(state, [0, 1, 2, 3, 4]);
16
+ });
17
+
18
+ test('should set position for currentSlide according to the animationType and the position for the next slides', t => {
19
+ const state = reducer([-1, -1, 0, 1, 2], {
20
+ type: NEXT_SLIDE,
21
+ payload: {
22
+ totalCorrectAnswers: 2,
23
+ answeredSlides: ['sli_1', 'sli_2', 'sli_3'],
24
+ currentSlideRef: 'sli_3',
25
+ nextSlideRef: 'sli_4',
26
+ animationType: 'restack'
27
+ }
28
+ });
29
+ t.deepEqual(state, [-1, -1, 2, 0, 1]);
30
+
31
+ const _state = reducer([-1, -1, 0, 1, 2], {
32
+ type: NEXT_SLIDE,
33
+ payload: {
34
+ totalCorrectAnswers: 2,
35
+ answeredSlides: ['sli_1', 'sli_2', 'sli_3'],
36
+ currentSlideRef: 'sli_3',
37
+ nextSlideRef: 'sli_4',
38
+ animationType: 'unstack'
39
+ }
40
+ });
41
+ t.deepEqual(_state, [-1, -1, -1, 0, 1]);
42
+ });
43
+
44
+ test('should set position for currentSlide according to the animationType and the position for the next slides when answering already bad slide', t => {
45
+ const state = reducer([-1, 2, -1, 0, 1], {
46
+ type: NEXT_SLIDE,
47
+ payload: {
48
+ totalCorrectAnswers: 2,
49
+ answeredSlides: ['sli_1', 'sli_2', 'sli_3', 'sli_4', 'sli_5'],
50
+ currentSlideRef: 'sli_4',
51
+ nextSlideRef: 'sli_5',
52
+ animationType: 'restack'
53
+ }
54
+ });
55
+ t.deepEqual(state, [-1, 1, -1, 2, 0]);
56
+
57
+ const _state = reducer([-1, 1, -1, 2, 0], {
58
+ type: NEXT_SLIDE,
59
+ payload: {
60
+ totalCorrectAnswers: 2,
61
+ answeredSlides: ['sli_1', 'sli_2', 'sli_3', 'sli_4', 'sli_5'],
62
+ currentSlideRef: 'sli_5',
63
+ nextSlideRef: 'sli_1',
64
+ animationType: 'unstack'
65
+ }
66
+ });
67
+ t.deepEqual(_state, [-1, 0, -1, 1, -1]);
68
+ });
@@ -66,7 +66,9 @@ test('should set animateCorrectionPopin to false and animationType to unstack or
66
66
  payload: {
67
67
  currentSlideRef: '1234',
68
68
  nextSlideRef: '5678',
69
- animationType: 'unstack'
69
+ animationType: 'unstack',
70
+ totalCorrectAnswers: 1,
71
+ answeredSlides: ['1234']
70
72
  }
71
73
  }
72
74
  );
@@ -1,4 +1,3 @@
1
- // TODO: EDIT_CHOICES -> specify typing
2
1
  export type ChoiceFromAPI = {
3
2
  _id: string;
4
3
  id?: string;
@@ -16,6 +16,7 @@ test('should create initial props when there are no skills on the state', t => {
16
16
  },
17
17
  ui: {
18
18
  currentSlideRef: '',
19
+ positions: [0, 1, 2, 3, 4],
19
20
  navigation: ['loader', 'skills'],
20
21
  answers: {},
21
22
  slide: {}
@@ -60,6 +61,7 @@ test('should create initial props when skills on the state', t => {
60
61
  },
61
62
  ui: {
62
63
  currentSlideRef: '',
64
+ positions: [0, 1, 2, 3, 4],
63
65
  navigation: ['loader', 'skills'],
64
66
  answers: {},
65
67
  slide: {}