scorm-again 1.7.1 → 2.1.0

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 (124) hide show
  1. package/.babelrc +18 -7
  2. package/.github/dependabot.yml +5 -0
  3. package/.github/workflows/main.yml +79 -0
  4. package/.github/workflows/stale.yml +14 -0
  5. package/.jsdoc.json +4 -5
  6. package/.mocharc.json +8 -0
  7. package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +6 -3
  8. package/.run/Template Mocha.run.xml +17 -0
  9. package/CONTRIBUTING.md +1 -1
  10. package/README.md +183 -71
  11. package/dist/aicc.js +3822 -7030
  12. package/dist/aicc.js.map +1 -1
  13. package/dist/aicc.min.js +2 -40
  14. package/dist/aicc.min.js.map +1 -0
  15. package/dist/scorm-again.js +5965 -10498
  16. package/dist/scorm-again.js.map +1 -1
  17. package/dist/scorm-again.min.js +2 -52
  18. package/dist/scorm-again.min.js.map +1 -0
  19. package/dist/scorm12.js +3028 -5373
  20. package/dist/scorm12.js.map +1 -1
  21. package/dist/scorm12.min.js +2 -34
  22. package/dist/scorm12.min.js.map +1 -0
  23. package/dist/scorm2004.js +4054 -6693
  24. package/dist/scorm2004.js.map +1 -1
  25. package/dist/scorm2004.min.js +2 -40
  26. package/dist/scorm2004.min.js.map +1 -0
  27. package/eslint.config.js +21 -0
  28. package/package.json +76 -34
  29. package/results.json +34254 -0
  30. package/src/AICC.ts +72 -0
  31. package/src/BaseAPI.ts +1300 -0
  32. package/src/Scorm12API.ts +387 -0
  33. package/src/Scorm2004API.ts +688 -0
  34. package/src/cmi/aicc/attempts.ts +94 -0
  35. package/src/cmi/aicc/cmi.ts +100 -0
  36. package/src/cmi/aicc/core.ts +360 -0
  37. package/src/cmi/aicc/evaluation.ts +157 -0
  38. package/src/cmi/aicc/paths.ts +180 -0
  39. package/src/cmi/aicc/student_data.ts +86 -0
  40. package/src/cmi/aicc/student_demographics.ts +367 -0
  41. package/src/cmi/aicc/student_preferences.ts +176 -0
  42. package/src/cmi/aicc/tries.ts +116 -0
  43. package/src/cmi/aicc/validation.ts +25 -0
  44. package/src/cmi/common/array.ts +77 -0
  45. package/src/cmi/common/base_cmi.ts +46 -0
  46. package/src/cmi/common/score.ts +203 -0
  47. package/src/cmi/common/validation.ts +60 -0
  48. package/src/cmi/scorm12/cmi.ts +224 -0
  49. package/src/cmi/scorm12/interactions.ts +368 -0
  50. package/src/cmi/scorm12/nav.ts +54 -0
  51. package/src/cmi/scorm12/objectives.ts +112 -0
  52. package/src/cmi/scorm12/student_data.ts +130 -0
  53. package/src/cmi/scorm12/student_preference.ts +158 -0
  54. package/src/cmi/scorm12/validation.ts +48 -0
  55. package/src/cmi/scorm2004/adl.ts +272 -0
  56. package/src/cmi/scorm2004/cmi.ts +599 -0
  57. package/src/cmi/scorm2004/comments.ts +163 -0
  58. package/src/cmi/scorm2004/interactions.ts +466 -0
  59. package/src/cmi/scorm2004/learner_preference.ts +152 -0
  60. package/src/cmi/scorm2004/objectives.ts +212 -0
  61. package/src/cmi/scorm2004/score.ts +78 -0
  62. package/src/cmi/scorm2004/validation.ts +42 -0
  63. package/src/constants/api_constants.ts +318 -0
  64. package/src/constants/default_settings.ts +81 -0
  65. package/src/constants/enums.ts +5 -0
  66. package/src/constants/error_codes.ts +88 -0
  67. package/src/constants/language_constants.ts +394 -0
  68. package/src/constants/regex.ts +97 -0
  69. package/src/constants/{response_constants.js → response_constants.ts} +69 -62
  70. package/src/exceptions.ts +154 -0
  71. package/src/exports/aicc.js +1 -1
  72. package/src/exports/scorm-again.js +3 -3
  73. package/src/exports/scorm12.js +1 -1
  74. package/src/exports/scorm2004.js +1 -1
  75. package/src/helpers/scheduled_commit.ts +42 -0
  76. package/src/interfaces/IBaseAPI.ts +35 -0
  77. package/src/types/api_types.ts +32 -0
  78. package/src/utilities/debounce.ts +31 -0
  79. package/src/utilities.ts +338 -0
  80. package/tea.yaml +6 -0
  81. package/test/{AICC.spec.js → AICC.spec.ts} +79 -71
  82. package/test/Scorm12API.spec.ts +833 -0
  83. package/test/Scorm2004API.spec.ts +1298 -0
  84. package/test/api_helpers.ts +176 -0
  85. package/test/cmi/aicc_cmi.spec.ts +845 -0
  86. package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +253 -271
  87. package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
  88. package/test/cmi_helpers.ts +207 -0
  89. package/test/exceptions.spec.ts +79 -0
  90. package/test/field_values.ts +202 -0
  91. package/test/types/api_types.spec.ts +126 -0
  92. package/test/utilities/debounce.spec.ts +56 -0
  93. package/test/utilities.spec.ts +322 -0
  94. package/tsconfig.json +18 -0
  95. package/webpack.config.js +65 -0
  96. package/.circleci/config.yml +0 -99
  97. package/.codeclimate.yml +0 -7
  98. package/.eslintrc.js +0 -36
  99. package/src/.flowconfig +0 -11
  100. package/src/AICC.js +0 -68
  101. package/src/BaseAPI.js +0 -1275
  102. package/src/Scorm12API.js +0 -308
  103. package/src/Scorm2004API.js +0 -572
  104. package/src/cmi/aicc_cmi.js +0 -1141
  105. package/src/cmi/common.js +0 -328
  106. package/src/cmi/scorm12_cmi.js +0 -1312
  107. package/src/cmi/scorm2004_cmi.js +0 -1692
  108. package/src/constants/api_constants.js +0 -218
  109. package/src/constants/error_codes.js +0 -87
  110. package/src/constants/language_constants.js +0 -76
  111. package/src/constants/regex.js +0 -84
  112. package/src/exceptions.js +0 -104
  113. package/src/utilities.js +0 -242
  114. package/test/Scorm12API.spec.js +0 -528
  115. package/test/Scorm2004API.spec.js +0 -775
  116. package/test/abstract_classes.spec.js +0 -17
  117. package/test/api_helpers.js +0 -128
  118. package/test/cmi/aicc_cmi.spec.js +0 -684
  119. package/test/cmi/scorm2004_cmi.spec.js +0 -1066
  120. package/test/cmi_helpers.js +0 -161
  121. package/test/exceptions.spec.js +0 -71
  122. package/test/field_values.js +0 -353
  123. package/test/utilities.spec.js +0 -339
  124. package/webpack.js +0 -78
