@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.
- package/es/actions/ui/next-slide.d.ts +14 -0
- package/es/actions/ui/next-slide.js +15 -0
- package/es/actions/ui/test/next-slide.test.d.ts +1 -0
- package/es/actions/ui/test/next-slide.test.js +63 -0
- package/es/index.js +3 -6
- package/es/test/index.test.js +1 -8
- package/es/types/common.d.ts +0 -9
- package/es/types/slides.d.ts +2 -1
- package/es/views/slides/index.d.ts +1 -1
- package/es/views/slides/index.js +3 -2
- package/es/views/slides/map-api-slide-to-ui.js +5 -0
- package/es/views/slides/test/fixtures/slider.js +2 -1
- package/es/views/slides/test/index.test.js +11 -11
- package/es/views/slides/test/slide.free-text.on-change.test.js +1 -2
- package/es/views/slides/test/slide.qcm-drag.on-click.test.js +1 -2
- package/es/views/slides/test/slide.qcm-graphic.on-click.test.js +1 -2
- package/es/views/slides/test/slide.qcm.on-click.test.js +1 -2
- package/es/views/slides/test/slide.slider.on-change.test.js +1 -2
- package/es/views/slides/test/slide.slider.on-slider-change.test.d.ts +1 -0
- package/es/views/slides/test/slide.slider.on-slider-change.test.js +63 -0
- package/es/views/slides/test/slide.template.on-change.test.js +2 -3
- package/lib/actions/ui/next-slide.d.ts +14 -0
- package/lib/actions/ui/next-slide.js +16 -0
- package/lib/actions/ui/test/next-slide.test.d.ts +1 -0
- package/lib/actions/ui/test/next-slide.test.js +64 -0
- package/lib/index.js +3 -7
- package/lib/test/index.test.js +1 -8
- package/lib/types/common.d.ts +0 -9
- package/lib/types/slides.d.ts +2 -1
- package/lib/views/slides/index.d.ts +1 -1
- package/lib/views/slides/index.js +3 -2
- package/lib/views/slides/map-api-slide-to-ui.js +5 -0
- package/lib/views/slides/test/fixtures/slider.js +2 -1
- package/lib/views/slides/test/index.test.js +11 -11
- package/lib/views/slides/test/slide.free-text.on-change.test.js +1 -2
- package/lib/views/slides/test/slide.qcm-drag.on-click.test.js +1 -2
- package/lib/views/slides/test/slide.qcm-graphic.on-click.test.js +1 -2
- package/lib/views/slides/test/slide.qcm.on-click.test.js +1 -2
- package/lib/views/slides/test/slide.slider.on-change.test.js +1 -2
- package/lib/views/slides/test/slide.slider.on-slider-change.test.d.ts +1 -0
- package/lib/views/slides/test/slide.slider.on-slider-change.test.js +65 -0
- package/lib/views/slides/test/slide.template.on-change.test.js +2 -3
- package/package.json +4 -4
- package/src/actions/ui/next-slide.ts +31 -0
- package/src/actions/ui/test/next-slide.test.ts +75 -0
- package/src/index.tsx +4 -7
- package/src/test/index.test.tsx +1 -8
- package/src/types/common.ts +0 -11
- package/src/types/slides.ts +2 -1
- package/src/views/slides/index.ts +3 -6
- package/src/views/slides/map-api-slide-to-ui.ts +5 -0
- package/src/views/slides/test/fixtures/slider.ts +2 -1
- package/src/views/slides/test/index.test.ts +11 -11
- package/src/views/slides/test/slide.free-text.on-change.test.ts +1 -2
- package/src/views/slides/test/slide.qcm-drag.on-click.test.ts +1 -2
- package/src/views/slides/test/slide.qcm-graphic.on-click.test.ts +1 -2
- package/src/views/slides/test/slide.qcm.on-click.test.ts +1 -2
- package/src/views/slides/test/slide.slider.on-change.test.ts +1 -2
- package/src/views/slides/test/slide.slider.on-slider-change.test.ts +71 -0
- package/src/views/slides/test/slide.template.on-change.test.ts +2 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
2
|
+
import type { StoreState } from '../../reducers';
|
|
3
|
+
export declare const NEXT_SLIDE: "@@slide/NEXT_SLIDE";
|
|
4
|
+
declare type NextSlidePayload = {
|
|
5
|
+
currentSlideRef: string;
|
|
6
|
+
nextSlideRef: string;
|
|
7
|
+
animationType: string;
|
|
8
|
+
};
|
|
9
|
+
export declare type NextSlide = {
|
|
10
|
+
type: typeof NEXT_SLIDE;
|
|
11
|
+
payload: NextSlidePayload;
|
|
12
|
+
};
|
|
13
|
+
export declare const nextSlide: (dispatch: Dispatch, getState: () => StoreState) => NextSlide;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import get from 'lodash/fp/get';
|
|
2
|
+
export const NEXT_SLIDE = '@@slide/NEXT_SLIDE';
|
|
3
|
+
export const nextSlide = (dispatch, getState) => {
|
|
4
|
+
const state = getState();
|
|
5
|
+
const payload = {
|
|
6
|
+
currentSlideRef: get(['ui', 'currentSlideRef'], state),
|
|
7
|
+
nextSlideRef: get(['data', 'progression', 'state', 'nextContent', 'ref'], state),
|
|
8
|
+
animationType: state.data.progression?.state.isCorrect ? 'unstack' : 'restack'
|
|
9
|
+
};
|
|
10
|
+
const action = {
|
|
11
|
+
type: NEXT_SLIDE,
|
|
12
|
+
payload
|
|
13
|
+
};
|
|
14
|
+
return dispatch(action);
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import pipe from 'lodash/fp/pipe';
|
|
3
|
+
import set from 'lodash/fp/set';
|
|
4
|
+
import { nextSlide, NEXT_SLIDE } from '../next-slide';
|
|
5
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
6
|
+
import { getChoicesCorrection, postAnswerResponses, services } from '../../../test/util/services.mock';
|
|
7
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
8
|
+
import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
|
|
9
|
+
const progression = postAnswerResponses[freeTextSlide.universalRef];
|
|
10
|
+
const skillRef = '_skill-ref';
|
|
11
|
+
const answer = ['Vous isoler dans un lieu calme'];
|
|
12
|
+
const state = {
|
|
13
|
+
data: {
|
|
14
|
+
progression,
|
|
15
|
+
slides: {
|
|
16
|
+
[freeTextSlide.universalRef]: freeTextSlide,
|
|
17
|
+
[qcmGraphicSlide.universalRef]: qcmGraphicSlide
|
|
18
|
+
},
|
|
19
|
+
skills: [{ skillRef, custom: false, name: skillRef, slidesToReview: 5 }],
|
|
20
|
+
token: '1234',
|
|
21
|
+
corrections: { [freeTextSlide.universalRef]: getChoicesCorrection(freeTextSlide.universalRef) },
|
|
22
|
+
rank: { start: 93 }
|
|
23
|
+
},
|
|
24
|
+
ui: {
|
|
25
|
+
currentSlideRef: freeTextSlide._id,
|
|
26
|
+
navigation: ['loader', 'slides'],
|
|
27
|
+
answers: answer,
|
|
28
|
+
slide: {
|
|
29
|
+
validateButton: false,
|
|
30
|
+
animateCorrectionPopin: true,
|
|
31
|
+
showCorrectionPopin: true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
test('should dispatch NEXT_SLIDE action when nextSlide is called and the progression state is correct', t => {
|
|
36
|
+
const expectedActions = [
|
|
37
|
+
{
|
|
38
|
+
type: NEXT_SLIDE,
|
|
39
|
+
payload: {
|
|
40
|
+
currentSlideRef: freeTextSlide.universalRef,
|
|
41
|
+
nextSlideRef: qcmGraphicSlide.universalRef,
|
|
42
|
+
animationType: 'unstack'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
const { dispatch } = createTestStore(t, state, services, expectedActions);
|
|
47
|
+
dispatch(nextSlide);
|
|
48
|
+
});
|
|
49
|
+
test('should dispatch NEXT_SLIDE action when nextSlide is called and the progression state is not correct', t => {
|
|
50
|
+
const stateWithWrongAnswer = pipe(set(['data', 'progression', 'state', 'isCorrect'], false), set(['data', 'progression', 'state', 'allAnswers', 0, 'isCorrect'], false))(state);
|
|
51
|
+
const expectedActions = [
|
|
52
|
+
{
|
|
53
|
+
type: NEXT_SLIDE,
|
|
54
|
+
payload: {
|
|
55
|
+
currentSlideRef: freeTextSlide.universalRef,
|
|
56
|
+
nextSlideRef: qcmGraphicSlide.universalRef,
|
|
57
|
+
animationType: 'restack'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
const { dispatch } = createTestStore(t, stateWithWrongAnswer, services, expectedActions);
|
|
62
|
+
dispatch(nextSlide);
|
|
63
|
+
});
|
package/es/index.js
CHANGED
|
@@ -11,21 +11,18 @@ import { postProgression } from './actions/api/post-progression';
|
|
|
11
11
|
import { VIEWS } from './common';
|
|
12
12
|
import { mapStateToSlidesProps } from './views/slides';
|
|
13
13
|
import { mapStateToSkillsProps } from './views/skills';
|
|
14
|
-
const ConnectedApp = (
|
|
14
|
+
const ConnectedApp = () => {
|
|
15
15
|
const dispatch = useDispatch();
|
|
16
16
|
const props = {
|
|
17
17
|
viewName: useSelector((state) => state.ui.navigation[state.ui.navigation.length - 1]),
|
|
18
|
-
slides: useSelector((state) => mapStateToSlidesProps(state, dispatch
|
|
18
|
+
slides: useSelector((state) => mapStateToSlidesProps(state, dispatch)),
|
|
19
19
|
skills: useSelector((state) => mapStateToSkillsProps(state))
|
|
20
20
|
};
|
|
21
|
-
// eslint-disable-next-line no-console
|
|
22
|
-
console.log(props);
|
|
23
21
|
return React.createElement(AppReviewTemplate, { ...props });
|
|
24
22
|
};
|
|
25
23
|
const AppReview = ({ options }) => {
|
|
26
24
|
const [store, setStore] = useState(null);
|
|
27
25
|
const [isProgressionCreated, setIsProgressionCreated] = useState(false);
|
|
28
|
-
const onQuitClick = get('onQuitClick', options);
|
|
29
26
|
useEffect(() => {
|
|
30
27
|
if (store)
|
|
31
28
|
return;
|
|
@@ -69,6 +66,6 @@ const AppReview = ({ options }) => {
|
|
|
69
66
|
if (!store)
|
|
70
67
|
return null;
|
|
71
68
|
return (React.createElement(Provider, { store: store },
|
|
72
|
-
React.createElement(ConnectedApp,
|
|
69
|
+
React.createElement(ConnectedApp, null)));
|
|
73
70
|
};
|
|
74
71
|
export default AppReview;
|
package/es/test/index.test.js
CHANGED
|
@@ -36,15 +36,8 @@ const clickAllSlides = async (t, container, accumulator = 0) => {
|
|
|
36
36
|
};
|
|
37
37
|
const appOptions = {
|
|
38
38
|
token: process.env.API_TEST_TOKEN || '',
|
|
39
|
-
templateContext: {
|
|
40
|
-
theme: { color: { primary: '#123' } }
|
|
41
|
-
},
|
|
42
39
|
skillRef: 'skill_NJC0jFKoH',
|
|
43
|
-
services
|
|
44
|
-
onQuitClick: () => {
|
|
45
|
-
// eslint-disable-next-line no-console
|
|
46
|
-
console.log('onQuitClick - options');
|
|
47
|
-
}
|
|
40
|
+
services
|
|
48
41
|
};
|
|
49
42
|
test('should show the loader while the app is fetching the data', async (t) => {
|
|
50
43
|
t.plan(2);
|
package/es/types/common.d.ts
CHANGED
|
@@ -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;
|
package/es/types/slides.d.ts
CHANGED
|
@@ -44,8 +44,9 @@ export declare type DropDown = {
|
|
|
44
44
|
export declare type QuestionRange = {
|
|
45
45
|
type: 'slider';
|
|
46
46
|
placeholder?: string;
|
|
47
|
-
onChange?:
|
|
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
|
|
92
|
+
export declare const mapStateToSlidesProps: (state: StoreState, dispatch: Dispatch) => SlidesViewProps;
|
|
93
93
|
export {};
|
package/es/views/slides/index.js
CHANGED
|
@@ -163,7 +163,7 @@ const getCorrectionPopinProps = (isCorrect, correctAnswer, klf) => ({
|
|
|
163
163
|
},
|
|
164
164
|
type: isCorrect ? 'right' : 'wrong'
|
|
165
165
|
});
|
|
166
|
-
export const mapStateToSlidesProps = (state, dispatch
|
|
166
|
+
export const mapStateToSlidesProps = (state, dispatch) => {
|
|
167
167
|
const currentSlideRef = get(['ui', 'currentSlideRef'], state);
|
|
168
168
|
const correction = get(['data', 'corrections', currentSlideRef], state);
|
|
169
169
|
const isCorrect = get(['data', 'progression', 'state', 'isCorrect'], state);
|
|
@@ -173,7 +173,8 @@ export const mapStateToSlidesProps = (state, dispatch, onQuitClick) => {
|
|
|
173
173
|
mode: '__revision_mode',
|
|
174
174
|
skillName: '__agility',
|
|
175
175
|
onQuitClick: () => {
|
|
176
|
-
|
|
176
|
+
// eslint-disable-next-line no-console
|
|
177
|
+
console.log('onQuitClick');
|
|
177
178
|
},
|
|
178
179
|
'aria-label': 'aria-header-wrapper',
|
|
179
180
|
closeButtonAriaLabel: 'aria-close-button',
|
|
@@ -132,8 +132,13 @@ const sliderProps = (dispatch) => (answers, question) => {
|
|
|
132
132
|
title: `${currentValue} ${question.content.unitLabel}`,
|
|
133
133
|
value: sliderPosition,
|
|
134
134
|
onChange: (position) => {
|
|
135
|
+
// atom/range handler
|
|
135
136
|
const newValue = pipe(multiply(maxValue), round, get(__, values), _toString)(position);
|
|
136
137
|
dispatch(editAnswer([newValue]));
|
|
138
|
+
},
|
|
139
|
+
onSliderChange: (newValue) => {
|
|
140
|
+
// mobile/slider handler
|
|
141
|
+
dispatch(editAnswer([`${newValue}`]));
|
|
137
142
|
}
|
|
138
143
|
};
|
|
139
144
|
};
|
|
@@ -57,7 +57,7 @@ test('should create initial props when fetched slide is not still received', t =
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
const props = mapStateToSlidesProps(state, identity
|
|
60
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
61
61
|
t.is(props.congratsProps, undefined);
|
|
62
62
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
63
63
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -146,7 +146,7 @@ test('should create props when first slide is on the state', t => {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
|
-
const props = mapStateToSlidesProps(state, identity
|
|
149
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
150
150
|
t.is(props.congratsProps, undefined);
|
|
151
151
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
152
152
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -248,7 +248,7 @@ test('should create props when slide is on the state and user has selected answe
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
|
-
const props = mapStateToSlidesProps(state, identity
|
|
251
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
252
252
|
t.is(props.congratsProps, undefined);
|
|
253
253
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
254
254
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -351,7 +351,7 @@ test('should verify props when first slide was answered correctly and next slide
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
};
|
|
354
|
-
const props = mapStateToSlidesProps(state, identity
|
|
354
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
355
355
|
t.is(props.congratsProps, undefined);
|
|
356
356
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
357
357
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -454,7 +454,7 @@ test('should verify props when first slide was answered with error and next slid
|
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
};
|
|
457
|
-
const props = mapStateToSlidesProps(state, identity
|
|
457
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
458
458
|
t.is(props.congratsProps, undefined);
|
|
459
459
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
460
460
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -517,7 +517,7 @@ test('should verify props when first slide was answered, next slide is fetched &
|
|
|
517
517
|
}
|
|
518
518
|
}
|
|
519
519
|
};
|
|
520
|
-
const props = mapStateToSlidesProps(state, identity
|
|
520
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
521
521
|
t.is(props.congratsProps, undefined);
|
|
522
522
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
523
523
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -628,7 +628,7 @@ test('should verify props when first slide was answered incorrectly, next slide
|
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
};
|
|
631
|
-
const props = mapStateToSlidesProps(state, identity
|
|
631
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
632
632
|
t.is(props.congratsProps, undefined);
|
|
633
633
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
634
634
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -737,7 +737,7 @@ test('should verify props when currentSlideRef has changed to nextContent of pro
|
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
739
|
};
|
|
740
|
-
const props = mapStateToSlidesProps(state, identity
|
|
740
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
741
741
|
t.is(props.congratsProps, undefined);
|
|
742
742
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
743
743
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -806,7 +806,7 @@ test('should verify props when progression is in success', t => {
|
|
|
806
806
|
}
|
|
807
807
|
}
|
|
808
808
|
};
|
|
809
|
-
const props = mapStateToSlidesProps(state, identity
|
|
809
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
810
810
|
t.is(props.congratsProps, undefined);
|
|
811
811
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
812
812
|
'aria-label': 'aria-header-wrapper',
|
|
@@ -875,7 +875,7 @@ test('should verify props when progression has answered a current pendingSlide',
|
|
|
875
875
|
}
|
|
876
876
|
}
|
|
877
877
|
};
|
|
878
|
-
const props = mapStateToSlidesProps(state, identity
|
|
878
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
879
879
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
880
880
|
'aria-label': 'aria-header-wrapper',
|
|
881
881
|
closeButtonAriaLabel: 'aria-close-button',
|
|
@@ -942,7 +942,7 @@ test('should verify props when progression still has a pendingSlide', t => {
|
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
944
|
};
|
|
945
|
-
const props = mapStateToSlidesProps(state, identity
|
|
945
|
+
const props = mapStateToSlidesProps(state, identity);
|
|
946
946
|
t.deepEqual(omit(['onQuitClick'], props.header), {
|
|
947
947
|
'aria-label': 'aria-header-wrapper',
|
|
948
948
|
closeButtonAriaLabel: 'aria-close-button',
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import omit from 'lodash/fp/omit';
|
|
3
3
|
import get from 'lodash/fp/get';
|
|
4
|
-
import identity from 'lodash/fp/identity';
|
|
5
4
|
import { mapStateToSlidesProps } from '..';
|
|
6
5
|
import { services } from '../../../test/util/services.mock';
|
|
7
6
|
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
@@ -57,7 +56,7 @@ test('should dispatch EDIT_BASIC action via the property onChange of a Free Text
|
|
|
57
56
|
}
|
|
58
57
|
];
|
|
59
58
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
60
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
59
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
60
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
62
61
|
animateCorrectionPopin: false,
|
|
63
62
|
showCorrectionPopin: false,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import omit from 'lodash/fp/omit';
|
|
3
3
|
import get from 'lodash/fp/get';
|
|
4
|
-
import identity from 'lodash/fp/identity';
|
|
5
4
|
import { mapStateToSlidesProps } from '..';
|
|
6
5
|
import { services } from '../../../test/util/services.mock';
|
|
7
6
|
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
@@ -57,7 +56,7 @@ test('should dispatch EDIT_QCM_DRAG action via the property onClick of a QCM Dra
|
|
|
57
56
|
}
|
|
58
57
|
];
|
|
59
58
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
60
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
59
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
60
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
62
61
|
animateCorrectionPopin: false,
|
|
63
62
|
showCorrectionPopin: false,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import omit from 'lodash/fp/omit';
|
|
3
3
|
import get from 'lodash/fp/get';
|
|
4
|
-
import identity from 'lodash/fp/identity';
|
|
5
4
|
import { mapStateToSlidesProps } from '..';
|
|
6
5
|
import { services } from '../../../test/util/services.mock';
|
|
7
6
|
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
@@ -57,7 +56,7 @@ test('should dispatch EDIT_QCM_GRAPHIC action via the property onClick of a QCM
|
|
|
57
56
|
}
|
|
58
57
|
];
|
|
59
58
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
60
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
59
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
60
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
62
61
|
animateCorrectionPopin: false,
|
|
63
62
|
showCorrectionPopin: false,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import omit from 'lodash/fp/omit';
|
|
3
3
|
import get from 'lodash/fp/get';
|
|
4
|
-
import identity from 'lodash/fp/identity';
|
|
5
4
|
import { mapStateToSlidesProps } from '..';
|
|
6
5
|
import { services } from '../../../test/util/services.mock';
|
|
7
6
|
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
@@ -59,7 +58,7 @@ test('should dispatch EDIT_QCM action via the property onClick of a QCM slide',
|
|
|
59
58
|
}
|
|
60
59
|
];
|
|
61
60
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
62
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
61
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
63
62
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
64
63
|
animateCorrectionPopin: false,
|
|
65
64
|
showCorrectionPopin: false,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import omit from 'lodash/fp/omit';
|
|
3
3
|
import get from 'lodash/fp/get';
|
|
4
|
-
import identity from 'lodash/fp/identity';
|
|
5
4
|
import { mapStateToSlidesProps } from '..';
|
|
6
5
|
import { services } from '../../../test/util/services.mock';
|
|
7
6
|
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
@@ -57,7 +56,7 @@ test('should dispatch EDIT_SLIDER action via the property onChange of a Slider s
|
|
|
57
56
|
}
|
|
58
57
|
];
|
|
59
58
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
60
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
59
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
60
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
62
61
|
animateCorrectionPopin: false,
|
|
63
62
|
showCorrectionPopin: false,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import get from 'lodash/fp/get';
|
|
3
|
+
import { mapStateToSlidesProps } from '..';
|
|
4
|
+
import { services } from '../../../test/util/services.mock';
|
|
5
|
+
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
6
|
+
import { EDIT_SLIDER } from '../../../actions/ui/answers';
|
|
7
|
+
import { sliderSlide } from './fixtures/slider';
|
|
8
|
+
const progression = {
|
|
9
|
+
_id: '123456789123',
|
|
10
|
+
content: { type: 'skill', ref: '_skill-ref' },
|
|
11
|
+
engine: {
|
|
12
|
+
ref: 'review'
|
|
13
|
+
},
|
|
14
|
+
state: {
|
|
15
|
+
allAnswers: [],
|
|
16
|
+
isCorrect: true,
|
|
17
|
+
nextContent: {
|
|
18
|
+
ref: sliderSlide._id,
|
|
19
|
+
type: 'slide'
|
|
20
|
+
},
|
|
21
|
+
pendingSlides: [],
|
|
22
|
+
slides: [],
|
|
23
|
+
step: {
|
|
24
|
+
current: 1
|
|
25
|
+
},
|
|
26
|
+
stars: 0
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const initialState = {
|
|
30
|
+
data: {
|
|
31
|
+
progression,
|
|
32
|
+
slides: {
|
|
33
|
+
[sliderSlide._id]: sliderSlide
|
|
34
|
+
},
|
|
35
|
+
skills: [],
|
|
36
|
+
token: '1234',
|
|
37
|
+
corrections: {},
|
|
38
|
+
rank: {}
|
|
39
|
+
},
|
|
40
|
+
ui: {
|
|
41
|
+
currentSlideRef: sliderSlide._id,
|
|
42
|
+
navigation: ['skills', 'slides'],
|
|
43
|
+
answers: [],
|
|
44
|
+
slide: {
|
|
45
|
+
validateButton: false
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
test('should dispatch EDIT_SLIDER action via the property onSliderChange of a Slider slide', t => {
|
|
50
|
+
t.plan(1);
|
|
51
|
+
const expectedActions = [
|
|
52
|
+
{
|
|
53
|
+
type: EDIT_SLIDER,
|
|
54
|
+
payload: ['111']
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
58
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
59
|
+
const SlideProps = props.stack.slides['0'].answerUI?.model;
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
61
|
+
const onSliderChange = get('onSliderChange', SlideProps);
|
|
62
|
+
onSliderChange(111);
|
|
63
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import omit from 'lodash/fp/omit';
|
|
3
3
|
import get from 'lodash/fp/get';
|
|
4
|
-
import identity from 'lodash/fp/identity';
|
|
5
4
|
import { mapStateToSlidesProps } from '..';
|
|
6
5
|
import { services } from '../../../test/util/services.mock';
|
|
7
6
|
import { createTestStore } from '../../../actions/test/create-test-store';
|
|
@@ -52,7 +51,7 @@ test('should dispatch EDIT_TEMPLATE action via the property onChange of a Templa
|
|
|
52
51
|
t.plan(2);
|
|
53
52
|
const expectedActions = [{ type: EDIT_TEMPLATE, payload: ['', 'test', ''] }];
|
|
54
53
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
55
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
54
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
56
55
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
57
56
|
animateCorrectionPopin: false,
|
|
58
57
|
showCorrectionPopin: false,
|
|
@@ -70,7 +69,7 @@ test('should dispatch EDIT_TEMPLATE action via the property onChange of a Templa
|
|
|
70
69
|
t.plan(2);
|
|
71
70
|
const expectedActions = [{ type: EDIT_TEMPLATE, payload: ['Catalogue', '', ''] }];
|
|
72
71
|
const { dispatch, getState } = createTestStore(t, initialState, services, expectedActions);
|
|
73
|
-
const props = mapStateToSlidesProps(getState(), dispatch
|
|
72
|
+
const props = mapStateToSlidesProps(getState(), dispatch);
|
|
74
73
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
75
74
|
animateCorrectionPopin: false,
|
|
76
75
|
showCorrectionPopin: false,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
2
|
+
import type { StoreState } from '../../reducers';
|
|
3
|
+
export declare const NEXT_SLIDE: "@@slide/NEXT_SLIDE";
|
|
4
|
+
declare type NextSlidePayload = {
|
|
5
|
+
currentSlideRef: string;
|
|
6
|
+
nextSlideRef: string;
|
|
7
|
+
animationType: string;
|
|
8
|
+
};
|
|
9
|
+
export declare type NextSlide = {
|
|
10
|
+
type: typeof NEXT_SLIDE;
|
|
11
|
+
payload: NextSlidePayload;
|
|
12
|
+
};
|
|
13
|
+
export declare const nextSlide: (dispatch: Dispatch, getState: () => StoreState) => NextSlide;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import get from 'lodash/fp/get';
|
|
2
|
+
export var NEXT_SLIDE = '@@slide/NEXT_SLIDE';
|
|
3
|
+
export var nextSlide = function (dispatch, getState) {
|
|
4
|
+
var _a;
|
|
5
|
+
var state = getState();
|
|
6
|
+
var payload = {
|
|
7
|
+
currentSlideRef: get(['ui', 'currentSlideRef'], state),
|
|
8
|
+
nextSlideRef: get(['data', 'progression', 'state', 'nextContent', 'ref'], state),
|
|
9
|
+
animationType: ((_a = state.data.progression) === null || _a === void 0 ? void 0 : _a.state.isCorrect) ? 'unstack' : 'restack'
|
|
10
|
+
};
|
|
11
|
+
var action = {
|
|
12
|
+
type: NEXT_SLIDE,
|
|
13
|
+
payload: payload
|
|
14
|
+
};
|
|
15
|
+
return dispatch(action);
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var _a, _b;
|
|
2
|
+
import test from 'ava';
|
|
3
|
+
import pipe from 'lodash/fp/pipe';
|
|
4
|
+
import set from 'lodash/fp/set';
|
|
5
|
+
import { nextSlide, NEXT_SLIDE } from '../next-slide';
|
|
6
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
7
|
+
import { getChoicesCorrection, postAnswerResponses, services } from '../../../test/util/services.mock';
|
|
8
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
9
|
+
import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
|
|
10
|
+
var progression = postAnswerResponses[freeTextSlide.universalRef];
|
|
11
|
+
var skillRef = '_skill-ref';
|
|
12
|
+
var answer = ['Vous isoler dans un lieu calme'];
|
|
13
|
+
var state = {
|
|
14
|
+
data: {
|
|
15
|
+
progression: progression,
|
|
16
|
+
slides: (_a = {},
|
|
17
|
+
_a[freeTextSlide.universalRef] = freeTextSlide,
|
|
18
|
+
_a[qcmGraphicSlide.universalRef] = qcmGraphicSlide,
|
|
19
|
+
_a),
|
|
20
|
+
skills: [{ skillRef: skillRef, custom: false, name: skillRef, slidesToReview: 5 }],
|
|
21
|
+
token: '1234',
|
|
22
|
+
corrections: (_b = {}, _b[freeTextSlide.universalRef] = getChoicesCorrection(freeTextSlide.universalRef), _b),
|
|
23
|
+
rank: { start: 93 }
|
|
24
|
+
},
|
|
25
|
+
ui: {
|
|
26
|
+
currentSlideRef: freeTextSlide._id,
|
|
27
|
+
navigation: ['loader', 'slides'],
|
|
28
|
+
answers: answer,
|
|
29
|
+
slide: {
|
|
30
|
+
validateButton: false,
|
|
31
|
+
animateCorrectionPopin: true,
|
|
32
|
+
showCorrectionPopin: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
test('should dispatch NEXT_SLIDE action when nextSlide is called and the progression state is correct', function (t) {
|
|
37
|
+
var expectedActions = [
|
|
38
|
+
{
|
|
39
|
+
type: NEXT_SLIDE,
|
|
40
|
+
payload: {
|
|
41
|
+
currentSlideRef: freeTextSlide.universalRef,
|
|
42
|
+
nextSlideRef: qcmGraphicSlide.universalRef,
|
|
43
|
+
animationType: 'unstack'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
var dispatch = createTestStore(t, state, services, expectedActions).dispatch;
|
|
48
|
+
dispatch(nextSlide);
|
|
49
|
+
});
|
|
50
|
+
test('should dispatch NEXT_SLIDE action when nextSlide is called and the progression state is not correct', function (t) {
|
|
51
|
+
var stateWithWrongAnswer = pipe(set(['data', 'progression', 'state', 'isCorrect'], false), set(['data', 'progression', 'state', 'allAnswers', 0, 'isCorrect'], false))(state);
|
|
52
|
+
var expectedActions = [
|
|
53
|
+
{
|
|
54
|
+
type: NEXT_SLIDE,
|
|
55
|
+
payload: {
|
|
56
|
+
currentSlideRef: freeTextSlide.universalRef,
|
|
57
|
+
nextSlideRef: qcmGraphicSlide.universalRef,
|
|
58
|
+
animationType: 'restack'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
var dispatch = createTestStore(t, stateWithWrongAnswer, services, expectedActions).dispatch;
|
|
63
|
+
dispatch(nextSlide);
|
|
64
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -22,23 +22,19 @@ import { postProgression } from './actions/api/post-progression';
|
|
|
22
22
|
import { VIEWS } from './common';
|
|
23
23
|
import { mapStateToSlidesProps } from './views/slides';
|
|
24
24
|
import { mapStateToSkillsProps } from './views/skills';
|
|
25
|
-
var ConnectedApp = function (
|
|
26
|
-
var onQuitClick = _a.onQuitClick;
|
|
25
|
+
var ConnectedApp = function () {
|
|
27
26
|
var dispatch = useDispatch();
|
|
28
27
|
var props = {
|
|
29
28
|
viewName: useSelector(function (state) { return state.ui.navigation[state.ui.navigation.length - 1]; }),
|
|
30
|
-
slides: useSelector(function (state) { return mapStateToSlidesProps(state, dispatch
|
|
29
|
+
slides: useSelector(function (state) { return mapStateToSlidesProps(state, dispatch); }),
|
|
31
30
|
skills: useSelector(function (state) { return mapStateToSkillsProps(state); })
|
|
32
31
|
};
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.log(props);
|
|
35
32
|
return React.createElement(AppReviewTemplate, __assign({}, props));
|
|
36
33
|
};
|
|
37
34
|
var AppReview = function (_a) {
|
|
38
35
|
var options = _a.options;
|
|
39
36
|
var _b = useState(null), store = _b[0], setStore = _b[1];
|
|
40
37
|
var _c = useState(false), isProgressionCreated = _c[0], setIsProgressionCreated = _c[1];
|
|
41
|
-
var onQuitClick = get('onQuitClick', options);
|
|
42
38
|
useEffect(function () {
|
|
43
39
|
if (store)
|
|
44
40
|
return;
|
|
@@ -82,6 +78,6 @@ var AppReview = function (_a) {
|
|
|
82
78
|
if (!store)
|
|
83
79
|
return null;
|
|
84
80
|
return (React.createElement(Provider, { store: store },
|
|
85
|
-
React.createElement(ConnectedApp,
|
|
81
|
+
React.createElement(ConnectedApp, null)));
|
|
86
82
|
};
|
|
87
83
|
export default AppReview;
|