@coorpacademy/app-review 0.1.15 → 0.1.17
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-skills.d.ts +5 -7
- package/es/actions/api/fetch-skills.js +12 -4
- package/es/actions/api/fetch-slide.d.ts +14 -7
- package/es/actions/api/fetch-slide.js +23 -18
- package/es/actions/api/post-answer.d.ts +10 -0
- package/es/actions/api/post-answer.js +25 -0
- package/es/actions/api/post-progression.d.ts +5 -7
- package/es/actions/api/post-progression.js +16 -8
- package/es/actions/api/test/fetch-skills.test.js +57 -0
- package/es/actions/api/test/fetch-slide.test.js +64 -0
- package/es/actions/api/test/post-answer.test.d.ts +1 -0
- package/es/actions/api/test/post-answer.test.js +82 -0
- package/es/actions/api/test/post-progression.test.d.ts +1 -0
- package/es/actions/api/test/post-progression.test.js +105 -0
- package/es/actions/data/test/token.test.d.ts +1 -0
- package/es/actions/data/test/token.test.js +25 -0
- package/es/actions/index.d.ts +1 -8
- package/es/actions/test/create-test-store.d.ts +5 -0
- package/es/actions/test/create-test-store.js +16 -0
- package/es/actions/ui/answers.d.ts +21 -0
- package/es/actions/ui/answers.js +43 -0
- package/es/actions/ui/slides.d.ts +0 -5
- package/es/actions/ui/slides.js +0 -4
- package/es/actions/ui/test/answers.test.d.ts +1 -0
- package/es/actions/ui/test/answers.test.js +90 -0
- package/es/actions/ui/test/slides.test.d.ts +1 -0
- package/es/actions/ui/test/slides.test.js +26 -0
- package/es/common/index.d.ts +0 -3
- package/es/common/index.js +0 -4
- package/es/index.js +11 -19
- package/es/reducers/data/index.d.ts +2 -2
- package/es/reducers/data/progression.d.ts +2 -3
- package/es/reducers/data/progression.js +0 -5
- package/es/reducers/data/slides.d.ts +3 -4
- package/es/reducers/data/slides.js +5 -1
- package/es/reducers/data/test/progression.test.d.ts +1 -0
- package/es/reducers/data/test/progression.test.js +38 -0
- package/es/reducers/data/test/skills.test.d.ts +1 -0
- package/es/reducers/data/test/skills.test.js +12 -0
- package/es/reducers/data/test/slides.test.d.ts +1 -0
- package/es/reducers/data/test/slides.test.js +20 -0
- package/es/reducers/data/test/token.test.d.ts +1 -0
- package/es/reducers/data/test/token.test.js +11 -0
- package/es/reducers/index.d.ts +3 -2
- package/es/reducers/ui/answers.d.ts +4 -0
- package/es/reducers/ui/answers.js +9 -0
- package/es/reducers/ui/index.d.ts +7 -4
- package/es/reducers/ui/index.js +4 -2
- package/es/reducers/ui/slide.d.ts +8 -0
- package/es/reducers/ui/slide.js +26 -0
- package/es/reducers/ui/test/answers.test.d.ts +1 -0
- package/es/reducers/ui/test/answers.test.js +27 -0
- package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
- package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
- package/es/reducers/ui/test/navigation.test.d.ts +1 -0
- package/es/reducers/ui/test/navigation.test.js +15 -0
- package/es/reducers/ui/test/slide.test.d.ts +1 -0
- package/es/reducers/ui/test/slide.test.js +12 -0
- package/es/services/fetch-slide.js +1 -1
- package/es/services/index.js +3 -1
- package/es/services/post-answer.d.ts +2 -0
- package/es/services/post-answer.js +18 -0
- package/es/services/test/fetch-slide.test.d.ts +1 -0
- package/es/services/test/fetch-slide.test.js +22 -0
- package/es/services/test/post-answer.test.d.ts +1 -0
- package/es/services/test/post-answer.test.js +57 -0
- package/es/services/test/post-progression.test.js +9 -1
- package/es/test/util/services.mock.d.ts +2 -1
- package/es/test/util/services.mock.js +88 -44
- package/es/types/common.d.ts +22 -33
- package/es/views/skills/index.d.ts +1 -1
- package/es/views/skills/index.js +0 -3
- package/es/views/skills/test/skills.test.d.ts +1 -0
- package/es/views/skills/test/skills.test.js +94 -0
- package/es/views/slides/index.d.ts +89 -2
- package/es/views/slides/index.js +80 -10
- package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
- package/es/views/slides/map-api-slide-to-ui.js +165 -0
- package/es/{helpers → views/slides}/test/fixtures/free-text.d.ts +2 -1
- package/es/views/slides/test/fixtures/free-text.js +38 -0
- package/es/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +2 -1
- package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
- package/es/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +2 -1
- package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
- package/es/{helpers → views/slides}/test/fixtures/qcm.d.ts +2 -1
- package/es/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
- package/es/{helpers → views/slides}/test/fixtures/select-template.d.ts +2 -1
- package/es/views/slides/test/fixtures/select-template.js +92 -0
- package/es/{helpers → views/slides}/test/fixtures/slider.d.ts +2 -1
- package/es/views/slides/test/fixtures/slider.js +36 -0
- package/es/{helpers → views/slides}/test/fixtures/text-template.d.ts +2 -1
- package/es/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
- package/es/views/slides/test/index.test.d.ts +1 -0
- package/es/views/slides/test/index.test.js +234 -0
- package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
- package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
- package/lib/actions/api/fetch-skills.d.ts +5 -7
- package/lib/actions/api/fetch-skills.js +58 -7
- package/lib/actions/api/fetch-slide.d.ts +14 -7
- package/lib/actions/api/fetch-slide.js +72 -20
- package/lib/actions/api/post-answer.d.ts +10 -0
- package/lib/actions/api/post-answer.js +75 -0
- package/lib/actions/api/post-progression.d.ts +5 -7
- package/lib/actions/api/post-progression.js +67 -10
- package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
- package/lib/actions/api/test/fetch-skills.test.js +116 -0
- package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
- package/lib/actions/api/test/fetch-slide.test.js +123 -0
- package/lib/actions/api/test/post-answer.test.d.ts +1 -0
- package/lib/actions/api/test/post-answer.test.js +145 -0
- package/lib/actions/api/test/post-progression.test.d.ts +1 -0
- package/lib/actions/api/test/post-progression.test.js +163 -0
- package/lib/actions/data/test/token.test.d.ts +1 -0
- package/lib/actions/data/test/token.test.js +70 -0
- package/lib/actions/index.d.ts +1 -8
- package/lib/actions/test/create-test-store.d.ts +5 -0
- package/lib/actions/test/create-test-store.js +18 -0
- package/lib/actions/ui/answers.d.ts +21 -0
- package/lib/actions/ui/answers.js +54 -0
- package/lib/actions/ui/slides.d.ts +0 -5
- package/lib/actions/ui/slides.js +0 -4
- package/lib/actions/ui/test/answers.test.d.ts +1 -0
- package/lib/actions/ui/test/answers.test.js +171 -0
- package/lib/actions/ui/test/slides.test.d.ts +1 -0
- package/lib/actions/ui/test/slides.test.js +71 -0
- package/lib/common/index.d.ts +0 -3
- package/lib/common/index.js +0 -4
- package/lib/index.js +22 -21
- package/lib/reducers/data/index.d.ts +2 -2
- package/lib/reducers/data/progression.d.ts +2 -3
- package/lib/reducers/data/progression.js +0 -5
- package/lib/reducers/data/slides.d.ts +3 -4
- package/lib/reducers/data/slides.js +5 -1
- package/lib/reducers/data/test/progression.test.d.ts +1 -0
- package/lib/reducers/data/test/progression.test.js +38 -0
- package/lib/reducers/data/test/skills.test.d.ts +1 -0
- package/lib/reducers/data/test/skills.test.js +12 -0
- package/lib/reducers/data/test/slides.test.d.ts +1 -0
- package/lib/reducers/data/test/slides.test.js +20 -0
- package/lib/reducers/data/test/token.test.d.ts +1 -0
- package/lib/reducers/data/test/token.test.js +11 -0
- package/lib/reducers/index.d.ts +3 -2
- package/lib/reducers/ui/answers.d.ts +4 -0
- package/lib/reducers/ui/answers.js +10 -0
- package/lib/reducers/ui/index.d.ts +7 -4
- package/lib/reducers/ui/index.js +4 -2
- package/lib/reducers/ui/slide.d.ts +8 -0
- package/lib/reducers/ui/slide.js +27 -0
- package/lib/reducers/ui/test/answers.test.d.ts +1 -0
- package/lib/reducers/ui/test/answers.test.js +27 -0
- package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
- package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
- package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
- package/lib/reducers/ui/test/navigation.test.js +15 -0
- package/lib/reducers/ui/test/slide.test.d.ts +1 -0
- package/lib/reducers/ui/test/slide.test.js +12 -0
- package/lib/services/fetch-slide.js +1 -1
- package/lib/services/index.js +3 -1
- package/lib/services/post-answer.d.ts +2 -0
- package/lib/services/post-answer.js +62 -0
- package/lib/services/test/fetch-slide.test.d.ts +1 -0
- package/lib/services/test/fetch-slide.test.js +76 -0
- package/lib/services/test/post-answer.test.d.ts +1 -0
- package/lib/services/test/post-answer.test.js +111 -0
- package/lib/services/test/post-progression.test.js +9 -1
- package/lib/test/util/services.mock.d.ts +2 -1
- package/lib/test/util/services.mock.js +88 -44
- package/lib/types/common.d.ts +22 -33
- package/lib/views/skills/index.d.ts +1 -1
- package/lib/views/skills/index.js +0 -3
- package/lib/views/skills/test/skills.test.d.ts +1 -0
- package/lib/views/skills/test/skills.test.js +94 -0
- package/lib/views/slides/index.d.ts +89 -2
- package/lib/views/slides/index.js +80 -10
- package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
- package/lib/views/slides/map-api-slide-to-ui.js +179 -0
- package/lib/{helpers → views/slides}/test/fixtures/free-text.d.ts +2 -1
- package/lib/views/slides/test/fixtures/free-text.js +38 -0
- package/lib/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +2 -1
- package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
- package/lib/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +2 -1
- package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
- package/lib/{helpers → views/slides}/test/fixtures/qcm.d.ts +2 -1
- package/lib/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
- package/lib/{helpers → views/slides}/test/fixtures/select-template.d.ts +2 -1
- package/lib/views/slides/test/fixtures/select-template.js +92 -0
- package/lib/{helpers → views/slides}/test/fixtures/slider.d.ts +2 -1
- package/lib/views/slides/test/fixtures/slider.js +36 -0
- package/lib/{helpers → views/slides}/test/fixtures/text-template.d.ts +2 -1
- package/lib/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
- package/lib/views/slides/test/index.test.d.ts +1 -0
- package/lib/views/slides/test/index.test.js +234 -0
- package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
- package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
- package/package.json +6 -5
- package/src/actions/api/fetch-skills.ts +19 -12
- package/src/actions/api/fetch-slide.ts +35 -29
- package/src/actions/api/post-answer.ts +39 -0
- package/src/actions/api/post-progression.ts +22 -22
- package/src/actions/api/test/fetch-skills.test.ts +73 -0
- package/src/actions/api/test/fetch-slide.test.ts +80 -0
- package/src/actions/api/test/post-answer.test.ts +101 -0
- package/src/actions/api/test/post-progression.test.ts +122 -0
- package/src/actions/data/test/token.test.ts +29 -0
- package/src/actions/index.ts +1 -17
- package/src/actions/test/create-test-store.ts +25 -0
- package/src/actions/ui/answers.ts +63 -0
- package/src/actions/ui/slides.ts +1 -8
- package/src/actions/ui/test/answers.test.ts +103 -0
- package/src/actions/ui/test/slides.test.ts +30 -0
- package/src/common/index.ts +0 -7
- package/src/index.tsx +15 -32
- package/src/reducers/data/index.ts +1 -1
- package/src/reducers/data/progression.ts +2 -7
- package/src/reducers/data/slides.ts +12 -4
- package/src/reducers/data/test/progression.test.ts +42 -0
- package/src/reducers/data/test/skills.test.ts +14 -0
- package/src/reducers/data/test/slides.test.ts +26 -0
- package/src/reducers/data/test/token.test.ts +13 -0
- package/src/reducers/ui/answers.ts +15 -0
- package/src/reducers/ui/index.ts +6 -3
- package/src/reducers/ui/slide.ts +43 -0
- package/src/reducers/ui/test/answers.test.ts +33 -0
- package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
- package/src/reducers/ui/test/navigation.test.ts +19 -0
- package/src/reducers/ui/test/slide.test.ts +15 -0
- package/src/services/fetch-slide.ts +1 -1
- package/src/services/index.ts +3 -1
- package/src/services/post-answer.ts +27 -0
- package/src/services/test/fetch-slide.test.ts +30 -0
- package/src/services/test/post-answer.test.ts +68 -0
- package/src/services/test/post-progression.test.ts +9 -1
- package/src/test/util/services.mock.ts +93 -45
- package/src/types/common.ts +34 -44
- package/src/views/skills/index.ts +1 -5
- package/src/views/skills/test/skills.test.ts +101 -0
- package/src/views/slides/index.ts +186 -12
- package/src/views/slides/map-api-slide-to-ui.ts +251 -0
- package/src/views/slides/test/fixtures/free-text.ts +44 -0
- package/src/views/slides/test/fixtures/qcm-drag.ts +112 -0
- package/src/views/slides/test/fixtures/qcm-graphic.ts +95 -0
- package/src/{helpers → views/slides}/test/fixtures/qcm.ts +7 -2
- package/src/views/slides/test/fixtures/select-template.ts +99 -0
- package/src/views/slides/test/fixtures/slider.ts +42 -0
- package/src/{helpers → views/slides}/test/fixtures/text-template.ts +7 -2
- package/src/views/slides/test/index.test.ts +240 -0
- package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +22 -10
- package/es/fixtures/qcm-slide.d.ts +0 -2
- package/es/fixtures/qcm-slide.js +0 -33
- package/es/fixtures/temp-fixture.d.ts +0 -3
- package/es/fixtures/temp-fixture.js +0 -84
- package/es/helpers/map-api-slide-to-ui.d.ts +0 -11
- package/es/helpers/map-api-slide-to-ui.js +0 -193
- package/es/helpers/test/fixtures/free-text.js +0 -30
- package/es/helpers/test/fixtures/qcm-drag.js +0 -112
- package/es/helpers/test/fixtures/qcm-graphic.js +0 -76
- package/es/helpers/test/fixtures/select-template.js +0 -94
- package/es/helpers/test/fixtures/slider.js +0 -33
- package/es/reducers/ui/slides.d.ts +0 -9
- package/es/reducers/ui/slides.js +0 -42
- package/es/types/views/slides.d.ts +0 -74
- package/es/types/views/slides.js +0 -6
- package/lib/fixtures/qcm-slide.d.ts +0 -2
- package/lib/fixtures/qcm-slide.js +0 -33
- package/lib/fixtures/temp-fixture.d.ts +0 -3
- package/lib/fixtures/temp-fixture.js +0 -84
- package/lib/helpers/map-api-slide-to-ui.d.ts +0 -11
- package/lib/helpers/map-api-slide-to-ui.js +0 -201
- package/lib/helpers/test/fixtures/free-text.js +0 -30
- package/lib/helpers/test/fixtures/qcm-drag.js +0 -112
- package/lib/helpers/test/fixtures/qcm-graphic.js +0 -76
- package/lib/helpers/test/fixtures/select-template.js +0 -94
- package/lib/helpers/test/fixtures/slider.js +0 -33
- package/lib/reducers/ui/slides.d.ts +0 -9
- package/lib/reducers/ui/slides.js +0 -43
- package/lib/types/views/slides.d.ts +0 -74
- package/lib/types/views/slides.js +0 -6
- package/src/fixtures/qcm-slide.ts +0 -35
- package/src/fixtures/temp-fixture.ts +0 -94
- package/src/helpers/map-api-slide-to-ui.ts +0 -279
- package/src/helpers/test/fixtures/free-text.ts +0 -33
- package/src/helpers/test/fixtures/qcm-drag.ts +0 -115
- package/src/helpers/test/fixtures/qcm-graphic.ts +0 -79
- package/src/helpers/test/fixtures/select-template.ts +0 -97
- package/src/helpers/test/fixtures/slider.ts +0 -36
- package/src/reducers/ui/slides.ts +0 -58
- package/src/types/views/slides.ts +0 -90
- /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
- /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/actions/api/test/fetch-slide.test.d.ts} +0 -0
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { AnyAction } from 'redux';
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
3
2
|
import type { StoreState } from '../../reducers';
|
|
4
|
-
import { Options, Skill } from '../../types/common';
|
|
3
|
+
import type { Options, Skill } from '../../types/common';
|
|
5
4
|
export declare const SKILLS_FETCH_REQUEST: "@@skills/FETCH_REQUEST";
|
|
6
5
|
export declare const SKILLS_FETCH_SUCCESS: "@@skills/FETCH_SUCCESS";
|
|
7
6
|
export declare const SKILLS_FETCH_FAILURE: "@@skills/FETCH_FAILURE";
|
|
8
|
-
export
|
|
7
|
+
export declare type ReceivedSkills = {
|
|
9
8
|
type: '@@skills/FETCH_SUCCESS';
|
|
10
9
|
payload: Skill[];
|
|
11
|
-
}
|
|
12
|
-
export declare
|
|
13
|
-
export declare const fetchSkills: (token: string) => FetchSkillsAction;
|
|
10
|
+
};
|
|
11
|
+
export declare const fetchSkills: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import buildTask from '@coorpacademy/redux-task';
|
|
2
|
+
import get from 'lodash/fp/get';
|
|
2
3
|
export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST';
|
|
3
4
|
export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS';
|
|
4
5
|
export const SKILLS_FETCH_FAILURE = '@@skills/FETCH_FAILURE';
|
|
5
|
-
export const fetchSkills = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export const fetchSkills = async (dispatch, getState, { services }) => {
|
|
7
|
+
const action = buildTask({
|
|
8
|
+
types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
|
|
9
|
+
task: () => {
|
|
10
|
+
const state = getState();
|
|
11
|
+
const token = get('data.token', state);
|
|
12
|
+
return services.fetchSkills(token);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
await dispatch(action);
|
|
16
|
+
};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ThunkAction } from 'redux-thunk';
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
3
2
|
import type { StoreState } from '../../reducers';
|
|
4
|
-
import type { Options,
|
|
3
|
+
import type { Options, SlideFromAPI } from '../../types/common';
|
|
5
4
|
export declare const SLIDE_FETCH_REQUEST: "@@slides/FETCH_REQUEST";
|
|
6
5
|
export declare const SLIDE_FETCH_SUCCESS: "@@slides/FETCH_SUCCESS";
|
|
7
6
|
export declare const SLIDE_FETCH_FAILURE: "@@slides/FETCH_FAILURE";
|
|
8
|
-
export
|
|
7
|
+
export declare type FetchSlide = {
|
|
8
|
+
type: typeof SLIDE_FETCH_REQUEST;
|
|
9
|
+
meta: {
|
|
10
|
+
slideRef: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare type ReceivedSlide = {
|
|
9
14
|
type: typeof SLIDE_FETCH_SUCCESS;
|
|
10
15
|
payload: SlideFromAPI;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
meta: {
|
|
17
|
+
slideRef: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare const fetchSlide: (slideRef: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
|
|
@@ -6,23 +6,28 @@ import { setCurrentSlide } from '../ui/slides';
|
|
|
6
6
|
export const SLIDE_FETCH_REQUEST = '@@slides/FETCH_REQUEST';
|
|
7
7
|
export const SLIDE_FETCH_SUCCESS = '@@slides/FETCH_SUCCESS';
|
|
8
8
|
export const SLIDE_FETCH_FAILURE = '@@slides/FETCH_FAILURE';
|
|
9
|
-
export const fetchSlide = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const { ref: slideRef } = get('state.nextContent', progressionFromAPI);
|
|
17
|
-
return services.fetchSlide(slideRef, token).then((slideFromAPI) => {
|
|
18
|
-
if (!slideFromAPI)
|
|
19
|
-
throw new Error('Slide not found');
|
|
9
|
+
export const fetchSlide = (slideRef) => async (dispatch, getState, { services }) => {
|
|
10
|
+
const action = buildTask({
|
|
11
|
+
types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
|
|
12
|
+
bailout: (state) => {
|
|
13
|
+
return has(`data.slide.${slideRef}`, state);
|
|
14
|
+
},
|
|
15
|
+
task: () => {
|
|
20
16
|
const state = getState();
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const token = get('data.token', state);
|
|
18
|
+
return services.fetchSlide(slideRef, token);
|
|
19
|
+
},
|
|
20
|
+
meta: { slideRef }
|
|
21
|
+
});
|
|
22
|
+
const response = await dispatch(action);
|
|
23
|
+
if (response.type === SLIDE_FETCH_SUCCESS) {
|
|
24
|
+
const slideFromAPI = response.payload;
|
|
25
|
+
if (!slideFromAPI)
|
|
26
|
+
throw new Error('Slide not found');
|
|
27
|
+
const state = getState();
|
|
28
|
+
const slides = get('data.progression.state.slides', state);
|
|
29
|
+
if (isEmpty(slides)) {
|
|
30
|
+
dispatch(setCurrentSlide(slideFromAPI));
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
|
-
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
2
|
+
import type { Options } from '../../types/common';
|
|
3
|
+
import type { StoreState } from '../../reducers';
|
|
4
|
+
export declare const POST_ANSWER_REQUEST: "@@answer/POST_REQUEST";
|
|
5
|
+
export declare const POST_ANSWER_SUCCESS: "@@answer/POST_SUCCESS";
|
|
6
|
+
export declare const POST_ANSWER_FAILURE: "@@answer/POST_FAILURE";
|
|
7
|
+
export declare type PostAnswerRequestAction = {
|
|
8
|
+
type: typeof POST_ANSWER_REQUEST;
|
|
9
|
+
};
|
|
10
|
+
export declare const postAnswer: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
2
|
+
import get from 'lodash/fp/get';
|
|
3
|
+
import { fetchSlide } from './fetch-slide';
|
|
4
|
+
export const POST_ANSWER_REQUEST = '@@answer/POST_REQUEST';
|
|
5
|
+
export const POST_ANSWER_SUCCESS = '@@answer/POST_SUCCESS';
|
|
6
|
+
export const POST_ANSWER_FAILURE = '@@answer/POST_FAILURE';
|
|
7
|
+
export const postAnswer = async (dispatch, getState, { services }) => {
|
|
8
|
+
const action = buildTask({
|
|
9
|
+
types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
|
|
10
|
+
task: () => {
|
|
11
|
+
const state = getState();
|
|
12
|
+
const token = get('data.token', state);
|
|
13
|
+
const answer = get('ui.answers', state);
|
|
14
|
+
const progressionId = get('data.progression._id', state);
|
|
15
|
+
const skillRef = get('data.progression.content.ref', state);
|
|
16
|
+
return services.postAnswer(skillRef, token, progressionId, answer);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const response = await dispatch(action);
|
|
20
|
+
if (response.type === POST_ANSWER_SUCCESS) {
|
|
21
|
+
const progression = response.payload;
|
|
22
|
+
const slideRef = progression.state.nextContent.ref;
|
|
23
|
+
await dispatch(fetchSlide(slideRef));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import { Options, ProgressionFromAPI } from '../../types/common';
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
2
|
+
import type { Options, ProgressionFromAPI } from '../../types/common';
|
|
4
3
|
import type { StoreState } from '../../reducers';
|
|
5
4
|
export declare const POST_PROGRESSION_REQUEST: "@@progression/POST_REQUEST";
|
|
6
5
|
export declare const POST_PROGRESSION_SUCCESS: "@@progression/POST_SUCCESS";
|
|
7
6
|
export declare const POST_PROGRESSION_FAILURE: "@@progression/POST_FAILURE";
|
|
8
|
-
export
|
|
7
|
+
export declare type ReceivedProgression = {
|
|
9
8
|
type: typeof POST_PROGRESSION_SUCCESS;
|
|
10
9
|
payload: ProgressionFromAPI;
|
|
11
|
-
}
|
|
12
|
-
export declare
|
|
13
|
-
export declare const postProgression: (skillRef: string, token: string) => PostProgressionAction;
|
|
10
|
+
};
|
|
11
|
+
export declare const postProgression: (skillRef: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import buildTask from '@coorpacademy/redux-task';
|
|
2
|
+
import get from 'lodash/fp/get';
|
|
2
3
|
import { fetchSlide } from './fetch-slide';
|
|
3
4
|
export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST';
|
|
4
5
|
export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS';
|
|
5
6
|
export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE';
|
|
6
|
-
export const postProgression = (skillRef,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export const postProgression = (skillRef) => async (dispatch, getState, { services }) => {
|
|
8
|
+
const state = getState();
|
|
9
|
+
const token = get('data.token', state);
|
|
10
|
+
const action = buildTask({
|
|
11
|
+
types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
|
|
12
|
+
task: () => {
|
|
13
|
+
return services.postProgression(skillRef, token);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const response = await dispatch(action);
|
|
17
|
+
if (response.type === POST_PROGRESSION_SUCCESS) {
|
|
18
|
+
const progression = response.payload;
|
|
19
|
+
const slideRef = progression.state.nextContent.ref;
|
|
20
|
+
await dispatch(fetchSlide(slideRef));
|
|
13
21
|
}
|
|
14
|
-
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { fetchSkills, SKILLS_FETCH_FAILURE, SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS } from '../fetch-skills';
|
|
3
|
+
import { services as mockedServices } from '../../../test/util/services.mock';
|
|
4
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
5
|
+
const initialState = {
|
|
6
|
+
data: {
|
|
7
|
+
progression: null,
|
|
8
|
+
slides: {},
|
|
9
|
+
skills: [],
|
|
10
|
+
token: '1234'
|
|
11
|
+
},
|
|
12
|
+
ui: {
|
|
13
|
+
currentSlideRef: '',
|
|
14
|
+
navigation: [],
|
|
15
|
+
answers: [],
|
|
16
|
+
slide: {
|
|
17
|
+
validateButton: false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a list of skills', async (t) => {
|
|
22
|
+
const services = {
|
|
23
|
+
...mockedServices,
|
|
24
|
+
fetchSkills: token => {
|
|
25
|
+
t.is(token, '1234');
|
|
26
|
+
return Promise.resolve([]);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const expectedActions = [
|
|
30
|
+
{ type: SKILLS_FETCH_REQUEST },
|
|
31
|
+
{
|
|
32
|
+
type: SKILLS_FETCH_SUCCESS,
|
|
33
|
+
payload: []
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
37
|
+
await dispatch(fetchSkills);
|
|
38
|
+
});
|
|
39
|
+
test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', async (t) => {
|
|
40
|
+
const services = {
|
|
41
|
+
...mockedServices,
|
|
42
|
+
fetchSkills: token => {
|
|
43
|
+
t.is(token, '1234');
|
|
44
|
+
return Promise.reject(new Error('unexpected'));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const expectedActions = [
|
|
48
|
+
{ type: SKILLS_FETCH_REQUEST },
|
|
49
|
+
{
|
|
50
|
+
type: SKILLS_FETCH_FAILURE,
|
|
51
|
+
payload: new Error('unexpected'),
|
|
52
|
+
error: true
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
56
|
+
await dispatch(fetchSkills);
|
|
57
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { fetchSlide, SLIDE_FETCH_FAILURE, SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
|
|
3
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
4
|
+
import { services as mockedServices } from '../../../test/util/services.mock';
|
|
5
|
+
import { SET_CURRENT_SLIDE } from '../../ui/slides';
|
|
6
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
7
|
+
const initialState = {
|
|
8
|
+
data: {
|
|
9
|
+
progression: null,
|
|
10
|
+
slides: {},
|
|
11
|
+
skills: [],
|
|
12
|
+
token: '1234'
|
|
13
|
+
},
|
|
14
|
+
ui: {
|
|
15
|
+
currentSlideRef: '',
|
|
16
|
+
navigation: [],
|
|
17
|
+
answers: [],
|
|
18
|
+
slide: {
|
|
19
|
+
validateButton: false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlide return a slide', async (t) => {
|
|
24
|
+
const services = {
|
|
25
|
+
...mockedServices,
|
|
26
|
+
fetchSlide: (slideRef, token) => {
|
|
27
|
+
t.is(token, '1234');
|
|
28
|
+
t.is(slideRef, 'sli_VJYjJnJhg');
|
|
29
|
+
return Promise.resolve(freeTextSlide);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const expectedActions = [
|
|
33
|
+
{ type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'sli_VJYjJnJhg' } },
|
|
34
|
+
{
|
|
35
|
+
type: SLIDE_FETCH_SUCCESS,
|
|
36
|
+
meta: { slideRef: 'sli_VJYjJnJhg' },
|
|
37
|
+
payload: freeTextSlide
|
|
38
|
+
},
|
|
39
|
+
{ type: SET_CURRENT_SLIDE, payload: freeTextSlide }
|
|
40
|
+
];
|
|
41
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
42
|
+
await dispatch(fetchSlide('sli_VJYjJnJhg'));
|
|
43
|
+
});
|
|
44
|
+
test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', async (t) => {
|
|
45
|
+
const services = {
|
|
46
|
+
...mockedServices,
|
|
47
|
+
fetchSlide: (slideRef, token) => {
|
|
48
|
+
t.is(token, '1234');
|
|
49
|
+
t.is(slideRef, 'slide_ref');
|
|
50
|
+
return Promise.reject(new Error('error'));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const expectedActions = [
|
|
54
|
+
{ type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'slide_ref' } },
|
|
55
|
+
{
|
|
56
|
+
type: SLIDE_FETCH_FAILURE,
|
|
57
|
+
meta: { slideRef: 'slide_ref' },
|
|
58
|
+
payload: new Error('error'),
|
|
59
|
+
error: true
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
63
|
+
await dispatch(fetchSlide('slide_ref'));
|
|
64
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
3
|
+
import { postAnswerResponse, services } from '../../../test/util/services.mock';
|
|
4
|
+
import { postAnswer, POST_ANSWER_FAILURE, POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS } from '../post-answer';
|
|
5
|
+
import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
|
|
6
|
+
import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
|
|
7
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
8
|
+
import { SET_CURRENT_SLIDE } from '../../ui/slides';
|
|
9
|
+
const progressionId = '123456789123';
|
|
10
|
+
const skillRef = '_skill-ref';
|
|
11
|
+
const answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
|
|
12
|
+
const initialState = {
|
|
13
|
+
data: {
|
|
14
|
+
progression: {
|
|
15
|
+
_id: progressionId,
|
|
16
|
+
content: { type: 'skill', ref: skillRef },
|
|
17
|
+
engine: {
|
|
18
|
+
ref: 'review'
|
|
19
|
+
},
|
|
20
|
+
state: {
|
|
21
|
+
allAnswers: [],
|
|
22
|
+
isCorrect: true,
|
|
23
|
+
nextContent: {
|
|
24
|
+
ref: 'sli_VJYjJnJhg',
|
|
25
|
+
type: 'slide'
|
|
26
|
+
},
|
|
27
|
+
pendingSlides: [],
|
|
28
|
+
slides: [],
|
|
29
|
+
step: {
|
|
30
|
+
current: 1
|
|
31
|
+
},
|
|
32
|
+
stars: 0
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
slides: {
|
|
36
|
+
[freeTextSlide.id]: freeTextSlide
|
|
37
|
+
},
|
|
38
|
+
skills: [{ skillRef, custom: false, name: skillRef, slidesToReview: 5 }],
|
|
39
|
+
token: '1234'
|
|
40
|
+
},
|
|
41
|
+
ui: {
|
|
42
|
+
currentSlideRef: 'sli_VJYjJnJhg',
|
|
43
|
+
navigation: ['skills', 'slides'],
|
|
44
|
+
answers: answer,
|
|
45
|
+
slide: {
|
|
46
|
+
validateButton: false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_SUCCESS when the updated progression is returned', async (t) => {
|
|
51
|
+
const expectedActions = [
|
|
52
|
+
{ type: POST_ANSWER_REQUEST },
|
|
53
|
+
{
|
|
54
|
+
type: POST_ANSWER_SUCCESS,
|
|
55
|
+
payload: postAnswerResponse
|
|
56
|
+
},
|
|
57
|
+
{ type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'sli_VkSQroQnx' } },
|
|
58
|
+
{
|
|
59
|
+
type: SLIDE_FETCH_SUCCESS,
|
|
60
|
+
meta: { slideRef: 'sli_VkSQroQnx' },
|
|
61
|
+
payload: qcmGraphicSlide
|
|
62
|
+
},
|
|
63
|
+
{ type: SET_CURRENT_SLIDE, payload: qcmGraphicSlide }
|
|
64
|
+
];
|
|
65
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
66
|
+
await dispatch(postAnswer);
|
|
67
|
+
});
|
|
68
|
+
test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_FAILURE on error', async (t) => {
|
|
69
|
+
const expectedActions = [
|
|
70
|
+
{ type: POST_ANSWER_REQUEST },
|
|
71
|
+
{
|
|
72
|
+
type: POST_ANSWER_FAILURE,
|
|
73
|
+
payload: new Error('unexpected'),
|
|
74
|
+
error: true
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
const { dispatch } = createTestStore(t, initialState, {
|
|
78
|
+
...services,
|
|
79
|
+
postAnswer: () => Promise.reject(new Error('unexpected'))
|
|
80
|
+
}, expectedActions);
|
|
81
|
+
await dispatch(postAnswer);
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { postProgression, POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE } from '../post-progression';
|
|
3
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
4
|
+
import { services as mockedServices } from '../../../test/util/services.mock';
|
|
5
|
+
import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
|
|
6
|
+
import { SET_CURRENT_SLIDE } from '../../ui/slides';
|
|
7
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
8
|
+
const initialState = {
|
|
9
|
+
data: {
|
|
10
|
+
progression: null,
|
|
11
|
+
slides: {},
|
|
12
|
+
skills: [],
|
|
13
|
+
token: '1234'
|
|
14
|
+
},
|
|
15
|
+
ui: {
|
|
16
|
+
currentSlideRef: '',
|
|
17
|
+
navigation: [],
|
|
18
|
+
answers: [],
|
|
19
|
+
slide: {
|
|
20
|
+
validateButton: false
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions when postProgression return a progression', async (t) => {
|
|
25
|
+
const progression = {
|
|
26
|
+
_id: '62b1d1087aa12f00253f40ee',
|
|
27
|
+
content: {
|
|
28
|
+
ref: '_skill-ref',
|
|
29
|
+
type: 'skill'
|
|
30
|
+
},
|
|
31
|
+
engine: {
|
|
32
|
+
ref: 'review'
|
|
33
|
+
},
|
|
34
|
+
state: {
|
|
35
|
+
allAnswers: [],
|
|
36
|
+
isCorrect: true,
|
|
37
|
+
nextContent: {
|
|
38
|
+
ref: 'sli_VJYjJnJhg',
|
|
39
|
+
type: 'slide'
|
|
40
|
+
},
|
|
41
|
+
pendingSlides: [],
|
|
42
|
+
slides: [],
|
|
43
|
+
step: {
|
|
44
|
+
current: 1
|
|
45
|
+
},
|
|
46
|
+
stars: 0
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const services = {
|
|
50
|
+
...mockedServices,
|
|
51
|
+
postProgression: (skillRef, token) => {
|
|
52
|
+
t.is(token, '1234');
|
|
53
|
+
t.is(skillRef, 'skill_12345');
|
|
54
|
+
return Promise.resolve(progression);
|
|
55
|
+
},
|
|
56
|
+
fetchSlide: (slideRef, token) => {
|
|
57
|
+
t.is(token, '1234');
|
|
58
|
+
t.is(slideRef, 'sli_VJYjJnJhg');
|
|
59
|
+
return Promise.resolve(freeTextSlide);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const expectedActions = [
|
|
63
|
+
{ type: POST_PROGRESSION_REQUEST },
|
|
64
|
+
{
|
|
65
|
+
type: POST_PROGRESSION_SUCCESS,
|
|
66
|
+
payload: progression
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: SLIDE_FETCH_REQUEST,
|
|
70
|
+
meta: {
|
|
71
|
+
slideRef: 'sli_VJYjJnJhg'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: SLIDE_FETCH_SUCCESS,
|
|
76
|
+
meta: {
|
|
77
|
+
slideRef: 'sli_VJYjJnJhg'
|
|
78
|
+
},
|
|
79
|
+
payload: freeTextSlide
|
|
80
|
+
},
|
|
81
|
+
{ type: SET_CURRENT_SLIDE, payload: freeTextSlide }
|
|
82
|
+
];
|
|
83
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
84
|
+
await dispatch(postProgression('skill_12345'));
|
|
85
|
+
});
|
|
86
|
+
test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails', async (t) => {
|
|
87
|
+
const services = {
|
|
88
|
+
...mockedServices,
|
|
89
|
+
postProgression: (skillRef, token) => {
|
|
90
|
+
t.is(token, '1234');
|
|
91
|
+
t.is(skillRef, 'skill_12345');
|
|
92
|
+
return Promise.reject(new Error('error'));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const expectedActions = [
|
|
96
|
+
{ type: POST_PROGRESSION_REQUEST },
|
|
97
|
+
{
|
|
98
|
+
type: POST_PROGRESSION_FAILURE,
|
|
99
|
+
payload: new Error('error'),
|
|
100
|
+
error: true
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
104
|
+
await dispatch(postProgression('skill_12345'));
|
|
105
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { createTestStore } from '../../test/create-test-store';
|
|
3
|
+
import { services } from '../../../test/util/services.mock';
|
|
4
|
+
import { storeToken, STORE_TOKEN } from '../token';
|
|
5
|
+
const initialState = {
|
|
6
|
+
data: {
|
|
7
|
+
progression: null,
|
|
8
|
+
slides: {},
|
|
9
|
+
skills: [],
|
|
10
|
+
token: '1234'
|
|
11
|
+
},
|
|
12
|
+
ui: {
|
|
13
|
+
currentSlideRef: '',
|
|
14
|
+
navigation: [],
|
|
15
|
+
answers: [],
|
|
16
|
+
slide: {
|
|
17
|
+
validateButton: false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
test('should dispatch STORE_TOKEN action when storeToken is called', async (t) => {
|
|
22
|
+
const expectedActions = [{ type: STORE_TOKEN, payload: 'JWT.token' }];
|
|
23
|
+
const { dispatch } = createTestStore(t, initialState, services, expectedActions);
|
|
24
|
+
await dispatch(storeToken('JWT.token'));
|
|
25
|
+
});
|
package/es/actions/index.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { navigateBack, navigateTo, NavigateBack, NavigateTo, StartApp } from './ui/navigation';
|
|
3
|
-
import { ReceivedSlide } from './api/fetch-slide';
|
|
4
|
-
import { ReceiveProgression } from './api/post-progression';
|
|
5
|
-
import { ReceivedSkills } from './api/fetch-skills';
|
|
6
|
-
import { validateSlide } from './ui/slides';
|
|
7
|
-
export declare type Action = NavigateBack | NavigateTo | ReceivedSkills | StartApp | ReceivedSlide | StoreToken | ReceiveProgression;
|
|
1
|
+
import { navigateBack, navigateTo } from './ui/navigation';
|
|
8
2
|
export declare type Dispatchers = {
|
|
9
3
|
navigateTo: typeof navigateTo;
|
|
10
4
|
navigateBack: typeof navigateBack;
|
|
11
|
-
validateSlide: typeof validateSlide;
|
|
12
5
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExecutionContext } from 'ava';
|
|
2
|
+
import { AnyAction, Store } from 'redux';
|
|
3
|
+
import { StoreState } from '../../reducers';
|
|
4
|
+
import { Services } from '../../types/common';
|
|
5
|
+
export declare const createTestStore: (t: ExecutionContext, initialState: StoreState, services: Services, actions: AnyAction[]) => Store;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import constant from 'lodash/fp/constant';
|
|
2
|
+
import { applyMiddleware, compose, createStore } from 'redux';
|
|
3
|
+
import thunk from 'redux-thunk';
|
|
4
|
+
import rootReducer from '../../reducers';
|
|
5
|
+
const assertActionsMiddleware = (t, ACTIONS) => constant((next) => (action) => {
|
|
6
|
+
const expectedAction = ACTIONS.shift();
|
|
7
|
+
if (!expectedAction)
|
|
8
|
+
throw new Error(`Missing {type: "${action.type}"} action`);
|
|
9
|
+
t.deepEqual(action, expectedAction);
|
|
10
|
+
return next(action);
|
|
11
|
+
});
|
|
12
|
+
export const createTestStore = (t, initialState, services, actions) => {
|
|
13
|
+
const thunkMiddleware = thunk.withExtraArgument({ services });
|
|
14
|
+
const enhancer = compose(applyMiddleware(thunkMiddleware, assertActionsMiddleware(t, actions)));
|
|
15
|
+
return createStore(rootReducer, initialState, enhancer);
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dispatch } from 'redux';
|
|
2
|
+
import type { StoreState } from '../../reducers';
|
|
3
|
+
export declare const EDIT_QCM: "@@answer/EDIT_QCM";
|
|
4
|
+
export declare const EDIT_QCM_GRAPHIC: "@@answer/EDIT_QCM_GRAPHIC";
|
|
5
|
+
export declare const EDIT_QCM_DRAG: "@@answer/EDIT_QCM_DRAG";
|
|
6
|
+
export declare const EDIT_TEMPLATE: "@@answer/EDIT_TEMPLATE";
|
|
7
|
+
export declare const EDIT_BASIC: "@@answer/EDIT_BASIC";
|
|
8
|
+
export declare const EDIT_SLIDER: "@@answer/EDIT_SLIDER";
|
|
9
|
+
export declare const ANSWER_EDIT: {
|
|
10
|
+
readonly qcm: "@@answer/EDIT_QCM";
|
|
11
|
+
readonly qcmGraphic: "@@answer/EDIT_QCM_GRAPHIC";
|
|
12
|
+
readonly qcmDrag: "@@answer/EDIT_QCM_DRAG";
|
|
13
|
+
readonly template: "@@answer/EDIT_TEMPLATE";
|
|
14
|
+
readonly basic: "@@answer/EDIT_BASIC";
|
|
15
|
+
readonly slider: "@@answer/EDIT_SLIDER";
|
|
16
|
+
};
|
|
17
|
+
export declare type EditAnswerAction = {
|
|
18
|
+
type: typeof EDIT_QCM | typeof EDIT_QCM_GRAPHIC | typeof EDIT_QCM_DRAG | typeof EDIT_TEMPLATE | typeof EDIT_BASIC | typeof EDIT_SLIDER;
|
|
19
|
+
payload: string[];
|
|
20
|
+
};
|
|
21
|
+
export declare const editAnswer: (answer: string) => (dispatch: Dispatch, getState: () => StoreState) => EditAnswerAction;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { flatten, get, includes, pull } from 'lodash/fp';
|
|
2
|
+
export const EDIT_QCM = '@@answer/EDIT_QCM';
|
|
3
|
+
export const EDIT_QCM_GRAPHIC = '@@answer/EDIT_QCM_GRAPHIC';
|
|
4
|
+
export const EDIT_QCM_DRAG = '@@answer/EDIT_QCM_DRAG';
|
|
5
|
+
export const EDIT_TEMPLATE = '@@answer/EDIT_TEMPLATE';
|
|
6
|
+
export const EDIT_BASIC = '@@answer/EDIT_BASIC';
|
|
7
|
+
export const EDIT_SLIDER = '@@answer/EDIT_SLIDER';
|
|
8
|
+
export const ANSWER_EDIT = {
|
|
9
|
+
qcm: EDIT_QCM,
|
|
10
|
+
qcmGraphic: EDIT_QCM_GRAPHIC,
|
|
11
|
+
qcmDrag: EDIT_QCM_DRAG,
|
|
12
|
+
template: EDIT_TEMPLATE,
|
|
13
|
+
basic: EDIT_BASIC,
|
|
14
|
+
slider: EDIT_SLIDER
|
|
15
|
+
};
|
|
16
|
+
const buildAnswer = (userAnswers, questionType, newValue) => {
|
|
17
|
+
switch (questionType) {
|
|
18
|
+
case 'qcm':
|
|
19
|
+
case 'qcmGraphic':
|
|
20
|
+
case 'qcmDrag': {
|
|
21
|
+
return includes(newValue, userAnswers)
|
|
22
|
+
? pull(newValue, userAnswers)
|
|
23
|
+
: flatten([...userAnswers, newValue]);
|
|
24
|
+
}
|
|
25
|
+
case 'basic':
|
|
26
|
+
case 'slider':
|
|
27
|
+
return [newValue];
|
|
28
|
+
default:
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const editAnswer = (answer) => (dispatch, getState) => {
|
|
33
|
+
const state = getState();
|
|
34
|
+
const currentSlideRef = get(['ui', 'currentSlideRef'])(state);
|
|
35
|
+
const userAnswers = get(['ui', 'answers'])(state);
|
|
36
|
+
const slide = get(['data', 'slides', currentSlideRef])(state);
|
|
37
|
+
const questionType = get(['question', 'type'])(slide);
|
|
38
|
+
const type = get(questionType, ANSWER_EDIT);
|
|
39
|
+
return dispatch({
|
|
40
|
+
type,
|
|
41
|
+
payload: buildAnswer(userAnswers, questionType, answer)
|
|
42
|
+
});
|
|
43
|
+
};
|