@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.
Files changed (289) hide show
  1. package/es/actions/api/fetch-skills.d.ts +5 -7
  2. package/es/actions/api/fetch-skills.js +12 -4
  3. package/es/actions/api/fetch-slide.d.ts +14 -7
  4. package/es/actions/api/fetch-slide.js +23 -18
  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 +5 -7
  8. package/es/actions/api/post-progression.js +16 -8
  9. package/es/actions/api/test/fetch-skills.test.js +57 -0
  10. package/es/actions/api/test/fetch-slide.test.js +64 -0
  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.d.ts +1 -0
  14. package/es/actions/api/test/post-progression.test.js +105 -0
  15. package/es/actions/data/test/token.test.d.ts +1 -0
  16. package/es/actions/data/test/token.test.js +25 -0
  17. package/es/actions/index.d.ts +1 -8
  18. package/es/actions/test/create-test-store.d.ts +5 -0
  19. package/es/actions/test/create-test-store.js +16 -0
  20. package/es/actions/ui/answers.d.ts +21 -0
  21. package/es/actions/ui/answers.js +43 -0
  22. package/es/actions/ui/slides.d.ts +0 -5
  23. package/es/actions/ui/slides.js +0 -4
  24. package/es/actions/ui/test/answers.test.d.ts +1 -0
  25. package/es/actions/ui/test/answers.test.js +90 -0
  26. package/es/actions/ui/test/slides.test.d.ts +1 -0
  27. package/es/actions/ui/test/slides.test.js +26 -0
  28. package/es/common/index.d.ts +0 -3
  29. package/es/common/index.js +0 -4
  30. package/es/index.js +11 -19
  31. package/es/reducers/data/index.d.ts +2 -2
  32. package/es/reducers/data/progression.d.ts +2 -3
  33. package/es/reducers/data/progression.js +0 -5
  34. package/es/reducers/data/slides.d.ts +3 -4
  35. package/es/reducers/data/slides.js +5 -1
  36. package/es/reducers/data/test/progression.test.d.ts +1 -0
  37. package/es/reducers/data/test/progression.test.js +38 -0
  38. package/es/reducers/data/test/skills.test.d.ts +1 -0
  39. package/es/reducers/data/test/skills.test.js +12 -0
  40. package/es/reducers/data/test/slides.test.d.ts +1 -0
  41. package/es/reducers/data/test/slides.test.js +20 -0
  42. package/es/reducers/data/test/token.test.d.ts +1 -0
  43. package/es/reducers/data/test/token.test.js +11 -0
  44. package/es/reducers/index.d.ts +3 -2
  45. package/es/reducers/ui/answers.d.ts +4 -0
  46. package/es/reducers/ui/answers.js +9 -0
  47. package/es/reducers/ui/index.d.ts +7 -4
  48. package/es/reducers/ui/index.js +4 -2
  49. package/es/reducers/ui/slide.d.ts +8 -0
  50. package/es/reducers/ui/slide.js +26 -0
  51. package/es/reducers/ui/test/answers.test.d.ts +1 -0
  52. package/es/reducers/ui/test/answers.test.js +27 -0
  53. package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  54. package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
  55. package/es/reducers/ui/test/navigation.test.d.ts +1 -0
  56. package/es/reducers/ui/test/navigation.test.js +15 -0
  57. package/es/reducers/ui/test/slide.test.d.ts +1 -0
  58. package/es/reducers/ui/test/slide.test.js +12 -0
  59. package/es/services/fetch-slide.js +1 -1
  60. package/es/services/index.js +3 -1
  61. package/es/services/post-answer.d.ts +2 -0
  62. package/es/services/post-answer.js +18 -0
  63. package/es/services/test/fetch-slide.test.d.ts +1 -0
  64. package/es/services/test/fetch-slide.test.js +22 -0
  65. package/es/services/test/post-answer.test.d.ts +1 -0
  66. package/es/services/test/post-answer.test.js +57 -0
  67. package/es/services/test/post-progression.test.js +9 -1
  68. package/es/test/util/services.mock.d.ts +2 -1
  69. package/es/test/util/services.mock.js +88 -44
  70. package/es/types/common.d.ts +22 -33
  71. package/es/views/skills/index.d.ts +1 -1
  72. package/es/views/skills/index.js +0 -3
  73. package/es/views/skills/test/skills.test.d.ts +1 -0
  74. package/es/views/skills/test/skills.test.js +94 -0
  75. package/es/views/slides/index.d.ts +89 -2
  76. package/es/views/slides/index.js +80 -10
  77. package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
  78. package/es/views/slides/map-api-slide-to-ui.js +165 -0
  79. package/es/{helpers → views/slides}/test/fixtures/free-text.d.ts +2 -1
  80. package/es/views/slides/test/fixtures/free-text.js +38 -0
  81. package/es/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +2 -1
  82. package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
  83. package/es/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +2 -1
  84. package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
  85. package/es/{helpers → views/slides}/test/fixtures/qcm.d.ts +2 -1
  86. package/es/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
  87. package/es/{helpers → views/slides}/test/fixtures/select-template.d.ts +2 -1
  88. package/es/views/slides/test/fixtures/select-template.js +92 -0
  89. package/es/{helpers → views/slides}/test/fixtures/slider.d.ts +2 -1
  90. package/es/views/slides/test/fixtures/slider.js +36 -0
  91. package/es/{helpers → views/slides}/test/fixtures/text-template.d.ts +2 -1
  92. package/es/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
  93. package/es/views/slides/test/index.test.d.ts +1 -0
  94. package/es/views/slides/test/index.test.js +234 -0
  95. package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  96. package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  97. package/lib/actions/api/fetch-skills.d.ts +5 -7
  98. package/lib/actions/api/fetch-skills.js +58 -7
  99. package/lib/actions/api/fetch-slide.d.ts +14 -7
  100. package/lib/actions/api/fetch-slide.js +72 -20
  101. package/lib/actions/api/post-answer.d.ts +10 -0
  102. package/lib/actions/api/post-answer.js +75 -0
  103. package/lib/actions/api/post-progression.d.ts +5 -7
  104. package/lib/actions/api/post-progression.js +67 -10
  105. package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
  106. package/lib/actions/api/test/fetch-skills.test.js +116 -0
  107. package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
  108. package/lib/actions/api/test/fetch-slide.test.js +123 -0
  109. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  110. package/lib/actions/api/test/post-answer.test.js +145 -0
  111. package/lib/actions/api/test/post-progression.test.d.ts +1 -0
  112. package/lib/actions/api/test/post-progression.test.js +163 -0
  113. package/lib/actions/data/test/token.test.d.ts +1 -0
  114. package/lib/actions/data/test/token.test.js +70 -0
  115. package/lib/actions/index.d.ts +1 -8
  116. package/lib/actions/test/create-test-store.d.ts +5 -0
  117. package/lib/actions/test/create-test-store.js +18 -0
  118. package/lib/actions/ui/answers.d.ts +21 -0
  119. package/lib/actions/ui/answers.js +54 -0
  120. package/lib/actions/ui/slides.d.ts +0 -5
  121. package/lib/actions/ui/slides.js +0 -4
  122. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  123. package/lib/actions/ui/test/answers.test.js +171 -0
  124. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  125. package/lib/actions/ui/test/slides.test.js +71 -0
  126. package/lib/common/index.d.ts +0 -3
  127. package/lib/common/index.js +0 -4
  128. package/lib/index.js +22 -21
  129. package/lib/reducers/data/index.d.ts +2 -2
  130. package/lib/reducers/data/progression.d.ts +2 -3
  131. package/lib/reducers/data/progression.js +0 -5
  132. package/lib/reducers/data/slides.d.ts +3 -4
  133. package/lib/reducers/data/slides.js +5 -1
  134. package/lib/reducers/data/test/progression.test.d.ts +1 -0
  135. package/lib/reducers/data/test/progression.test.js +38 -0
  136. package/lib/reducers/data/test/skills.test.d.ts +1 -0
  137. package/lib/reducers/data/test/skills.test.js +12 -0
  138. package/lib/reducers/data/test/slides.test.d.ts +1 -0
  139. package/lib/reducers/data/test/slides.test.js +20 -0
  140. package/lib/reducers/data/test/token.test.d.ts +1 -0
  141. package/lib/reducers/data/test/token.test.js +11 -0
  142. package/lib/reducers/index.d.ts +3 -2
  143. package/lib/reducers/ui/answers.d.ts +4 -0
  144. package/lib/reducers/ui/answers.js +10 -0
  145. package/lib/reducers/ui/index.d.ts +7 -4
  146. package/lib/reducers/ui/index.js +4 -2
  147. package/lib/reducers/ui/slide.d.ts +8 -0
  148. package/lib/reducers/ui/slide.js +27 -0
  149. package/lib/reducers/ui/test/answers.test.d.ts +1 -0
  150. package/lib/reducers/ui/test/answers.test.js +27 -0
  151. package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  152. package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
  153. package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
  154. package/lib/reducers/ui/test/navigation.test.js +15 -0
  155. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  156. package/lib/reducers/ui/test/slide.test.js +12 -0
  157. package/lib/services/fetch-slide.js +1 -1
  158. package/lib/services/index.js +3 -1
  159. package/lib/services/post-answer.d.ts +2 -0
  160. package/lib/services/post-answer.js +62 -0
  161. package/lib/services/test/fetch-slide.test.d.ts +1 -0
  162. package/lib/services/test/fetch-slide.test.js +76 -0
  163. package/lib/services/test/post-answer.test.d.ts +1 -0
  164. package/lib/services/test/post-answer.test.js +111 -0
  165. package/lib/services/test/post-progression.test.js +9 -1
  166. package/lib/test/util/services.mock.d.ts +2 -1
  167. package/lib/test/util/services.mock.js +88 -44
  168. package/lib/types/common.d.ts +22 -33
  169. package/lib/views/skills/index.d.ts +1 -1
  170. package/lib/views/skills/index.js +0 -3
  171. package/lib/views/skills/test/skills.test.d.ts +1 -0
  172. package/lib/views/skills/test/skills.test.js +94 -0
  173. package/lib/views/slides/index.d.ts +89 -2
  174. package/lib/views/slides/index.js +80 -10
  175. package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
  176. package/lib/views/slides/map-api-slide-to-ui.js +179 -0
  177. package/lib/{helpers → views/slides}/test/fixtures/free-text.d.ts +2 -1
  178. package/lib/views/slides/test/fixtures/free-text.js +38 -0
  179. package/lib/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +2 -1
  180. package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
  181. package/lib/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +2 -1
  182. package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
  183. package/lib/{helpers → views/slides}/test/fixtures/qcm.d.ts +2 -1
  184. package/lib/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
  185. package/lib/{helpers → views/slides}/test/fixtures/select-template.d.ts +2 -1
  186. package/lib/views/slides/test/fixtures/select-template.js +92 -0
  187. package/lib/{helpers → views/slides}/test/fixtures/slider.d.ts +2 -1
  188. package/lib/views/slides/test/fixtures/slider.js +36 -0
  189. package/lib/{helpers → views/slides}/test/fixtures/text-template.d.ts +2 -1
  190. package/lib/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
  191. package/lib/views/slides/test/index.test.d.ts +1 -0
  192. package/lib/views/slides/test/index.test.js +234 -0
  193. package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  194. package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  195. package/package.json +6 -5
  196. package/src/actions/api/fetch-skills.ts +19 -12
  197. package/src/actions/api/fetch-slide.ts +35 -29
  198. package/src/actions/api/post-answer.ts +39 -0
  199. package/src/actions/api/post-progression.ts +22 -22
  200. package/src/actions/api/test/fetch-skills.test.ts +73 -0
  201. package/src/actions/api/test/fetch-slide.test.ts +80 -0
  202. package/src/actions/api/test/post-answer.test.ts +101 -0
  203. package/src/actions/api/test/post-progression.test.ts +122 -0
  204. package/src/actions/data/test/token.test.ts +29 -0
  205. package/src/actions/index.ts +1 -17
  206. package/src/actions/test/create-test-store.ts +25 -0
  207. package/src/actions/ui/answers.ts +63 -0
  208. package/src/actions/ui/slides.ts +1 -8
  209. package/src/actions/ui/test/answers.test.ts +103 -0
  210. package/src/actions/ui/test/slides.test.ts +30 -0
  211. package/src/common/index.ts +0 -7
  212. package/src/index.tsx +15 -32
  213. package/src/reducers/data/index.ts +1 -1
  214. package/src/reducers/data/progression.ts +2 -7
  215. package/src/reducers/data/slides.ts +12 -4
  216. package/src/reducers/data/test/progression.test.ts +42 -0
  217. package/src/reducers/data/test/skills.test.ts +14 -0
  218. package/src/reducers/data/test/slides.test.ts +26 -0
  219. package/src/reducers/data/test/token.test.ts +13 -0
  220. package/src/reducers/ui/answers.ts +15 -0
  221. package/src/reducers/ui/index.ts +6 -3
  222. package/src/reducers/ui/slide.ts +43 -0
  223. package/src/reducers/ui/test/answers.test.ts +33 -0
  224. package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
  225. package/src/reducers/ui/test/navigation.test.ts +19 -0
  226. package/src/reducers/ui/test/slide.test.ts +15 -0
  227. package/src/services/fetch-slide.ts +1 -1
  228. package/src/services/index.ts +3 -1
  229. package/src/services/post-answer.ts +27 -0
  230. package/src/services/test/fetch-slide.test.ts +30 -0
  231. package/src/services/test/post-answer.test.ts +68 -0
  232. package/src/services/test/post-progression.test.ts +9 -1
  233. package/src/test/util/services.mock.ts +93 -45
  234. package/src/types/common.ts +34 -44
  235. package/src/views/skills/index.ts +1 -5
  236. package/src/views/skills/test/skills.test.ts +101 -0
  237. package/src/views/slides/index.ts +186 -12
  238. package/src/views/slides/map-api-slide-to-ui.ts +251 -0
  239. package/src/views/slides/test/fixtures/free-text.ts +44 -0
  240. package/src/views/slides/test/fixtures/qcm-drag.ts +112 -0
  241. package/src/views/slides/test/fixtures/qcm-graphic.ts +95 -0
  242. package/src/{helpers → views/slides}/test/fixtures/qcm.ts +7 -2
  243. package/src/views/slides/test/fixtures/select-template.ts +99 -0
  244. package/src/views/slides/test/fixtures/slider.ts +42 -0
  245. package/src/{helpers → views/slides}/test/fixtures/text-template.ts +7 -2
  246. package/src/views/slides/test/index.test.ts +240 -0
  247. package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +22 -10
  248. package/es/fixtures/qcm-slide.d.ts +0 -2
  249. package/es/fixtures/qcm-slide.js +0 -33
  250. package/es/fixtures/temp-fixture.d.ts +0 -3
  251. package/es/fixtures/temp-fixture.js +0 -84
  252. package/es/helpers/map-api-slide-to-ui.d.ts +0 -11
  253. package/es/helpers/map-api-slide-to-ui.js +0 -193
  254. package/es/helpers/test/fixtures/free-text.js +0 -30
  255. package/es/helpers/test/fixtures/qcm-drag.js +0 -112
  256. package/es/helpers/test/fixtures/qcm-graphic.js +0 -76
  257. package/es/helpers/test/fixtures/select-template.js +0 -94
  258. package/es/helpers/test/fixtures/slider.js +0 -33
  259. package/es/reducers/ui/slides.d.ts +0 -9
  260. package/es/reducers/ui/slides.js +0 -42
  261. package/es/types/views/slides.d.ts +0 -74
  262. package/es/types/views/slides.js +0 -6
  263. package/lib/fixtures/qcm-slide.d.ts +0 -2
  264. package/lib/fixtures/qcm-slide.js +0 -33
  265. package/lib/fixtures/temp-fixture.d.ts +0 -3
  266. package/lib/fixtures/temp-fixture.js +0 -84
  267. package/lib/helpers/map-api-slide-to-ui.d.ts +0 -11
  268. package/lib/helpers/map-api-slide-to-ui.js +0 -201
  269. package/lib/helpers/test/fixtures/free-text.js +0 -30
  270. package/lib/helpers/test/fixtures/qcm-drag.js +0 -112
  271. package/lib/helpers/test/fixtures/qcm-graphic.js +0 -76
  272. package/lib/helpers/test/fixtures/select-template.js +0 -94
  273. package/lib/helpers/test/fixtures/slider.js +0 -33
  274. package/lib/reducers/ui/slides.d.ts +0 -9
  275. package/lib/reducers/ui/slides.js +0 -43
  276. package/lib/types/views/slides.d.ts +0 -74
  277. package/lib/types/views/slides.js +0 -6
  278. package/src/fixtures/qcm-slide.ts +0 -35
  279. package/src/fixtures/temp-fixture.ts +0 -94
  280. package/src/helpers/map-api-slide-to-ui.ts +0 -279
  281. package/src/helpers/test/fixtures/free-text.ts +0 -33
  282. package/src/helpers/test/fixtures/qcm-drag.ts +0 -115
  283. package/src/helpers/test/fixtures/qcm-graphic.ts +0 -79
  284. package/src/helpers/test/fixtures/select-template.ts +0 -97
  285. package/src/helpers/test/fixtures/slider.ts +0 -36
  286. package/src/reducers/ui/slides.ts +0 -58
  287. package/src/types/views/slides.ts +0 -90
  288. /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
  289. /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/actions/api/test/fetch-slide.test.d.ts} +0 -0
