@coorpacademy/app-review 0.1.16 → 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.
Files changed (183) hide show
  1. package/es/actions/api/fetch-skills.d.ts +3 -3
  2. package/es/actions/api/fetch-skills.js +7 -2
  3. package/es/actions/api/fetch-slide.d.ts +1 -1
  4. package/es/actions/api/fetch-slide.js +3 -1
  5. package/es/actions/api/post-answer.d.ts +10 -0
  6. package/es/actions/api/post-answer.js +25 -0
  7. package/es/actions/api/post-progression.d.ts +3 -3
  8. package/es/actions/api/post-progression.js +5 -2
  9. package/es/actions/api/test/fetch-skills.test.js +7 -4
  10. package/es/actions/api/test/fetch-slide.test.js +7 -4
  11. package/es/actions/api/test/post-answer.test.d.ts +1 -0
  12. package/es/actions/api/test/post-answer.test.js +82 -0
  13. package/es/actions/api/test/post-progression.test.js +7 -4
  14. package/es/actions/data/test/token.test.d.ts +1 -0
  15. package/es/actions/data/test/token.test.js +25 -0
  16. package/es/actions/index.d.ts +1 -8
  17. package/es/actions/{api/test → test}/create-test-store.d.ts +2 -2
  18. package/es/actions/{api/test → test}/create-test-store.js +1 -1
  19. package/es/actions/ui/answers.d.ts +17 -3
  20. package/es/actions/ui/answers.js +39 -3
  21. package/es/actions/ui/slides.d.ts +0 -5
  22. package/es/actions/ui/slides.js +0 -4
  23. package/es/actions/ui/test/answers.test.d.ts +1 -0
  24. package/es/actions/ui/test/answers.test.js +90 -0
  25. package/es/actions/ui/test/slides.test.d.ts +1 -0
  26. package/es/actions/ui/test/slides.test.js +26 -0
  27. package/es/common/index.d.ts +0 -3
  28. package/es/common/index.js +0 -4
  29. package/es/index.js +1 -3
  30. package/es/reducers/data/index.d.ts +1 -1
  31. package/es/reducers/data/progression.d.ts +2 -3
  32. package/es/reducers/data/progression.js +0 -5
  33. package/es/reducers/data/slides.d.ts +2 -3
  34. package/es/reducers/data/test/progression.test.js +1 -1
  35. package/es/reducers/index.d.ts +2 -1
  36. package/es/reducers/ui/answers.d.ts +2 -2
  37. package/es/reducers/ui/answers.js +4 -8
  38. package/es/reducers/ui/index.d.ts +4 -1
  39. package/es/reducers/ui/index.js +3 -1
  40. package/es/reducers/ui/slide.d.ts +8 -0
  41. package/es/reducers/ui/slide.js +26 -0
  42. package/es/reducers/ui/test/answers.test.js +19 -3
  43. package/es/reducers/ui/test/current-slide-ref.test.js +1 -1
  44. package/es/reducers/ui/test/navigation.test.js +5 -5
  45. package/es/reducers/ui/test/slide.test.d.ts +1 -0
  46. package/es/reducers/ui/test/slide.test.js +12 -0
  47. package/es/test/util/services.mock.d.ts +2 -1
  48. package/es/test/util/services.mock.js +86 -72
  49. package/es/types/common.d.ts +0 -25
  50. package/es/views/skills/index.d.ts +1 -1
  51. package/es/views/skills/index.js +0 -3
  52. package/es/views/skills/test/skills.test.d.ts +1 -0
  53. package/es/views/skills/test/skills.test.js +94 -0
  54. package/es/views/slides/index.d.ts +13 -2
  55. package/es/views/slides/index.js +18 -14
  56. package/es/views/slides/map-api-slide-to-ui.js +44 -51
  57. package/es/views/slides/test/fixtures/free-text.d.ts +2 -1
  58. package/es/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  59. package/es/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  60. package/es/views/slides/test/fixtures/qcm.d.ts +2 -1
  61. package/es/views/slides/test/fixtures/select-template.d.ts +2 -1
  62. package/es/views/slides/test/fixtures/slider.d.ts +2 -1
  63. package/es/views/slides/test/fixtures/text-template.d.ts +2 -1
  64. package/es/views/slides/test/index.test.d.ts +1 -0
  65. package/es/views/slides/test/index.test.js +234 -0
  66. package/lib/actions/api/fetch-skills.d.ts +3 -3
  67. package/lib/actions/api/fetch-skills.js +22 -19
  68. package/lib/actions/api/fetch-slide.d.ts +1 -1
  69. package/lib/actions/api/fetch-slide.js +3 -1
  70. package/lib/actions/api/post-answer.d.ts +10 -0
  71. package/lib/actions/api/post-answer.js +75 -0
  72. package/lib/actions/api/post-progression.d.ts +3 -3
  73. package/lib/actions/api/post-progression.js +6 -3
  74. package/lib/actions/api/test/fetch-skills.test.js +7 -4
  75. package/lib/actions/api/test/fetch-slide.test.js +7 -4
  76. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  77. package/lib/actions/api/test/post-answer.test.js +145 -0
  78. package/lib/actions/api/test/post-progression.test.js +7 -4
  79. package/lib/actions/data/test/token.test.d.ts +1 -0
  80. package/lib/actions/data/test/token.test.js +70 -0
  81. package/lib/actions/index.d.ts +1 -8
  82. package/lib/actions/{api/test → test}/create-test-store.d.ts +2 -2
  83. package/lib/actions/{api/test → test}/create-test-store.js +1 -1
  84. package/lib/actions/ui/answers.d.ts +17 -3
  85. package/lib/actions/ui/answers.js +48 -3
  86. package/lib/actions/ui/slides.d.ts +0 -5
  87. package/lib/actions/ui/slides.js +0 -4
  88. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  89. package/lib/actions/ui/test/answers.test.js +171 -0
  90. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  91. package/lib/actions/ui/test/slides.test.js +71 -0
  92. package/lib/common/index.d.ts +0 -3
  93. package/lib/common/index.js +0 -4
  94. package/lib/index.js +1 -3
  95. package/lib/reducers/data/index.d.ts +1 -1
  96. package/lib/reducers/data/progression.d.ts +2 -3
  97. package/lib/reducers/data/progression.js +0 -5
  98. package/lib/reducers/data/slides.d.ts +2 -3
  99. package/lib/reducers/data/test/progression.test.js +1 -1
  100. package/lib/reducers/index.d.ts +2 -1
  101. package/lib/reducers/ui/answers.d.ts +2 -2
  102. package/lib/reducers/ui/answers.js +4 -8
  103. package/lib/reducers/ui/index.d.ts +4 -1
  104. package/lib/reducers/ui/index.js +3 -1
  105. package/lib/reducers/ui/slide.d.ts +8 -0
  106. package/lib/reducers/ui/slide.js +27 -0
  107. package/lib/reducers/ui/test/answers.test.js +19 -3
  108. package/lib/reducers/ui/test/current-slide-ref.test.js +1 -1
  109. package/lib/reducers/ui/test/navigation.test.js +5 -5
  110. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  111. package/lib/reducers/ui/test/slide.test.js +12 -0
  112. package/lib/test/util/services.mock.d.ts +2 -1
  113. package/lib/test/util/services.mock.js +86 -72
  114. package/lib/types/common.d.ts +0 -25
  115. package/lib/views/skills/index.d.ts +1 -1
  116. package/lib/views/skills/index.js +0 -3
  117. package/lib/views/skills/test/skills.test.d.ts +1 -0
  118. package/lib/views/skills/test/skills.test.js +94 -0
  119. package/lib/views/slides/index.d.ts +13 -2
  120. package/lib/views/slides/index.js +18 -14
  121. package/lib/views/slides/map-api-slide-to-ui.js +77 -76
  122. package/lib/views/slides/test/fixtures/free-text.d.ts +2 -1
  123. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  124. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  125. package/lib/views/slides/test/fixtures/qcm.d.ts +2 -1
  126. package/lib/views/slides/test/fixtures/select-template.d.ts +2 -1
  127. package/lib/views/slides/test/fixtures/slider.d.ts +2 -1
  128. package/lib/views/slides/test/fixtures/text-template.d.ts +2 -1
  129. package/lib/views/slides/test/index.test.d.ts +1 -0
  130. package/lib/views/slides/test/index.test.js +234 -0
  131. package/package.json +6 -5
  132. package/src/actions/api/fetch-skills.ts +18 -11
  133. package/src/actions/api/fetch-slide.ts +3 -1
  134. package/src/actions/api/post-answer.ts +39 -0
  135. package/src/actions/api/post-progression.ts +7 -4
  136. package/src/actions/api/test/fetch-skills.test.ts +9 -6
  137. package/src/actions/api/test/fetch-slide.test.ts +9 -6
  138. package/src/actions/api/test/post-answer.test.ts +101 -0
  139. package/src/actions/api/test/post-progression.test.ts +9 -6
  140. package/src/actions/data/test/token.test.ts +29 -0
  141. package/src/actions/index.ts +1 -17
  142. package/src/actions/{api/test → test}/create-test-store.ts +2 -2
  143. package/src/actions/ui/answers.ts +52 -5
  144. package/src/actions/ui/slides.ts +1 -8
  145. package/src/actions/ui/test/answers.test.ts +103 -0
  146. package/src/actions/ui/test/slides.test.ts +30 -0
  147. package/src/common/index.ts +0 -7
  148. package/src/index.tsx +1 -3
  149. package/src/reducers/data/progression.ts +2 -7
  150. package/src/reducers/data/slides.ts +2 -3
  151. package/src/reducers/data/test/progression.test.ts +3 -3
  152. package/src/reducers/ui/answers.ts +5 -9
  153. package/src/reducers/ui/index.ts +4 -1
  154. package/src/reducers/ui/slide.ts +43 -0
  155. package/src/reducers/ui/test/answers.test.ts +24 -4
  156. package/src/reducers/ui/test/current-slide-ref.test.ts +1 -1
  157. package/src/reducers/ui/test/navigation.test.ts +5 -5
  158. package/src/reducers/ui/test/slide.test.ts +15 -0
  159. package/src/test/util/services.mock.ts +91 -73
  160. package/src/types/common.ts +0 -30
  161. package/src/views/skills/index.ts +1 -5
  162. package/src/views/skills/test/skills.test.ts +101 -0
  163. package/src/views/slides/index.ts +37 -22
  164. package/src/views/slides/map-api-slide-to-ui.ts +89 -89
  165. package/src/views/slides/test/fixtures/free-text.ts +2 -1
  166. package/src/views/slides/test/fixtures/qcm-drag.ts +2 -1
  167. package/src/views/slides/test/fixtures/qcm-graphic.ts +2 -1
  168. package/src/views/slides/test/fixtures/qcm.ts +2 -1
  169. package/src/views/slides/test/fixtures/select-template.ts +2 -1
  170. package/src/views/slides/test/fixtures/slider.ts +2 -1
  171. package/src/views/slides/test/fixtures/text-template.ts +2 -1
  172. package/src/views/slides/test/index.test.ts +240 -0
  173. package/src/views/slides/test/map-api-slide-to-ui.test.ts +2 -1
  174. package/es/fixtures/qcm-slide.d.ts +0 -2
  175. package/es/fixtures/qcm-slide.js +0 -33
  176. package/es/fixtures/temp-fixture.d.ts +0 -3
  177. package/es/fixtures/temp-fixture.js +0 -84
  178. package/lib/fixtures/qcm-slide.d.ts +0 -2
  179. package/lib/fixtures/qcm-slide.js +0 -33
  180. package/lib/fixtures/temp-fixture.d.ts +0 -3
  181. package/lib/fixtures/temp-fixture.js +0 -84
  182. package/src/fixtures/qcm-slide.ts +0 -35
  183. package/src/fixtures/temp-fixture.ts +0 -94
