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
@@ -1,528 +0,0 @@
1
- import {expect} from 'chai';
2
- import {after, before, describe, it} from 'mocha';
3
- import Scorm12API from '../src/Scorm12API';
4
- import * as h from './api_helpers';
5
- import ErrorCodes from '../src/constants/error_codes';
6
- import {scorm12_values} from './field_values';
7
- import * as sinon from 'sinon';
8
- import Pretender from 'fetch-pretender';
9
-
10
- const scorm12_error_codes = ErrorCodes.scorm12;
11
-
12
- let clock;
13
- const api = (settings = {}) => {
14
- const API = new Scorm12API(settings);
15
- API.apiLogLevel = 1;
16
- return API;
17
- };
18
- const apiInitialized = (settings = {}) => {
19
- const API = api(settings);
20
- API.lmsInitialize();
21
- return API;
22
- };
23
-
24
- describe('SCORM 1.2 API Tests', () => {
25
- before(() => {
26
- clock = sinon.useFakeTimers();
27
-
28
- const server = new Pretender(() => {
29
- });
30
- server.post('/scorm12', () => {
31
- return [200, {'Content-Type': 'application/json'}, '{}'];
32
- }, false);
33
-
34
- server.post('/scorm12/error', () => {
35
- return [500, {'Content-Type': 'application/json'}, '{}'];
36
- }, false);
37
- });
38
-
39
- after(() => {
40
- clock.restore();
41
- });
42
-
43
- describe('LMSSetValue()', () => {
44
- h.checkValidValues({
45
- api: apiInitialized(),
46
- fieldName: 'cmi.core.score.raw',
47
- validValues: scorm12_values.validScoreRange,
48
- invalidValues: scorm12_values.invalidScoreRange,
49
- });
50
- h.checkValidValues({
51
- api: apiInitialized(),
52
- fieldName: 'cmi.core.score.min',
53
- validValues: scorm12_values.validScoreRange,
54
- invalidValues: scorm12_values.invalidScoreRange,
55
- });
56
- h.checkValidValues({
57
- api: apiInitialized(),
58
- fieldName: 'cmi.core.score.max',
59
- validValues: scorm12_values.validScoreRange,
60
- invalidValues: scorm12_values.invalidScoreRange,
61
- });
62
- });
63
-
64
- describe('setCMIValue()', () => {
65
- describe('Invalid Sets - Should Always Fail', () => {
66
- h.checkSetCMIValue({
67
- api: api(),
68
- fieldName: 'cmi._version',
69
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
70
- });
71
- h.checkSetCMIValue({
72
- api: api(),
73
- fieldName: 'cmi._children',
74
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
75
- });
76
- h.checkSetCMIValue({
77
- api: api(),
78
- fieldName: 'cmi.core._children',
79
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
80
- });
81
- h.checkSetCMIValue({
82
- api: api(),
83
- fieldName: 'cmi.core.score._children',
84
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
85
- });
86
- h.checkSetCMIValue({
87
- api: api(),
88
- fieldName: 'cmi.objectives._children',
89
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
90
- });
91
- h.checkSetCMIValue({
92
- api: api(),
93
- fieldName: 'cmi.objectives._count',
94
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
95
- });
96
- h.checkSetCMIValue({
97
- api: api(),
98
- fieldName: 'cmi.interactions._children',
99
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
100
- });
101
- h.checkSetCMIValue({
102
- api: api(),
103
- fieldName: 'cmi.interactions._count',
104
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
105
- });
106
- h.checkSetCMIValue({
107
- api: api(),
108
- fieldName: 'cmi.interactions.0.objectives._count',
109
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
110
- });
111
- h.checkSetCMIValue({
112
- api: api(),
113
- fieldName: 'cmi.interactions.0.correct_responses._count',
114
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
115
- });
116
- });
117
-
118
- describe('Invalid Sets - Should Fail After Initialization', () => {
119
- h.checkSetCMIValue({
120
- api: apiInitialized(),
121
- fieldName: 'cmi.launch_data',
122
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
123
- });
124
- h.checkSetCMIValue({
125
- api: apiInitialized(),
126
- fieldName: 'cmi.comments_from_lms',
127
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
128
- });
129
- h.checkSetCMIValue({
130
- api: apiInitialized(),
131
- fieldName: 'cmi.core.student_id',
132
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
133
- });
134
- h.checkSetCMIValue({
135
- api: apiInitialized(),
136
- fieldName: 'cmi.core.student_name',
137
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
138
- });
139
- h.checkSetCMIValue({
140
- api: apiInitialized(),
141
- fieldName: 'cmi.core.credit',
142
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
143
- });
144
- h.checkSetCMIValue({
145
- api: apiInitialized(),
146
- fieldName: 'cmi.core.entry',
147
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
148
- });
149
- h.checkSetCMIValue({
150
- api: apiInitialized(),
151
- fieldName: 'cmi.core.total_time',
152
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
153
- });
154
- h.checkSetCMIValue({
155
- api: apiInitialized(),
156
- fieldName: 'cmi.core.lesson_mode',
157
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
158
- });
159
- h.checkSetCMIValue({
160
- api: apiInitialized(),
161
- fieldName: 'cmi.student_data.mastery_score',
162
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
163
- });
164
- h.checkSetCMIValue({
165
- api: apiInitialized(),
166
- fieldName: 'cmi.student_data.max_time_allowed',
167
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
168
- });
169
- h.checkSetCMIValue({
170
- api: apiInitialized(),
171
- fieldName: 'cmi.student_data.time_limit_action',
172
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
173
- });
174
- });
175
- });
176
-
177
- describe('LMSGetValue()', () => {
178
- describe('Invalid Properties - Should Always Fail', () => {
179
- h.checkLMSGetValue({
180
- api: apiInitialized(),
181
- fieldName: 'cmi.core.close',
182
- expectedError: scorm12_error_codes.GENERAL,
183
- errorThrown: false,
184
- });
185
- h.checkLMSGetValue({
186
- api: apiInitialized(),
187
- fieldName: 'cmi.exit',
188
- expectedError: scorm12_error_codes.GENERAL,
189
- errorThrown: false,
190
- });
191
- h.checkLMSGetValue({
192
- api: apiInitialized(),
193
- fieldName: 'cmi.entry',
194
- expectedError: scorm12_error_codes.GENERAL,
195
- errorThrown: false,
196
- });
197
- });
198
-
199
- describe('Read and Write Properties - Should Success', () => {
200
- h.checkLMSGetValue({
201
- api: apiInitialized(),
202
- fieldName: 'cmi.interactions.0.objectives.0.id',
203
- initializeFirst: true,
204
- initializationValue: 'AAA',
205
- expectedValue: 'AAA',
206
- });
207
- });
208
-
209
- describe('Write-Only Properties - Should Always Fail', () => {
210
- h.checkLMSGetValue({
211
- api: apiInitialized(),
212
- fieldName: 'cmi.core.exit',
213
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
214
- });
215
- h.checkLMSGetValue({
216
- api: apiInitialized(),
217
- fieldName: 'cmi.core.session_time',
218
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
219
- });
220
- h.checkLMSGetValue({
221
- api: apiInitialized(),
222
- fieldName: 'cmi.interactions.0.id',
223
- initializeFirst: true,
224
- initializationValue: 'AAA',
225
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
226
- });
227
- h.checkLMSGetValue({
228
- api: apiInitialized(),
229
- fieldName: 'cmi.interactions.0.time',
230
- initializeFirst: true,
231
- initializationValue: '12:59:59',
232
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
233
- });
234
- h.checkLMSGetValue({
235
- api: apiInitialized(),
236
- fieldName: 'cmi.interactions.0.type',
237
- initializeFirst: true,
238
- initializationValue: 'true-false',
239
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
240
- });
241
- h.checkLMSGetValue({
242
- api: apiInitialized(),
243
- fieldName: 'cmi.interactions.0.weighting',
244
- initializeFirst: true,
245
- initializationValue: '0',
246
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
247
- });
248
- h.checkLMSGetValue({
249
- api: apiInitialized(),
250
- fieldName: 'cmi.interactions.0.student_response',
251
- initializeFirst: true,
252
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
253
- });
254
- h.checkLMSGetValue({
255
- api: apiInitialized(),
256
- fieldName: 'cmi.interactions.0.result',
257
- initializeFirst: true,
258
- initializationValue: 'correct',
259
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
260
- });
261
- h.checkLMSGetValue({
262
- api: apiInitialized(),
263
- fieldName: 'cmi.interactions.0.latency',
264
- initializeFirst: true,
265
- initializationValue: '01:59:59.99',
266
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
267
- });
268
- h.checkLMSGetValue({
269
- api: apiInitialized(),
270
- fieldName: 'cmi.interactions.0.correct_responses.0.pattern',
271
- initializeFirst: true,
272
- initializationValue: 'AAA',
273
- expectedValue: 'AAA',
274
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
275
- });
276
- });
277
- });
278
-
279
- describe('LMSSetValue()', () => {
280
- describe('Uninitialized - Should Fail', () => {
281
- h.checkLMSSetValue({
282
- api: api(),
283
- fieldName: 'cmi.objectives.0.id',
284
- expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
285
- });
286
- h.checkLMSSetValue({
287
- api: api(),
288
- fieldName: 'cmi.interactions.0.id',
289
- expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
290
- });
291
- });
292
-
293
- describe('Initialized - Should Succeed', () => {
294
- h.checkLMSSetValue({
295
- api: apiInitialized(),
296
- fieldName: 'cmi.objectives.0.id',
297
- valueToTest: 'AAA',
298
- });
299
- h.checkLMSSetValue({
300
- api: apiInitialized(),
301
- fieldName: 'cmi.interactions.0.id',
302
- valueToTest: 'AAA',
303
- });
304
- h.checkLMSSetValue({
305
- api: apiInitialized(),
306
- fieldName: 'cmi.interactions.0.objectives.0.id',
307
- valueToTest: 'AAA',
308
- });
309
- h.checkLMSSetValue({
310
- api: apiInitialized(),
311
- fieldName: 'cmi.interactions.10.correct_responses.0.pattern',
312
- valueToTest: 't',
313
- });
314
- });
315
- });
316
-
317
- describe('replaceWithAnotherScormAPI()', () => {
318
- const firstAPI = api();
319
- const secondAPI = api();
320
-
321
- firstAPI.cmi.core.student_id = 'student_1';
322
- secondAPI.cmi.core.student_id = 'student_2';
323
-
324
- firstAPI.replaceWithAnotherScormAPI(secondAPI);
325
- expect(
326
- firstAPI.cmi.core.student_id,
327
- ).to.equal('student_2');
328
- });
329
-
330
- describe('renderCommitCMI()', () => {
331
- it('should calculate total time when terminateCommit passed',
332
- () => {
333
- const scorm12API = api();
334
- scorm12API.cmi.core.total_time = '12:34:56';
335
- scorm12API.cmi.core.session_time = '23:59:59';
336
- const cmiExport = scorm12API.renderCommitCMI(true);
337
- expect(
338
- cmiExport.cmi.core.total_time,
339
- ).to.equal('36:34:55');
340
- });
341
- it('if the user passes, should calculate total time when terminateCommit passed',
342
- () => {
343
- const scorm12API = api();
344
- scorm12API.cmi.core.score.max = '100';
345
- scorm12API.cmi.core.score.min = '0';
346
- scorm12API.cmi.core.score.raw = '100';
347
- scorm12API.cmi.core.exit = 'suspend';
348
- scorm12API.cmi.core.lesson_status = 'completed';
349
- scorm12API.cmi.core.total_time = '0000:00:00';
350
- scorm12API.cmi.core.session_time = '23:59:59';
351
- const cmiExport = scorm12API.renderCommitCMI(true);
352
- expect(
353
- cmiExport.cmi.core.total_time,
354
- ).to.equal('23:59:59');
355
- });
356
- });
357
-
358
- describe('storeData()', () => {
359
- it('should set cmi.core.lesson_status to "completed"', () => {
360
- const scorm12API = api();
361
- scorm12API.storeData(true);
362
- expect(scorm12API.cmi.core.lesson_status).to.equal('completed');
363
- });
364
- it('should set cmi.core.lesson_status to "browsed"', () => {
365
- const scorm12API = api();
366
- scorm12API.cmi.core.lesson_mode = 'browse';
367
- scorm12API.storeData(true);
368
- expect(scorm12API.cmi.core.lesson_status).to.equal('browsed');
369
- });
370
- it('should set cmi.core.lesson_status to "browsed" - Initial Status',
371
- () => {
372
- const scorm12API = api();
373
- scorm12API.startingData = {'cmi': {'core': {'lesson_status': ''}}};
374
- scorm12API.cmi.core.lesson_mode = 'browse';
375
- scorm12API.storeData(true);
376
- expect(scorm12API.cmi.core.lesson_status).to.equal('browsed');
377
- });
378
- it('should set cmi.core.lesson_status to "passed" - mastery_override: true',
379
- () => {
380
- const scorm12API = api({mastery_override: true});
381
- scorm12API.cmi.core.credit = 'credit';
382
- scorm12API.cmi.student_data.mastery_score = '60.0';
383
- scorm12API.cmi.core.score.raw = '75.0';
384
- scorm12API.storeData(true);
385
- expect(scorm12API.cmi.core.lesson_status).to.equal('passed');
386
- });
387
- it('should set cmi.core.lesson_status to "failed" - mastery_override: true',
388
- () => {
389
- const scorm12API = api({mastery_override: true});
390
- scorm12API.cmi.core.credit = 'credit';
391
- scorm12API.cmi.student_data.mastery_score = '60.0';
392
- scorm12API.cmi.core.score.raw = '55.0';
393
- scorm12API.storeData(true);
394
- expect(scorm12API.cmi.core.lesson_status).to.equal('failed');
395
- });
396
- it('should set cmi.core.lesson_status to "passed" - mastery_override: false',
397
- () => {
398
- const scorm12API = api({mastery_override: false});
399
- scorm12API.cmi.core.lesson_status = 'failed'; // module author wanted the user to pass, so we don't override
400
- scorm12API.cmi.core.credit = 'credit';
401
- scorm12API.cmi.student_data.mastery_score = '60.0';
402
- scorm12API.cmi.core.score.raw = '75.0';
403
- scorm12API.storeData(true);
404
- expect(scorm12API.cmi.core.lesson_status).to.equal('failed');
405
- });
406
- it('should set cmi.core.lesson_status to "failed" - mastery_override: false',
407
- () => {
408
- const scorm12API = api({mastery_override: false});
409
- scorm12API.cmi.core.lesson_status = 'passed'; // module author wanted the user to pass, so we don't override
410
- scorm12API.cmi.core.credit = 'credit';
411
- scorm12API.cmi.student_data.mastery_score = '60.0';
412
- scorm12API.cmi.core.score.raw = '55.0';
413
- scorm12API.storeData(true);
414
- expect(scorm12API.cmi.core.lesson_status).to.equal('passed');
415
- });
416
- });
417
-
418
- describe('Event Handlers', () => {
419
- it('Should handle SetValue.cmi.core.student_name event',
420
- () => {
421
- const scorm12API = apiInitialized();
422
- const callback = sinon.spy();
423
- scorm12API.on('LMSSetValue.cmi.core.student_name', callback);
424
- scorm12API.lmsSetValue('cmi.core.student_name', '@jcputney');
425
- expect(callback.called).to.be.true;
426
- });
427
- it('Should handle SetValue.cmi.* event',
428
- () => {
429
- const scorm12API = apiInitialized();
430
- const callback = sinon.spy();
431
- scorm12API.on('LMSSetValue.cmi.*', callback);
432
- scorm12API.lmsSetValue('cmi.core.student_name', '@jcputney');
433
- expect(callback.called).to.be.true;
434
- });
435
- it('Should handle CommitSuccess event',
436
- () => {
437
- const scorm12API = api({
438
- lmsCommitUrl: '/scorm12',
439
- autocommit: true,
440
- autocommitSeconds: 1,
441
- });
442
- scorm12API.lmsInitialize();
443
-
444
- const callback = sinon.spy();
445
- scorm12API.on('CommitSuccess', callback);
446
-
447
- scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
448
- clock.tick(2000);
449
- expect(callback.called).to.be.true;
450
- });
451
- it('Should clear all event listeners for CommitSuccess',
452
- () => {
453
- const scorm12API = api({
454
- lmsCommitUrl: '/scorm12',
455
- autocommit: true,
456
- autocommitSeconds: 1,
457
- });
458
- scorm12API.lmsInitialize();
459
-
460
- const callback = sinon.spy();
461
- const callback2 = sinon.spy();
462
- scorm12API.on('CommitSuccess', callback);
463
- scorm12API.on('CommitSuccess', callback2);
464
-
465
- scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
466
- clock.tick(2000);
467
- expect(callback.calledOnce).to.be.true;
468
- expect(callback2.calledOnce).to.be.true;
469
-
470
- scorm12API.clear('CommitSuccess');
471
-
472
- scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
473
- clock.tick(2000);
474
- expect(callback.calledTwice).to.be.false;
475
- expect(callback2.calledTwice).to.be.false;
476
- });
477
- it('Should clear only the specific event listener for CommitSuccess',
478
- () => {
479
- const scorm12API = api({
480
- lmsCommitUrl: '/scorm12',
481
- autocommit: true,
482
- autocommitSeconds: 1,
483
- });
484
- scorm12API.lmsInitialize();
485
-
486
- const callback = sinon.spy(() => 1);
487
- const callback2 = sinon.spy(() => 2);
488
- const callback3 = sinon.spy(() => 3);
489
- const callback4 = sinon.spy(() => 4);
490
- scorm12API.on('CommitSuccess', callback);
491
- scorm12API.on('CommitSuccess', callback2);
492
- scorm12API.on('LMSCommit', callback3);
493
- scorm12API.on('LMSSetValue', callback4);
494
-
495
- scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
496
- clock.tick(2000);
497
- expect(callback.calledOnce).to.be.true;
498
- expect(callback2.calledOnce).to.be.true;
499
- expect(callback3.calledOnce).to.be.true;
500
- expect(callback4.calledOnce).to.be.true;
501
-
502
- scorm12API.off('CommitSuccess', callback);
503
-
504
- scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
505
- clock.tick(2000);
506
- expect(callback.calledTwice).to.be.false; // removed callback should not be called a second time
507
- expect(callback2.calledTwice).to.be.true;
508
- expect(callback3.calledTwice).to.be.true;
509
- expect(callback4.calledTwice).to.be.true;
510
- });
511
- it('Should handle CommitError event',
512
- () => {
513
- const scorm12API = api({
514
- lmsCommitUrl: '/scorm12/error',
515
- autocommit: true,
516
- autocommitSeconds: 1,
517
- });
518
- scorm12API.lmsInitialize();
519
-
520
- const callback = sinon.spy();
521
- scorm12API.on('CommitError', callback);
522
-
523
- scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
524
- clock.tick(2000);
525
- expect(callback.called).to.be.true;
526
- });
527
- });
528
- });