@coorpacademy/app-review 0.2.7 → 0.2.9-alpha.5
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-rank.d.ts +32 -0
- package/es/actions/api/fetch-rank.js +30 -0
- package/es/actions/api/test/fetch-correction.test.js +2 -1
- package/es/actions/api/test/fetch-rank.test.d.ts +1 -0
- package/es/actions/api/test/fetch-rank.test.js +100 -0
- package/es/actions/api/test/fetch-skills.test.js +2 -1
- package/es/actions/api/test/fetch-slide.test.js +2 -1
- package/es/actions/api/test/post-answer.test.js +2 -1
- package/es/actions/api/test/post-progression.test.js +2 -1
- package/es/actions/data/test/token.test.js +2 -1
- package/es/actions/ui/test/answers.test.js +2 -1
- package/es/actions/ui/test/slides.test.js +2 -1
- package/es/reducers/data/corrections.d.ts +1 -1
- package/es/reducers/data/index.d.ts +4 -1
- package/es/reducers/data/index.js +2 -1
- package/es/reducers/data/rank.d.ts +7 -0
- package/es/reducers/data/rank.js +36 -0
- package/es/reducers/data/test/rank.test.d.ts +1 -0
- package/es/reducers/data/test/rank.test.js +59 -0
- package/es/reducers/index.d.ts +4 -3
- package/es/reducers/ui/slide.d.ts +1 -0
- package/es/reducers/ui/slide.js +1 -1
- package/es/services/index.js +2 -0
- package/es/test/util/services.mock.d.ts +1 -0
- package/es/test/util/services.mock.js +21 -1
- package/es/types/common.d.ts +1 -0
- package/es/views/skills/test/skills.test.js +4 -2
- package/es/views/slides/index.d.ts +21 -19
- package/es/views/slides/index.js +29 -3
- package/es/views/slides/test/fixtures/qcm-graphic.js +190 -28
- package/es/views/slides/test/index.test.js +200 -19
- package/es/views/slides/test/slide.free-text.on-change.test.js +4 -1
- package/es/views/slides/test/slide.qcm-drag.on-click.test.js +4 -1
- package/es/views/slides/test/slide.qcm-graphic.on-click.test.js +6 -3
- package/es/views/slides/test/slide.qcm.on-click.test.js +4 -1
- package/es/views/slides/test/slide.slider.on-change.test.js +4 -1
- package/es/views/slides/test/slide.template.on-change.test.js +6 -1
- package/lib/actions/api/fetch-rank.d.ts +32 -0
- package/lib/actions/api/fetch-rank.js +32 -0
- package/lib/actions/api/test/fetch-correction.test.js +2 -1
- package/lib/actions/api/test/fetch-rank.test.d.ts +1 -0
- package/lib/actions/api/test/fetch-rank.test.js +171 -0
- package/lib/actions/api/test/fetch-skills.test.js +2 -1
- package/lib/actions/api/test/fetch-slide.test.js +2 -1
- package/lib/actions/api/test/post-answer.test.js +2 -1
- package/lib/actions/api/test/post-progression.test.js +2 -1
- package/lib/actions/data/test/token.test.js +2 -1
- package/lib/actions/ui/test/answers.test.js +2 -1
- package/lib/actions/ui/test/slides.test.js +2 -1
- package/lib/reducers/data/corrections.d.ts +1 -1
- package/lib/reducers/data/index.d.ts +4 -1
- package/lib/reducers/data/index.js +2 -1
- package/lib/reducers/data/rank.d.ts +7 -0
- package/lib/reducers/data/rank.js +37 -0
- package/lib/reducers/data/test/rank.test.d.ts +1 -0
- package/lib/reducers/data/test/rank.test.js +59 -0
- package/lib/reducers/index.d.ts +4 -3
- package/lib/reducers/ui/slide.d.ts +1 -0
- package/lib/reducers/ui/slide.js +1 -1
- package/lib/services/index.js +2 -0
- package/lib/test/util/services.mock.d.ts +1 -0
- package/lib/test/util/services.mock.js +12 -1
- package/lib/types/common.d.ts +1 -0
- package/lib/views/skills/test/skills.test.js +4 -2
- package/lib/views/slides/index.d.ts +21 -19
- package/lib/views/slides/index.js +29 -3
- package/lib/views/slides/test/fixtures/qcm-graphic.js +190 -28
- package/lib/views/slides/test/index.test.js +211 -22
- package/lib/views/slides/test/slide.free-text.on-change.test.js +4 -1
- package/lib/views/slides/test/slide.qcm-drag.on-click.test.js +4 -1
- package/lib/views/slides/test/slide.qcm-graphic.on-click.test.js +6 -3
- package/lib/views/slides/test/slide.qcm.on-click.test.js +4 -1
- package/lib/views/slides/test/slide.slider.on-change.test.js +4 -1
- package/lib/views/slides/test/slide.template.on-change.test.js +6 -1
- package/package.json +4 -4
- package/src/actions/api/fetch-rank.ts +84 -0
- package/src/actions/api/test/fetch-correction.test.ts +2 -1
- package/src/actions/api/test/fetch-rank.test.ts +130 -0
- package/src/actions/api/test/fetch-skills.test.ts +2 -1
- package/src/actions/api/test/fetch-slide.test.ts +2 -1
- package/src/actions/api/test/post-answer.test.ts +2 -1
- package/src/actions/api/test/post-progression.test.ts +2 -1
- package/src/actions/data/test/token.test.ts +2 -1
- package/src/actions/ui/test/answers.test.ts +2 -1
- package/src/actions/ui/test/slides.test.ts +2 -1
- package/src/reducers/data/corrections.ts +1 -1
- package/src/reducers/data/index.ts +3 -1
- package/src/reducers/data/rank.ts +60 -0
- package/src/reducers/data/test/rank.test.ts +78 -0
- package/src/reducers/index.ts +2 -2
- package/src/reducers/ui/slide.ts +2 -1
- package/src/services/index.ts +2 -0
- package/src/test/util/services.mock.ts +23 -1
- package/src/types/common.ts +1 -0
- package/src/views/skills/test/skills.test.ts +4 -2
- package/src/views/slides/index.ts +65 -22
- package/src/views/slides/test/fixtures/qcm-graphic.ts +196 -29
- package/src/views/slides/test/index.test.ts +210 -21
- package/src/views/slides/test/slide.free-text.on-change.test.ts +4 -1
- package/src/views/slides/test/slide.qcm-drag.on-click.test.ts +4 -1
- package/src/views/slides/test/slide.qcm-graphic.on-click.test.ts +6 -4
- package/src/views/slides/test/slide.qcm.on-click.test.ts +4 -1
- package/src/views/slides/test/slide.slider.on-change.test.ts +4 -1
- package/src/views/slides/test/slide.template.on-change.test.ts +6 -1
|
@@ -36,7 +36,8 @@ var initialState = {
|
|
|
36
36
|
_a),
|
|
37
37
|
skills: [],
|
|
38
38
|
token: '1234',
|
|
39
|
-
corrections: {}
|
|
39
|
+
corrections: {},
|
|
40
|
+
rank: {}
|
|
40
41
|
},
|
|
41
42
|
ui: {
|
|
42
43
|
currentSlideRef: freeTextSlide._id,
|
|
@@ -59,6 +60,8 @@ test('should dispatch EDIT_BASIC action via the property onChange of a Free Text
|
|
|
59
60
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
60
61
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
62
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
63
|
+
animateCorrectionPopin: false,
|
|
64
|
+
showCorrectionPopin: false,
|
|
62
65
|
hidden: false,
|
|
63
66
|
position: 0,
|
|
64
67
|
loading: false,
|
|
@@ -36,7 +36,8 @@ var initialState = {
|
|
|
36
36
|
_a),
|
|
37
37
|
skills: [],
|
|
38
38
|
token: '1234',
|
|
39
|
-
corrections: {}
|
|
39
|
+
corrections: {},
|
|
40
|
+
rank: {}
|
|
40
41
|
},
|
|
41
42
|
ui: {
|
|
42
43
|
currentSlideRef: qcmDragSlide._id,
|
|
@@ -59,6 +60,8 @@ test('should dispatch EDIT_QCM_DRAG action via the property onClick of a QCM Dra
|
|
|
59
60
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
60
61
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
62
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
63
|
+
animateCorrectionPopin: false,
|
|
64
|
+
showCorrectionPopin: false,
|
|
62
65
|
hidden: false,
|
|
63
66
|
position: 0,
|
|
64
67
|
loading: false,
|
|
@@ -36,7 +36,8 @@ var initialState = {
|
|
|
36
36
|
_a),
|
|
37
37
|
skills: [],
|
|
38
38
|
token: '1234',
|
|
39
|
-
corrections: {}
|
|
39
|
+
corrections: {},
|
|
40
|
+
rank: {}
|
|
40
41
|
},
|
|
41
42
|
ui: {
|
|
42
43
|
currentSlideRef: qcmGraphicSlide._id,
|
|
@@ -53,17 +54,19 @@ test('should dispatch EDIT_QCM_GRAPHIC action via the property onClick of a QCM
|
|
|
53
54
|
var expectedActions = [
|
|
54
55
|
{
|
|
55
56
|
type: EDIT_QCM_GRAPHIC,
|
|
56
|
-
payload: ['
|
|
57
|
+
payload: ['Le retour d’information']
|
|
57
58
|
}
|
|
58
59
|
];
|
|
59
60
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
60
61
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
62
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
63
|
+
animateCorrectionPopin: false,
|
|
64
|
+
showCorrectionPopin: false,
|
|
62
65
|
hidden: false,
|
|
63
66
|
position: 0,
|
|
64
67
|
loading: false,
|
|
65
68
|
parentContentTitle: 'From "Developing the review app" course',
|
|
66
|
-
questionText: '
|
|
69
|
+
questionText: 'Quels sont les 4 piliers de l’apprentissage ?'
|
|
67
70
|
});
|
|
68
71
|
var SlideProps = (_a = props.stack.slides['0'].answerUI) === null || _a === void 0 ? void 0 : _a.model;
|
|
69
72
|
var onClick = get(['1', 'onClick'], SlideProps.answers);
|
|
@@ -36,7 +36,8 @@ var initialState = {
|
|
|
36
36
|
_a),
|
|
37
37
|
skills: [],
|
|
38
38
|
token: '1234',
|
|
39
|
-
corrections: {}
|
|
39
|
+
corrections: {},
|
|
40
|
+
rank: {}
|
|
40
41
|
},
|
|
41
42
|
ui: {
|
|
42
43
|
currentSlideRef: qcmSlide._id,
|
|
@@ -61,6 +62,8 @@ test('should dispatch EDIT_QCM action via the property onClick of a QCM slide',
|
|
|
61
62
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
62
63
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
63
64
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
65
|
+
animateCorrectionPopin: false,
|
|
66
|
+
showCorrectionPopin: false,
|
|
64
67
|
hidden: false,
|
|
65
68
|
position: 0,
|
|
66
69
|
loading: false,
|
|
@@ -36,7 +36,8 @@ var initialState = {
|
|
|
36
36
|
_a),
|
|
37
37
|
skills: [],
|
|
38
38
|
token: '1234',
|
|
39
|
-
corrections: {}
|
|
39
|
+
corrections: {},
|
|
40
|
+
rank: {}
|
|
40
41
|
},
|
|
41
42
|
ui: {
|
|
42
43
|
currentSlideRef: sliderSlide._id,
|
|
@@ -59,6 +60,8 @@ test('should dispatch EDIT_SLIDER action via the property onChange of a Slider s
|
|
|
59
60
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
60
61
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
61
62
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
63
|
+
animateCorrectionPopin: false,
|
|
64
|
+
showCorrectionPopin: false,
|
|
62
65
|
hidden: false,
|
|
63
66
|
position: 0,
|
|
64
67
|
loading: false,
|
|
@@ -36,7 +36,8 @@ var initialState = {
|
|
|
36
36
|
_a),
|
|
37
37
|
skills: [],
|
|
38
38
|
token: '1234',
|
|
39
|
-
corrections: {}
|
|
39
|
+
corrections: {},
|
|
40
|
+
rank: {}
|
|
40
41
|
},
|
|
41
42
|
ui: {
|
|
42
43
|
currentSlideRef: templateSlide._id,
|
|
@@ -54,6 +55,8 @@ test('should dispatch EDIT_TEMPLATE action via the property onChange of a Templa
|
|
|
54
55
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
55
56
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
56
57
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
58
|
+
animateCorrectionPopin: false,
|
|
59
|
+
showCorrectionPopin: false,
|
|
57
60
|
hidden: false,
|
|
58
61
|
position: 0,
|
|
59
62
|
loading: false,
|
|
@@ -71,6 +74,8 @@ test('should dispatch EDIT_TEMPLATE action via the property onChange of a Templa
|
|
|
71
74
|
var _b = createTestStore(t, initialState, services, expectedActions), dispatch = _b.dispatch, getState = _b.getState;
|
|
72
75
|
var props = mapStateToSlidesProps(getState(), dispatch);
|
|
73
76
|
t.deepEqual(omit('answerUI', props.stack.slides['0']), {
|
|
77
|
+
animateCorrectionPopin: false,
|
|
78
|
+
showCorrectionPopin: false,
|
|
74
79
|
hidden: false,
|
|
75
80
|
position: 0,
|
|
76
81
|
loading: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coorpacademy/app-review",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9-alpha.5+31142bfd9",
|
|
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.
|
|
45
|
-
"@coorpacademy/redux-task": "
|
|
44
|
+
"@coorpacademy/components": "10.22.24-alpha.5+31142bfd9",
|
|
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": "31142bfd914b3f169048c3e0bc261835ab74c030"
|
|
82
82
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
2
|
+
import get from 'lodash/fp/get';
|
|
3
|
+
import type {Dispatch} from 'redux';
|
|
4
|
+
import type {StoreState} from '../../reducers';
|
|
5
|
+
import type {Rank, Services, Options} from '../../types/common';
|
|
6
|
+
|
|
7
|
+
export const RANK_FETCH_START_REQUEST = '@@rank/FETCH_START_REQUEST' as const;
|
|
8
|
+
export const RANK_FETCH_START_SUCCESS = '@@rank/FETCH_START_SUCCESS' as const;
|
|
9
|
+
export const RANK_FETCH_START_FAILURE = '@@rank/FETCH_START_FAILURE' as const;
|
|
10
|
+
|
|
11
|
+
export const RANK_FETCH_END_REQUEST = '@@rank/FETCH_END_REQUEST' as const;
|
|
12
|
+
export const RANK_FETCH_END_SUCCESS = '@@rank/FETCH_END_SUCCESS' as const;
|
|
13
|
+
export const RANK_FETCH_END_FAILURE = '@@rank/FETCH_END_FAILURE' as const;
|
|
14
|
+
|
|
15
|
+
type RankFetchStartRequestType = typeof RANK_FETCH_START_REQUEST;
|
|
16
|
+
type RankFetchStartSuccessType = typeof RANK_FETCH_START_SUCCESS;
|
|
17
|
+
type RankFetchStartFailureType = typeof RANK_FETCH_START_FAILURE;
|
|
18
|
+
type RankFetchEndRequestType = typeof RANK_FETCH_END_REQUEST;
|
|
19
|
+
type RankFetchEndSuccessType = typeof RANK_FETCH_END_SUCCESS;
|
|
20
|
+
type RankFetchEndFailureType = typeof RANK_FETCH_END_FAILURE;
|
|
21
|
+
|
|
22
|
+
export type RankRequestAction = {
|
|
23
|
+
type: RankFetchStartRequestType | RankFetchEndRequestType;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type RankSuccessAction = {
|
|
27
|
+
type: RankFetchStartSuccessType | RankFetchEndSuccessType;
|
|
28
|
+
payload: Rank;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type RankFailureAction = {
|
|
32
|
+
type: RankFetchStartFailureType | RankFetchEndFailureType;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type RankAction = RankRequestAction | RankSuccessAction | RankFailureAction;
|
|
36
|
+
|
|
37
|
+
type RankStart = [RankFetchStartRequestType, RankFetchStartSuccessType, RankFetchStartFailureType];
|
|
38
|
+
type RankEnd = [RankFetchEndRequestType, RankFetchEndSuccessType, RankFetchEndFailureType];
|
|
39
|
+
|
|
40
|
+
export const fetchRank = (
|
|
41
|
+
dispatch: Dispatch,
|
|
42
|
+
getState: () => StoreState,
|
|
43
|
+
services: Services,
|
|
44
|
+
types: RankStart | RankEnd,
|
|
45
|
+
path?: string
|
|
46
|
+
): RankAction => {
|
|
47
|
+
const action = buildTask({
|
|
48
|
+
types,
|
|
49
|
+
task: () => {
|
|
50
|
+
const state = getState();
|
|
51
|
+
const token = get(['data', 'token'], state);
|
|
52
|
+
return services.fetchRank(token);
|
|
53
|
+
},
|
|
54
|
+
bailout: path ? (state: StoreState): boolean => !!get(path, state) : undefined
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return dispatch(action);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const fetchStartRank = (
|
|
61
|
+
dispatch: Dispatch,
|
|
62
|
+
getState: () => StoreState,
|
|
63
|
+
{services}: Options
|
|
64
|
+
): RankAction => {
|
|
65
|
+
return fetchRank(
|
|
66
|
+
dispatch,
|
|
67
|
+
getState,
|
|
68
|
+
services,
|
|
69
|
+
[RANK_FETCH_START_REQUEST, RANK_FETCH_START_SUCCESS, RANK_FETCH_START_FAILURE],
|
|
70
|
+
'data.rank.start'
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const fetchEndRank = (
|
|
75
|
+
dispatch: Dispatch,
|
|
76
|
+
getState: () => StoreState,
|
|
77
|
+
{services}: Options
|
|
78
|
+
): RankAction => {
|
|
79
|
+
return fetchRank(dispatch, getState, services, [
|
|
80
|
+
RANK_FETCH_END_REQUEST,
|
|
81
|
+
RANK_FETCH_END_SUCCESS,
|
|
82
|
+
RANK_FETCH_END_FAILURE
|
|
83
|
+
]);
|
|
84
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import type {Services} from '../../../types/common';
|
|
3
|
+
import type {StoreState} from '../../../reducers';
|
|
4
|
+
import {
|
|
5
|
+
fetchStartRank,
|
|
6
|
+
fetchEndRank,
|
|
7
|
+
RANK_FETCH_START_REQUEST,
|
|
8
|
+
RANK_FETCH_START_SUCCESS,
|
|
9
|
+
RANK_FETCH_START_FAILURE,
|
|
10
|
+
RANK_FETCH_END_REQUEST,
|
|
11
|
+
RANK_FETCH_END_SUCCESS,
|
|
12
|
+
RANK_FETCH_END_FAILURE
|
|
13
|
+
} from '../fetch-rank';
|
|
14
|
+
import {services as mockedServices} from '../../../test/util/services.mock';
|
|
15
|
+
import {createTestStore} from '../../test/create-test-store';
|
|
16
|
+
|
|
17
|
+
const initialState: StoreState = {
|
|
18
|
+
data: {
|
|
19
|
+
progression: null,
|
|
20
|
+
slides: {},
|
|
21
|
+
skills: [],
|
|
22
|
+
token: '1234',
|
|
23
|
+
corrections: {},
|
|
24
|
+
rank: {}
|
|
25
|
+
},
|
|
26
|
+
ui: {
|
|
27
|
+
currentSlideRef: '',
|
|
28
|
+
navigation: [],
|
|
29
|
+
answers: [],
|
|
30
|
+
slide: {
|
|
31
|
+
validateButton: false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
test('should dispatch FETCH_START_SUCCESS action when fetchStartRank returns the start rank', async t => {
|
|
37
|
+
t.plan(3);
|
|
38
|
+
|
|
39
|
+
const services: Services = {
|
|
40
|
+
...mockedServices,
|
|
41
|
+
fetchRank: token => {
|
|
42
|
+
t.is(token, '1234');
|
|
43
|
+
return Promise.resolve({rank: 93});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const expectedActions = [
|
|
47
|
+
{type: RANK_FETCH_START_REQUEST},
|
|
48
|
+
{
|
|
49
|
+
type: RANK_FETCH_START_SUCCESS,
|
|
50
|
+
payload: {rank: 93}
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const {dispatch} = createTestStore(t, initialState, services, expectedActions);
|
|
55
|
+
await dispatch(fetchStartRank);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should dispatch FETCH_START_FAILURE action when fetchStartRank fails', async t => {
|
|
59
|
+
t.plan(3);
|
|
60
|
+
|
|
61
|
+
const services: Services = {
|
|
62
|
+
...mockedServices,
|
|
63
|
+
fetchRank: token => {
|
|
64
|
+
t.is(token, '1234');
|
|
65
|
+
return Promise.reject(new Error('unexpected'));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const expectedActions = [
|
|
70
|
+
{type: RANK_FETCH_START_REQUEST},
|
|
71
|
+
{
|
|
72
|
+
type: RANK_FETCH_START_FAILURE,
|
|
73
|
+
payload: new Error('unexpected'),
|
|
74
|
+
error: true
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
const {dispatch} = createTestStore(t, initialState, services, expectedActions);
|
|
79
|
+
|
|
80
|
+
await dispatch(fetchStartRank);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('should dispatch FETCH_END_SUCCESS action when fetchEndRank returns the end rank', async t => {
|
|
84
|
+
t.plan(3);
|
|
85
|
+
|
|
86
|
+
const services: Services = {
|
|
87
|
+
...mockedServices,
|
|
88
|
+
fetchRank: token => {
|
|
89
|
+
t.is(token, '1234');
|
|
90
|
+
return Promise.resolve({rank: 93});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const expectedActions = [
|
|
95
|
+
{type: RANK_FETCH_END_REQUEST},
|
|
96
|
+
{
|
|
97
|
+
type: RANK_FETCH_END_SUCCESS,
|
|
98
|
+
payload: {rank: 93}
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
const {dispatch} = createTestStore(t, initialState, services, expectedActions);
|
|
103
|
+
|
|
104
|
+
await dispatch(fetchEndRank);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('should dispatch FETCH_END_FAILURE action when fetchEndRank fails', async t => {
|
|
108
|
+
t.plan(3);
|
|
109
|
+
|
|
110
|
+
const services: Services = {
|
|
111
|
+
...mockedServices,
|
|
112
|
+
fetchRank: token => {
|
|
113
|
+
t.is(token, '1234');
|
|
114
|
+
return Promise.reject(new Error('unexpected'));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const expectedActions = [
|
|
119
|
+
{type: RANK_FETCH_END_REQUEST},
|
|
120
|
+
{
|
|
121
|
+
type: RANK_FETCH_END_FAILURE,
|
|
122
|
+
payload: new Error('unexpected'),
|
|
123
|
+
error: true
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const {dispatch} = createTestStore(t, initialState, services, expectedActions);
|
|
128
|
+
|
|
129
|
+
await dispatch(fetchEndRank);
|
|
130
|
+
});
|
|
@@ -5,6 +5,7 @@ import progression, {ProgressionState} from './progression';
|
|
|
5
5
|
import skills, {SkillsState} from './skills';
|
|
6
6
|
import slides, {SlidesState} from './slides';
|
|
7
7
|
import token, {TokenState} from './token';
|
|
8
|
+
import rank, {RankState} from './rank';
|
|
8
9
|
|
|
9
10
|
export type DataState = {
|
|
10
11
|
corrections: CorrectionsState;
|
|
@@ -12,6 +13,7 @@ export type DataState = {
|
|
|
12
13
|
skills: SkillsState;
|
|
13
14
|
slides: SlidesState;
|
|
14
15
|
token: TokenState;
|
|
16
|
+
rank: RankState;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
|
-
export default combineReducers({corrections, progression, skills, slides, token});
|
|
19
|
+
export default combineReducers({corrections, progression, skills, slides, token, rank});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {get, isNull, isUndefined, pipe, set, unset, update} from 'lodash/fp';
|
|
2
|
+
import {
|
|
3
|
+
RankAction,
|
|
4
|
+
RANK_FETCH_START_REQUEST,
|
|
5
|
+
RANK_FETCH_START_SUCCESS,
|
|
6
|
+
RANK_FETCH_START_FAILURE,
|
|
7
|
+
RANK_FETCH_END_REQUEST,
|
|
8
|
+
RANK_FETCH_END_SUCCESS,
|
|
9
|
+
RANK_FETCH_END_FAILURE
|
|
10
|
+
} from '../../actions/api/fetch-rank';
|
|
11
|
+
|
|
12
|
+
export type RankState = {
|
|
13
|
+
start?: number | null;
|
|
14
|
+
end?: number | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const initialState: RankState = {};
|
|
18
|
+
|
|
19
|
+
const reducer = (
|
|
20
|
+
// eslint-disable-next-line default-param-last
|
|
21
|
+
state: RankState = initialState,
|
|
22
|
+
action: RankAction
|
|
23
|
+
): RankState => {
|
|
24
|
+
switch (action.type) {
|
|
25
|
+
case RANK_FETCH_START_REQUEST: {
|
|
26
|
+
return update(
|
|
27
|
+
'start',
|
|
28
|
+
(startRank: RankState['start']) => (isUndefined(startRank) ? null : startRank),
|
|
29
|
+
state
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
case RANK_FETCH_START_SUCCESS: {
|
|
33
|
+
const {payload} = action;
|
|
34
|
+
return set('start', payload.rank, state);
|
|
35
|
+
}
|
|
36
|
+
case RANK_FETCH_START_FAILURE: {
|
|
37
|
+
if (pipe(get('start'), isNull)(state)) return unset('start', state);
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
case RANK_FETCH_END_REQUEST: {
|
|
41
|
+
return update(
|
|
42
|
+
'end',
|
|
43
|
+
(endRank: RankState['end']) => (isUndefined(endRank) ? null : endRank),
|
|
44
|
+
state
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
case RANK_FETCH_END_SUCCESS: {
|
|
48
|
+
const {payload} = action;
|
|
49
|
+
return set('end', payload.rank, state);
|
|
50
|
+
}
|
|
51
|
+
case RANK_FETCH_END_FAILURE: {
|
|
52
|
+
if (pipe(get('end'), isNull)(state)) return unset('end', state);
|
|
53
|
+
return state;
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
return state;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default reducer;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import reducer from '../rank';
|
|
3
|
+
import {
|
|
4
|
+
RankAction,
|
|
5
|
+
RANK_FETCH_START_REQUEST,
|
|
6
|
+
RANK_FETCH_START_SUCCESS,
|
|
7
|
+
RANK_FETCH_START_FAILURE,
|
|
8
|
+
RANK_FETCH_END_REQUEST,
|
|
9
|
+
RANK_FETCH_END_SUCCESS,
|
|
10
|
+
RANK_FETCH_END_FAILURE
|
|
11
|
+
} from '../../../actions/api/fetch-rank';
|
|
12
|
+
|
|
13
|
+
test('should have initial value', t => {
|
|
14
|
+
const state = reducer(undefined, {} as RankAction);
|
|
15
|
+
t.deepEqual(state, {});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("should set the start value to null if the value doesn't exist of FETCH_START_REQUEST action", t => {
|
|
19
|
+
const state = reducer({}, {type: RANK_FETCH_START_REQUEST});
|
|
20
|
+
t.deepEqual(state, {
|
|
21
|
+
start: null
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('should do nothing if a start value already exists of FETCH_START_REQUEST action', t => {
|
|
26
|
+
const state = reducer({start: 93}, {type: RANK_FETCH_START_REQUEST});
|
|
27
|
+
t.deepEqual(state, {
|
|
28
|
+
start: 93
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('should set the start value of FETCH_START_SUCCESS action', t => {
|
|
33
|
+
const state = reducer({}, {type: RANK_FETCH_START_SUCCESS, payload: {rank: 93}});
|
|
34
|
+
t.deepEqual(state, {
|
|
35
|
+
start: 93
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should unset the start value if the value is null of FETCH_START_FAILURE action', t => {
|
|
40
|
+
const state = reducer({start: null}, {type: RANK_FETCH_START_FAILURE});
|
|
41
|
+
t.deepEqual(state, {});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should do nothing if the start value already exists of FETCH_START_FAILURE action', t => {
|
|
45
|
+
const state = reducer({start: 93}, {type: RANK_FETCH_START_FAILURE});
|
|
46
|
+
t.deepEqual(state, {start: 93});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("should set the end value to null if the value doesn't exist of FETCH_END_REQUEST action", t => {
|
|
50
|
+
const state = reducer({}, {type: RANK_FETCH_END_REQUEST});
|
|
51
|
+
t.deepEqual(state, {
|
|
52
|
+
end: null
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should do nothing if an end value already exists of FETCH_END_REQUEST action', t => {
|
|
57
|
+
const state = reducer({end: 94}, {type: RANK_FETCH_END_REQUEST});
|
|
58
|
+
t.deepEqual(state, {
|
|
59
|
+
end: 94
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should set the end value of FETCH_END_SUCCESS action', t => {
|
|
64
|
+
const state = reducer({}, {type: RANK_FETCH_END_SUCCESS, payload: {rank: 94}});
|
|
65
|
+
t.deepEqual(state, {
|
|
66
|
+
end: 94
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('should unset the end value if the value is null of FETCH_END_FAILURE action', t => {
|
|
71
|
+
const state = reducer({end: null}, {type: RANK_FETCH_END_FAILURE});
|
|
72
|
+
t.deepEqual(state, {});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('should do nothing if the end value already exists of FETCH_END_FAILURE action', t => {
|
|
76
|
+
const state = reducer({end: 94}, {type: RANK_FETCH_END_FAILURE});
|
|
77
|
+
t.deepEqual(state, {end: 94});
|
|
78
|
+
});
|
package/src/reducers/index.ts
CHANGED
package/src/reducers/ui/slide.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {CORRECTION_FETCH_SUCCESS, ReceivedCorrection} from '../../actions/api/fe
|
|
|
17
17
|
export type UISlideState = {
|
|
18
18
|
validateButton: boolean;
|
|
19
19
|
animateCorrectionPopin?: boolean;
|
|
20
|
+
showCorrectionPopin?: boolean;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export const initialState: UISlideState = {validateButton: false};
|
|
@@ -39,7 +40,7 @@ const reducer = (
|
|
|
39
40
|
return initialState;
|
|
40
41
|
}
|
|
41
42
|
case CORRECTION_FETCH_SUCCESS: {
|
|
42
|
-
return set(['animateCorrectionPopin'], true, state);
|
|
43
|
+
return pipe(set(['animateCorrectionPopin'], true), set(['showCorrectionPopin'], true))(state);
|
|
43
44
|
}
|
|
44
45
|
default:
|
|
45
46
|
return state;
|
package/src/services/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {Services} from '../types/common';
|
|
2
2
|
import {fetchCorrection} from './fetch-correction';
|
|
3
|
+
import {fetchRank} from './fetch-rank';
|
|
3
4
|
import {fetchSkills} from './fetch-skills';
|
|
4
5
|
import {fetchSlide} from './fetch-slide';
|
|
5
6
|
import {postAnswer} from './post-answer';
|
|
@@ -7,6 +8,7 @@ import {postProgression} from './post-progression';
|
|
|
7
8
|
|
|
8
9
|
export const getServices = (): Services => ({
|
|
9
10
|
fetchCorrection,
|
|
11
|
+
fetchRank,
|
|
10
12
|
fetchSkills,
|
|
11
13
|
fetchSlide,
|
|
12
14
|
postAnswer,
|