@@ -0,0 +1,845 @@
1
+ import { describe, it } from "mocha";
2
+ import APIConstants from "../../src/constants/api_constants";
3
+ import ErrorCodes from "../../src/constants/error_codes";
4
+ import { CMI } from "../../src/cmi/aicc/cmi";
5
+ import * as h from "../cmi_helpers";
6
+ import { expect } from "expect";
7
+ import { scorm12Values } from "../field_values";
8
+ import { CMITriesObject } from "../../src/cmi/aicc/tries";
9
+ import { CMIEvaluationCommentsObject } from "../../src/cmi/aicc/evaluation";
10
+ import { CMIObjectivesObject } from "../../src/cmi/scorm12/objectives";
11
+ import { CMIInteractionsObject } from "../../src/cmi/scorm12/interactions";
12
+ import { NAV } from "../../src/cmi/scorm12/nav";
13
+ import { CMIPathsObject } from "../../src/cmi/aicc/paths";
14
+ import { CMIStudentDemographics } from "../../src/cmi/aicc/student_demographics";
15
+
16
+ const aicc_constants = APIConstants.aicc;
17
+ const scorm12_error_codes = ErrorCodes.scorm12;
18
+
19
+ const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
20
+ const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
21
+ const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT;
22
+ const read_only = scorm12_error_codes.READ_ONLY_ELEMENT;
23
+
24
+ describe("AICC CMI Tests", () => {
25
+ describe("CMI Spec Tests", () => {
26
+ describe("Pre-Initialize Tests", () => {
27
+ const cmi = () => {
28
+ return new CMI();
29
+ };
30
+
31
+ /**
32
+ * Base CMI Properties
33
+ */
34
+ h.checkReadOnly({
35
+ cmi: cmi(),
36
+ fieldName: "cmi._version",
37
+ expectedValue: "3.4",
38
+ expectedError: invalid_set,
39
+ });
40
+ h.checkReadOnly({
41
+ cmi: cmi(),
42
+ fieldName: "cmi._children",
43
+ expectedValue: aicc_constants.cmi_children,
44
+ expectedError: invalid_set,
45
+ });
46
+
47
+ h.checkFieldConstraintSize({
48
+ cmi: cmi(),
49
+ fieldName: "cmi.suspend_data",
50
+ limit: 4096,
51
+ expectedError: type_mismatch,
52
+ });
53
+ h.checkReadAndWrite({
54
+ cmi: cmi(),
55
+ fieldName: "cmi.launch_data",
56
+ });
57
+ h.checkFieldConstraintSize({
58
+ cmi: cmi(),
59
+ fieldName: "cmi.comments",
60
+ limit: 4096,
61
+ expectedError: type_mismatch,
62
+ });
63
+ h.checkReadAndWrite({
64
+ cmi: cmi(),
65
+ fieldName: "cmi.comments_from_lms",
66
+ });
67
+
68
+ /**
69
+ * cmi.core Properties
70
+ */
71
+ h.checkReadOnly({
72
+ cmi: cmi(),
73
+ fieldName: "cmi.core._children",
74
+ expectedValue: aicc_constants.core_children,
75
+ expectedError: invalid_set,
76
+ });
77
+ h.checkReadAndWrite({
78
+ cmi: cmi(),
79
+ fieldName: "cmi.core.student_id",
80
+ });
81
+ h.checkReadAndWrite({
82
+ cmi: cmi(),
83
+ fieldName: "cmi.core.student_name",
84
+ });
85
+ h.checkFieldConstraintSize({
86
+ cmi: cmi(),
87
+ fieldName: "cmi.core.lesson_location",
88
+ limit: 255,
89
+ expectedError: type_mismatch,
90
+ });
91
+ h.checkReadAndWrite({
92
+ cmi: cmi(),
93
+ fieldName: "cmi.core.credit",
94
+ });
95
+ h.checkRead({
96
+ cmi: cmi(),
97
+ fieldName: "cmi.core.lesson_status",
98
+ expectedValue: "not attempted",
99
+ });
100
+ h.checkValidValues({
101
+ cmi: cmi(),
102
+ fieldName: "cmi.core.lesson_status",
103
+ validValues: scorm12Values.validLessonStatus,
104
+ invalidValues: scorm12Values.invalidLessonStatus,
105
+ });
106
+ h.checkReadAndWrite({
107
+ cmi: cmi(),
108
+ fieldName: "cmi.core.entry",
109
+ });
110
+ h.checkReadAndWrite({
111
+ cmi: cmi(),
112
+ fieldName: "cmi.core.total_time",
113
+ });
114
+ h.checkReadAndWrite({
115
+ cmi: cmi(),
116
+ fieldName: "cmi.core.lesson_mode",
117
+ expectedValue: "normal",
118
+ });
119
+ h.checkWrite({
120
+ cmi: cmi(),
121
+ fieldName: "cmi.core.exit",
122
+ valueToTest: "suspend",
123
+ });
124
+ h.checkValidValues({
125
+ cmi: cmi(),
126
+ fieldName: "cmi.core.exit",
127
+ validValues: scorm12Values.validExit,
128
+ invalidValues: scorm12Values.invalidExit,
129
+ });
130
+
131
+ h.checkWriteOnly({
132
+ cmi: cmi(),
133
+ fieldName: "cmi.core.session_time",
134
+ valueToTest: "00:00:00",
135
+ expectedError: write_only,
136
+ });
137
+ h.checkValidValues({
138
+ cmi: cmi(),
139
+ fieldName: "cmi.core.session_time",
140
+ validValues: scorm12Values.validTimespan,
141
+ invalidValues: scorm12Values.invalidTimespan,
142
+ });
143
+
144
+ /**
145
+ * cmi.core.score Properties
146
+ */
147
+ h.checkReadOnly({
148
+ cmi: cmi(),
149
+ fieldName: "cmi.core.score._children",
150
+ expectedValue: aicc_constants.score_children,
151
+ expectedError: invalid_set,
152
+ });
153
+
154
+ h.checkValidValues({
155
+ cmi: cmi(),
156
+ fieldName: "cmi.core.score.raw",
157
+ validValues: scorm12Values.validScoreRange,
158
+ invalidValues: scorm12Values.invalidScoreRange,
159
+ });
160
+ h.checkValidValues({
161
+ cmi: cmi(),
162
+ fieldName: "cmi.core.score.min",
163
+ validValues: scorm12Values.validScoreRange,
164
+ invalidValues: scorm12Values.invalidScoreRange,
165
+ });
166
+ h.checkValidValues({
167
+ cmi: cmi(),
168
+ fieldName: "cmi.core.score.max",
169
+ validValues: scorm12Values.validScoreRange,
170
+ invalidValues: scorm12Values.invalidScoreRange,
171
+ });
172
+
173
+ /**
174
+ * cmi.objectives Properties
175
+ */
176
+ h.checkReadOnly({
177
+ cmi: cmi(),
178
+ fieldName: "cmi.objectives._children",
179
+ expectedValue: aicc_constants.objectives_children,
180
+ expectedError: invalid_set,
181
+ });
182
+ h.checkReadOnly({
183
+ cmi: cmi(),
184
+ fieldName: "cmi.objectives._count",
185
+ expectedValue: 0,
186
+ expectedError: invalid_set,
187
+ });
188
+
189
+ /**
190
+ * cmi.student_data Properties
191
+ */
192
+ h.checkReadOnly({
193
+ cmi: cmi(),
194
+ fieldName: "cmi.student_data._children",
195
+ expectedValue: aicc_constants.student_data_children,
196
+ expectedError: invalid_set,
197
+ });
198
+ h.checkReadAndWrite({
199
+ cmi: cmi(),
200
+ fieldName: "cmi.student_data.mastery_score",
201
+ });
202
+ h.checkReadAndWrite({
203
+ cmi: cmi(),
204
+ fieldName: "cmi.student_data.max_time_allowed",
205
+ });
206
+ h.checkReadAndWrite({
207
+ cmi: cmi(),
208
+ fieldName: "cmi.student_data.time_limit_action",
209
+ });
210
+ h.checkReadAndWrite({
211
+ cmi: cmi(),
212
+ fieldName: "cmi.student_data.tries_during_lesson",
213
+ });
214
+
215
+ /**
216
+ * cmi.student_preference Properties
217
+ */
218
+ h.checkReadOnly({
219
+ cmi: cmi(),
220
+ fieldName: "cmi.student_preference._children",
221
+ expectedValue: aicc_constants.student_preference_children,
222
+ expectedError: invalid_set,
223
+ });
224
+ h.checkValidValues({
225
+ cmi: cmi(),
226
+ fieldName: "cmi.student_preference.audio",
227
+ validValues: scorm12Values.valid0To100Range.concat(["-1"]),
228
+ invalidValues: scorm12Values.invalid0To100Range,
229
+ });
230
+ h.checkFieldConstraintSize({
231
+ cmi: cmi(),
232
+ fieldName: "cmi.student_preference.language",
233
+ limit: 255,
234
+ expectedError: type_mismatch,
235
+ });
236
+ h.checkValidValues({
237
+ cmi: cmi(),
238
+ fieldName: "cmi.student_preference.speed",
239
+ validValues: scorm12Values.validSpeedRange,
240
+ invalidValues: scorm12Values.invalidSpeedRange,
241
+ });
242
+ h.checkValidValues({
243
+ cmi: cmi(),
244
+ fieldName: "cmi.student_preference.text",
245
+ validValues: scorm12Values.validIntegerScaledRange,
246
+ invalidValues: scorm12Values.invalidIntegerScaledRange,
247
+ });
248
+
249
+ /**
250
+ * cmi.interactions Properties
251
+ */
252
+ h.checkReadOnly({
253
+ cmi: cmi(),
254
+ fieldName: "cmi.interactions._children",
255
+ expectedValue: aicc_constants.interactions_children,
256
+ expectedError: invalid_set,
257
+ });
258
+ h.checkReadOnly({
259
+ cmi: cmi(),
260
+ fieldName: "cmi.interactions._count",
261
+ expectedValue: 0,
262
+ expectedError: invalid_set,
263
+ });
264
+ });
265
+
266
+ describe("Post-Initialize Tests", () => {
267
+ const cmi = () => {
268
+ const obj = new CMI();
269
+ obj.initialize();
270
+ return obj;
271
+ };
272
+
273
+ /**
274
+ * Base CMI Properties
275
+ */
276
+ h.checkReadOnly({
277
+ cmi: cmi(),
278
+ fieldName: "cmi._version",
279
+ expectedValue: "3.4",
280
+ expectedError: invalid_set,
281
+ });
282
+ h.checkReadOnly({
283
+ cmi: cmi(),
284
+ fieldName: "cmi._children",
285
+ expectedValue: aicc_constants.cmi_children,
286
+ expectedError: invalid_set,
287
+ });
288
+ h.checkFieldConstraintSize({
289
+ cmi: cmi(),
290
+ fieldName: "cmi.suspend_data",
291
+ limit: 4096,
292
+ expectedError: type_mismatch,
293
+ });
294
+ h.checkReadOnly({
295
+ cmi: cmi(),
296
+ fieldName: "cmi.launch_data",
297
+ expectedError: read_only,
298
+ });
299
+ h.checkFieldConstraintSize({
300
+ cmi: cmi(),
301
+ fieldName: "cmi.comments",
302
+ limit: 4096,
303
+ expectedError: type_mismatch,
304
+ });
305
+ h.checkReadOnly({
306
+ cmi: cmi(),
307
+ fieldName: "cmi.comments_from_lms",
308
+ expectedError: read_only,
309
+ });
310
+
311
+ /**
312
+ * cmi.core Properties
313
+ */
314
+ h.checkReadOnly({
315
+ cmi: cmi(),
316
+ fieldName: "cmi.core._children",
317
+ expectedValue: aicc_constants.core_children,
318
+ expectedError: invalid_set,
319
+ });
320
+ h.checkReadOnly({
321
+ cmi: cmi(),
322
+ fieldName: "cmi.core.student_id",
323
+ expectedError: read_only,
324
+ });
325
+ h.checkReadOnly({
326
+ cmi: cmi(),
327
+ fieldName: "cmi.core.student_name",
328
+ expectedError: read_only,
329
+ });
330
+ h.checkFieldConstraintSize({
331
+ cmi: cmi(),
332
+ fieldName: "cmi.core.lesson_location",
333
+ limit: 255,
334
+ expectedError: type_mismatch,
335
+ });
336
+ h.checkReadOnly({
337
+ cmi: cmi(),
338
+ fieldName: "cmi.core.credit",
339
+ expectedError: read_only,
340
+ });
341
+ h.checkRead({
342
+ cmi: cmi(),
343
+ fieldName: "cmi.core.lesson_status",
344
+ expectedValue: "not attempted",
345
+ });
346
+ h.checkValidValues({
347
+ cmi: cmi(),
348
+ fieldName: "cmi.core.lesson_status",
349
+ validValues: scorm12Values.validLessonStatus,
350
+ invalidValues: scorm12Values.invalidLessonStatus,
351
+ });
352
+ h.checkReadOnly({
353
+ cmi: cmi(),
354
+ fieldName: "cmi.core.entry",
355
+ expectedError: read_only,
356
+ });
357
+ h.checkReadOnly({
358
+ cmi: cmi(),
359
+ fieldName: "cmi.core.total_time",
360
+ expectedError: read_only,
361
+ });
362
+ h.checkReadOnly({
363
+ cmi: cmi(),
364
+ fieldName: "cmi.core.lesson_mode",
365
+ expectedValue: "normal",
366
+ expectedError: read_only,
367
+ });
368
+ h.checkWrite({
369
+ cmi: cmi(),
370
+ fieldName: "cmi.core.exit",
371
+ valueToTest: "suspend",
372
+ });
373
+ h.checkValidValues({
374
+ cmi: cmi(),
375
+ fieldName: "cmi.core.exit",
376
+ validValues: scorm12Values.validExit,
377
+ invalidValues: scorm12Values.invalidExit,
378
+ });
379
+ h.checkWriteOnly({
380
+ cmi: cmi(),
381
+ fieldName: "cmi.core.session_time",
382
+ valueToTest: "00:00:00",
383
+ expectedError: write_only,
384
+ });
385
+ h.checkValidValues({
386
+ cmi: cmi(),
387
+ fieldName: "cmi.core.session_time",
388
+ validValues: scorm12Values.validTimespan,
389
+ invalidValues: scorm12Values.invalidTimespan,
390
+ });
391
+
392
+ /**
393
+ * cmi.core.score Properties
394
+ */
395
+ h.checkReadOnly({
396
+ cmi: cmi(),
397
+ fieldName: "cmi.core.score._children",
398
+ expectedValue: aicc_constants.score_children,
399
+ expectedError: invalid_set,
400
+ });
401
+ h.checkValidValues({
402
+ cmi: cmi(),
403
+ fieldName: "cmi.core.score.raw",
404
+ validValues: scorm12Values.validScoreRange,
405
+ invalidValues: scorm12Values.invalidScoreRange,
406
+ });
407
+ h.checkValidValues({
408
+ cmi: cmi(),
409
+ fieldName: "cmi.core.score.min",
410
+ validValues: scorm12Values.validScoreRange,
411
+ invalidValues: scorm12Values.invalidScoreRange,
412
+ });
413
+ h.checkValidValues({
414
+ cmi: cmi(),
415
+ fieldName: "cmi.core.score.max",
416
+ validValues: scorm12Values.validScoreRange,
417
+ invalidValues: scorm12Values.invalidScoreRange,
418
+ });
419
+
420
+ /**
421
+ * cmi.objectives Properties
422
+ */
423
+ h.checkReadOnly({
424
+ cmi: cmi(),
425
+ fieldName: "cmi.objectives._children",
426
+ expectedValue: aicc_constants.objectives_children,
427
+ expectedError: invalid_set,
428
+ });
429
+ h.checkReadOnly({
430
+ cmi: cmi(),
431
+ fieldName: "cmi.objectives._count",
432
+ expectedValue: 0,
433
+ expectedError: invalid_set,
434
+ });
435
+
436
+ /**
437
+ * cmi.student_data Properties
438
+ */
439
+ h.checkReadOnly({
440
+ cmi: cmi(),
441
+ fieldName: "cmi.student_data._children",
442
+ expectedValue: aicc_constants.student_data_children,
443
+ expectedError: invalid_set,
444
+ });
445
+ h.checkReadOnly({
446
+ cmi: cmi(),
447
+ fieldName: "cmi.student_data.mastery_score",
448
+ expectedError: read_only,
449
+ });
450
+ h.checkReadOnly({
451
+ cmi: cmi(),
452
+ fieldName: "cmi.student_data.max_time_allowed",
453
+ expectedError: read_only,
454
+ });
455
+ h.checkReadOnly({
456
+ cmi: cmi(),
457
+ fieldName: "cmi.student_data.time_limit_action",
458
+ expectedError: read_only,
459
+ });
460
+ h.checkReadOnly({
461
+ cmi: cmi(),
462
+ fieldName: "cmi.student_data.tries_during_lesson",
463
+ expectedError: read_only,
464
+ });
465
+
466
+ /**
467
+ * cmi.student_preference Properties
468
+ */
469
+ h.checkReadOnly({
470
+ cmi: cmi(),
471
+ fieldName: "cmi.student_preference._children",
472
+ expectedValue: aicc_constants.student_preference_children,
473
+ expectedError: invalid_set,
474
+ });
475
+ h.checkValidValues({
476
+ cmi: cmi(),
477
+ fieldName: "cmi.student_preference.audio",
478
+ validValues: scorm12Values.valid0To100Range.concat(["-1"]),
479
+ invalidValues: scorm12Values.invalid0To100Range,
480
+ });
481
+ h.checkFieldConstraintSize({
482
+ cmi: cmi(),
483
+ fieldName: "cmi.student_preference.language",
484
+ limit: 255,
485
+ expectedError: type_mismatch,
486
+ });
487
+ h.checkValidValues({
488
+ cmi: cmi(),
489
+ fieldName: "cmi.student_preference.speed",
490
+ validValues: scorm12Values.validSpeedRange,
491
+ invalidValues: scorm12Values.invalidSpeedRange,
492
+ });
493
+ h.checkValidValues({
494
+ cmi: cmi(),
495
+ fieldName: "cmi.student_preference.text",
496
+ validValues: scorm12Values.validIntegerScaledRange,
497
+ invalidValues: scorm12Values.invalidIntegerScaledRange,
498
+ });
499
+
500
+ /**
501
+ * cmi.interactions Properties
502
+ */
503
+ h.checkReadOnly({
504
+ cmi: cmi(),
505
+ fieldName: "cmi.interactions._children",
506
+ expectedValue: aicc_constants.interactions_children,
507
+ expectedError: invalid_set,
508
+ });
509
+ h.checkReadOnly({
510
+ cmi: cmi(),
511
+ fieldName: "cmi.interactions._count",
512
+ expectedValue: 0,
513
+ expectedError: invalid_set,
514
+ });
515
+
516
+ it("should export JSON", () => {
517
+ const cmiObj = cmi();
518
+ cmiObj.objectives.childArray.push(new CMIObjectivesObject());
519
+ cmiObj.interactions.childArray.push(new CMIInteractionsObject());
520
+ cmiObj.evaluation.comments.childArray.push(
521
+ new CMIEvaluationCommentsObject(),
522
+ );
523
+ cmiObj.student_data.tries.childArray.push(new CMITriesObject());
524
+ expect(JSON.stringify(cmiObj)).toEqual(
525
+ '{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","entry":"","lesson_mode":"normal","exit":"","session_time":"00:00:00","score":{"raw":"","min":"","max":"100"}},"objectives":{"0":{"id":"","status":"","score":{"raw":"","min":"","max":"100"}}},"student_data":{"mastery_score":"","max_time_allowed":"","time_limit_action":"","tries":{"0":{"status":"","time":"","score":{"raw":"","min":"","max":"100"}}},"attempt_records":{}},"student_preference":{"audio":"","language":"","lesson_type":"","speed":"","text":"","text_color":"","text_location":"","text_size":"","video":"","windows":{}},"student_demographics":{"city":"","class":"","company":"","country":"","experience":"","familiar_name":"","instructor_name":"","title":"","native_language":"","state":"","street_address":"","telephone":"","years_experience":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}},"evaluation":{"comments":{"0":{"content":"","location":"","time":""}}},"paths":{}}',
526
+ );
527
+ });
528
+ });
529
+
530
+ describe("CMITriesObject Tests", () => {
531
+ const triesObject = () => {
532
+ return new CMITriesObject();
533
+ };
534
+ const triesInitialized = () => {
535
+ const cmi = new CMITriesObject();
536
+ cmi.initialize();
537
+ return cmi;
538
+ };
539
+
540
+ /**
541
+ * cmi.interactions.n.objectives.n object
542
+ */
543
+ h.checkRead({
544
+ cmi: triesObject(),
545
+ fieldName: "cmi.status",
546
+ });
547
+ h.checkRead({
548
+ cmi: triesInitialized(),
549
+ fieldName: "cmi.status",
550
+ });
551
+ h.checkValidValues({
552
+ cmi: triesObject(),
553
+ fieldName: "cmi.status",
554
+ validValues: scorm12Values.validLessonStatus.concat(["not attempted"]),
555
+ invalidValues: scorm12Values.invalidLessonStatus,
556
+ });
557
+ h.checkReadAndWrite({
558
+ cmi: triesObject(),
559
+ fieldName: "cmi.time",
560
+ valueToTest: "23:59:59",
561
+ });
562
+ h.checkValidValues({
563
+ cmi: triesObject(),
564
+ fieldName: "cmi.time",
565
+ validValues: scorm12Values.validTime,
566
+ invalidValues: scorm12Values.invalidTime,
567
+ });
568
+
569
+ /**
570
+ * cmi.student_data.tries.n.score Properties
571
+ */
572
+ h.checkReadOnly({
573
+ cmi: triesObject(),
574
+ fieldName: "cmi.score._children",
575
+ expectedValue: aicc_constants.score_children,
576
+ expectedError: invalid_set,
577
+ });
578
+ h.checkValidValues({
579
+ cmi: triesObject(),
580
+ fieldName: "cmi.score.raw",
581
+ validValues: scorm12Values.validScoreRange,
582
+ invalidValues: scorm12Values.invalidScoreRange,
583
+ });
584
+ h.checkValidValues({
585
+ cmi: triesObject(),
586
+ fieldName: "cmi.score.min",
587
+ validValues: scorm12Values.validScoreRange,
588
+ invalidValues: scorm12Values.invalidScoreRange,
589
+ });
590
+ h.checkValidValues({
591
+ cmi: triesObject(),
592
+ fieldName: "cmi.score.max",
593
+ validValues: scorm12Values.validScoreRange,
594
+ invalidValues: scorm12Values.invalidScoreRange,
595
+ });
596
+
597
+ it("should export JSON", () => {
598
+ const cmi = triesObject();
599
+ expect(JSON.stringify(cmi)).toEqual(
600
+ '{"status":"","time":"","score":{"raw":"","min":"","max":"100"}}',
601
+ );
602
+ });
603
+ });
604
+
605
+ describe("CMIPathsObject Tests", () => {
606
+ const paths = () => {
607
+ return new CMIPathsObject();
608
+ };
609
+
610
+ h.checkFieldConstraintSize({
611
+ cmi: paths(),
612
+ fieldName: "cmi.location_id",
613
+ expectedError: type_mismatch,
614
+ limit: 255,
615
+ });
616
+ h.checkReadAndWrite({
617
+ cmi: paths(),
618
+ fieldName: "cmi.date",
619
+ valueToTest: "2021-01-01",
620
+ });
621
+ h.checkValidValues({
622
+ cmi: paths(),
623
+ fieldName: "cmi.time",
624
+ validValues: scorm12Values.validTime,
625
+ invalidValues: scorm12Values.invalidTime,
626
+ });
627
+ h.checkValidValues({
628
+ cmi: paths(),
629
+ fieldName: "cmi.status",
630
+ validValues: scorm12Values.validLessonStatus,
631
+ invalidValues: scorm12Values.invalidLessonStatus,
632
+ });
633
+ h.checkFieldConstraintSize({
634
+ cmi: paths(),
635
+ fieldName: "cmi.why_left",
636
+ expectedError: type_mismatch,
637
+ limit: 255,
638
+ });
639
+ h.checkValidValues({
640
+ cmi: paths(),
641
+ fieldName: "cmi.time_in_element",
642
+ validValues: scorm12Values.validTime,
643
+ invalidValues: scorm12Values.invalidTime,
644
+ });
645
+
646
+ it("should export JSON", () => {
647
+ const cmi = paths();
648
+ expect(JSON.stringify(cmi)).toEqual(
649
+ '{"location_id":"","date":"","time":"","status":"","why_left":"","time_in_element":""}',
650
+ );
651
+ });
652
+ });
653
+
654
+ describe("CMIStudentDemographicsObject Tests", () => {
655
+ const cmiInit = () => {
656
+ const cmiStudentDemographics = new CMIStudentDemographics();
657
+ cmiStudentDemographics.initialize();
658
+ return cmiStudentDemographics;
659
+ };
660
+ const cmi = () => {
661
+ return new CMIStudentDemographics();
662
+ };
663
+
664
+ h.checkReadOnly({
665
+ cmi: cmiInit(),
666
+ fieldName: "cmi.city",
667
+ expectedError: read_only,
668
+ });
669
+ h.checkReadOnly({
670
+ cmi: cmiInit(),
671
+ fieldName: "cmi.class",
672
+ expectedError: read_only,
673
+ });
674
+ h.checkReadOnly({
675
+ cmi: cmiInit(),
676
+ fieldName: "cmi.company",
677
+ expectedError: read_only,
678
+ });
679
+ h.checkReadOnly({
680
+ cmi: cmiInit(),
681
+ fieldName: "cmi.country",
682
+ expectedError: read_only,
683
+ });
684
+ h.checkReadOnly({
685
+ cmi: cmiInit(),
686
+ fieldName: "cmi.experience",
687
+ expectedError: read_only,
688
+ });
689
+ h.checkReadOnly({
690
+ cmi: cmiInit(),
691
+ fieldName: "cmi.familiar_name",
692
+ expectedError: read_only,
693
+ });
694
+ h.checkReadOnly({
695
+ cmi: cmiInit(),
696
+ fieldName: "cmi.instructor_name",
697
+ expectedError: read_only,
698
+ });
699
+ h.checkReadOnly({
700
+ cmi: cmiInit(),
701
+ fieldName: "cmi.title",
702
+ expectedError: read_only,
703
+ });
704
+ h.checkReadOnly({
705
+ cmi: cmiInit(),
706
+ fieldName: "cmi.native_language",
707
+ expectedError: read_only,
708
+ });
709
+ h.checkReadOnly({
710
+ cmi: cmiInit(),
711
+ fieldName: "cmi.state",
712
+ expectedError: read_only,
713
+ });
714
+ h.checkReadOnly({
715
+ cmi: cmiInit(),
716
+ fieldName: "cmi.street_address",
717
+ expectedError: read_only,
718
+ });
719
+ h.checkReadOnly({
720
+ cmi: cmiInit(),
721
+ fieldName: "cmi.telephone",
722
+ expectedError: read_only,
723
+ });
724
+ h.checkReadOnly({
725
+ cmi: cmiInit(),
726
+ fieldName: "cmi.years_experience",
727
+ expectedError: read_only,
728
+ });
729
+
730
+ h.checkReadAndWrite({
731
+ cmi: cmi(),
732
+ fieldName: "cmi.city",
733
+ });
734
+ h.checkReadAndWrite({
735
+ cmi: cmi(),
736
+ fieldName: "cmi.class",
737
+ });
738
+ h.checkReadAndWrite({
739
+ cmi: cmi(),
740
+ fieldName: "cmi.company",
741
+ });
742
+ h.checkReadAndWrite({
743
+ cmi: cmi(),
744
+ fieldName: "cmi.country",
745
+ });
746
+ h.checkReadAndWrite({
747
+ cmi: cmi(),
748
+ fieldName: "cmi.experience",
749
+ });
750
+ h.checkReadAndWrite({
751
+ cmi: cmi(),
752
+ fieldName: "cmi.familiar_name",
753
+ });
754
+ h.checkReadAndWrite({
755
+ cmi: cmi(),
756
+ fieldName: "cmi.instructor_name",
757
+ });
758
+ h.checkReadAndWrite({
759
+ cmi: cmi(),
760
+ fieldName: "cmi.title",
761
+ });
762
+ h.checkReadAndWrite({
763
+ cmi: cmi(),
764
+ fieldName: "cmi.native_language",
765
+ });
766
+ h.checkReadAndWrite({
767
+ cmi: cmi(),
768
+ fieldName: "cmi.state",
769
+ });
770
+ h.checkReadAndWrite({
771
+ cmi: cmi(),
772
+ fieldName: "cmi.street_address",
773
+ });
774
+ h.checkReadAndWrite({
775
+ cmi: cmi(),
776
+ fieldName: "cmi.telephone",
777
+ });
778
+ h.checkReadAndWrite({
779
+ cmi: cmi(),
780
+ fieldName: "cmi.years_experience",
781
+ });
782
+ });
783
+
784
+ describe("CMIEvaluationCommentsObject Tests", () => {
785
+ const evaluationComment = () => {
786
+ return new CMIEvaluationCommentsObject();
787
+ };
788
+
789
+ /**
790
+ * cmi.evaluation.comments.n object
791
+ */
792
+ h.checkFieldConstraintSize({
793
+ cmi: evaluationComment(),
794
+ fieldName: "cmi.content",
795
+ expectedError: type_mismatch,
796
+ limit: 255,
797
+ });
798
+ h.checkFieldConstraintSize({
799
+ cmi: evaluationComment(),
800
+ fieldName: "cmi.location",
801
+ expectedError: type_mismatch,
802
+ limit: 255,
803
+ });
804
+ h.checkReadAndWrite({
805
+ cmi: evaluationComment(),
806
+ fieldName: "cmi.time",
807
+ valueToTest: "23:59:59",
808
+ });
809
+ h.checkValidValues({
810
+ cmi: evaluationComment(),
811
+ fieldName: "cmi.time",
812
+ validValues: scorm12Values.validTime,
813
+ invalidValues: scorm12Values.invalidTime,
814
+ });
815
+
816
+ it("should export JSON", () => {
817
+ const cmi = evaluationComment();
818
+ expect(JSON.stringify(cmi)).toEqual(
819
+ '{"content":"","location":"","time":""}',
820
+ );
821
+ });
822
+ });
823
+
824
+ describe("NAV Tests", () => {
825
+ const nav = () => {
826
+ return new NAV();
827
+ };
828
+
829
+ /**
830
+ * cmi.interactions.n.correct_responses.n object
831
+ */
832
+ h.checkValidValues({
833
+ cmi: nav(),
834
+ fieldName: "cmi.event",
835
+ validValues: ["previous", "continue"],
836
+ invalidValues: ["P", "f", "complete", "started", "in progress"],
837
+ });
838
+
839
+ it("should export JSON", () => {
840
+ const cmi = nav();
841
+ expect(JSON.stringify(cmi)).toEqual('{"event":""}');
842
+ });
843
+ });
844
+ });
845
+ });