@coorpacademy/app-review 0.2.1-alpha.10 → 0.2.1
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/api/fetch-correction.d.ts +10 -1
- package/es/actions/api/fetch-correction.js +7 -8
- package/es/actions/api/test/fetch-correction.test.js +19 -3
- package/es/index.js +4 -1
- package/es/reducers/data/corrections.d.ts +6 -0
- package/es/reducers/data/corrections.js +21 -0
- package/es/reducers/data/test/corrections.test.d.ts +1 -0
- package/es/reducers/data/test/corrections.test.js +27 -0
- package/es/reducers/data/test/skills.test.js +1 -1
- package/es/reducers/data/test/slides.test.js +4 -3
- package/es/test/util/services.mock.js +0 -3
- package/es/views/slides/index.js +2 -2
- package/lib/actions/api/fetch-correction.d.ts +10 -1
- package/lib/actions/api/fetch-correction.js +7 -8
- package/lib/actions/api/test/fetch-correction.test.js +19 -3
- package/lib/index.js +4 -1
- package/lib/reducers/data/corrections.d.ts +6 -0
- package/lib/reducers/data/corrections.js +22 -0
- package/lib/reducers/data/test/corrections.test.d.ts +1 -0
- package/lib/reducers/data/test/corrections.test.js +28 -0
- package/lib/reducers/data/test/skills.test.js +1 -1
- package/lib/reducers/data/test/slides.test.js +7 -5
- package/lib/test/util/services.mock.js +0 -3
- package/lib/views/slides/index.js +2 -2
- package/package.json +4 -4
- package/src/actions/api/fetch-correction.ts +15 -9
- package/src/actions/api/test/fetch-correction.test.ts +19 -3
- package/src/index.tsx +6 -1
- package/src/reducers/data/corrections.ts +36 -0
- package/src/reducers/data/test/corrections.test.ts +36 -0
- package/src/reducers/data/test/skills.test.ts +1 -1
- package/src/reducers/data/test/slides.test.ts +4 -3
- package/src/test/util/services.mock.ts +0 -3
- package/src/views/slides/index.ts +2 -2
|
@@ -5,7 +5,16 @@ export declare const CORRECTION_FETCH_REQUEST: "@@correction/FETCH_REQUEST";
|
|
|
5
5
|
export declare const CORRECTION_FETCH_SUCCESS: "@@correction/FETCH_SUCCESS";
|
|
6
6
|
export declare const CORRECTION_FETCH_FAILURE: "@@correction/FETCH_FAILURE";
|
|
7
7
|
export declare type FetchCorrection = {
|
|
8
|
+
type: typeof CORRECTION_FETCH_REQUEST;
|
|
9
|
+
meta: {
|
|
10
|
+
slideRef: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare type ReceivedCorrection = {
|
|
8
14
|
type: typeof CORRECTION_FETCH_SUCCESS;
|
|
9
15
|
payload: CorrectionFromAPI | void;
|
|
16
|
+
meta: {
|
|
17
|
+
slideRef: string;
|
|
18
|
+
};
|
|
10
19
|
};
|
|
11
|
-
export declare const fetchCorrection: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) =>
|
|
20
|
+
export declare const fetchCorrection: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => ReceivedCorrection;
|
|
@@ -4,16 +4,15 @@ export const CORRECTION_FETCH_REQUEST = '@@correction/FETCH_REQUEST';
|
|
|
4
4
|
export const CORRECTION_FETCH_SUCCESS = '@@correction/FETCH_SUCCESS';
|
|
5
5
|
export const CORRECTION_FETCH_FAILURE = '@@correction/FETCH_FAILURE';
|
|
6
6
|
export const fetchCorrection = (dispatch, getState, { services }) => {
|
|
7
|
+
const state = getState();
|
|
8
|
+
const slideRef = get(['ui', 'currentSlideRef'], state);
|
|
9
|
+
const token = get(['data', 'token'], state);
|
|
10
|
+
const progressionId = get(['data', 'progression', '_id'], state);
|
|
11
|
+
const answer = get(['ui', 'answers'], state);
|
|
7
12
|
const action = buildTask({
|
|
8
13
|
types: [CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_FAILURE],
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const token = get(['data', 'token'], state);
|
|
12
|
-
const progressionId = get(['data', 'progression', '_id'], state);
|
|
13
|
-
const answer = get(['ui', 'answers'], state);
|
|
14
|
-
const slideRef = get(['ui', 'currentSlideRef'], state);
|
|
15
|
-
return services.fetchCorrection(slideRef, token, progressionId, answer);
|
|
16
|
-
}
|
|
14
|
+
meta: { slideRef },
|
|
15
|
+
task: () => services.fetchCorrection(slideRef, token, progressionId, answer)
|
|
17
16
|
});
|
|
18
17
|
return dispatch(action);
|
|
19
18
|
};
|
|
@@ -39,10 +39,18 @@ test('should dispatch CORRECTION_FETCH_SUCCESS actions when fetchCorrection retu
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
const expectedActions = [
|
|
42
|
-
{
|
|
42
|
+
{
|
|
43
|
+
type: CORRECTION_FETCH_REQUEST,
|
|
44
|
+
meta: {
|
|
45
|
+
slideRef: freeTextSlide.universalRef
|
|
46
|
+
}
|
|
47
|
+
},
|
|
43
48
|
{
|
|
44
49
|
type: CORRECTION_FETCH_SUCCESS,
|
|
45
|
-
payload: getChoicesCorrection(freeTextSlide.universalRef)
|
|
50
|
+
payload: getChoicesCorrection(freeTextSlide.universalRef),
|
|
51
|
+
meta: {
|
|
52
|
+
slideRef: freeTextSlide.universalRef
|
|
53
|
+
}
|
|
46
54
|
}
|
|
47
55
|
];
|
|
48
56
|
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
@@ -61,9 +69,17 @@ test('should dispatch CORRECTION_FETCH_FAILURE action when fetchCorrection fails
|
|
|
61
69
|
}
|
|
62
70
|
};
|
|
63
71
|
const expectedActions = [
|
|
64
|
-
{
|
|
72
|
+
{
|
|
73
|
+
type: CORRECTION_FETCH_REQUEST,
|
|
74
|
+
meta: {
|
|
75
|
+
slideRef: freeTextSlide.universalRef
|
|
76
|
+
}
|
|
77
|
+
},
|
|
65
78
|
{
|
|
66
79
|
type: CORRECTION_FETCH_FAILURE,
|
|
80
|
+
meta: {
|
|
81
|
+
slideRef: freeTextSlide.universalRef
|
|
82
|
+
},
|
|
67
83
|
payload: new Error('unexpected'),
|
|
68
84
|
error: true
|
|
69
85
|
}
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { useSelector, useDispatch, Provider } from 'react-redux';
|
|
3
3
|
import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
|
|
4
|
+
import { TemplateContext } from '@coorpacademy/components/es/template/app-review/template-context';
|
|
4
5
|
import isEmpty from 'lodash/fp/isEmpty';
|
|
5
6
|
import get from 'lodash/fp/get';
|
|
6
7
|
import configureStore from './configure-store';
|
|
@@ -65,7 +66,9 @@ const AppReview = ({ options }) => {
|
|
|
65
66
|
}, [isProgressionCreated, options, store]);
|
|
66
67
|
if (!store)
|
|
67
68
|
return null;
|
|
69
|
+
const { templateContext: values } = options;
|
|
68
70
|
return (React.createElement(Provider, { store: store },
|
|
69
|
-
React.createElement(
|
|
71
|
+
React.createElement(TemplateContext, { values: values },
|
|
72
|
+
React.createElement(ConnectedApp, null))));
|
|
70
73
|
};
|
|
71
74
|
export default AppReview;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CorrectionFromAPI } from '../../types/common';
|
|
2
|
+
import { ReceivedCorrection, FetchCorrection } from '../../actions/api/fetch-correction';
|
|
3
|
+
export declare type CorrectionsState = Record<string, CorrectionFromAPI>;
|
|
4
|
+
export declare type CorrectionsAction = ReceivedCorrection | FetchCorrection;
|
|
5
|
+
declare const reducer: (state: CorrectionsState | undefined, action: CorrectionsAction) => CorrectionsState;
|
|
6
|
+
export default reducer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import set from 'lodash/fp/set';
|
|
2
|
+
import { CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_REQUEST } from '../../actions/api/fetch-correction';
|
|
3
|
+
const initialState = {};
|
|
4
|
+
const reducer = (
|
|
5
|
+
// eslint-disable-next-line default-param-last
|
|
6
|
+
state = initialState, action) => {
|
|
7
|
+
switch (action.type) {
|
|
8
|
+
case CORRECTION_FETCH_REQUEST: {
|
|
9
|
+
const { meta } = action;
|
|
10
|
+
return set(meta.slideRef, null, state);
|
|
11
|
+
}
|
|
12
|
+
case CORRECTION_FETCH_SUCCESS: {
|
|
13
|
+
const { meta } = action;
|
|
14
|
+
const correction = action.payload;
|
|
15
|
+
return set(meta.slideRef, correction, state);
|
|
16
|
+
}
|
|
17
|
+
default:
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export default reducer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import reducer from '../corrections';
|
|
3
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
4
|
+
import { CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS } from '../../../actions/api/fetch-correction';
|
|
5
|
+
import { getChoicesCorrection } from '../../../test/util/services.mock';
|
|
6
|
+
test('should have an initial empty record value', t => {
|
|
7
|
+
const state = reducer(undefined, {});
|
|
8
|
+
t.deepEqual(state, {});
|
|
9
|
+
});
|
|
10
|
+
test("should set the key (slide's id) of the correction to null when a CORRECTION_FETCH_REQUEST is received", t => {
|
|
11
|
+
const slideRef = freeTextSlide._id;
|
|
12
|
+
const state = reducer({}, { type: CORRECTION_FETCH_REQUEST, meta: { slideRef: freeTextSlide._id } });
|
|
13
|
+
t.deepEqual(state, {
|
|
14
|
+
[slideRef]: null
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
test('should set the value of CORRECTION_FETCH_SUCCESS', t => {
|
|
18
|
+
const expectedCorrection = getChoicesCorrection(freeTextSlide._id);
|
|
19
|
+
const state = reducer({}, {
|
|
20
|
+
type: CORRECTION_FETCH_SUCCESS,
|
|
21
|
+
payload: expectedCorrection,
|
|
22
|
+
meta: { slideRef: freeTextSlide._id }
|
|
23
|
+
});
|
|
24
|
+
t.deepEqual(state, {
|
|
25
|
+
sli_VJYjJnJhg: expectedCorrection
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import reducer from '../skills';
|
|
3
3
|
import { SKILLS_FETCH_SUCCESS } from '../../../actions/api/fetch-skills';
|
|
4
|
-
test('should have
|
|
4
|
+
test('should have initial value', t => {
|
|
5
5
|
const state = reducer(undefined, {});
|
|
6
6
|
t.deepEqual(state, []);
|
|
7
7
|
});
|
|
@@ -2,14 +2,15 @@ import test from 'ava';
|
|
|
2
2
|
import reducer from '../slides';
|
|
3
3
|
import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../../../actions/api/fetch-slide';
|
|
4
4
|
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
5
|
-
test('should have
|
|
5
|
+
test('should have initial value', t => {
|
|
6
6
|
const state = reducer(undefined, {});
|
|
7
7
|
t.deepEqual(state, {});
|
|
8
8
|
});
|
|
9
9
|
test('should set the value of SLIDE_FETCH_REQUEST action', t => {
|
|
10
|
-
const
|
|
10
|
+
const slideRef = 'sli_VJYjJnJhg';
|
|
11
|
+
const state = reducer({}, { type: SLIDE_FETCH_REQUEST, meta: { slideRef } });
|
|
11
12
|
t.deepEqual(state, {
|
|
12
|
-
slideRef: null
|
|
13
|
+
[slideRef]: null
|
|
13
14
|
});
|
|
14
15
|
});
|
|
15
16
|
test('should set the value of SLIDE_FETCH_SUCCESS action', t => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import get from 'lodash/fp/get';
|
|
2
|
-
import { qcmDragSlide } from '../../views/slides/test/fixtures/qcm-drag';
|
|
3
2
|
import { qcmSlide } from '../../views/slides/test/fixtures/qcm';
|
|
4
3
|
import { qcmGraphicSlide } from '../../views/slides/test/fixtures/qcm-graphic';
|
|
5
4
|
import { freeTextSlide } from '../../views/slides/test/fixtures/free-text';
|
|
@@ -22,8 +21,6 @@ const getSlideFixture = (ref) => {
|
|
|
22
21
|
return freeTextSlide;
|
|
23
22
|
case templateSlide.universalRef:
|
|
24
23
|
return templateSlide;
|
|
25
|
-
case qcmDragSlide.universalRef:
|
|
26
|
-
return qcmDragSlide;
|
|
27
24
|
default:
|
|
28
25
|
return sliderSlide;
|
|
29
26
|
}
|
package/es/views/slides/index.js
CHANGED
|
@@ -74,10 +74,10 @@ const buildStackSlides = (state, dispatch) => {
|
|
|
74
74
|
}, initialState, initialState);
|
|
75
75
|
return stack;
|
|
76
76
|
};
|
|
77
|
-
const getIconForCurrentStep = (slideRef, lastGivenAnswerForSlide, currentSlideRef,
|
|
77
|
+
const getIconForCurrentStep = (slideRef, lastGivenAnswerForSlide, currentSlideRef, lastGivenAnswer) => {
|
|
78
78
|
if (slideRef !== currentSlideRef)
|
|
79
79
|
return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
|
|
80
|
-
if (
|
|
80
|
+
if (lastGivenAnswer.slideRef !== slideRef)
|
|
81
81
|
return 'no-answer';
|
|
82
82
|
return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
|
|
83
83
|
};
|
|
@@ -5,7 +5,16 @@ export declare const CORRECTION_FETCH_REQUEST: "@@correction/FETCH_REQUEST";
|
|
|
5
5
|
export declare const CORRECTION_FETCH_SUCCESS: "@@correction/FETCH_SUCCESS";
|
|
6
6
|
export declare const CORRECTION_FETCH_FAILURE: "@@correction/FETCH_FAILURE";
|
|
7
7
|
export declare type FetchCorrection = {
|
|
8
|
+
type: typeof CORRECTION_FETCH_REQUEST;
|
|
9
|
+
meta: {
|
|
10
|
+
slideRef: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare type ReceivedCorrection = {
|
|
8
14
|
type: typeof CORRECTION_FETCH_SUCCESS;
|
|
9
15
|
payload: CorrectionFromAPI | void;
|
|
16
|
+
meta: {
|
|
17
|
+
slideRef: string;
|
|
18
|
+
};
|
|
10
19
|
};
|
|
11
|
-
export declare const fetchCorrection: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) =>
|
|
20
|
+
export declare const fetchCorrection: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => ReceivedCorrection;
|
|
@@ -5,16 +5,15 @@ export var CORRECTION_FETCH_SUCCESS = '@@correction/FETCH_SUCCESS';
|
|
|
5
5
|
export var CORRECTION_FETCH_FAILURE = '@@correction/FETCH_FAILURE';
|
|
6
6
|
export var fetchCorrection = function (dispatch, getState, _a) {
|
|
7
7
|
var services = _a.services;
|
|
8
|
+
var state = getState();
|
|
9
|
+
var slideRef = get(['ui', 'currentSlideRef'], state);
|
|
10
|
+
var token = get(['data', 'token'], state);
|
|
11
|
+
var progressionId = get(['data', 'progression', '_id'], state);
|
|
12
|
+
var answer = get(['ui', 'answers'], state);
|
|
8
13
|
var action = buildTask({
|
|
9
14
|
types: [CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_FAILURE],
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var token = get(['data', 'token'], state);
|
|
13
|
-
var progressionId = get(['data', 'progression', '_id'], state);
|
|
14
|
-
var answer = get(['ui', 'answers'], state);
|
|
15
|
-
var slideRef = get(['ui', 'currentSlideRef'], state);
|
|
16
|
-
return services.fetchCorrection(slideRef, token, progressionId, answer);
|
|
17
|
-
}
|
|
15
|
+
meta: { slideRef: slideRef },
|
|
16
|
+
task: function () { return services.fetchCorrection(slideRef, token, progressionId, answer); }
|
|
18
17
|
});
|
|
19
18
|
return dispatch(action);
|
|
20
19
|
};
|
|
@@ -88,10 +88,18 @@ test('should dispatch CORRECTION_FETCH_SUCCESS actions when fetchCorrection retu
|
|
|
88
88
|
return Promise.resolve(getChoicesCorrection(slideRef));
|
|
89
89
|
} });
|
|
90
90
|
expectedActions = [
|
|
91
|
-
{
|
|
91
|
+
{
|
|
92
|
+
type: CORRECTION_FETCH_REQUEST,
|
|
93
|
+
meta: {
|
|
94
|
+
slideRef: freeTextSlide.universalRef
|
|
95
|
+
}
|
|
96
|
+
},
|
|
92
97
|
{
|
|
93
98
|
type: CORRECTION_FETCH_SUCCESS,
|
|
94
|
-
payload: getChoicesCorrection(freeTextSlide.universalRef)
|
|
99
|
+
payload: getChoicesCorrection(freeTextSlide.universalRef),
|
|
100
|
+
meta: {
|
|
101
|
+
slideRef: freeTextSlide.universalRef
|
|
102
|
+
}
|
|
95
103
|
}
|
|
96
104
|
];
|
|
97
105
|
dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
|
|
@@ -116,9 +124,17 @@ test('should dispatch CORRECTION_FETCH_FAILURE action when fetchCorrection fails
|
|
|
116
124
|
return Promise.reject(new Error('unexpected'));
|
|
117
125
|
} });
|
|
118
126
|
expectedActions = [
|
|
119
|
-
{
|
|
127
|
+
{
|
|
128
|
+
type: CORRECTION_FETCH_REQUEST,
|
|
129
|
+
meta: {
|
|
130
|
+
slideRef: freeTextSlide.universalRef
|
|
131
|
+
}
|
|
132
|
+
},
|
|
120
133
|
{
|
|
121
134
|
type: CORRECTION_FETCH_FAILURE,
|
|
135
|
+
meta: {
|
|
136
|
+
slideRef: freeTextSlide.universalRef
|
|
137
|
+
},
|
|
122
138
|
payload: new Error('unexpected'),
|
|
123
139
|
error: true
|
|
124
140
|
}
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import React, { useEffect, useState } from 'react';
|
|
13
13
|
import { useSelector, useDispatch, Provider } from 'react-redux';
|
|
14
14
|
import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
|
|
15
|
+
import { TemplateContext } from '@coorpacademy/components/es/template/app-review/template-context';
|
|
15
16
|
import isEmpty from 'lodash/fp/isEmpty';
|
|
16
17
|
import get from 'lodash/fp/get';
|
|
17
18
|
import configureStore from './configure-store';
|
|
@@ -77,7 +78,9 @@ var AppReview = function (_a) {
|
|
|
77
78
|
}, [isProgressionCreated, options, store]);
|
|
78
79
|
if (!store)
|
|
79
80
|
return null;
|
|
81
|
+
var values = options.templateContext;
|
|
80
82
|
return (React.createElement(Provider, { store: store },
|
|
81
|
-
React.createElement(
|
|
83
|
+
React.createElement(TemplateContext, { values: values },
|
|
84
|
+
React.createElement(ConnectedApp, null))));
|
|
82
85
|
};
|
|
83
86
|
export default AppReview;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CorrectionFromAPI } from '../../types/common';
|
|
2
|
+
import { ReceivedCorrection, FetchCorrection } from '../../actions/api/fetch-correction';
|
|
3
|
+
export declare type CorrectionsState = Record<string, CorrectionFromAPI>;
|
|
4
|
+
export declare type CorrectionsAction = ReceivedCorrection | FetchCorrection;
|
|
5
|
+
declare const reducer: (state: CorrectionsState | undefined, action: CorrectionsAction) => CorrectionsState;
|
|
6
|
+
export default reducer;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import set from 'lodash/fp/set';
|
|
2
|
+
import { CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_REQUEST } from '../../actions/api/fetch-correction';
|
|
3
|
+
var initialState = {};
|
|
4
|
+
var reducer = function (
|
|
5
|
+
// eslint-disable-next-line default-param-last
|
|
6
|
+
state, action) {
|
|
7
|
+
if (state === void 0) { state = initialState; }
|
|
8
|
+
switch (action.type) {
|
|
9
|
+
case CORRECTION_FETCH_REQUEST: {
|
|
10
|
+
var meta = action.meta;
|
|
11
|
+
return set(meta.slideRef, null, state);
|
|
12
|
+
}
|
|
13
|
+
case CORRECTION_FETCH_SUCCESS: {
|
|
14
|
+
var meta = action.meta;
|
|
15
|
+
var correction = action.payload;
|
|
16
|
+
return set(meta.slideRef, correction, state);
|
|
17
|
+
}
|
|
18
|
+
default:
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export default reducer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import reducer from '../corrections';
|
|
3
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
4
|
+
import { CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS } from '../../../actions/api/fetch-correction';
|
|
5
|
+
import { getChoicesCorrection } from '../../../test/util/services.mock';
|
|
6
|
+
test('should have an initial empty record value', function (t) {
|
|
7
|
+
var state = reducer(undefined, {});
|
|
8
|
+
t.deepEqual(state, {});
|
|
9
|
+
});
|
|
10
|
+
test("should set the key (slide's id) of the correction to null when a CORRECTION_FETCH_REQUEST is received", function (t) {
|
|
11
|
+
var _a;
|
|
12
|
+
var slideRef = freeTextSlide._id;
|
|
13
|
+
var state = reducer({}, { type: CORRECTION_FETCH_REQUEST, meta: { slideRef: freeTextSlide._id } });
|
|
14
|
+
t.deepEqual(state, (_a = {},
|
|
15
|
+
_a[slideRef] = null,
|
|
16
|
+
_a));
|
|
17
|
+
});
|
|
18
|
+
test('should set the value of CORRECTION_FETCH_SUCCESS', function (t) {
|
|
19
|
+
var expectedCorrection = getChoicesCorrection(freeTextSlide._id);
|
|
20
|
+
var state = reducer({}, {
|
|
21
|
+
type: CORRECTION_FETCH_SUCCESS,
|
|
22
|
+
payload: expectedCorrection,
|
|
23
|
+
meta: { slideRef: freeTextSlide._id }
|
|
24
|
+
});
|
|
25
|
+
t.deepEqual(state, {
|
|
26
|
+
sli_VJYjJnJhg: expectedCorrection
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import reducer from '../skills';
|
|
3
3
|
import { SKILLS_FETCH_SUCCESS } from '../../../actions/api/fetch-skills';
|
|
4
|
-
test('should have
|
|
4
|
+
test('should have initial value', function (t) {
|
|
5
5
|
var state = reducer(undefined, {});
|
|
6
6
|
t.deepEqual(state, []);
|
|
7
7
|
});
|
|
@@ -2,15 +2,17 @@ import test from 'ava';
|
|
|
2
2
|
import reducer from '../slides';
|
|
3
3
|
import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../../../actions/api/fetch-slide';
|
|
4
4
|
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
5
|
-
test('should have
|
|
5
|
+
test('should have initial value', function (t) {
|
|
6
6
|
var state = reducer(undefined, {});
|
|
7
7
|
t.deepEqual(state, {});
|
|
8
8
|
});
|
|
9
9
|
test('should set the value of SLIDE_FETCH_REQUEST action', function (t) {
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
10
|
+
var _a;
|
|
11
|
+
var slideRef = 'sli_VJYjJnJhg';
|
|
12
|
+
var state = reducer({}, { type: SLIDE_FETCH_REQUEST, meta: { slideRef: slideRef } });
|
|
13
|
+
t.deepEqual(state, (_a = {},
|
|
14
|
+
_a[slideRef] = null,
|
|
15
|
+
_a));
|
|
14
16
|
});
|
|
15
17
|
test('should set the value of SLIDE_FETCH_SUCCESS action', function (t) {
|
|
16
18
|
var state = reducer({}, { type: SLIDE_FETCH_SUCCESS, payload: freeTextSlide, meta: { slideRef: 'sli_VJYjJnJhg' } });
|
|
@@ -11,7 +11,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
var _a;
|
|
13
13
|
import get from 'lodash/fp/get';
|
|
14
|
-
import { qcmDragSlide } from '../../views/slides/test/fixtures/qcm-drag';
|
|
15
14
|
import { qcmSlide } from '../../views/slides/test/fixtures/qcm';
|
|
16
15
|
import { qcmGraphicSlide } from '../../views/slides/test/fixtures/qcm-graphic';
|
|
17
16
|
import { freeTextSlide } from '../../views/slides/test/fixtures/free-text';
|
|
@@ -34,8 +33,6 @@ var getSlideFixture = function (ref) {
|
|
|
34
33
|
return freeTextSlide;
|
|
35
34
|
case templateSlide.universalRef:
|
|
36
35
|
return templateSlide;
|
|
37
|
-
case qcmDragSlide.universalRef:
|
|
38
|
-
return qcmDragSlide;
|
|
39
36
|
default:
|
|
40
37
|
return sliderSlide;
|
|
41
38
|
}
|
|
@@ -85,10 +85,10 @@ var buildStackSlides = function (state, dispatch) {
|
|
|
85
85
|
}, initialState, initialState);
|
|
86
86
|
return stack;
|
|
87
87
|
};
|
|
88
|
-
var getIconForCurrentStep = function (slideRef, lastGivenAnswerForSlide, currentSlideRef,
|
|
88
|
+
var getIconForCurrentStep = function (slideRef, lastGivenAnswerForSlide, currentSlideRef, lastGivenAnswer) {
|
|
89
89
|
if (slideRef !== currentSlideRef)
|
|
90
90
|
return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
|
|
91
|
-
if (
|
|
91
|
+
if (lastGivenAnswer.slideRef !== slideRef)
|
|
92
92
|
return 'no-answer';
|
|
93
93
|
return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
|
|
94
94
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coorpacademy/app-review",
|
|
3
|
-
"version": "0.2.1
|
|
3
|
+
"version": "0.2.1",
|
|
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.16
|
|
45
|
-
"@coorpacademy/redux-task": "1.1.5",
|
|
44
|
+
"@coorpacademy/components": "10.22.16",
|
|
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": "
|
|
81
|
+
"gitHead": "c060dbe987664394284b360e07f37d0344e6d2b4"
|
|
82
82
|
}
|
|
@@ -9,25 +9,31 @@ export const CORRECTION_FETCH_SUCCESS = '@@correction/FETCH_SUCCESS' as const;
|
|
|
9
9
|
export const CORRECTION_FETCH_FAILURE = '@@correction/FETCH_FAILURE' as const;
|
|
10
10
|
|
|
11
11
|
export type FetchCorrection = {
|
|
12
|
+
type: typeof CORRECTION_FETCH_REQUEST;
|
|
13
|
+
meta: {slideRef: string};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ReceivedCorrection = {
|
|
12
17
|
type: typeof CORRECTION_FETCH_SUCCESS;
|
|
13
18
|
payload: CorrectionFromAPI | void;
|
|
19
|
+
meta: {slideRef: string};
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
export const fetchCorrection = (
|
|
17
23
|
dispatch: Dispatch,
|
|
18
24
|
getState: () => StoreState,
|
|
19
25
|
{services}: Options
|
|
20
|
-
):
|
|
26
|
+
): ReceivedCorrection => {
|
|
27
|
+
const state = getState();
|
|
28
|
+
const slideRef = get(['ui', 'currentSlideRef'], state);
|
|
29
|
+
const token = get(['data', 'token'], state);
|
|
30
|
+
const progressionId = get(['data', 'progression', '_id'], state);
|
|
31
|
+
const answer = get(['ui', 'answers'], state);
|
|
32
|
+
|
|
21
33
|
const action = buildTask({
|
|
22
34
|
types: [CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_FAILURE],
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const token = get(['data', 'token'], state);
|
|
26
|
-
const progressionId = get(['data', 'progression', '_id'], state);
|
|
27
|
-
const answer = get(['ui', 'answers'], state);
|
|
28
|
-
const slideRef = get(['ui', 'currentSlideRef'], state);
|
|
29
|
-
return services.fetchCorrection(slideRef, token, progressionId, answer);
|
|
30
|
-
}
|
|
35
|
+
meta: {slideRef},
|
|
36
|
+
task: () => services.fetchCorrection(slideRef, token, progressionId, answer)
|
|
31
37
|
});
|
|
32
38
|
return dispatch(action);
|
|
33
39
|
};
|
|
@@ -54,10 +54,18 @@ test('should dispatch CORRECTION_FETCH_SUCCESS actions when fetchCorrection retu
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
const expectedActions = [
|
|
57
|
-
{
|
|
57
|
+
{
|
|
58
|
+
type: CORRECTION_FETCH_REQUEST,
|
|
59
|
+
meta: {
|
|
60
|
+
slideRef: freeTextSlide.universalRef
|
|
61
|
+
}
|
|
62
|
+
},
|
|
58
63
|
{
|
|
59
64
|
type: CORRECTION_FETCH_SUCCESS,
|
|
60
|
-
payload: getChoicesCorrection(freeTextSlide.universalRef)
|
|
65
|
+
payload: getChoicesCorrection(freeTextSlide.universalRef),
|
|
66
|
+
meta: {
|
|
67
|
+
slideRef: freeTextSlide.universalRef
|
|
68
|
+
}
|
|
61
69
|
}
|
|
62
70
|
];
|
|
63
71
|
|
|
@@ -80,9 +88,17 @@ test('should dispatch CORRECTION_FETCH_FAILURE action when fetchCorrection fails
|
|
|
80
88
|
};
|
|
81
89
|
|
|
82
90
|
const expectedActions = [
|
|
83
|
-
{
|
|
91
|
+
{
|
|
92
|
+
type: CORRECTION_FETCH_REQUEST,
|
|
93
|
+
meta: {
|
|
94
|
+
slideRef: freeTextSlide.universalRef
|
|
95
|
+
}
|
|
96
|
+
},
|
|
84
97
|
{
|
|
85
98
|
type: CORRECTION_FETCH_FAILURE,
|
|
99
|
+
meta: {
|
|
100
|
+
slideRef: freeTextSlide.universalRef
|
|
101
|
+
},
|
|
86
102
|
payload: new Error('unexpected'),
|
|
87
103
|
error: true
|
|
88
104
|
}
|
package/src/index.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import type {} from 'redux-thunk/extend-redux'; // https://github.com/reduxjs/re
|
|
|
3
3
|
import {AnyAction, Store} from 'redux';
|
|
4
4
|
import {useSelector, useDispatch, Provider} from 'react-redux';
|
|
5
5
|
import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
|
|
6
|
+
import {TemplateContext} from '@coorpacademy/components/es/template/app-review/template-context';
|
|
6
7
|
|
|
7
8
|
import isEmpty from 'lodash/fp/isEmpty';
|
|
8
9
|
import get from 'lodash/fp/get';
|
|
@@ -86,9 +87,13 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
|
|
|
86
87
|
|
|
87
88
|
if (!store) return null;
|
|
88
89
|
|
|
90
|
+
const {templateContext: values} = options;
|
|
91
|
+
|
|
89
92
|
return (
|
|
90
93
|
<Provider store={store}>
|
|
91
|
-
<
|
|
94
|
+
<TemplateContext values={values}>
|
|
95
|
+
<ConnectedApp />
|
|
96
|
+
</TemplateContext>
|
|
92
97
|
</Provider>
|
|
93
98
|
);
|
|
94
99
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import set from 'lodash/fp/set';
|
|
2
|
+
import {CorrectionFromAPI} from '../../types/common';
|
|
3
|
+
import {
|
|
4
|
+
ReceivedCorrection,
|
|
5
|
+
CORRECTION_FETCH_SUCCESS,
|
|
6
|
+
CORRECTION_FETCH_REQUEST,
|
|
7
|
+
FetchCorrection
|
|
8
|
+
} from '../../actions/api/fetch-correction';
|
|
9
|
+
|
|
10
|
+
export type CorrectionsState = Record<string, CorrectionFromAPI>;
|
|
11
|
+
|
|
12
|
+
export type CorrectionsAction = ReceivedCorrection | FetchCorrection;
|
|
13
|
+
|
|
14
|
+
const initialState: CorrectionsState = {};
|
|
15
|
+
|
|
16
|
+
const reducer = (
|
|
17
|
+
// eslint-disable-next-line default-param-last
|
|
18
|
+
state: CorrectionsState = initialState,
|
|
19
|
+
action: CorrectionsAction
|
|
20
|
+
): CorrectionsState => {
|
|
21
|
+
switch (action.type) {
|
|
22
|
+
case CORRECTION_FETCH_REQUEST: {
|
|
23
|
+
const {meta} = action;
|
|
24
|
+
return set(meta.slideRef, null, state);
|
|
25
|
+
}
|
|
26
|
+
case CORRECTION_FETCH_SUCCESS: {
|
|
27
|
+
const {meta} = action;
|
|
28
|
+
const correction = action.payload;
|
|
29
|
+
return set(meta.slideRef, correction, state);
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
return state;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default reducer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import reducer, {type CorrectionsAction} from '../corrections';
|
|
3
|
+
import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
|
|
4
|
+
import {
|
|
5
|
+
CORRECTION_FETCH_REQUEST,
|
|
6
|
+
CORRECTION_FETCH_SUCCESS
|
|
7
|
+
} from '../../../actions/api/fetch-correction';
|
|
8
|
+
import {getChoicesCorrection} from '../../../test/util/services.mock';
|
|
9
|
+
|
|
10
|
+
test('should have an initial empty record value', t => {
|
|
11
|
+
const state = reducer(undefined, {} as CorrectionsAction);
|
|
12
|
+
t.deepEqual(state, {});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("should set the key (slide's id) of the correction to null when a CORRECTION_FETCH_REQUEST is received", t => {
|
|
16
|
+
const slideRef = freeTextSlide._id;
|
|
17
|
+
const state = reducer({}, {type: CORRECTION_FETCH_REQUEST, meta: {slideRef: freeTextSlide._id}});
|
|
18
|
+
t.deepEqual(state, {
|
|
19
|
+
[slideRef]: null
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should set the value of CORRECTION_FETCH_SUCCESS', t => {
|
|
24
|
+
const expectedCorrection = getChoicesCorrection(freeTextSlide._id);
|
|
25
|
+
const state = reducer(
|
|
26
|
+
{},
|
|
27
|
+
{
|
|
28
|
+
type: CORRECTION_FETCH_SUCCESS,
|
|
29
|
+
payload: expectedCorrection,
|
|
30
|
+
meta: {slideRef: freeTextSlide._id}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
t.deepEqual(state, {
|
|
34
|
+
sli_VJYjJnJhg: expectedCorrection
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -2,7 +2,7 @@ import test from 'ava';
|
|
|
2
2
|
import reducer from '../skills';
|
|
3
3
|
import {ReceivedSkills, SKILLS_FETCH_SUCCESS} from '../../../actions/api/fetch-skills';
|
|
4
4
|
|
|
5
|
-
test('should have
|
|
5
|
+
test('should have initial value', t => {
|
|
6
6
|
const state = reducer(undefined, {} as ReceivedSkills);
|
|
7
7
|
t.deepEqual(state, []);
|
|
8
8
|
});
|
|
@@ -3,15 +3,16 @@ import reducer, {type SlidesAction} from '../slides';
|
|
|
3
3
|
import {SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS} from '../../../actions/api/fetch-slide';
|
|
4
4
|
import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
|
|
5
5
|
|
|
6
|
-
test('should have
|
|
6
|
+
test('should have initial value', t => {
|
|
7
7
|
const state = reducer(undefined, {} as SlidesAction);
|
|
8
8
|
t.deepEqual(state, {});
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test('should set the value of SLIDE_FETCH_REQUEST action', t => {
|
|
12
|
-
const
|
|
12
|
+
const slideRef = 'sli_VJYjJnJhg';
|
|
13
|
+
const state = reducer({}, {type: SLIDE_FETCH_REQUEST, meta: {slideRef}});
|
|
13
14
|
t.deepEqual(state, {
|
|
14
|
-
slideRef: null
|
|
15
|
+
[slideRef]: null
|
|
15
16
|
});
|
|
16
17
|
});
|
|
17
18
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import get from 'lodash/fp/get';
|
|
2
|
-
import {qcmDragSlide} from '../../views/slides/test/fixtures/qcm-drag';
|
|
3
2
|
import {qcmSlide} from '../../views/slides/test/fixtures/qcm';
|
|
4
3
|
import {qcmGraphicSlide} from '../../views/slides/test/fixtures/qcm-graphic';
|
|
5
4
|
import {freeTextSlide} from '../../views/slides/test/fixtures/free-text';
|
|
@@ -33,8 +32,6 @@ const getSlideFixture = (ref: string): SlideFromAPI => {
|
|
|
33
32
|
return freeTextSlide;
|
|
34
33
|
case templateSlide.universalRef:
|
|
35
34
|
return templateSlide;
|
|
36
|
-
case qcmDragSlide.universalRef:
|
|
37
|
-
return qcmDragSlide;
|
|
38
35
|
default:
|
|
39
36
|
return sliderSlide;
|
|
40
37
|
}
|
|
@@ -185,11 +185,11 @@ const getIconForCurrentStep = (
|
|
|
185
185
|
slideRef: string,
|
|
186
186
|
lastGivenAnswerForSlide: ProgressionAnswerItem,
|
|
187
187
|
currentSlideRef: string,
|
|
188
|
-
|
|
188
|
+
lastGivenAnswer: ProgressionAnswerItem
|
|
189
189
|
): IconValue => {
|
|
190
190
|
if (slideRef !== currentSlideRef) return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
|
|
191
191
|
|
|
192
|
-
if (
|
|
192
|
+
if (lastGivenAnswer.slideRef !== slideRef) return 'no-answer';
|
|
193
193
|
return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
|
|
194
194
|
};
|
|
195
195
|
|