@@ -1,35 +0,0 @@
1
- import noop from 'lodash/fp/noop';
2
- import {UISlide} from '../types/common';
3
-
4
- export const slide: Pick<UISlide, 'questionText' | 'answerUI'> = {
5
- questionText: 'QCM',
6
- answerUI: {
7
- help: '__help',
8
- model: {
9
- type: 'qcm',
10
- answers: [
11
- {
12
- selected: false,
13
- title: 'choix1',
14
- help: '(help choix1)',
15
- ariaLabel: '__ariaLabel1',
16
- onClick: noop
17
- },
18
- {
19
- selected: false,
20
- title: 'choix2',
21
- help: '(help choix2)',
22
- ariaLabel: '__ariaLabel2',
23
- onClick: noop
24
- },
25
- {
26
- selected: false,
27
- title: 'choix3',
28
- help: '(help choix3)',
29
- ariaLabel: '__ariaLabel3',
30
- onClick: noop
31
- }
32
- ]
33
- }
34
- }
35
- };
@@ -1,94 +0,0 @@
1
- /* eslint-disable no-console */
2
- import {SlidesViewProps, CorrectionPopinProps} from '../types/views/slides';
3
-
4
- export const correctionPopinProps: CorrectionPopinProps = {
5
- klf: {
6
- label: 'Key learning factor',
7
- tooltip: 'Some tooltip info.',
8
- onClick: () => {
9
- console.log('klf onClick');
10
- }
11
- },
12
- information: {
13
- label: 'Key learning factor',
14
- message: 'info msg'
15
- },
16
- next: {
17
- label: 'Next',
18
- ariaLabel: 'Next'
19
- },
20
- successLabel: 'CORRECT ANSWER',
21
- failureLabel: 'WRONG ANSWER'
22
- };
23
-
24
- const confettiAnimationProps = {
25
- 'aria-label': 'aria lottie',
26
- 'data-name': 'default-lottie',
27
- className: undefined,
28
- animationSrc: 'https://static-staging.coorpacademy.com/animations/review/confetti.json',
29
- loop: undefined,
30
- autoplay: true,
31
- rendererSettings: {
32
- hideOnTransparent: false,
33
- animationClassName: ''
34
- },
35
- ie11ImageBackup:
36
- 'https://static-staging.coorpacademy.com/animations/review/conffeti_congrats.svg',
37
- animationControl: undefined
38
- };
39
-
40
- const starAnimationProps = {
41
- 'aria-label': 'Review Card Congrats Container',
42
- 'data-name': 'card-star',
43
- animationLottie: {
44
- 'aria-label': 'aria lottie',
45
- 'data-name': 'default-lottie',
46
- animationSrc: 'https://static-staging.coorpacademy.com/animations/review/star.json',
47
- ie11ImageBackup:
48
- 'https://static-staging.coorpacademy.com/animations/review/stars_icon_congrats.svg'
49
- },
50
- iconAriaLabel: 'Image without information',
51
- cardType: 'card-star',
52
- reviewCardTitle: 'You have won',
53
- reviewCardValue: '100',
54
- timerAnimation: 200
55
- };
56
-
57
- const rankAnimationProps = {
58
- 'aria-label': 'Review Card Congrats Container',
59
- 'data-name': 'card-rank',
60
- animationLottie: {
61
- 'aria-label': 'aria lottie',
62
- 'data-name': 'default-lottie',
63
- animationSrc: 'https://static-staging.coorpacademy.com/animations/review/rank.json',
64
- ie11ImageBackup:
65
- 'https://static-staging.coorpacademy.com/animations/review/rank_icon_congrats.svg'
66
- },
67
- cardType: 'card-rank',
68
- iconAriaLabel: 'Image without information',
69
- reviewCardTitle: 'You are now',
70
- reviewCardValue: '14',
71
- rankSuffix: 'th',
72
- timerAnimation: 200
73
- };
74
-
75
- export const congratsProps: SlidesViewProps['congratsProps'] = {
76
- 'aria-label': 'Review Congratulations',
77
- 'data-name': 'review-congrats',
78
- animationLottie: confettiAnimationProps,
79
- title: 'Congratulations!',
80
- cardCongratsStar: starAnimationProps,
81
- cardCongratsRank: rankAnimationProps,
82
- buttonRevising: {
83
- 'aria-label': 'Continue revising button',
84
- label: 'Continue revising',
85
- onClick: () => console.log('Continue revising'),
86
- type: 'tertiary'
87
- },
88
- buttonRevisingSkill: {
89
- label: 'Revise another skill',
90
- 'aria-label': 'Revise another skill button',
91
- onClick: () => console.log('Revise another skill'),
92
- type: 'primary'
93
- }
94
- };
@@ -1,279 +0,0 @@
1
- import {
2
- concat,
3
- divide,
4
- get,
5
- getOr,
6
- head,
7
- includes,
8
- indexOf,
9
- isEmpty,
10
- map,
11
- pipe,
12
- rangeStep,
13
- size,
14
- toInteger
15
- } from 'lodash/fp';
16
- import {
17
- AnswerUI,
18
- FreeText,
19
- Qcm,
20
- QcmDrag,
21
- QcmGraphic,
22
- QuestionRange,
23
- SelectionTemplate,
24
- Template,
25
- TextTemplate
26
- } from '../types/slides';
27
- import {
28
- ChoiceFromAPI,
29
- QcmDragQuestion,
30
- QcmGraphicQuestion,
31
- QcmQuestion,
32
- SlideFromAPI,
33
- SliderQuestion,
34
- TemplateQuestion
35
- } from '../types/common';
36
-
37
- type UiUtils = {translate: (text: string) => string};
38
-
39
- const qcmProps = (question: QcmQuestion): Qcm => {
40
- // TODO: EDIT_CHOICES -> getAnswerValues
41
- const answers: string[] = [];
42
-
43
- return {
44
- type: 'qcm',
45
- answers: map(
46
- choice => ({
47
- title: choice.label,
48
- selected: includes(choice.label, answers),
49
- // TODO: EDIT_CHOICES
50
- // eslint-disable-next-line no-console
51
- onClick: () => console.log('TODO: on choice click'),
52
- ariaLabel: choice.label
53
- }),
54
- // TODO: EDIT_CHOICES -> getChoices
55
- question.content.choices
56
- )
57
- };
58
- };
59
-
60
- const qcmDragProps = (question: QcmDragQuestion): QcmDrag => {
61
- // TODO: EDIT_CHOICES -> getAnswerValues
62
- const answers: string[] = [];
63
- return {
64
- type: 'qcmDrag',
65
- answers: map(choice => {
66
- const indexInAnswer = indexOf(choice.label, answers);
67
- return {
68
- title: choice.label,
69
- selected: indexInAnswer !== -1,
70
- order: indexInAnswer,
71
- // TODO: EDIT_CHOICES
72
- // eslint-disable-next-line no-console
73
- onClick: () => console.log('TODO: on choice click')
74
- };
75
- // TODO: EDIT_CHOICES -> getChoices
76
- }, question.content.choices)
77
- };
78
- };
79
-
80
- const qcmGraphicProps = (question: QcmGraphicQuestion): QcmGraphic => {
81
- // mock the answers
82
- // TODO: EDIT_CHOICES -> getAnswerValues
83
- const answers: string[] = [];
84
- return {
85
- type: 'qcmGraphic',
86
- answers: map(
87
- choice => ({
88
- title: choice.label,
89
- image: get('media.src.0.url', choice),
90
- selected: includes(choice.label, answers),
91
- // TODO: EDIT_CHOICES
92
- // eslint-disable-next-line no-console
93
- onClick: () => console.log('TODO: on choice click')
94
- }),
95
- // TODO: EDIT_CHOICES -> getChoices
96
- question.content.choices
97
- )
98
- };
99
- };
100
-
101
- const templateTextProps =
102
- (uiUtils: UiUtils) =>
103
- (choice: ChoiceFromAPI, index: number): TextTemplate => {
104
- const {translate} = uiUtils;
105
- // TODO: EDIT_CHOICES -> getAnswerValues
106
- const answers: string[] = [];
107
- return {
108
- type: 'text',
109
- name: getOr('', 'name', choice),
110
- placeholder: translate('Type here'),
111
- value: get(index, answers),
112
- // TODO: EDIT_CHOICES
113
- // eslint-disable-next-line no-console
114
- onChange: () => console.log('TODO: on choice change')
115
- };
116
- };
117
-
118
- // const getItemText = (item: ChoiceFromAPI['items'][0]): item['text'] is string =>
119
-
120
- const templateSelectProps = (uiUtils: UiUtils) => {
121
- return (choice: ChoiceFromAPI, index: number): SelectionTemplate => {
122
- const {translate} = uiUtils;
123
- // TODO: EDIT_CHOICES -> getAnswerValues
124
- const answers: string[] = [];
125
- const answer = get(index, answers);
126
- const temporaryOption = {
127
- name: translate('Select an answer'),
128
- value: '',
129
- validOption: false,
130
- selected: true
131
- };
132
- const selectOptions = choice.items.map(item => {
133
- const itemText = getOr('', 'text', item);
134
- return {
135
- name: itemText,
136
- value: itemText,
137
- validOption: true,
138
- selected: itemText === answer
139
- };
140
- });
141
-
142
- return {
143
- type: 'select',
144
- name: getOr('', 'name', choice),
145
- // TODO: EDIT_CHOICES
146
- // eslint-disable-next-line no-console
147
- onChange: () => console.log('TODO: on choice change'),
148
- options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
149
- };
150
- };
151
- };
152
-
153
- const templateProps = (uiUtils: UiUtils): ((question: TemplateQuestion) => Template) => {
154
- const templateTextProps_ = templateTextProps(uiUtils);
155
- const templateSelectProps_ = templateSelectProps(uiUtils);
156
-
157
- return question => {
158
- // TODO: EDIT_CHOICES -> getChoices
159
- const choices = question.content.choices;
160
- return {
161
- type: 'template',
162
- template: get('content.template', question),
163
- answers: choices.map((choice, index) =>
164
- choice.type === 'text'
165
- ? templateTextProps_(choice, index)
166
- : templateSelectProps_(choice, index)
167
- )
168
- };
169
- };
170
- };
171
-
172
- const basicProps = (uiUtils: UiUtils): (() => FreeText) => {
173
- const {translate} = uiUtils;
174
- // TODO: EDIT_CHOICES -> getAnswerValues
175
- const answers: string[] = [];
176
-
177
- return () => {
178
- return {
179
- type: 'freeText',
180
- placeholder: translate('Type here'),
181
- value: head(answers),
182
- // TODO: EDIT_CHOICES
183
- // eslint-disable-next-line no-console
184
- onChange: () => console.log('TODO: on choice change')
185
- };
186
- };
187
- };
188
-
189
- const sliderProps = (question: SliderQuestion): QuestionRange => {
190
- const values: number[] = rangeStep(
191
- getOr(1, 'content.step', question),
192
- getOr(Number.NaN, 'content.min', question),
193
- getOr(Number.NaN, 'content.max', question) + 1
194
- // Lodash doesn't infer the type very well here
195
- ) as unknown as number[];
196
-
197
- // TODO: EDIT_CHOICES -> getAnswerValues
198
- const answers: string[] = [];
199
-
200
- const stateValue = head(answers);
201
- const currentValue = toInteger(stateValue);
202
-
203
- const indexValue = indexOf(currentValue, values);
204
- const sliderPosition = divide(indexValue, size(values) - 1);
205
-
206
- const unitLabel = get('question.content.unitLabel', question);
207
-
208
- return {
209
- type: 'slider',
210
- placeholder: question.explanation,
211
- minLabel: `${question.content.min} ${unitLabel}`,
212
- maxLabel: `${question.content.max} ${unitLabel}`,
213
- title: `${currentValue} ${question.content.unitLabel}`,
214
- value: sliderPosition,
215
- // TODO: EDIT_CHOICES
216
- // eslint-disable-next-line no-console
217
- onChange: () => console.log('TODO: on choice change')
218
- };
219
- };
220
-
221
- export const getQuestionType = (slide: SlideFromAPI): SlideFromAPI['question']['type'] =>
222
- slide.question.type;
223
-
224
- const getHelp =
225
- (uiUtils: UiUtils) =>
226
- (slide: SlideFromAPI): string => {
227
- const {translate} = uiUtils;
228
- return get('question.explanation', slide) || translate('Select something below');
229
- };
230
-
231
- const getAnswerUIModel = (uiUtils: UiUtils): ((slide: SlideFromAPI) => AnswerUI['model']) => {
232
- const basicProps_ = basicProps(uiUtils);
233
- const templateProps_ = templateProps(uiUtils);
234
-
235
- return slide => {
236
- const type = getQuestionType(slide);
237
- switch (type) {
238
- case 'qcm':
239
- return pipe(get('question'), qcmProps)(slide);
240
-
241
- case 'qcmGraphic':
242
- return pipe(get('question'), qcmGraphicProps)(slide);
243
-
244
- case 'qcmDrag':
245
- return pipe(get('question'), qcmDragProps)(slide);
246
-
247
- case 'basic':
248
- return basicProps_();
249
-
250
- case 'template':
251
- return pipe(get('question'), templateProps_)(slide);
252
-
253
- case 'slider':
254
- return pipe(get('question'), sliderProps)(slide);
255
-
256
- default:
257
- throw new Error(`${type} is not an handled question.type`);
258
- }
259
- };
260
- };
261
-
262
- export const mapApiSlideToUi = (
263
- uiUtils: UiUtils
264
- ): ((slide: SlideFromAPI) => {questionText: string; answerUI: AnswerUI}) => {
265
- const getAnswerUIModel_ = getAnswerUIModel(uiUtils);
266
- const getHelp_ = getHelp(uiUtils);
267
-
268
- return slide => {
269
- if (!slide) {
270
- throw new Error('no slide was found');
271
- }
272
- const questionText = pipe<[SlideFromAPI], string, string>(
273
- getOr('', 'question.header') as unknown as (_slide: SlideFromAPI) => string,
274
- uiUtils.translate
275
- )(slide);
276
-
277
- return {questionText, answerUI: {model: getAnswerUIModel_(slide), help: getHelp_(slide)}};
278
- };
279
- };
@@ -1,33 +0,0 @@
1
- import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../types/common';
3
-
4
- export const freeTextSlide: SlideFromAPI = {
5
- id: 'sli_E1Pcl-XAYbi',
6
- universalRef: 'sli_E1Pcl-XAYbi',
7
- question: {
8
- type: 'basic',
9
- header: 'sli_E1Pcl-XAYbi.header',
10
- explanation: 'sli_E1Pcl-XAYbi.explanation',
11
- content: {
12
- label: 'sli_E1Pcl-XAYbi.label',
13
- placeholder: 'sli_E1Pcl-XAYbi.placeholder',
14
- id: 'sli_E1Pcl-XAYbi.choice_1'
15
- }
16
- },
17
- clue: 'sli_E1Pcl-XAYbi.clue',
18
- klf: 'sli_E1Pcl-XAYbi.klf',
19
- tips: 'sli_E1Pcl-XAYbi.tips'
20
- };
21
-
22
- export const freeTextUISlide: Partial<UISlide> = {
23
- answerUI: {
24
- help: 'sli_E1Pcl-XAYbi.explanation',
25
- model: {
26
- type: 'freeText',
27
- placeholder: 'Type here',
28
- value: undefined,
29
- onChange: noop
30
- }
31
- },
32
- questionText: 'sli_E1Pcl-XAYbi.header'
33
- };
@@ -1,115 +0,0 @@
1
- import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../types/common';
3
-
4
- export const qcmDragSlide: SlideFromAPI = {
5
- id: 'sli_419IlQQnf',
6
- universalRef: 'sli_419IlQQnf',
7
- question: {
8
- type: 'qcmDrag',
9
- header: 'sli_419IlQQnf.header',
10
- explanation: 'sli_419IlQQnf.explanation',
11
- content: {
12
- choices: [
13
- {
14
- media: {
15
- src: [],
16
- posters: [],
17
- subtitles: []
18
- },
19
- _id: '62b1ba3ec4f4015504212571',
20
- label: 'sli_419IlQQnf.choice_4kWwlQXhG',
21
- value: 'sli_419IlQQnf.choice_4kWwlQXhG',
22
- items: []
23
- },
24
- {
25
- media: {
26
- src: [],
27
- posters: [],
28
- subtitles: []
29
- },
30
- _id: '62b1ba3ec4f4015504212572',
31
- label: 'sli_419IlQQnf.choice_NJxbwgXm2G',
32
- value: 'sli_419IlQQnf.choice_NJxbwgXm2G',
33
- items: []
34
- },
35
- {
36
- media: {
37
- src: [],
38
- posters: [],
39
- subtitles: []
40
- },
41
- _id: '62b1ba3ec4f4015504212573',
42
- label: 'sli_419IlQQnf.choice_41fwgQXnf',
43
- value: 'sli_419IlQQnf.choice_41fwgQXnf',
44
- items: []
45
- },
46
- {
47
- media: {
48
- src: [],
49
- posters: [],
50
- subtitles: []
51
- },
52
- _id: '62b1ba3ec4f4015504212574',
53
- label: 'sli_419IlQQnf.choice_VJmweQ7nz',
54
- value: 'sli_419IlQQnf.choice_VJmweQ7nz',
55
- items: []
56
- },
57
- {
58
- media: {
59
- src: [],
60
- posters: [],
61
- subtitles: []
62
- },
63
- _id: '62b1ba3ec4f4015504212575',
64
- label: 'sli_419IlQQnf.choice_4kDDgXQhz',
65
- value: 'sli_419IlQQnf.choice_4kDDgXQhz',
66
- items: []
67
- }
68
- ]
69
- }
70
- },
71
- klf: 'sli_419IlQQnf.klf',
72
- tips: 'sli_419IlQQnf.tips'
73
- };
74
-
75
- export const qcmDragUISlide: Partial<UISlide> = {
76
- questionText: 'sli_419IlQQnf.header',
77
- answerUI: {
78
- help: 'sli_419IlQQnf.explanation',
79
- model: {
80
- type: 'qcmDrag',
81
- answers: [
82
- {
83
- title: 'sli_419IlQQnf.choice_4kWwlQXhG',
84
- selected: false,
85
- order: -1,
86
- onClick: noop
87
- },
88
- {
89
- title: 'sli_419IlQQnf.choice_NJxbwgXm2G',
90
- selected: false,
91
- order: -1,
92
- onClick: noop
93
- },
94
- {
95
- title: 'sli_419IlQQnf.choice_41fwgQXnf',
96
- selected: false,
97
- order: -1,
98
- onClick: noop
99
- },
100
- {
101
- title: 'sli_419IlQQnf.choice_VJmweQ7nz',
102
- selected: false,
103
- order: -1,
104
- onClick: noop
105
- },
106
- {
107
- title: 'sli_419IlQQnf.choice_4kDDgXQhz',
108
- selected: false,
109
- order: -1,
110
- onClick: noop
111
- }
112
- ]
113
- }
114
- }
115
- };
@@ -1,79 +0,0 @@
1
- import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../types/common';
3
-
4
- export const qcmGraphicSlide: SlideFromAPI = {
5
- id: 'sli_41~RSVclH',
6
- universalRef: 'sli_41~RSVclH',
7
- question: {
8
- type: 'qcmGraphic',
9
- header: 'sli_41~RSVclH.header',
10
- explanation: 'sli_41~RSVclH.explanation',
11
- content: {
12
- choices: [
13
- {
14
- media: {
15
- type: 'img',
16
- src: [
17
- {
18
- _id: '5fdce726359bf4003ee66997',
19
- mimeType: 'image/png',
20
- url: 'med_4JVRrE5gH.mediaUrl_VkBtUV9gB'
21
- }
22
- ],
23
- posters: [],
24
- subtitles: []
25
- },
26
- _id: '5fdce726359bf4003ee66996',
27
- label: 'sli_41~RSVclH.choice_V1gN0r4qgS',
28
- value: 'sli_41~RSVclH.choice_V1gN0r4qgS',
29
- items: []
30
- },
31
- {
32
- media: {
33
- type: 'img',
34
- src: [
35
- {
36
- _id: '5fdce726359bf4003ee66999',
37
- mimeType: 'image/png',
38
- url: 'med_Ek8gIEqxB.mediaUrl_EkcFUEclH'
39
- }
40
- ],
41
- posters: [],
42
- subtitles: []
43
- },
44
- _id: '5fdce726359bf4003ee66998',
45
- label: 'sli_41~RSVclH.choice_4JlLeLE5lS',
46
- value: 'sli_41~RSVclH.choice_4JlLeLE5lS',
47
- items: []
48
- }
49
- ]
50
- }
51
- },
52
- clue: 'sli_41~RSVclH.clue',
53
- klf: 'sli_41~RSVclH.klf',
54
- tips: 'sli_41~RSVclH.tips'
55
- };
56
-
57
- export const qcmGraphicUISlide: Partial<UISlide> = {
58
- questionText: 'sli_41~RSVclH.header',
59
- answerUI: {
60
- help: 'sli_41~RSVclH.explanation',
61
- model: {
62
- type: 'qcmGraphic',
63
- answers: [
64
- {
65
- title: 'sli_41~RSVclH.choice_V1gN0r4qgS',
66
- image: 'med_4JVRrE5gH.mediaUrl_VkBtUV9gB',
67
- selected: false,
68
- onClick: noop
69
- },
70
- {
71
- title: 'sli_41~RSVclH.choice_4JlLeLE5lS',
72
- image: 'med_Ek8gIEqxB.mediaUrl_EkcFUEclH',
73
- selected: false,
74
- onClick: noop
75
- }
76
- ]
77
- }
78
- }
79
- };