@@ -0,0 +1,75 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import buildTask from '@coorpacademy/redux-task';
38
+ import get from 'lodash/fp/get';
39
+ import { fetchSlide } from './fetch-slide';
40
+ export var POST_ANSWER_REQUEST = '@@answer/POST_REQUEST';
41
+ export var POST_ANSWER_SUCCESS = '@@answer/POST_SUCCESS';
42
+ export var POST_ANSWER_FAILURE = '@@answer/POST_FAILURE';
43
+ export var postAnswer = function (dispatch, getState, _a) {
44
+ var services = _a.services;
45
+ return __awaiter(void 0, void 0, void 0, function () {
46
+ var action, response, progression, slideRef;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ action = buildTask({
51
+ types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
52
+ task: function () {
53
+ var state = getState();
54
+ var token = get('data.token', state);
55
+ var answer = get('ui.answers', state);
56
+ var progressionId = get('data.progression._id', state);
57
+ var skillRef = get('data.progression.content.ref', state);
58
+ return services.postAnswer(skillRef, token, progressionId, answer);
59
+ }
60
+ });
61
+ return [4 /*yield*/, dispatch(action)];
62
+ case 1:
63
+ response = _b.sent();
64
+ if (!(response.type === POST_ANSWER_SUCCESS)) return [3 /*break*/, 3];
65
+ progression = response.payload;
66
+ slideRef = progression.state.nextContent.ref;
67
+ return [4 /*yield*/, dispatch(fetchSlide(slideRef))];
68
+ case 2:
69
+ _b.sent();
70
+ _b.label = 3;
71
+ case 3: return [2 /*return*/];
72
+ }
73
+ });
74
+ });
75
+ };
@@ -1,11 +1,11 @@
1
1
  import type { Dispatch } from 'redux';
