Fixing eslint issues, and still working on test cases
This commit is contained in:
3
.babelrc
3
.babelrc
@@ -5,6 +5,7 @@
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-proposal-private-methods"
|
||||
"@babel/plugin-proposal-private-methods",
|
||||
"@babel/plugin-proposal-optional-chaining"
|
||||
]
|
||||
}
|
||||
@@ -49,11 +49,11 @@ jobs:
|
||||
when: always
|
||||
|
||||
# Run eslint
|
||||
# - run:
|
||||
# name: eslint
|
||||
# command: |
|
||||
# ./node_modules/.bin/eslint ./ --format junit --output-file ./reports/eslint/eslint.xml
|
||||
# when: always
|
||||
- run:
|
||||
name: eslint
|
||||
command: |
|
||||
./node_modules/.bin/eslint ./ --format junit --output-file ./reports/eslint/eslint.xml
|
||||
when: always
|
||||
|
||||
# Run coverage report for Code Climate
|
||||
- run:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
parser: "babel-eslint",
|
||||
parser: 'babel-eslint',
|
||||
env: {
|
||||
browser: true,
|
||||
es6: true,
|
||||
@@ -10,18 +10,19 @@ module.exports = {
|
||||
SharedArrayBuffer: 'readonly',
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: "module",
|
||||
sourceType: 'module',
|
||||
allowImportExportEverywhere: false,
|
||||
classPrivateMethods: true,
|
||||
ecmaFeatures: {
|
||||
globalReturn: false,
|
||||
},
|
||||
babelOptions: {
|
||||
configFile: "./.babelrc",
|
||||
configFile: './.babelrc',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
camelcase: 'off',
|
||||
'camelcase': 'off',
|
||||
'max-len': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
},
|
||||
};
|
||||
|
||||
25
package-lock.json
generated
25
package-lock.json
generated
@@ -423,6 +423,16 @@
|
||||
"@babel/plugin-syntax-optional-catch-binding": "^7.2.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-proposal-optional-chaining": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.6.0.tgz",
|
||||
"integrity": "sha512-kj4gkZ6qUggkprRq3Uh5KP8XnE1MdIO0J7MhdDX8+rAbB6dJ2UrensGIS+0NPZAaaJ1Vr0PN6oLUgXMU1uMcSg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-plugin-utils": "^7.0.0",
|
||||
"@babel/plugin-syntax-optional-chaining": "^7.2.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-proposal-private-methods": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-methods/-/plugin-proposal-private-methods-7.6.0.tgz",
|
||||
@@ -497,6 +507,15 @@
|
||||
"@babel/helper-plugin-utils": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-syntax-optional-chaining": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.2.0.tgz",
|
||||
"integrity": "sha512-HtGCtvp5Uq/jH/WNUPkK6b7rufnCPLLlDAFN7cmACoIjaOOiXxUt3SswU5loHqrhtqTsa/WoLQ1OQ1AGuZqaWA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-plugin-utils": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-syntax-top-level-await": {
|
||||
"version": "7.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.7.0.tgz",
|
||||
@@ -960,6 +979,12 @@
|
||||
"to-fast-properties": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"@types/chai": {
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.4.tgz",
|
||||
"integrity": "sha512-7qvf9F9tMTzo0akeswHPGqgUx/gIaJqrOEET/FCD8CFRkSUHlygQiM5yB6OvjrtdxBVLSyw7COJubsFYs0683g==",
|
||||
"dev": true
|
||||
},
|
||||
"acorn": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz",
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
"@babel/core": "^7.7.2",
|
||||
"@babel/node": "^7.7.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.7.0",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
|
||||
"@babel/plugin-proposal-private-methods": "^7.6.0",
|
||||
"@babel/preset-env": "^7.7.1",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"@babel/register": "^7.7.0",
|
||||
"@types/chai": "^4.2.4",
|
||||
"babel-eslint": "^11.0.0-beta.0",
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^6.6.0",
|
||||
|
||||
169
src/BaseAPI.js
169
src/BaseAPI.js
@@ -134,7 +134,7 @@ export default class BaseAPI {
|
||||
* @param {string} callbackName
|
||||
* @param {boolean} checkTerminated
|
||||
* @param {string} CMIElement
|
||||
* @param {any} value
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
*/
|
||||
setValue(
|
||||
@@ -204,7 +204,7 @@ export default class BaseAPI {
|
||||
* Returns the errorNumber error description
|
||||
*
|
||||
* @param {string} callbackName
|
||||
* @param {number} CMIErrorCode
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
getErrorString(callbackName: String, CMIErrorCode) {
|
||||
@@ -224,8 +224,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Returns a comprehensive description of the errorNumber error.
|
||||
*
|
||||
* @param callbackName
|
||||
* @param CMIErrorCode
|
||||
* @param {string} callbackName
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
getDiagnostic(callbackName: String, CMIErrorCode) {
|
||||
@@ -243,10 +243,16 @@ export default class BaseAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the LMS state and ensures it has been initialized
|
||||
* Checks the LMS state and ensures it has been initialized.
|
||||
*
|
||||
* @param {boolean} checkTerminated
|
||||
* @param {number} beforeInitError
|
||||
* @param {number} afterTermError
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkState(
|
||||
checkTerminated: boolean, beforeInitError: number,
|
||||
checkTerminated: boolean,
|
||||
beforeInitError: number,
|
||||
afterTermError?: number) {
|
||||
if (_self.isNotInitialized()) {
|
||||
_self.throwSCORMError(beforeInitError);
|
||||
@@ -262,13 +268,15 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Logging for all SCORM actions
|
||||
*
|
||||
* @param functionName
|
||||
* @param CMIElement
|
||||
* @param logMessage
|
||||
* @param messageLevel
|
||||
* @param {string} functionName
|
||||
* @param {string} CMIElement
|
||||
* @param {string} logMessage
|
||||
* @param {number}messageLevel
|
||||
*/
|
||||
apiLog(
|
||||
functionName: String, CMIElement: String, logMessage: String,
|
||||
functionName: String,
|
||||
CMIElement: String,
|
||||
logMessage: String,
|
||||
messageLevel: number) {
|
||||
logMessage = _self.formatMessage(functionName, CMIElement, logMessage);
|
||||
|
||||
@@ -287,21 +295,12 @@ export default class BaseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the last SCORM error code on success
|
||||
*/
|
||||
clearSCORMError(success: String) {
|
||||
if (success !== api_constants.SCORM_FALSE) {
|
||||
_self.lastErrorCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the SCORM messages for easy reading
|
||||
*
|
||||
* @param functionName
|
||||
* @param CMIElement
|
||||
* @param message
|
||||
* @param {string} functionName
|
||||
* @param {string} CMIElement
|
||||
* @param {string} message
|
||||
* @return {string}
|
||||
*/
|
||||
formatMessage(functionName: String, CMIElement: String, message: String) {
|
||||
@@ -340,8 +339,9 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Checks to see if {str} contains {tester}
|
||||
*
|
||||
* @param str String to check against
|
||||
* @param tester String to check for
|
||||
* @param {string} str String to check against
|
||||
* @param {string} tester String to check for
|
||||
* @return {boolean}
|
||||
*/
|
||||
stringContains(str: String, tester: String) {
|
||||
return str.indexOf(tester) > -1;
|
||||
@@ -350,6 +350,10 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Returns the message that corresponds to errorNumber
|
||||
* APIs that inherit BaseAPI should override this function
|
||||
*
|
||||
* @param {(string|number)} _errorNumber
|
||||
* @param {boolean} _detail
|
||||
* @return {string}
|
||||
*/
|
||||
getLmsErrorMessageDetails(_errorNumber, _detail) {
|
||||
return 'No error';
|
||||
@@ -358,6 +362,9 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Gets the value for the specific element.
|
||||
* APIs that inherit BaseAPI should override this function
|
||||
*
|
||||
* @param {string} _CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
getCMIValue(_CMIElement) {
|
||||
return '';
|
||||
@@ -366,11 +373,24 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Sets the value for the specific element.
|
||||
* APIs that inherit BaseAPI should override this function
|
||||
*
|
||||
* @param {string} _CMIElement
|
||||
* @param {any} _value
|
||||
*/
|
||||
setCMIValue(_CMIElement, _value) {
|
||||
return '';
|
||||
// just a stub method
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared API method to set a valid for a given element.
|
||||
*
|
||||
* @param {string} methodName
|
||||
* @param {boolean} scorm2004
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
_commonSetCMIValue(
|
||||
methodName: String, scorm2004: boolean, CMIElement, value) {
|
||||
if (!CMIElement || CMIElement === '') {
|
||||
@@ -393,7 +413,7 @@ export default class BaseAPI {
|
||||
if (scorm2004 && (attribute.substr(0, 8) === '{target=') &&
|
||||
(typeof refObject._isTargetValid == 'function')) {
|
||||
_self.throwSCORMError(_self.#error_codes.READ_ONLY_ELEMENT);
|
||||
} else if (!refObject.hasOwnProperty(attribute)) {
|
||||
} else if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||
_self.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||
} else {
|
||||
if (_self.stringContains(CMIElement, '.correct_responses')) {
|
||||
@@ -412,7 +432,7 @@ export default class BaseAPI {
|
||||
break;
|
||||
}
|
||||
|
||||
if (refObject.prototype === CMIArray) {
|
||||
if (refObject instanceof CMIArray) {
|
||||
const index = parseInt(structure[i + 1], 10);
|
||||
|
||||
// SCO is trying to set an item on an array
|
||||
@@ -448,24 +468,34 @@ export default class BaseAPI {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for validating that a response is correct.
|
||||
*
|
||||
* @param {string} _CMIElement
|
||||
* @param {*} _value
|
||||
*/
|
||||
validateCorrectResponse(_CMIElement, _value) {
|
||||
return false;
|
||||
// just a stub method
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or builds a new child element to add to the array.
|
||||
* APIs that inherit BaseAPI should override this method
|
||||
* APIs that inherit BaseAPI should override this method.
|
||||
*
|
||||
* @param {string} _CMIElement - unused
|
||||
* @param {*} _value - unused
|
||||
* @return {*}
|
||||
*/
|
||||
getChildElement(_CMIElement) {
|
||||
getChildElement(_CMIElement, _value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from the CMI Object
|
||||
*
|
||||
* @param methodName
|
||||
* @param scorm2004
|
||||
* @param CMIElement
|
||||
* @param {string} methodName
|
||||
* @param {boolean} scorm2004
|
||||
* @param {string} CMIElement
|
||||
* @return {*}
|
||||
*/
|
||||
_commonGetCMIValue(methodName: String, scorm2004: boolean, CMIElement) {
|
||||
@@ -482,7 +512,7 @@ export default class BaseAPI {
|
||||
|
||||
if (!scorm2004) {
|
||||
if (i === structure.length - 1) {
|
||||
if (!refObject.hasOwnProperty(attribute)) {
|
||||
if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||
_self.throwSCORMError(101,
|
||||
'getCMIValue did not find a value for: ' + CMIElement);
|
||||
}
|
||||
@@ -493,7 +523,7 @@ export default class BaseAPI {
|
||||
const target = String(attribute).
|
||||
substr(8, String(attribute).length - 9);
|
||||
return refObject._isTargetValid(target);
|
||||
} else if (!refObject.hasOwnProperty(attribute)) {
|
||||
} else if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||
_self.throwSCORMError(401,
|
||||
'The data model element passed to GetValue (' + CMIElement +
|
||||
') is not a valid SCORM data model element.');
|
||||
@@ -520,6 +550,8 @@ export default class BaseAPI {
|
||||
|
||||
/**
|
||||
* Returns true if the API's current state is STATE_INITIALIZED
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isInitialized() {
|
||||
return _self.currentState === api_constants.STATE_INITIALIZED;
|
||||
@@ -527,6 +559,8 @@ export default class BaseAPI {
|
||||
|
||||
/**
|
||||
* Returns true if the API's current state is STATE_NOT_INITIALIZED
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isNotInitialized() {
|
||||
return _self.currentState === api_constants.STATE_NOT_INITIALIZED;
|
||||
@@ -534,6 +568,8 @@ export default class BaseAPI {
|
||||
|
||||
/**
|
||||
* Returns true if the API's current state is STATE_TERMINATED
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isTerminated() {
|
||||
return _self.currentState === api_constants.STATE_TERMINATED;
|
||||
@@ -542,8 +578,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Provides a mechanism for attaching to a specific SCORM event
|
||||
*
|
||||
* @param listenerName
|
||||
* @param callback
|
||||
* @param {string} listenerName
|
||||
* @param {function} callback
|
||||
*/
|
||||
on(listenerName: String, callback: function) {
|
||||
if (!callback) return;
|
||||
@@ -571,9 +607,9 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Processes any 'on' listeners that have been created
|
||||
*
|
||||
* @param functionName
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @param {string} functionName
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
*/
|
||||
processListeners(functionName: String, CMIElement: String, value: any) {
|
||||
for (let i = 0; i < _self.listenerArray.length; i++) {
|
||||
@@ -591,8 +627,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Throws a SCORM error
|
||||
*
|
||||
* @param errorNumber
|
||||
* @param message
|
||||
* @param {number} errorNumber
|
||||
* @param {string} message
|
||||
*/
|
||||
throwSCORMError(errorNumber: number, message: String) {
|
||||
if (!message) {
|
||||
@@ -605,20 +641,34 @@ export default class BaseAPI {
|
||||
_self.lastErrorCode = String(errorNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the last SCORM error code on success.
|
||||
*
|
||||
* @param {string} success
|
||||
*/
|
||||
clearSCORMError(success: String) {
|
||||
if (success !== api_constants.SCORM_FALSE) {
|
||||
_self.lastErrorCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads CMI data from a JSON object.
|
||||
*
|
||||
* @param {object} json
|
||||
* @param {string} CMIElement
|
||||
*/
|
||||
loadFromJSON(json, CMIElement) {
|
||||
if (!_self.isNotInitialized()) {
|
||||
console.error(
|
||||
'loadFromJSON can only be called before the call to LMSInitialize.');
|
||||
'loadFromJSON can only be called before the call to lmsInitialize.');
|
||||
return;
|
||||
}
|
||||
|
||||
CMIElement = CMIElement || 'cmi';
|
||||
|
||||
for (const key in json) {
|
||||
if (json.hasOwnProperty(key) && json[key]) {
|
||||
if ({}.hasOwnProperty.call(json, key) && json[key]) {
|
||||
const currentCMIElement = CMIElement + '.' + key;
|
||||
const value = json[key];
|
||||
|
||||
@@ -636,6 +686,11 @@ export default class BaseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the CMI object to JSON for sending to an LMS.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
renderCMIToJSON() {
|
||||
const cmi = _self.cmi;
|
||||
// Do we want/need to return fields that have no set value?
|
||||
@@ -646,8 +701,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Check if the value matches the proper format. If not, throw proper error code.
|
||||
*
|
||||
* @param value
|
||||
* @param regexPattern
|
||||
* @param {string} value
|
||||
* @param {string} regexPattern
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkValidFormat(value: String, regexPattern: String) {
|
||||
@@ -662,8 +717,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Check if the value matches the proper range. If not, throw proper error code.
|
||||
*
|
||||
* @param value
|
||||
* @param rangePattern
|
||||
* @param {*} value
|
||||
* @param {string} rangePattern
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkValidRange(value: any, rangePattern: String) {
|
||||
@@ -686,7 +741,7 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Throws a SCORM error
|
||||
*
|
||||
* @param when the number of milliseconds to wait before committing
|
||||
* @param {number} when - the number of milliseconds to wait before committing
|
||||
*/
|
||||
scheduleCommit(when: number) {
|
||||
_self.#timeout = new ScheduledCommit(this, when);
|
||||
@@ -703,16 +758,27 @@ export default class BaseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Private class that wraps a timeout call to the commit() function
|
||||
*/
|
||||
class ScheduledCommit {
|
||||
#API;
|
||||
#cancelled: false;
|
||||
#timeout;
|
||||
|
||||
/**
|
||||
* Constructor for ScheduledCommit
|
||||
* @param {BaseAPI} API
|
||||
* @param {number} when
|
||||
*/
|
||||
constructor(API: any, when: number) {
|
||||
_self.#API = API;
|
||||
_self.#timeout = setTimeout(_self.#wrapper, when);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel any currently scheduled commit
|
||||
*/
|
||||
cancel() {
|
||||
_self.#cancelled = true;
|
||||
if (_self.#timeout) {
|
||||
@@ -720,6 +786,9 @@ class ScheduledCommit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the API commit call to check if the call has already been cancelled
|
||||
*/
|
||||
#wrapper = () => {
|
||||
if (!_self.#cancelled) {
|
||||
_self.#API.commit();
|
||||
|
||||
@@ -13,134 +13,170 @@ import {scorm12_error_codes} from './constants/error_codes';
|
||||
import {scorm12_regex} from './regex';
|
||||
|
||||
const constants = scorm12_constants;
|
||||
let _self;
|
||||
|
||||
/**
|
||||
* API class for SCORM 1.2
|
||||
*/
|
||||
export default class Scorm12API extends BaseAPI {
|
||||
/**
|
||||
* Constructor for SCORM 1.2 API
|
||||
*/
|
||||
constructor() {
|
||||
super(scorm12_error_codes);
|
||||
_self = this;
|
||||
|
||||
this.cmi = new CMI(this);
|
||||
_self.cmi = new CMI(this);
|
||||
// Rename functions to match 1.2 Spec and expose to modules
|
||||
_self.LMSInitialize = _self.lmsInitialize;
|
||||
_self.LMSFinish = _self.lmsFinish;
|
||||
_self.LMSGetValue = _self.lmsGetValue;
|
||||
_self.LMSSetValue = _self.lmsSetValue;
|
||||
_self.LMSCommit = _self.lmsCommit;
|
||||
_self.LMSGetLastError = _self.lmsGetLastError;
|
||||
_self.LMSGetErrorString = _self.lmsGetErrorString;
|
||||
_self.LMSGetDiagnostic = _self.lmsGetDiagnostic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSInitialize() {
|
||||
return this.initialize('LMSInitialize', 'LMS was already initialized!',
|
||||
* lmsInitialize function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
lmsInitialize() {
|
||||
return _self.initialize('LMSInitialize', 'LMS was already initialized!',
|
||||
'LMS is already finished!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSFinish() {
|
||||
return this.terminate('LMSFinish', false);
|
||||
* LMSFinish function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
lmsFinish() {
|
||||
return _self.terminate('LMSFinish', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetValue(CMIElement) {
|
||||
return this.getValue('LMSGetValue', false, CMIElement);
|
||||
* LMSGetValue function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetValue(CMIElement) {
|
||||
return _self.getValue('LMSGetValue', false, CMIElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @return {string}
|
||||
*/
|
||||
LMSSetValue(CMIElement, value) {
|
||||
return this.setValue('LMSSetValue', false, CMIElement, value);
|
||||
* LMSSetValue function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
*/
|
||||
lmsSetValue(CMIElement, value) {
|
||||
return _self.setValue('LMSSetValue', false, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders LMS to store all content parameters
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSCommit() {
|
||||
return this.commit('LMSCommit', false);
|
||||
* LMSCommit function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
lmsCommit() {
|
||||
return _self.commit('LMSCommit', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last error code
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetLastError() {
|
||||
return this.getLastError('LMSGetLastError');
|
||||
* LMSGetLastError function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetLastError() {
|
||||
return _self.getLastError('LMSGetLastError');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the errorNumber error description
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetErrorString(CMIErrorCode) {
|
||||
return this.getErrorString('LMSGetErrorString', CMIErrorCode);
|
||||
* LMSGetErrorString function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetErrorString(CMIErrorCode) {
|
||||
return _self.getErrorString('LMSGetErrorString', CMIErrorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comprehensive description of the errorNumber error.
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetDiagnostic(CMIErrorCode) {
|
||||
return this.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
||||
* LMSGetDiagnostic function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetDiagnostic(CMIErrorCode) {
|
||||
return _self.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value on the CMI Object
|
||||
*
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @return {string}
|
||||
*/
|
||||
* Sets a value on the CMI Object
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
*/
|
||||
setCMIValue(CMIElement, value) {
|
||||
this._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
||||
_self._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from the CMI Object
|
||||
*
|
||||
* @param CMIElement
|
||||
* @return {*}
|
||||
*/
|
||||
* Gets a value from the CMI Object
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @return {*}
|
||||
*/
|
||||
getCMIValue(CMIElement) {
|
||||
return this._commonGetCMIValue('getCMIValue', false, CMIElement);
|
||||
return _self._commonGetCMIValue('getCMIValue', false, CMIElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or builds a new child element to add to the array.
|
||||
*
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {object}
|
||||
*/
|
||||
getChildElement(CMIElement, value) {
|
||||
let newChild;
|
||||
|
||||
if (this.stringContains(CMIElement, 'cmi.objectives')) {
|
||||
if (_self.stringContains(CMIElement, 'cmi.objectives')) {
|
||||
newChild = new CMIObjectivesObject(this);
|
||||
} else if (this.stringContains(CMIElement, '.correct_responses')) {
|
||||
} else if (_self.stringContains(CMIElement, '.correct_responses')) {
|
||||
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
||||
} else if (this.stringContains(CMIElement, '.objectives')) {
|
||||
} else if (_self.stringContains(CMIElement, '.objectives')) {
|
||||
newChild = new CMIInteractionsObjectivesObject(this);
|
||||
} else if (this.stringContains(CMIElement, 'cmi.interactions')) {
|
||||
} else if (_self.stringContains(CMIElement, 'cmi.interactions')) {
|
||||
newChild = new CMIInteractionsObject(this);
|
||||
}
|
||||
|
||||
return newChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates Correct Response values
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
validateCorrectResponse(CMIElement, value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message that corresponds to errorNumber.
|
||||
*/
|
||||
* Returns the message that corresponds to errorNumber.
|
||||
*
|
||||
* @param {*} errorNumber
|
||||
* @param {boolean }detail
|
||||
* @return {string}
|
||||
*/
|
||||
getLmsErrorMessageDetails(errorNumber, detail) {
|
||||
let basicMessage = 'No Error';
|
||||
let detailMessage = 'No Error';
|
||||
@@ -156,25 +192,26 @@ export default class Scorm12API extends BaseAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current session time to the existing total time.
|
||||
*/
|
||||
* Adds the current session time to the existing total time.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
getCurrentTotalTime() {
|
||||
const timeRegex = new RegExp(scorm12_regex.CMITime);
|
||||
|
||||
const totalTime = this.cmi.core.total_time;
|
||||
const sessionTime = this.cmi.core.session_time;
|
||||
const totalTime = _self.cmi.core.total_time;
|
||||
const sessionTime = _self.cmi.core.session_time;
|
||||
|
||||
const totalSeconds = Utilities.getTimeAsSeconds(totalTime, timeRegex);
|
||||
const sessionSeconds = Utilities.getTimeAsSeconds(sessionTime, timeRegex);
|
||||
|
||||
return Utilities.getSecondsAsHHMMSS(totalSeconds + sessionSeconds);
|
||||
return Utilities.addHHMMSSTimeStrings(totalTime, sessionTime, timeRegex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the whole API with another
|
||||
*/
|
||||
* Replace the whole API with another
|
||||
*
|
||||
* @param {Scorm12API} newAPI
|
||||
*/
|
||||
replaceWithAnotherScormAPI(newAPI) {
|
||||
// Data Model
|
||||
this.cmi = newAPI.cmi;
|
||||
_self.cmi = newAPI.cmi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ let _self;
|
||||
* API class for SCORM 2004
|
||||
*/
|
||||
class Scorm2004API extends BaseAPI {
|
||||
version: '1.0';
|
||||
#version: '1.0';
|
||||
|
||||
/**
|
||||
* Constructor for SCORM 2004 API
|
||||
@@ -36,28 +36,36 @@ class Scorm2004API extends BaseAPI {
|
||||
_self.cmi = new CMI(_self);
|
||||
_self.adl = new ADL(_self);
|
||||
|
||||
// Rename functions to match 2004 Spec
|
||||
_self.Initialize = _self.LMSInitialize;
|
||||
_self.Terminate = _self.LMSTerminate;
|
||||
_self.GetValue = _self.LMSGetValue;
|
||||
_self.SetValue = _self.LMSSetValue;
|
||||
_self.Commit = _self.LMSCommit;
|
||||
_self.GetLastError = _self.LMSGetLastError;
|
||||
_self.GetErrorString = _self.LMSGetErrorString;
|
||||
_self.GetDiagnostic = _self.LMSGetDiagnostic;
|
||||
// Rename functions to match 2004 Spec and expose to modules
|
||||
_self.Initialize = _self.lmsInitialize;
|
||||
_self.Terminate = _self.lmsTerminate;
|
||||
_self.GetValue = _self.lmsGetValue;
|
||||
_self.SetValue = _self.lmsSetValue;
|
||||
_self.Commit = _self.lmsCommit;
|
||||
_self.GetLastError = _self.lmsGetLastError;
|
||||
_self.GetErrorString = _self.lmsGetErrorString;
|
||||
_self.GetDiagnostic = _self.lmsGetDiagnostic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #version
|
||||
* @return {string}
|
||||
*/
|
||||
get version() {
|
||||
return this.#version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSInitialize() {
|
||||
lmsInitialize() {
|
||||
return _self.initialize('Initialize');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSTerminate() {
|
||||
lmsTerminate() {
|
||||
return _self.terminate('Terminate', true);
|
||||
}
|
||||
|
||||
@@ -65,7 +73,7 @@ class Scorm2004API extends BaseAPI {
|
||||
* @param {string} CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetValue(CMIElement) {
|
||||
lmsGetValue(CMIElement) {
|
||||
return _self.getValue('GetValue', true, CMIElement);
|
||||
}
|
||||
|
||||
@@ -74,7 +82,7 @@ class Scorm2004API extends BaseAPI {
|
||||
* @param {any} value
|
||||
* @return {string}
|
||||
*/
|
||||
LMSSetValue(CMIElement, value) {
|
||||
lmsSetValue(CMIElement, value) {
|
||||
return _self.setValue('SetValue', true, CMIElement, value);
|
||||
}
|
||||
|
||||
@@ -83,7 +91,7 @@ class Scorm2004API extends BaseAPI {
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSCommit() {
|
||||
lmsCommit() {
|
||||
return _self.commit('Commit');
|
||||
}
|
||||
|
||||
@@ -92,27 +100,27 @@ class Scorm2004API extends BaseAPI {
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetLastError() {
|
||||
lmsGetLastError() {
|
||||
return _self.getLastError('GetLastError');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the errorNumber error description
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetErrorString(CMIErrorCode) {
|
||||
lmsGetErrorString(CMIErrorCode) {
|
||||
return _self.getErrorString('GetErrorString', CMIErrorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comprehensive description of the errorNumber error.
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetDiagnostic(CMIErrorCode) {
|
||||
lmsGetDiagnostic(CMIErrorCode) {
|
||||
return _self.getDiagnostic('GetDiagnostic', CMIErrorCode);
|
||||
}
|
||||
|
||||
@@ -160,7 +168,7 @@ class Scorm2004API extends BaseAPI {
|
||||
const response_type = correct_responses[interaction_type];
|
||||
let nodes = [];
|
||||
if (response_type.delimiter !== '') {
|
||||
nodes = value.split(response_type.delimiter);
|
||||
nodes = String(value).split(response_type.delimiter);
|
||||
} else {
|
||||
nodes[0] = value;
|
||||
}
|
||||
@@ -191,7 +199,7 @@ class Scorm2004API extends BaseAPI {
|
||||
/**
|
||||
* Validate correct response.
|
||||
* @param {string} CMIElement
|
||||
* @param {any} value
|
||||
* @param {*} value
|
||||
*/
|
||||
validateCorrectResponse(CMIElement, value) {
|
||||
const parts = CMIElement.split('.');
|
||||
@@ -215,7 +223,7 @@ class Scorm2004API extends BaseAPI {
|
||||
response_type.limit) {
|
||||
let nodes = [];
|
||||
if (response_type.delimiter !== '') {
|
||||
nodes = value.split(response_type.delimiter);
|
||||
nodes = String(value).split(response_type.delimiter);
|
||||
} else {
|
||||
nodes[0] = value;
|
||||
}
|
||||
@@ -258,8 +266,8 @@ class Scorm2004API extends BaseAPI {
|
||||
/**
|
||||
* Returns the message that corresponds to errorNumber.
|
||||
*
|
||||
* @param {string,number} errorNumber
|
||||
* @param {string} detail
|
||||
* @param {(string|number)} errorNumber
|
||||
* @param {boolean} detail
|
||||
* @return {string}
|
||||
*/
|
||||
getLmsErrorMessageDetails(errorNumber, detail) {
|
||||
@@ -276,6 +284,13 @@ class Scorm2004API extends BaseAPI {
|
||||
return detail ? detailMessage : basicMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a correct_response value has been duplicated
|
||||
* @param {CMIArray} correct_response
|
||||
* @param {number} current_index
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
#checkDuplicatedPattern = (correct_response, current_index, value) => {
|
||||
let found = false;
|
||||
const count = correct_response._count;
|
||||
@@ -287,6 +302,12 @@ class Scorm2004API extends BaseAPI {
|
||||
return found;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks for a valid correct_response value
|
||||
* @param {string} interaction_type
|
||||
* @param {Array} nodes
|
||||
* @param {*} value
|
||||
*/
|
||||
#checkCorrectResponseValue = (interaction_type, nodes, value) => {
|
||||
const response = correct_responses[interaction_type];
|
||||
const formatRegex = new RegExp(response.format);
|
||||
@@ -334,6 +355,11 @@ class Scorm2004API extends BaseAPI {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove prefixes from correct_response
|
||||
* @param {string} node
|
||||
* @return {*}
|
||||
*/
|
||||
#removeCorrectResponsePrefixes = (node) => {
|
||||
let seenOrder = false;
|
||||
let seenCase = false;
|
||||
@@ -404,11 +430,7 @@ class Scorm2004API extends BaseAPI {
|
||||
const totalTime = _self.cmi.total_time;
|
||||
const sessionTime = _self.cmi.session_time;
|
||||
|
||||
const durationRegex = scorm2004_regex.CMITimespan;
|
||||
const totalSeconds = Util.getDurationAsSeconds(totalTime, durationRegex);
|
||||
const sessionSeconds = Util.getDurationAsSeconds(sessionTime,
|
||||
durationRegex);
|
||||
|
||||
return Util.getSecondsAsISODuration(totalSeconds + sessionSeconds);
|
||||
return Util.addTwoDurations(totalTime, sessionTime,
|
||||
scorm2004_regex.CMITimespan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,17 +39,18 @@ class CMIEvaluation extends BaseCMI {
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API);
|
||||
}
|
||||
|
||||
comments = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for AICC Evaluation Comments object
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, constants.comments_children, 402);
|
||||
}
|
||||
};
|
||||
this.comments = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for AICC Evaluation Comments object
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, constants.comments_children,
|
||||
scorm12_error_codes.INVALID_SET_VALUE);
|
||||
}
|
||||
}(API);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +63,16 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, constants.student_data_children);
|
||||
|
||||
this.tries = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for inline Tries Array class
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, aicc_constants.tries_children);
|
||||
}
|
||||
}(API);
|
||||
}
|
||||
|
||||
#tries_during_lesson = '';
|
||||
@@ -84,34 +95,20 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
|
||||
this.#tries_during_lesson = tries_during_lesson :
|
||||
throwReadOnlyError();
|
||||
}
|
||||
|
||||
tries = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for inline Tries Array class
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, aicc_constants.tries_children);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let _self;
|
||||
|
||||
/**
|
||||
* Class for AICC Tries
|
||||
*/
|
||||
export class CMITriesObject extends BaseCMI {
|
||||
#API;
|
||||
|
||||
/**
|
||||
* Constructor for AICC Tries object
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API);
|
||||
this.#API = API;
|
||||
_self = this;
|
||||
|
||||
this.score = new CMIScore(API);
|
||||
}
|
||||
|
||||
#status = '';
|
||||
@@ -152,8 +149,6 @@ export class CMITriesObject extends BaseCMI {
|
||||
this.#time = time;
|
||||
}
|
||||
}
|
||||
|
||||
score = new CMIScore(_self.#API);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +241,9 @@ export class NAV extends BaseCMI {
|
||||
* @return {string}
|
||||
*/
|
||||
get event() {
|
||||
return (!this.jsonString) ? this.API.throwSCORMError(404) : this.#event;
|
||||
return (!this.jsonString) ?
|
||||
this.API.throwSCORMError(scorm12_error_codes.WRITE_ONLY_ELEMENT) :
|
||||
this.#event;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,78 +1,154 @@
|
||||
// @flow
|
||||
import {scorm12_constants} from '../constants/api_constants';
|
||||
import {scorm12_error_codes} from '../constants/error_codes';
|
||||
|
||||
/**
|
||||
* Base class for API cmi objects
|
||||
*/
|
||||
export class BaseCMI {
|
||||
jsonString = false;
|
||||
API;
|
||||
jsonString = false;
|
||||
API;
|
||||
|
||||
constructor(API: any) {
|
||||
this.API = API;
|
||||
}
|
||||
/**
|
||||
* Constructor for base cmi
|
||||
* @param {BaseAPI} API
|
||||
*/
|
||||
constructor(API: any) {
|
||||
this.API = API;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for cmi *.score objects
|
||||
*/
|
||||
export class CMIScore extends BaseCMI {
|
||||
/**
|
||||
* Constructor for *.score
|
||||
* @param {BaseAPI} API
|
||||
* @param {string} score_children
|
||||
* @param {string} score_range
|
||||
* @param {number} invalidErrorCode
|
||||
*/
|
||||
constructor(API, score_children?, score_range?, invalidErrorCode) {
|
||||
super(API);
|
||||
|
||||
this.#_children = score_children? score_children : scorm12_constants.score_children;
|
||||
this.#_score_range = score_range? score_range : false;
|
||||
this.#_invalid_error_code = invalidErrorCode ? invalidErrorCode : scorm12_error_codes.INVALID_SET_VALUE;
|
||||
this.#_children = score_children ?
|
||||
score_children :
|
||||
scorm12_constants.score_children;
|
||||
this.#_score_range = score_range ? score_range : false;
|
||||
this.#_invalid_error_code = invalidErrorCode ?
|
||||
invalidErrorCode :
|
||||
scorm12_error_codes.INVALID_SET_VALUE;
|
||||
}
|
||||
|
||||
#_children;
|
||||
#_score_range;
|
||||
#_invalid_error_code;
|
||||
#raw = '';
|
||||
#min = '';
|
||||
#max = '100';
|
||||
#_children;
|
||||
#_score_range;
|
||||
#_invalid_error_code;
|
||||
#raw = '';
|
||||
#min = '';
|
||||
#max = '100';
|
||||
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#_invalid_error_code);
|
||||
}
|
||||
/**
|
||||
* Getter for _children
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
|
||||
get raw() {
|
||||
return this.#raw;
|
||||
}
|
||||
set raw(raw) {
|
||||
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range || this.API.checkValidRange(raw, this.#_score_range))) {
|
||||
this.#raw = raw;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Setter for _children. Just throws an error.
|
||||
* @param {string} _children
|
||||
* @private
|
||||
*/
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#_invalid_error_code);
|
||||
}
|
||||
|
||||
get min() {
|
||||
return this.#min;
|
||||
}
|
||||
set min(min) {
|
||||
if (this.API.checkValidFormat(min, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range || this.API.checkValidRange(min, this.#_score_range))) {
|
||||
this.#min = min;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Getter for #raw
|
||||
* @return {string}
|
||||
*/
|
||||
get raw() {
|
||||
return this.#raw;
|
||||
}
|
||||
|
||||
get max() {
|
||||
return this.#max;
|
||||
}
|
||||
set max(max) {
|
||||
if (this.API.checkValidFormat(max, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range || this.API.checkValidRange(max, this.#_score_range))) {
|
||||
this.#max = max;
|
||||
}
|
||||
/**
|
||||
* Setter for #raw
|
||||
* @param {string} raw
|
||||
*/
|
||||
set raw(raw) {
|
||||
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range ||
|
||||
this.API.checkValidRange(raw, this.#_score_range))) {
|
||||
this.#raw = raw;
|
||||
}
|
||||
}
|
||||
|
||||
toJSON = () => {
|
||||
return {
|
||||
'raw': this.raw,
|
||||
'min': this.min,
|
||||
'max': this.max,
|
||||
};
|
||||
/**
|
||||
* Getter for #min
|
||||
* @return {string}
|
||||
*/
|
||||
get min() {
|
||||
return this.#min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #min
|
||||
* @param {string} min
|
||||
*/
|
||||
set min(min) {
|
||||
if (this.API.checkValidFormat(min, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range ||
|
||||
this.API.checkValidRange(min, this.#_score_range))) {
|
||||
this.#min = min;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #max
|
||||
* @return {string}
|
||||
*/
|
||||
get max() {
|
||||
return this.#max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #max
|
||||
* @param {string} max
|
||||
*/
|
||||
set max(max) {
|
||||
if (this.API.checkValidFormat(max, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range ||
|
||||
this.API.checkValidRange(max, this.#_score_range))) {
|
||||
this.#max = max;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toJSON for *.score
|
||||
* @return {{min: string, max: string, raw: string}}
|
||||
*/
|
||||
toJSON() {
|
||||
return {
|
||||
'raw': this.raw,
|
||||
'min': this.min,
|
||||
'max': this.max,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for cmi *.n objects
|
||||
*/
|
||||
export class CMIArray extends BaseCMI {
|
||||
/**
|
||||
* Constructor cmi *.n arrays
|
||||
* @param {BaseAPI} API
|
||||
* @param {string} children
|
||||
* @param {number} errorCode
|
||||
*/
|
||||
constructor({API, children, errorCode}) {
|
||||
super(API);
|
||||
this.#_children = children;
|
||||
@@ -80,30 +156,56 @@ export class CMIArray extends BaseCMI {
|
||||
this.childArray = [];
|
||||
}
|
||||
|
||||
#errorCode;
|
||||
#_children;
|
||||
#errorCode;
|
||||
#_children;
|
||||
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
/**
|
||||
* Getter for _children
|
||||
* @return {*}
|
||||
* @private
|
||||
*/
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
|
||||
get _count() {
|
||||
return this.childArray.length;
|
||||
}
|
||||
set _count(_count) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
/**
|
||||
* Setter for _children. Just throws an error.
|
||||
* @param {string} _children
|
||||
* @private
|
||||
*/
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
|
||||
toJSON = () => {
|
||||
this.jsonString = true;
|
||||
const result = {};
|
||||
for (let i = 0; i < this.childArray.length; i++) {
|
||||
result[i + ''] = this.childArray[i];
|
||||
}
|
||||
delete this.jsonString;
|
||||
return result;
|
||||
/**
|
||||
* Getter for _count
|
||||
* @return {number}
|
||||
* @private
|
||||
*/
|
||||
get _count() {
|
||||
return this.childArray.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for _count. Just throws an error.
|
||||
* @param {number} _count
|
||||
* @private
|
||||
*/
|
||||
set _count(_count) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* toJSON for *.n arrays
|
||||
* @return {object}
|
||||
*/
|
||||
toJSON() {
|
||||
this.jsonString = true;
|
||||
const result = {};
|
||||
for (let i = 0; i < this.childArray.length; i++) {
|
||||
result[i + ''] = this.childArray[i];
|
||||
}
|
||||
delete this.jsonString;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@ export const scorm12_constants = {
|
||||
},
|
||||
'301': {
|
||||
basicMessage: 'Not initialized',
|
||||
detailMessage: 'Indicates that an API call was made before the call to LMSInitialize.',
|
||||
detailMessage: 'Indicates that an API call was made before the call to lmsInitialize.',
|
||||
},
|
||||
'401': {
|
||||
basicMessage: 'Not implemented error',
|
||||
|
||||
@@ -71,4 +71,4 @@ export const valid_languages = {
|
||||
'ukr': 'ukr', 'urd': 'urd', 'uzb': 'uzb', 'ven': 'ven', 'vie': 'vie',
|
||||
'vol': 'vol', 'wln': 'wln', 'wol': 'wol', 'xho': 'xho', 'yid': 'yid',
|
||||
'yor': 'yor', 'zha': 'zha', 'chi': 'chi', 'zho': 'zho', 'zul': 'zul',
|
||||
};
|
||||
};
|
||||
|
||||
126
src/regex.js
126
src/regex.js
@@ -1,76 +1,76 @@
|
||||
// @flow
|
||||
|
||||
export const scorm12_regex = {
|
||||
CMIString256: '^.{0,255}$',
|
||||
CMIString4096: '^.{0,4096}$',
|
||||
CMITime: '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,6})?$',
|
||||
CMITimespan: '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$',
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$',
|
||||
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
|
||||
CMIFeedback: '^.{0,255}$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
CMIString256: '^.{0,255}$',
|
||||
CMIString4096: '^.{0,4096}$',
|
||||
CMITime: '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,6})?$', // eslint-disable-line
|
||||
CMITimespan: '^([0-9]{2,}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$', // eslint-disable-line
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$', // eslint-disable-line
|
||||
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
|
||||
CMIFeedback: '^.{0,255}$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
|
||||
// Vocabulary Data Type Definition
|
||||
CMIStatus: '^passed$|^completed$|^failed$|^incomplete$|^browsed$',
|
||||
CMIStatus2: '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^$',
|
||||
CMIType: '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$',
|
||||
CMIResult: '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$',
|
||||
NAVEvent: '^previous$|^continue$',
|
||||
// Vocabulary Data Type Definition
|
||||
CMIStatus: '^passed$|^completed$|^failed$|^incomplete$|^browsed$',
|
||||
CMIStatus2: '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^$',
|
||||
CMIType: '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$',
|
||||
CMIResult: '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$', // eslint-disable-line
|
||||
NAVEvent: '^previous$|^continue$',
|
||||
|
||||
// Data ranges
|
||||
score_range: '0#100',
|
||||
audio_range: '-1#100',
|
||||
speed_range: '-100#100',
|
||||
weighting_range: '-100#100',
|
||||
text_range: '-1#1',
|
||||
// Data ranges
|
||||
score_range: '0#100',
|
||||
audio_range: '-1#100',
|
||||
speed_range: '-100#100',
|
||||
weighting_range: '-100#100',
|
||||
text_range: '-1#1',
|
||||
};
|
||||
|
||||
export const aicc_regex = {
|
||||
...scorm12_regex, ...{
|
||||
CMIIdentifier: '^\\w{1,255}$',
|
||||
}
|
||||
...scorm12_regex, ...{
|
||||
CMIIdentifier: '^\\w{1,255}$',
|
||||
},
|
||||
};
|
||||
|
||||
export const scorm2004_regex = {
|
||||
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
|
||||
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
|
||||
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
|
||||
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
|
||||
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
|
||||
CMILang: '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$',
|
||||
CMILangString250: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?',
|
||||
CMILangcr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$',
|
||||
CMILangString250cr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$',
|
||||
CMILangString4000: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?',
|
||||
CMITime: '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$',
|
||||
CMITimespan: '^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$',
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
|
||||
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
|
||||
CMIShortIdentifier: '^[\\w\.]{1,250}$',
|
||||
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
|
||||
CMIFeedback: '^.*$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
CMIIndexStore: '.N(\\d+).',
|
||||
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
|
||||
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
|
||||
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
|
||||
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
|
||||
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
|
||||
CMILang: '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$', // eslint-disable-line
|
||||
CMILangString250: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?', // eslint-disable-line
|
||||
CMILangcr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$', // eslint-disable-line
|
||||
CMILangString250cr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$', // eslint-disable-line
|
||||
CMILangString4000: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?', // eslint-disable-line
|
||||
CMITime: '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$',
|
||||
CMITimespan: '^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$',
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
|
||||
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
|
||||
CMIShortIdentifier: '^[\\w\.]{1,250}$', // eslint-disable-line
|
||||
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
|
||||
CMIFeedback: '^.*$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
CMIIndexStore: '.N(\\d+).',
|
||||
|
||||
// Vocabulary Data Type Definition
|
||||
CMICStatus: '^completed$|^incomplete$|^not attempted$|^unknown$',
|
||||
CMISStatus: '^passed$|^failed$|^unknown$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^normal$|^$',
|
||||
CMIType: '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$',
|
||||
CMIResult: '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$',
|
||||
NAVEvent: '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump$',
|
||||
NAVBoolean: '^unknown$|^true$|^false$',
|
||||
NAVTarget: '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$',
|
||||
// Vocabulary Data Type Definition
|
||||
CMICStatus: '^completed$|^incomplete$|^not attempted$|^unknown$',
|
||||
CMISStatus: '^passed$|^failed$|^unknown$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^normal$|^$',
|
||||
CMIType: '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$',
|
||||
CMIResult: '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$',
|
||||
NAVEvent: '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump$', // eslint-disable-line
|
||||
NAVBoolean: '^unknown$|^true$|^false$',
|
||||
NAVTarget: '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$',
|
||||
|
||||
// Data ranges
|
||||
scaled_range: '-1#1',
|
||||
audio_range: '0#*',
|
||||
speed_range: '0#*',
|
||||
text_range: '-1#1',
|
||||
progress_range: '0#1',
|
||||
};
|
||||
// Data ranges
|
||||
scaled_range: '-1#1',
|
||||
audio_range: '0#*',
|
||||
speed_range: '0#*',
|
||||
text_range: '-1#1',
|
||||
progress_range: '0#1',
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
export const SECONDS_PER_SECOND = 1;
|
||||
export const SECONDS_PER_SECOND = 1.0;
|
||||
export const SECONDS_PER_MINUTE = 60;
|
||||
export const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
||||
export const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
||||
@@ -27,11 +27,12 @@ export function getSecondsAsHHMMSS(totalSeconds: Number) {
|
||||
|
||||
const dateObj = new Date(totalSeconds * 1000);
|
||||
const minutes = dateObj.getUTCMinutes();
|
||||
const seconds = dateObj.getSeconds();
|
||||
// make sure we add any possible decimal value
|
||||
const seconds = dateObj.getSeconds() + (totalSeconds % 1.0);
|
||||
|
||||
return hours.toString().padStart(2, '0') + ':' +
|
||||
minutes.toString().padStart(2, '0') + ':' +
|
||||
seconds.toString().padStart(2, '0');
|
||||
minutes.toString().padStart(2, '0') + ':' +
|
||||
seconds.toString().padStart(2, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,9 +51,14 @@ export function getSecondsAsISODuration(seconds: Number) {
|
||||
let remainder = seconds;
|
||||
|
||||
designations.forEach(([sign, current_seconds]) => {
|
||||
const value = Math.floor(remainder / current_seconds);
|
||||
let value = Math.floor(remainder / current_seconds);
|
||||
|
||||
remainder = remainder % current_seconds;
|
||||
// If we have anything left in the remainder, and we're currently adding
|
||||
// seconds to the duration, go ahead and add the decimal to the seconds
|
||||
if (sign === 'S' && remainder > 0) {
|
||||
value += remainder;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
duration += `${value}${sign}`;
|
||||
@@ -104,10 +110,45 @@ export function getDurationAsSeconds(duration: String, durationRegex: RegExp) {
|
||||
anchor.setHours(anchor.getHours() + Number(hours || 0));
|
||||
anchor.setMinutes(anchor.getMinutes() + Number(minutes || 0));
|
||||
anchor.setSeconds(anchor.getSeconds() + Number(seconds || 0));
|
||||
if (seconds) {
|
||||
if (seconds && String(seconds).indexOf('.') > 0) {
|
||||
const milliseconds = Number(Number(seconds) % 1).toFixed(6) * 1000.0;
|
||||
anchor.setMilliseconds(anchor.getMilliseconds() + milliseconds);
|
||||
}
|
||||
|
||||
return (anchor - now) / 1000.0;
|
||||
return ((anchor * 1.0) - now) / 1000.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds together two ISO8601 Duration strings
|
||||
*
|
||||
* @param {string} first
|
||||
* @param {string} second
|
||||
* @param {RegExp} durationRegex
|
||||
* @return {string}
|
||||
*/
|
||||
export function addTwoDurations(
|
||||
first: String,
|
||||
second: String,
|
||||
durationRegex: RegExp) {
|
||||
const firstSeconds = getDurationAsSeconds(first, durationRegex);
|
||||
const secondSeconds = getDurationAsSeconds(second, durationRegex);
|
||||
|
||||
return getSecondsAsISODuration(firstSeconds + secondSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add together two HH:MM:SS.DD strings
|
||||
*
|
||||
* @param {string} first
|
||||
* @param {string} second
|
||||
* @param {RegExp} timeRegex
|
||||
* @return {string}
|
||||
*/
|
||||
export function addHHMMSSTimeStrings(
|
||||
first: String,
|
||||
second: String,
|
||||
timeRegex: RegExp) {
|
||||
const firstSeconds = getTimeAsSeconds(first, timeRegex);
|
||||
const secondSeconds = getTimeAsSeconds(second, timeRegex);
|
||||
return getSecondsAsHHMMSS(firstSeconds + secondSeconds);
|
||||
}
|
||||
|
||||
@@ -1,283 +0,0 @@
|
||||
import {expect, assert} from 'chai';
|
||||
import {describe, it, before, beforeEach, after, afterEach} from 'mocha';
|
||||
import Scorm12API from '../src/Scorm12API';
|
||||
import {scorm12_constants} from '../src/constants/api_constants';
|
||||
import {scorm12_error_codes} from '../src/constants/error_codes';
|
||||
|
||||
let API;
|
||||
|
||||
const checkFieldConstraintSize = (fieldName: String, limit: Number, expectedValue: String = '') => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
|
||||
it(`Should be able to write upto ${limit} characters to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = 'x'.repeat(${limit})`);
|
||||
expect(0).to.equal(API.lastErrorCode);
|
||||
});
|
||||
|
||||
it(`Should fail to write more than ${limit} characters to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = 'x'.repeat(${limit + 1})`);
|
||||
expect(scorm12_error_codes.TYPE_MISMATCH + '').to.equal(API.lastErrorCode);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkInvalidSet = (fieldName: String, expectedValue: String = '') => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
|
||||
it(`Should fail to write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = 'xxx'`);
|
||||
expect(API.lastErrorCode).to.equal(scorm12_error_codes.INVALID_SET_VALUE + '');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkReadOnly = (fieldName: String, expectedValue: String = '') => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
|
||||
it(`Should fail to write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = 'xxx'`);
|
||||
expect(API.lastErrorCode).to.equal(scorm12_error_codes.READ_ONLY_ELEMENT + '');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkRead = (fieldName: String, expectedValue: String = '') => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkWriteOnly = (fieldName: String, valueToTest: String = 'xxx') => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should fail to read from ${fieldName}`, () => {
|
||||
eval(`API.${fieldName}`);
|
||||
expect(API.lastErrorCode).to.equal(scorm12_error_codes.WRITE_ONLY_ELEMENT + '');
|
||||
});
|
||||
|
||||
it(`Should successfully write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = '${valueToTest}'`);
|
||||
expect(API.lastErrorCode).to.equal(0);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkWrite = (fieldName: String, valueToTest: String = 'xxx') => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should successfully write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = '${valueToTest}'`);
|
||||
expect(API.lastErrorCode).to.equal(0);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkValidValues = (fieldName: String, expectedError: Number, validValues: Array, invalidValues: Array) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
for (const idx in validValues) {
|
||||
it(`Should successfully write '${validValues[idx]}' to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = '${validValues[idx]}'`);
|
||||
expect(API.lastErrorCode).to.equal(0);
|
||||
});
|
||||
}
|
||||
|
||||
for (const idx in invalidValues) {
|
||||
it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = '${invalidValues[idx]}'`);
|
||||
expect(API.lastErrorCode).to.equal(expectedError + '');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
describe('SCORM 1.2 API Tests', () => {
|
||||
describe('CMI Spec Tests', () => {
|
||||
describe('Post-LMSInitialize Tests', () => {
|
||||
beforeEach('Create the API object', () => {
|
||||
API = new Scorm12API();
|
||||
API.LMSInitialize();
|
||||
});
|
||||
afterEach('Destroy API object', () => {
|
||||
API = null;
|
||||
});
|
||||
|
||||
it('LMSInitialize should create CMI object', () => {
|
||||
assert(API.cmi !== undefined, 'CMI object is created');
|
||||
});
|
||||
|
||||
it('Exporting CMI to JSON produces proper Object', () => {
|
||||
expect(
|
||||
JSON.parse(API.renderCMIToJSON())
|
||||
).to.hasOwnProperty('core');
|
||||
});
|
||||
|
||||
/**
|
||||
* Base CMI Properties
|
||||
*/
|
||||
checkInvalidSet('cmi._version', '3.4');
|
||||
checkInvalidSet('cmi._children', scorm12_constants.cmi_children);
|
||||
checkFieldConstraintSize('cmi.suspend_data', 4096);
|
||||
checkReadOnly('cmi.launch_data');
|
||||
checkFieldConstraintSize('cmi.comments', 4096);
|
||||
checkReadOnly('cmi.comments_from_lms');
|
||||
|
||||
/**
|
||||
* cmi.core Properties
|
||||
*/
|
||||
checkInvalidSet('cmi.core._children', scorm12_constants.core_children);
|
||||
checkReadOnly('cmi.core.student_id');
|
||||
checkReadOnly('cmi.core.student_name');
|
||||
checkFieldConstraintSize('cmi.core.lesson_location', 255);
|
||||
checkReadOnly('cmi.core.credit');
|
||||
checkRead('cmi.core.lesson_status');
|
||||
checkValidValues('cmi.core.lesson_status', scorm12_error_codes.TYPE_MISMATCH, [
|
||||
'passed',
|
||||
'completed',
|
||||
'failed',
|
||||
'incomplete',
|
||||
'browsed',
|
||||
], [
|
||||
'Passed',
|
||||
'P',
|
||||
'F',
|
||||
'p',
|
||||
'true',
|
||||
'false',
|
||||
'complete',
|
||||
]);
|
||||
checkReadOnly('cmi.core.entry');
|
||||
checkReadOnly('cmi.core.total_time');
|
||||
checkReadOnly('cmi.core.lesson_mode', 'normal');
|
||||
checkWrite('cmi.core.exit', 'suspend');
|
||||
checkValidValues('cmi.core.exit', scorm12_error_codes.TYPE_MISMATCH, [
|
||||
'time-out',
|
||||
'suspend',
|
||||
'logout',
|
||||
], [
|
||||
'complete',
|
||||
'exit',
|
||||
]);
|
||||
checkWriteOnly('cmi.core.session_time', '00:00:00');
|
||||
checkValidValues('cmi.core.session_time', scorm12_error_codes.TYPE_MISMATCH, [
|
||||
'10:06:57',
|
||||
'00:00:01.56',
|
||||
'23:59:59',
|
||||
'47:59:59',
|
||||
], [
|
||||
'06:5:13',
|
||||
'23:59:59.123',
|
||||
'P1DT23H59M59S',
|
||||
]);
|
||||
|
||||
/**
|
||||
* cmi.core.score Properties
|
||||
*/
|
||||
checkInvalidSet('cmi.core.score._children', scorm12_constants.score_children);
|
||||
checkValidValues('cmi.core.score.raw', scorm12_error_codes.VALUE_OUT_OF_RANGE, [
|
||||
'0',
|
||||
'25.1',
|
||||
'50.5',
|
||||
'75',
|
||||
'100',
|
||||
], [
|
||||
'-1',
|
||||
'101',
|
||||
]);
|
||||
checkValidValues('cmi.core.score.min', scorm12_error_codes.VALUE_OUT_OF_RANGE, [
|
||||
'0',
|
||||
'25.1',
|
||||
'50.5',
|
||||
'75',
|
||||
'100',
|
||||
], [
|
||||
'-1',
|
||||
'101',
|
||||
]);
|
||||
checkValidValues('cmi.core.score.max', scorm12_error_codes.VALUE_OUT_OF_RANGE, [
|
||||
'0',
|
||||
'25.1',
|
||||
'50.5',
|
||||
'75',
|
||||
'100',
|
||||
], [
|
||||
'-1',
|
||||
'101',
|
||||
]);
|
||||
|
||||
/**
|
||||
* cmi.objectives Properties
|
||||
*/
|
||||
checkInvalidSet('cmi.objectives._children', scorm12_constants.objectives_children);
|
||||
checkInvalidSet('cmi.objectives._count', 0);
|
||||
|
||||
/**
|
||||
* cmi.student_data Properties
|
||||
*/
|
||||
checkInvalidSet('cmi.student_data._children', scorm12_constants.student_data_children);
|
||||
checkReadOnly('cmi.student_data.mastery_score');
|
||||
checkReadOnly('cmi.student_data.max_time_allowed');
|
||||
checkReadOnly('cmi.student_data.time_limit_action');
|
||||
|
||||
/**
|
||||
* cmi.student_preference Properties
|
||||
*/
|
||||
checkInvalidSet('cmi.student_preference._children', scorm12_constants.student_preference_children);
|
||||
checkValidValues('cmi.student_preference.audio', scorm12_error_codes.TYPE_MISMATCH, [
|
||||
'1',
|
||||
'-1',
|
||||
'50',
|
||||
'100',
|
||||
], [
|
||||
'invalid',
|
||||
'a100',
|
||||
]);
|
||||
checkValidValues('cmi.student_preference.audio', scorm12_error_codes.VALUE_OUT_OF_RANGE, [], [
|
||||
'101',
|
||||
'5000000',
|
||||
'-500',
|
||||
]);
|
||||
checkFieldConstraintSize('cmi.student_preference.language', 255);
|
||||
checkValidValues('cmi.student_preference.speed', scorm12_error_codes.TYPE_MISMATCH, [
|
||||
'1',
|
||||
'-100',
|
||||
'50',
|
||||
'100',
|
||||
], [
|
||||
'invalid',
|
||||
'a100',
|
||||
]);
|
||||
checkValidValues('cmi.student_preference.speed', scorm12_error_codes.VALUE_OUT_OF_RANGE, [], [
|
||||
'101',
|
||||
'-101',
|
||||
'5000000',
|
||||
'-500',
|
||||
]);
|
||||
checkValidValues('cmi.student_preference.text', scorm12_error_codes.TYPE_MISMATCH, [
|
||||
'1',
|
||||
'-1',
|
||||
], [
|
||||
'invalid',
|
||||
'a100',
|
||||
]);
|
||||
checkValidValues('cmi.student_preference.text', scorm12_error_codes.VALUE_OUT_OF_RANGE, [], [
|
||||
'2',
|
||||
'-2',
|
||||
]);
|
||||
|
||||
/**
|
||||
* cmi.interactions Properties
|
||||
*/
|
||||
checkInvalidSet('cmi.interactions._children', scorm12_constants.interactions_children);
|
||||
checkInvalidSet('cmi.interactions._count', 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
389
test/cmi/scorm12_cmi.spec.js
Normal file
389
test/cmi/scorm12_cmi.spec.js
Normal file
@@ -0,0 +1,389 @@
|
||||
import {expect, assert} from 'chai';
|
||||
import {describe, it, beforeEach, afterEach} from 'mocha';
|
||||
import Scorm12API from '../../src/Scorm12API';
|
||||
import {scorm12_constants} from '../../src/constants/api_constants';
|
||||
import {scorm12_error_codes} from '../../src/constants/error_codes';
|
||||
|
||||
let API;
|
||||
|
||||
const checkFieldConstraintSize = ({fieldName, limit, expectedValue = ''}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
|
||||
it(`Should be able to write upto ${limit} characters to ${fieldName}`,
|
||||
() => {
|
||||
eval(`API.${fieldName} = 'x'.repeat(${limit})`);
|
||||
expect(0).to.equal(API.lastErrorCode);
|
||||
});
|
||||
|
||||
it(`Should fail to write more than ${limit} characters to ${fieldName}`,
|
||||
() => {
|
||||
eval(`API.${fieldName} = 'x'.repeat(${limit + 1})`);
|
||||
expect(scorm12_error_codes.TYPE_MISMATCH + '').
|
||||
to.
|
||||
equal(API.lastErrorCode);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkInvalidSet = ({fieldName, expectedValue = ''}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
|
||||
it(`Should fail to write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = 'xxx'`);
|
||||
expect(API.lastErrorCode).
|
||||
to.
|
||||
equal(scorm12_error_codes.INVALID_SET_VALUE + '');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkReadOnly = ({fieldName, expectedValue = ''}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
|
||||
it(`Should fail to write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = 'xxx'`);
|
||||
expect(API.lastErrorCode).
|
||||
to.
|
||||
equal(scorm12_error_codes.READ_ONLY_ELEMENT + '');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkRead = ({fieldName, expectedValue = ''}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should be able to read from ${fieldName}`, () => {
|
||||
expect(eval(`API.${fieldName}`)).to.equal(expectedValue);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkWriteOnly = ({fieldName, valueToTest = 'xxx'}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should fail to read from ${fieldName}`, () => {
|
||||
eval(`API.${fieldName}`);
|
||||
expect(API.lastErrorCode).
|
||||
to.
|
||||
equal(scorm12_error_codes.WRITE_ONLY_ELEMENT + '');
|
||||
});
|
||||
|
||||
it(`Should successfully write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = '${valueToTest}'`);
|
||||
expect(API.lastErrorCode).to.equal(0);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkWrite = ({fieldName, valueToTest = 'xxx'}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
it(`Should successfully write to ${fieldName}`, () => {
|
||||
eval(`API.${fieldName} = '${valueToTest}'`);
|
||||
expect(API.lastErrorCode).to.equal(0);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkValidValues = ({fieldName, expectedError, validValues, invalidValues}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
for (const idx in validValues) {
|
||||
if ({}.hasOwnProperty.call(validValues, idx)) {
|
||||
it(`Should successfully write '${validValues[idx]}' to ${fieldName}`,
|
||||
() => {
|
||||
eval(`API.${fieldName} = '${validValues[idx]}'`);
|
||||
expect(API.lastErrorCode).to.equal(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const idx in invalidValues) {
|
||||
if ({}.hasOwnProperty.call(invalidValues, idx)) {
|
||||
it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`,
|
||||
() => {
|
||||
eval(`API.${fieldName} = '${invalidValues[idx]}'`);
|
||||
expect(API.lastErrorCode).to.equal(expectedError + '');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
describe('SCORM 1.2 API Tests', () => {
|
||||
describe('CMI Spec Tests', () => {
|
||||
describe('Post-lmsInitialize Tests', () => {
|
||||
beforeEach('Create the API object', () => {
|
||||
API = new Scorm12API();
|
||||
API.lmsInitialize();
|
||||
});
|
||||
afterEach('Destroy API object', () => {
|
||||
API = null;
|
||||
});
|
||||
|
||||
it('lmsInitialize should create CMI object', () => {
|
||||
assert(API.cmi !== undefined, 'CMI object is created');
|
||||
});
|
||||
|
||||
it('Exporting CMI to JSON produces proper Object', () => {
|
||||
expect(
|
||||
JSON.parse(API.renderCMIToJSON()).cmi?.core !== undefined,
|
||||
).to.be.true;
|
||||
});
|
||||
|
||||
/**
|
||||
* Base CMI Properties
|
||||
*/
|
||||
checkInvalidSet({fieldName: 'cmi._version', expectedValue: '3.4'});
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi._children',
|
||||
expectedValue: scorm12_constants.cmi_children,
|
||||
});
|
||||
checkFieldConstraintSize({fieldName: 'cmi.suspend_data', limit: 4096});
|
||||
checkReadOnly({fieldName: 'cmi.launch_data'});
|
||||
checkFieldConstraintSize({fieldName: 'cmi.comments', limit: 4096});
|
||||
checkReadOnly({fieldName: 'cmi.comments_from_lms'});
|
||||
|
||||
/**
|
||||
* cmi.core Properties
|
||||
*/
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi.core._children',
|
||||
expectedValue: scorm12_constants.core_children,
|
||||
});
|
||||
checkReadOnly({fieldName: 'cmi.core.student_id'});
|
||||
checkReadOnly({fieldName: 'cmi.core.student_name'});
|
||||
checkFieldConstraintSize({
|
||||
fieldName: 'cmi.core.lesson_location',
|
||||
limit: 255,
|
||||
});
|
||||
checkReadOnly({fieldName: 'cmi.core.credit'});
|
||||
checkRead({fieldName: 'cmi.core.lesson_status'});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.core.lesson_status',
|
||||
expectedError: scorm12_error_codes.TYPE_MISMATCH,
|
||||
validValues: [
|
||||
'passed',
|
||||
'completed',
|
||||
'failed',
|
||||
'incomplete',
|
||||
'browsed',
|
||||
],
|
||||
invalidValues: [
|
||||
'Passed',
|
||||
'P',
|
||||
'F',
|
||||
'p',
|
||||
'true',
|
||||
'false',
|
||||
'complete',
|
||||
],
|
||||
});
|
||||
checkReadOnly({fieldName: 'cmi.core.entry'});
|
||||
checkReadOnly({fieldName: 'cmi.core.total_time'});
|
||||
checkReadOnly(
|
||||
{fieldName: 'cmi.core.lesson_mode', expectedValue: 'normal'});
|
||||
checkWrite({fieldName: 'cmi.core.exit', valueToTest: 'suspend'});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.core.exit',
|
||||
expectedError: scorm12_error_codes.TYPE_MISMATCH,
|
||||
validValues: [
|
||||
'time-out',
|
||||
'suspend',
|
||||
'logout',
|
||||
], invalidValues: [
|
||||
'complete',
|
||||
'exit',
|
||||
],
|
||||
});
|
||||
checkWriteOnly({
|
||||
fieldName: 'cmi.core.session_time',
|
||||
valueToTest: '00:00:00',
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.core.session_time',
|
||||
expectedError: scorm12_error_codes.TYPE_MISMATCH,
|
||||
validValues: [
|
||||
'10:06:57',
|
||||
'00:00:01.56',
|
||||
'23:59:59',
|
||||
'47:59:59',
|
||||
],
|
||||
invalidValues: [
|
||||
'06:5:13',
|
||||
'23:59:59.123',
|
||||
'P1DT23H59M59S',
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
* cmi.core.score Properties
|
||||
*/
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi.core.score._children',
|
||||
expectedValue: scorm12_constants.score_children,
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.core.score.raw',
|
||||
expectedError: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
||||
validValues: [
|
||||
'0',
|
||||
'25.1',
|
||||
'50.5',
|
||||
'75',
|
||||
'100',
|
||||
],
|
||||
invalidValues: [
|
||||
'-1',
|
||||
'101',
|
||||
],
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.core.score.min',
|
||||
expectedError: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
||||
validValues: [
|
||||
'0',
|
||||
'25.1',
|
||||
'50.5',
|
||||
'75',
|
||||
'100',
|
||||
],
|
||||
invalidValues: [
|
||||
'-1',
|
||||
'101',
|
||||
],
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.core.score.max',
|
||||
expectedError: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
||||
validValues: [
|
||||
'0',
|
||||
'25.1',
|
||||
'50.5',
|
||||
'75',
|
||||
'100',
|
||||
],
|
||||
invalidValues: [
|
||||
'-1',
|
||||
'101',
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
* cmi.objectives Properties
|
||||
*/
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi.objectives._children',
|
||||
expectedValue: scorm12_constants.objectives_children,
|
||||
});
|
||||
checkInvalidSet({fieldName: 'cmi.objectives._count', expectedValue: 0});
|
||||
|
||||
/**
|
||||
* cmi.student_data Properties
|
||||
*/
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi.student_data._children',
|
||||
expectedValue: scorm12_constants.student_data_children,
|
||||
});
|
||||
checkReadOnly({fieldName: 'cmi.student_data.mastery_score'});
|
||||
checkReadOnly({fieldName: 'cmi.student_data.max_time_allowed'});
|
||||
checkReadOnly({fieldName: 'cmi.student_data.time_limit_action'});
|
||||
|
||||
/**
|
||||
* cmi.student_preference Properties
|
||||
*/
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi.student_preference._children',
|
||||
expectedValue: scorm12_constants.student_preference_children,
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.student_preference.audio',
|
||||
expectedError: scorm12_error_codes.TYPE_MISMATCH,
|
||||
validValues: [
|
||||
'1',
|
||||
'-1',
|
||||
'50',
|
||||
'100',
|
||||
],
|
||||
invalidValues: [
|
||||
'invalid',
|
||||
'a100',
|
||||
],
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.student_preference.audio',
|
||||
expectedError: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
||||
validValues: [],
|
||||
invalidValues: [
|
||||
'101',
|
||||
'5000000',
|
||||
'-500',
|
||||
],
|
||||
});
|
||||
checkFieldConstraintSize({
|
||||
fieldName: 'cmi.student_preference.language',
|
||||
limit: 255,
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.student_preference.speed',
|
||||
expectedError: scorm12_error_codes.TYPE_MISMATCH,
|
||||
validValues: [
|
||||
'1',
|
||||
'-100',
|
||||
'50',
|
||||
'100',
|
||||
],
|
||||
invalidValues: [
|
||||
'invalid',
|
||||
'a100',
|
||||
],
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.student_preference.speed',
|
||||
expectedError: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
||||
validValues: [],
|
||||
invalidValues: [
|
||||
'101',
|
||||
'-101',
|
||||
'5000000',
|
||||
'-500',
|
||||
],
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.student_preference.text',
|
||||
expectedError: scorm12_error_codes.TYPE_MISMATCH,
|
||||
validValues: [
|
||||
'1',
|
||||
'-1',
|
||||
],
|
||||
invalidValues: [
|
||||
'invalid',
|
||||
'a100',
|
||||
],
|
||||
});
|
||||
checkValidValues({
|
||||
fieldName: 'cmi.student_preference.text',
|
||||
expectedError: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
||||
validValues: [],
|
||||
invalidValues: [
|
||||
'2',
|
||||
'-2',
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
* cmi.interactions Properties
|
||||
*/
|
||||
checkInvalidSet({
|
||||
fieldName: 'cmi.interactions._children',
|
||||
expectedValue: scorm12_constants.interactions_children,
|
||||
});
|
||||
checkInvalidSet({fieldName: 'cmi.interactions._count', expectedValue: 0});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,220 +1,277 @@
|
||||
import { expect } from 'chai';
|
||||
import {describe, it} from "mocha";
|
||||
import * as Utilities from '../src/utilities';
|
||||
import {scorm12_regex, scorm2004_regex} from "../src/regex";
|
||||
import {expect} from 'chai';
|
||||
import {describe, it} from 'mocha';
|
||||
import * as Utilities from '../src/utilities';
|
||||
import {scorm12_regex, scorm2004_regex} from '../src/regex';
|
||||
|
||||
describe('Utility Tests', () => {
|
||||
describe('function getSecondsAsHHMMSS()', () => {
|
||||
it('10 returns 00:00:10', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(10)
|
||||
).to.equal('00:00:10');
|
||||
});
|
||||
describe('getSecondsAsHHMMSS()', () => {
|
||||
it('10 returns 00:00:10', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(10),
|
||||
).to.equal('00:00:10');
|
||||
});
|
||||
|
||||
it('60 returns 00:01:00', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(60)
|
||||
).to.equal('00:01:00');
|
||||
});
|
||||
it('60 returns 00:01:00', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(60),
|
||||
).to.equal('00:01:00');
|
||||
});
|
||||
|
||||
it('3600 returns 01:00:00', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(3600)
|
||||
).to.equal('01:00:00');
|
||||
});
|
||||
it('3600 returns 01:00:00', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(3600),
|
||||
).to.equal('01:00:00');
|
||||
});
|
||||
|
||||
it('70 returns 00:01:10', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(70)
|
||||
).to.equal('00:01:10');
|
||||
});
|
||||
it('70 returns 00:01:10', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(70),
|
||||
).to.equal('00:01:10');
|
||||
});
|
||||
|
||||
it('3670 returns 01:01:10', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(3670)
|
||||
).to.equal('01:01:10');
|
||||
});
|
||||
it('3670 returns 01:01:10', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(3670),
|
||||
).to.equal('01:01:10');
|
||||
});
|
||||
|
||||
it('90000 returns 25:00:00, check for hours greater than 24', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(90000)
|
||||
).to.equal('25:00:00');
|
||||
});
|
||||
it('90000 returns 25:00:00, check for hours greater than 24', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(90000),
|
||||
).to.equal('25:00:00');
|
||||
});
|
||||
|
||||
it('-3600 returns 00:00:00, negative time not allowed in SCORM session times', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(-3600)
|
||||
).to.equal('00:00:00');
|
||||
});
|
||||
it('-3600 returns 00:00:00, negative time not allowed in SCORM session times',
|
||||
() => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(-3600),
|
||||
).to.equal('00:00:00');
|
||||
});
|
||||
|
||||
it('Empty seconds returns 00:00:00', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(null)
|
||||
).to.equal('00:00:00');
|
||||
});
|
||||
});
|
||||
it('Empty seconds returns 00:00:00', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsHHMMSS(null),
|
||||
).to.equal('00:00:00');
|
||||
});
|
||||
});
|
||||
|
||||
describe('function getSecondsAsISODuration()', () => {
|
||||
it('10 returns P10S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(10)
|
||||
).to.equal('P10S');
|
||||
});
|
||||
describe('getSecondsAsISODuration()', () => {
|
||||
it('10 returns P10S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(10),
|
||||
).to.equal('P10S');
|
||||
});
|
||||
|
||||
it('60 returns P1M', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(60)
|
||||
).to.equal('P1M');
|
||||
});
|
||||
it('60 returns P1M', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(60),
|
||||
).to.equal('P1M');
|
||||
});
|
||||
|
||||
it('3600 returns P1H', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(3600)
|
||||
).to.equal('P1H');
|
||||
});
|
||||
it('3600 returns P1H', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(3600),
|
||||
).to.equal('P1H');
|
||||
});
|
||||
|
||||
it('70 returns P1M10S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(70)
|
||||
).to.equal('P1M10S');
|
||||
});
|
||||
it('70 returns P1M10S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(70),
|
||||
).to.equal('P1M10S');
|
||||
});
|
||||
|
||||
it('3670 returns P1H1M10S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(3670)
|
||||
).to.equal('P1H1M10S');
|
||||
});
|
||||
it('3670 returns P1H1M10S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(3670),
|
||||
).to.equal('P1H1M10S');
|
||||
});
|
||||
|
||||
it('90000 returns P1D1H', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(90000)
|
||||
).to.equal('P1D1H');
|
||||
});
|
||||
it('90000 returns P1D1H', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(90000),
|
||||
).to.equal('P1D1H');
|
||||
});
|
||||
|
||||
it('90061 returns P1D1H1M1S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(90061)
|
||||
).to.equal('P1D1H1M1S');
|
||||
});
|
||||
it('90061 returns P1D1H1M1S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(90061),
|
||||
).to.equal('P1D1H1M1S');
|
||||
});
|
||||
|
||||
it('-3600 returns P0S, negative time not allowed in SCORM session times', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(-3600)
|
||||
).to.equal('P0S');
|
||||
});
|
||||
it('-3600 returns P0S, negative time not allowed in SCORM session times',
|
||||
() => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(-3600),
|
||||
).to.equal('P0S');
|
||||
});
|
||||
|
||||
it('Empty seconds returns P0S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(null)
|
||||
).to.equal('P0S');
|
||||
});
|
||||
});
|
||||
it('Empty seconds returns P0S', () => {
|
||||
expect(
|
||||
Utilities.getSecondsAsISODuration(null),
|
||||
).to.equal('P0S');
|
||||
});
|
||||
});
|
||||
|
||||
describe('function getTimeAsSeconds()', () => {
|
||||
it('00:00:10 returns 10', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan)
|
||||
).to.equal(10);
|
||||
});
|
||||
describe('getTimeAsSeconds()', () => {
|
||||
it('00:00:10 returns 10', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan),
|
||||
).to.equal(10);
|
||||
});
|
||||
|
||||
it('00:01:10 returns 70', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan)
|
||||
).to.equal(70);
|
||||
});
|
||||
it('00:01:10 returns 70', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan),
|
||||
).to.equal(70);
|
||||
});
|
||||
|
||||
it('01:01:10 returns 3670', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan)
|
||||
).to.equal(3670);
|
||||
});
|
||||
it('01:01:10 returns 3670', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan),
|
||||
).to.equal(3670);
|
||||
});
|
||||
|
||||
it('100:00:00 returns 3670', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan)
|
||||
).to.equal(360000);
|
||||
});
|
||||
it('100:00:00 returns 3670', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan),
|
||||
).to.equal(360000);
|
||||
});
|
||||
|
||||
it('-01:00:00 returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
it('-01:00:00 returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
|
||||
it('Number value returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
it('Number value returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
|
||||
it('boolean value returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
it('boolean value returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
|
||||
it('Empty value returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
});
|
||||
it('Empty value returns 0', () => {
|
||||
expect(
|
||||
Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('function getDurationAsSeconds()', () => {
|
||||
it('P0S returns 0', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
describe('getDurationAsSeconds()', () => {
|
||||
it('P0S returns 0', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
|
||||
it('P70S returns 70', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan)
|
||||
).to.equal(70);
|
||||
});
|
||||
it('P70S returns 70', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan),
|
||||
).to.equal(70);
|
||||
});
|
||||
|
||||
it('PT1M10S returns 70', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('PT1M10S', scorm2004_regex.CMITimespan)
|
||||
).to.equal(70);
|
||||
});
|
||||
it('PT1M10S returns 70', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('PT1M10S',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal(70);
|
||||
});
|
||||
|
||||
it('P1D returns 86400', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan)
|
||||
).to.equal(86400);
|
||||
});
|
||||
it('P1D returns 86400', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan),
|
||||
).to.equal(86400);
|
||||
});
|
||||
|
||||
it('P1M returns number of seconds for one month from now', () => {
|
||||
const now = new Date();
|
||||
let oneMonthFromNow = new Date(now);
|
||||
oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1);
|
||||
it('P1M returns number of seconds for one month from now', () => {
|
||||
const now = new Date();
|
||||
const oneMonthFromNow = new Date(now);
|
||||
oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1);
|
||||
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P1M', scorm2004_regex.CMITimespan)
|
||||
).to.equal((oneMonthFromNow - now) / 1000.0);
|
||||
});
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P1M', scorm2004_regex.CMITimespan),
|
||||
).to.equal((oneMonthFromNow - now) / 1000.0);
|
||||
});
|
||||
|
||||
it('P1Y returns number of seconds for one year from now', () => {
|
||||
const now = new Date();
|
||||
let oneYearFromNow = new Date(now);
|
||||
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
|
||||
it('P1Y returns number of seconds for one year from now', () => {
|
||||
const now = new Date();
|
||||
const oneYearFromNow = new Date(now);
|
||||
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
|
||||
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan)
|
||||
).to.equal((oneYearFromNow - now) / 1000.0);
|
||||
});
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan),
|
||||
).to.equal((oneYearFromNow - now) / 1000.0);
|
||||
});
|
||||
|
||||
it('Invalid duration returns 0', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
it('Invalid duration returns 0', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
|
||||
it('Empty duration returns 0', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan)
|
||||
).to.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('Empty duration returns 0', () => {
|
||||
expect(
|
||||
Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan),
|
||||
).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addTwoDurations()', () => {
|
||||
it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => {
|
||||
expect(
|
||||
Utilities.addTwoDurations('P1H5M30.5S', 'PT15M10S',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal('P1H20M40.5S');
|
||||
});
|
||||
it('P1Y364D plus P2D1H45M52S equals P732D1H45M52S', () => {
|
||||
expect(
|
||||
Utilities.addTwoDurations('P1Y364D', 'P2D1H45M52S',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal('P732D1H45M52S');
|
||||
});
|
||||
it('Invalid plus valid equals valid', () => {
|
||||
expect(
|
||||
Utilities.addTwoDurations('NOT A VALID DURATION', 'P1H30M45S',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal('P1H30M45S');
|
||||
});
|
||||
it('Valid plus invalid equals valid', () => {
|
||||
expect(
|
||||
Utilities.addTwoDurations('P1H30M45S', 'NOT A VALID DURATION',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal('P1H30M45S');
|
||||
});
|
||||
});
|
||||
|
||||
describe('addHHMMSSTimeStrings()', () => {
|
||||
it('01:05:30.5 plus 00:15:10 equals 01:20:40.5', () => {
|
||||
expect(
|
||||
Utilities.addHHMMSSTimeStrings('01:05:30.5', '00:15:10',
|
||||
scorm12_regex.CMITimespan),
|
||||
).to.equal('01:20:40.5');
|
||||
});
|
||||
it('17496:00:00 plus 49:35:52 equals 17545:35:52', () => {
|
||||
expect(
|
||||
Utilities.addHHMMSSTimeStrings('17496:00:00', '49:35:52',
|
||||
scorm12_regex.CMITimespan),
|
||||
).to.equal('17545:35:52');
|
||||
});
|
||||
it('Invalid plus valid equals valid', () => {
|
||||
expect(
|
||||
Utilities.addHHMMSSTimeStrings('-00:15:10', '01:05:30.5',
|
||||
scorm12_regex.CMITimespan),
|
||||
).to.equal('01:05:30.5');
|
||||
});
|
||||
it('Valid plus invalid equals valid', () => {
|
||||
expect(
|
||||
Utilities.addHHMMSSTimeStrings('01:05:30.5', 'NOT A VALID DURATION',
|
||||
scorm12_regex.CMITimespan),
|
||||
).to.equal('01:05:30.5');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user