2
- import { Options, ProgressionFromAPI } from '../../types/common';
2
+ import type { Options, ProgressionFromAPI } from '../../types/common';
3
3
  import type { StoreState } from '../../reducers';
4
4
  export declare const POST_PROGRESSION_REQUEST: "@@progression/POST_REQUEST";
5
5
  export declare const POST_PROGRESSION_SUCCESS: "@@progression/POST_SUCCESS";
6
6
  export declare const POST_PROGRESSION_FAILURE: "@@progression/POST_FAILURE";
7
- export declare type ReceiveProgression = {
7
+ export declare type ReceivedProgression = {
8
8
  type: typeof POST_PROGRESSION_SUCCESS;
9
9
  payload: ProgressionFromAPI;
10
10
  };
11
- export declare const postProgression: (skillRef: string, token: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
11
+ export declare const postProgression: (skillRef: string) => (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -35,18 +35,21 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import buildTask from '@coorpacademy/redux-task';
38
+ import get from 'lodash/fp/get';
38
39
  import { fetchSlide } from './fetch-slide';
39
40
  export var POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST';
40
41
  export var POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS';
41
42
  export var POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE';
42
- export var postProgression = function (skillRef, token) {
43
+ export var postProgression = function (skillRef) {
43
44
  return function (dispatch, getState, _a) {
44
45
  var services = _a.services;
45
46
  return __awaiter(void 0, void 0, void 0, function () {
46
- var action, response, progression, slideRef;
47
+ var state, token, action, response, progression, slideRef;
47
48
  return __generator(this, function (_b) {
48
49
  switch (_b.label) {
49
50
  case 0:
51
+ state = getState();
52
+ token = get('data.token', state);
50
53
  action = buildTask({
51
54
  types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
52
55
  task: function () {
@@ -59,7 +62,7 @@ export var postProgression = function (skillRef, token) {
59
62
  if (!(response.type === POST_PROGRESSION_SUCCESS)) return [3 /*break*/, 3];
60
63
  progression = response.payload;
61
64
  slideRef = progression.state.nextContent.ref;
62
- return [4 /*yield*/, dispatch(fetchSlide(slideRef, token))];
65
+ return [4 /*yield*/, dispatch(fetchSlide(slideRef))];
63
66
  case 2:
64
67
  _b.sent();
65
68
  _b.label = 3;
@@ -48,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  import test from 'ava';
49
49
  import { fetchSkills, SKILLS_FETCH_FAILURE, SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS } from '../fetch-skills';
50
50
  import { services as mockedServices } from '../../../test/util/services.mock';
51
- import { createTestStore } from './create-test-store';
51
+ import { createTestStore } from '../../test/create-test-store';
52
52
  var initialState = {
53
53
  data: {
54
54
  progression: null,
@@ -59,7 +59,10 @@ var initialState = {
59
59
  ui: {
60
60
  currentSlideRef: '',
61
61
  navigation: [],
62
- answers: []
62
+ answers: [],
63
+ slide: {
64
+ validateButton: false
65
+ }
63
66
  }
64
67
  };
65
68
  test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a list of skills', function (t) { return __awaiter(void 0, void 0, void 0, function () {
@@ -79,7 +82,7 @@ test('should dispatch SKILLS_FETCH_SUCCESS actions when fetchSkills return a lis
79
82
  }
80
83
  ];
81
84
  dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
82
- return [4 /*yield*/, dispatch(fetchSkills('1234'))];
85
+ return [4 /*yield*/, dispatch(fetchSkills)];
83
86
  case 1:
84
87
  _a.sent();
85
88
  return [2 /*return*/];
@@ -104,7 +107,7 @@ test('should dispatch SKILLS_FETCH_FAILURE action when fetchSkills fails', funct
104
107
  }
105
108
  ];
106
109
  dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
107
- return [4 /*yield*/, dispatch(fetchSkills('1234'))];
110
+ return [4 /*yield*/, dispatch(fetchSkills)];
108
111
  case 1:
109
112
  _a.sent();
110
113
  return [2 /*return*/];
@@ -50,7 +50,7 @@ import { fetchSlide, SLIDE_FETCH_FAILURE, SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCE
50
50
  import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
51
51
  import { services as mockedServices } from '../../../test/util/services.mock';
52
52
  import { SET_CURRENT_SLIDE } from '../../ui/slides';
53
- import { createTestStore } from './create-test-store';
53
+ import { createTestStore } from '../../test/create-test-store';
54
54
  var initialState = {
55
55
  data: {
56
56
  progression: null,
@@ -61,7 +61,10 @@ var initialState = {
61
61
  ui: {
62
62
  currentSlideRef: '',
63
63
  navigation: [],
64
- answers: []
64
+ answers: [],
65
+ slide: {
66
+ validateButton: false
67
+ }
65
68
  }
66
69
  };
67
70
  test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlide return a slide', function (t) { return __awaiter(void 0, void 0, void 0, function () {
@@ -84,7 +87,7 @@ test('should dispatch FETCH_SUCCESS and SET_CURRENT_SLIDE actions when fetchSlid
84
87
  { type: SET_CURRENT_SLIDE, payload: freeTextSlide }
85
88
  ];
86
89
  dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
87
- return [4 /*yield*/, dispatch(fetchSlide('sli_VJYjJnJhg', '1234'))];
90
+ return [4 /*yield*/, dispatch(fetchSlide('sli_VJYjJnJhg'))];
88
91
  case 1:
89
92
  _a.sent();
90
93
  return [2 /*return*/];
@@ -111,7 +114,7 @@ test('should dispatch SLIDE_FETCH_FAILURE action when fetchSlide fails', functio
111
114
  }
112
115
  ];
113
116
  dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
114
- return [4 /*yield*/, dispatch(fetchSlide('slide_ref', '1234'))];
117
+ return [4 /*yield*/, dispatch(fetchSlide('slide_ref'))];
115
118
  case 1:
116
119
  _a.sent();
117
120
  return [2 /*return*/];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,145 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var _a;
49
+ import test from 'ava';
50
+ import { createTestStore } from '../../test/create-test-store';
51
+ import { postAnswerResponse, services } from '../../../test/util/services.mock';
52
+ import { postAnswer, POST_ANSWER_FAILURE, POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS } from '../post-answer';
53
+ import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
54
+ import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
55
+ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
56
+ import { SET_CURRENT_SLIDE } from '../../ui/slides';
57
+ var progressionId = '123456789123';
58
+ var skillRef = '_skill-ref';
59
+ var answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
60
+ var initialState = {
61
+ data: {
62
+ progression: {
63
+ _id: progressionId,
64
+ content: { type: 'skill', ref: skillRef },
65
+ engine: {
66
+ ref: 'review'
67
+ },
68
+ state: {
69
+ allAnswers: [],
70
+ isCorrect: true,
71
+ nextContent: {
72
+ ref: 'sli_VJYjJnJhg',
73
+ type: 'slide'
74
+ },
75
+ pendingSlides: [],
76
+ slides: [],
77
+ step: {
78
+ current: 1
79
+ },
80
+ stars: 0
81
+ }
82
+ },
83
+ slides: (_a = {},
84
+ _a[freeTextSlide.id] = freeTextSlide,
85
+ _a),
86
+ skills: [{ skillRef: skillRef, custom: false, name: skillRef, slidesToReview: 5 }],
87
+ token: '1234'
88
+ },
89
+ ui: {
90
+ currentSlideRef: 'sli_VJYjJnJhg',
91
+ navigation: ['skills', 'slides'],
92
+ answers: answer,
93
+ slide: {
94
+ validateButton: false
95
+ }
96
+ }
97
+ };
98
+ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_SUCCESS when the updated progression is returned', function (t) { return __awaiter(void 0, void 0, void 0, function () {
99
+ var expectedActions, dispatch;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ expectedActions = [
104
+ { type: POST_ANSWER_REQUEST },
105
+ {
106
+ type: POST_ANSWER_SUCCESS,
107
+ payload: postAnswerResponse
108
+ },
109
+ { type: SLIDE_FETCH_REQUEST, meta: { slideRef: 'sli_VkSQroQnx' } },
110
+ {
111
+ type: SLIDE_FETCH_SUCCESS,
112
+ meta: { slideRef: 'sli_VkSQroQnx' },
113
+ payload: qcmGraphicSlide
114
+ },
115
+ { type: SET_CURRENT_SLIDE, payload: qcmGraphicSlide }
116
+ ];
117
+ dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
118
+ return [4 /*yield*/, dispatch(postAnswer)];
119
+ case 1:
120
+ _a.sent();
121
+ return [2 /*return*/];
122
+ }
123
+ });
124
+ }); });
125
+ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_FAILURE on error', function (t) { return __awaiter(void 0, void 0, void 0, function () {
126
+ var expectedActions, dispatch;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0:
130
+ expectedActions = [
131
+ { type: POST_ANSWER_REQUEST },
132
+ {
133
+ type: POST_ANSWER_FAILURE,
134
+ payload: new Error('unexpected'),
135
+ error: true
136
+ }
137
+ ];
138
+ dispatch = createTestStore(t, initialState, __assign(__assign({}, services), { postAnswer: function () { return Promise.reject(new Error('unexpected')); } }), expectedActions).dispatch;
139
+ return [4 /*yield*/, dispatch(postAnswer)];
140
+ case 1:
141
+ _a.sent();
142
+ return [2 /*return*/];
143
+ }
144
+ });
145
+ }); });
@@ -51,7 +51,7 @@ import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
51
51
  import { services as mockedServices } from '../../../test/util/services.mock';
52
52
  import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
53
53
  import { SET_CURRENT_SLIDE } from '../../ui/slides';
54
- import { createTestStore } from './create-test-store';
54
+ import { createTestStore } from '../../test/create-test-store';
55
55
  var initialState = {
56
56
  data: {
57
57
  progression: null,
@@ -62,7 +62,10 @@ var initialState = {
62
62
  ui: {
63
63
  currentSlideRef: '',
64
64
  navigation: [],
65
- answers: []
65
+ answers: [],
66
+ slide: {
67
+ validateButton: false
68
+ }
66
69
  }
67
70
  };
68
71
  test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions when postProgression return a progression', function (t) { return __awaiter(void 0, void 0, void 0, function () {
@@ -125,7 +128,7 @@ test('should dispatch POST_PROGRESSION_SUCCESS and SLIDE_FETCH_REQUEST actions w
125
128
  { type: SET_CURRENT_SLIDE, payload: freeTextSlide }
126
129
  ];
127
130
  dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
128
- return [4 /*yield*/, dispatch(postProgression('skill_12345', '1234'))];
131
+ return [4 /*yield*/, dispatch(postProgression('skill_12345'))];
129
132
  case 1:
130
133
  _a.sent();
131
134
  return [2 /*return*/];
@@ -151,7 +154,7 @@ test('should dispatch POST_PROGRESSION_FAILURE action when postProgression fails
151
154
  }
152
155
  ];
153
156
  dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
154
- return [4 /*yield*/, dispatch(postProgression('skill_12345', '1234'))];
157
+ return [4 /*yield*/, dispatch(postProgression('skill_12345'))];
155
158
  case 1:
156
159
  _a.sent();
157
160
  return [2 /*return*/];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import test from 'ava';
38
+ import { createTestStore } from '../../test/create-test-store';
39
+ import { services } from '../../../test/util/services.mock';
40
+ import { storeToken, STORE_TOKEN } from '../token';
41
+ var initialState = {
42
+ data: {
43
+ progression: null,
44
+ slides: {},
45
+ skills: [],
46
+ token: '1234'
47
+ },
48
+ ui: {
49
+ currentSlideRef: '',
50
+ navigation: [],
51
+ answers: [],
52
+ slide: {
53
+ validateButton: false
54
+ }
55
+ }
56
+ };
57
+ test('should dispatch STORE_TOKEN action when storeToken is called', function (t) { return __awaiter(void 0, void 0, void 0, function () {
58
+ var expectedActions, dispatch;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ expectedActions = [{ type: STORE_TOKEN, payload: 'JWT.token' }];
63
+ dispatch = createTestStore(t, initialState, services, expectedActions).dispatch;
64
+ return [4 /*yield*/, dispatch(storeToken('JWT.token'))];
65
+ case 1:
66
+ _a.sent();
67
+ return [2 /*return*/];
68
+ }
69
+ });
70
+ }); });
@@ -1,12 +1,5 @@
1
- import { StoreToken } from './data/token';
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
  };
@@ -1,5 +1,5 @@
1
1
  import type { ExecutionContext } from 'ava';
2
2
  import { AnyAction, Store } from 'redux';
3
- import { StoreState } from '../../../reducers';
4
- import { Services } from '../../../types/common';
3
+ import { StoreState } from '../../reducers';
4
+ import { Services } from '../../types/common';
5
5
  export declare const createTestStore: (t: ExecutionContext, initialState: StoreState, services: Services, actions: AnyAction[]) => Store;
@@ -1,7 +1,7 @@
1
1
  import constant from 'lodash/fp/constant';
2
2
  import { applyMiddleware, compose, createStore } from 'redux';
3
3
  import thunk from 'redux-thunk';
4
- import rootReducer from '../../../reducers';
4
+ import rootReducer from '../../reducers';
5
5
  var assertActionsMiddleware = function (t, ACTIONS) {
6
6
  return constant(function (next) { return function (action) {
7
7
  var expectedAction = ACTIONS.shift();
@@ -1,7 +1,21 @@
1
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";
2
7
  export declare const EDIT_BASIC: "@@answer/EDIT_BASIC";
3
- export declare type EditBasicAction = {
4
- type: typeof 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;
5
19
  payload: string[];
6
20
  };
7
- export declare const editAnswer: (answer: string) => (dispatch: Dispatch) => EditBasicAction;
21
+ export declare const editAnswer: (answer: string) => (dispatch: Dispatch, getState: () => StoreState) => EditAnswerAction;
@@ -1,9 +1,54 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { flatten, get, includes, pull } from 'lodash/fp';
11
+ export var EDIT_QCM = '@@answer/EDIT_QCM';
12
+ export var EDIT_QCM_GRAPHIC = '@@answer/EDIT_QCM_GRAPHIC';
13
+ export var EDIT_QCM_DRAG = '@@answer/EDIT_QCM_DRAG';
14
+ export var EDIT_TEMPLATE = '@@answer/EDIT_TEMPLATE';
1
15
  export var EDIT_BASIC = '@@answer/EDIT_BASIC';
16
+ export var EDIT_SLIDER = '@@answer/EDIT_SLIDER';
17
+ export var ANSWER_EDIT = {
18
+ qcm: EDIT_QCM,
19
+ qcmGraphic: EDIT_QCM_GRAPHIC,
20
+ qcmDrag: EDIT_QCM_DRAG,
21
+ template: EDIT_TEMPLATE,
22
+ basic: EDIT_BASIC,
23
+ slider: EDIT_SLIDER
24
+ };
25
+ var buildAnswer = function (userAnswers, questionType, newValue) {
26
+ switch (questionType) {
27
+ case 'qcm':
28
+ case 'qcmGraphic':
29
+ case 'qcmDrag': {
30
+ return includes(newValue, userAnswers)
31
+ ? pull(newValue, userAnswers)
32
+ : flatten(__spreadArray(__spreadArray([], userAnswers, true), [newValue], false));
33
+ }
34
+ case 'basic':
35
+ case 'slider':
36
+ return [newValue];
37
+ default:
38
+ return [];
39
+ }
40
+ };
2
41
  export var editAnswer = function (answer) {
3
- return function (dispatch) {
42
+ return function (dispatch, getState) {
43
+ var state = getState();
44
+ var currentSlideRef = get(['ui', 'currentSlideRef'])(state);
45
+ var userAnswers = get(['ui', 'answers'])(state);
46
+ var slide = get(['data', 'slides', currentSlideRef])(state);
47
+ var questionType = get(['question', 'type'])(slide);
48
+ var type = get(questionType, ANSWER_EDIT);
4
49
  return dispatch({
5
- type: EDIT_BASIC,
6
- payload: [answer]
50
+ type: type,
51
+ payload: buildAnswer(userAnswers, questionType, answer)
7
52
  });
8
53
  };
9
54
  };
@@ -17,10 +17,5 @@ export declare type SetCurrentSlide = {
17
17
  payload: SlideFromAPI;
18
18
  };
19
19
  export declare const setCurrentSlide: (payload: SlideFromAPI) => SetCurrentSlide;
20
- export declare const VALIDATE_SLIDE = "@@slide/VALIDATE";
21
- export declare type ValidateSlide = {
22
- type: typeof VALIDATE_SLIDE;
23
- };
24
- export declare const validateSlide: () => ValidateSlide;
25
20
  export declare type UISlidesAction = SetCurrentSlide;
26
21
  export {};
@@ -3,7 +3,3 @@ export var setCurrentSlide = function (payload) { return ({
3
3
  type: SET_CURRENT_SLIDE,
4
4
  payload: payload
5
5
  }); };
6
- export var VALIDATE_SLIDE = '@@slide/VALIDATE';
7
- export var validateSlide = function () { return ({
8
- type: VALIDATE_SLIDE
9
- }); };
@@ -0,0 +1 @@
1
+ export {};