Fixing eslint issues, and still working on test cases
This commit is contained in:
3
.babelrc
3
.babelrc
@@ -5,6 +5,7 @@
|
|||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"@babel/plugin-proposal-class-properties",
|
"@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
|
when: always
|
||||||
|
|
||||||
# Run eslint
|
# Run eslint
|
||||||
# - run:
|
- run:
|
||||||
# name: eslint
|
name: eslint
|
||||||
# command: |
|
command: |
|
||||||
# ./node_modules/.bin/eslint ./ --format junit --output-file ./reports/eslint/eslint.xml
|
./node_modules/.bin/eslint ./ --format junit --output-file ./reports/eslint/eslint.xml
|
||||||
# when: always
|
when: always
|
||||||
|
|
||||||
# Run coverage report for Code Climate
|
# Run coverage report for Code Climate
|
||||||
- run:
|
- run:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
parser: "babel-eslint",
|
parser: 'babel-eslint',
|
||||||
env: {
|
env: {
|
||||||
browser: true,
|
browser: true,
|
||||||
es6: true,
|
es6: true,
|
||||||
@@ -10,18 +10,19 @@ module.exports = {
|
|||||||
SharedArrayBuffer: 'readonly',
|
SharedArrayBuffer: 'readonly',
|
||||||
},
|
},
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
sourceType: "module",
|
sourceType: 'module',
|
||||||
allowImportExportEverywhere: false,
|
allowImportExportEverywhere: false,
|
||||||
classPrivateMethods: true,
|
classPrivateMethods: true,
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
globalReturn: false,
|
globalReturn: false,
|
||||||
},
|
},
|
||||||
babelOptions: {
|
babelOptions: {
|
||||||
configFile: "./.babelrc",
|
configFile: './.babelrc',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
camelcase: 'off',
|
'camelcase': 'off',
|
||||||
'max-len': '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-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": {
|
"@babel/plugin-proposal-private-methods": {
|
||||||
"version": "7.6.0",
|
"version": "7.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-methods/-/plugin-proposal-private-methods-7.6.0.tgz",
|
"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/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": {
|
"@babel/plugin-syntax-top-level-await": {
|
||||||
"version": "7.7.0",
|
"version": "7.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.7.0.tgz",
|
"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"
|
"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": {
|
"acorn": {
|
||||||
"version": "7.1.0",
|
"version": "7.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz",
|
||||||
|
|||||||
@@ -11,10 +11,12 @@
|
|||||||
"@babel/core": "^7.7.2",
|
"@babel/core": "^7.7.2",
|
||||||
"@babel/node": "^7.7.0",
|
"@babel/node": "^7.7.0",
|
||||||
"@babel/plugin-proposal-class-properties": "^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/plugin-proposal-private-methods": "^7.6.0",
|
||||||
"@babel/preset-env": "^7.7.1",
|
"@babel/preset-env": "^7.7.1",
|
||||||
"@babel/preset-flow": "^7.0.0",
|
"@babel/preset-flow": "^7.0.0",
|
||||||
"@babel/register": "^7.7.0",
|
"@babel/register": "^7.7.0",
|
||||||
|
"@types/chai": "^4.2.4",
|
||||||
"babel-eslint": "^11.0.0-beta.0",
|
"babel-eslint": "^11.0.0-beta.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"eslint": "^6.6.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 {string} callbackName
|
||||||
* @param {boolean} checkTerminated
|
* @param {boolean} checkTerminated
|
||||||
* @param {string} CMIElement
|
* @param {string} CMIElement
|
||||||
* @param {any} value
|
* @param {*} value
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
setValue(
|
setValue(
|
||||||
@@ -204,7 +204,7 @@ export default class BaseAPI {
|
|||||||
* Returns the errorNumber error description
|
* Returns the errorNumber error description
|
||||||
*
|
*
|
||||||
* @param {string} callbackName
|
* @param {string} callbackName
|
||||||
* @param {number} CMIErrorCode
|
* @param {(string|number)} CMIErrorCode
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getErrorString(callbackName: String, CMIErrorCode) {
|
getErrorString(callbackName: String, CMIErrorCode) {
|
||||||
@@ -224,8 +224,8 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Returns a comprehensive description of the errorNumber error.
|
* Returns a comprehensive description of the errorNumber error.
|
||||||
*
|
*
|
||||||
* @param callbackName
|
* @param {string} callbackName
|
||||||
* @param CMIErrorCode
|
* @param {(string|number)} CMIErrorCode
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getDiagnostic(callbackName: String, CMIErrorCode) {
|
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(
|
checkState(
|
||||||
checkTerminated: boolean, beforeInitError: number,
|
checkTerminated: boolean,
|
||||||
|
beforeInitError: number,
|
||||||
afterTermError?: number) {
|
afterTermError?: number) {
|
||||||
if (_self.isNotInitialized()) {
|
if (_self.isNotInitialized()) {
|
||||||
_self.throwSCORMError(beforeInitError);
|
_self.throwSCORMError(beforeInitError);
|
||||||
@@ -262,13 +268,15 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Logging for all SCORM actions
|
* Logging for all SCORM actions
|
||||||
*
|
*
|
||||||
* @param functionName
|
* @param {string} functionName
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @param logMessage
|
* @param {string} logMessage
|
||||||
* @param messageLevel
|
* @param {number}messageLevel
|
||||||
*/
|
*/
|
||||||
apiLog(
|
apiLog(
|
||||||
functionName: String, CMIElement: String, logMessage: String,
|
functionName: String,
|
||||||
|
CMIElement: String,
|
||||||
|
logMessage: String,
|
||||||
messageLevel: number) {
|
messageLevel: number) {
|
||||||
logMessage = _self.formatMessage(functionName, CMIElement, logMessage);
|
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
|
* Formats the SCORM messages for easy reading
|
||||||
*
|
*
|
||||||
* @param functionName
|
* @param {string} functionName
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @param message
|
* @param {string} message
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
formatMessage(functionName: String, CMIElement: String, message: String) {
|
formatMessage(functionName: String, CMIElement: String, message: String) {
|
||||||
@@ -340,8 +339,9 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Checks to see if {str} contains {tester}
|
* Checks to see if {str} contains {tester}
|
||||||
*
|
*
|
||||||
* @param str String to check against
|
* @param {string} str String to check against
|
||||||
* @param tester String to check for
|
* @param {string} tester String to check for
|
||||||
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
stringContains(str: String, tester: String) {
|
stringContains(str: String, tester: String) {
|
||||||
return str.indexOf(tester) > -1;
|
return str.indexOf(tester) > -1;
|
||||||
@@ -350,6 +350,10 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Returns the message that corresponds to errorNumber
|
* Returns the message that corresponds to errorNumber
|
||||||
* APIs that inherit BaseAPI should override this function
|
* APIs that inherit BaseAPI should override this function
|
||||||
|
*
|
||||||
|
* @param {(string|number)} _errorNumber
|
||||||
|
* @param {boolean} _detail
|
||||||
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getLmsErrorMessageDetails(_errorNumber, _detail) {
|
getLmsErrorMessageDetails(_errorNumber, _detail) {
|
||||||
return 'No error';
|
return 'No error';
|
||||||
@@ -358,6 +362,9 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Gets the value for the specific element.
|
* Gets the value for the specific element.
|
||||||
* APIs that inherit BaseAPI should override this function
|
* APIs that inherit BaseAPI should override this function
|
||||||
|
*
|
||||||
|
* @param {string} _CMIElement
|
||||||
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getCMIValue(_CMIElement) {
|
getCMIValue(_CMIElement) {
|
||||||
return '';
|
return '';
|
||||||
@@ -366,11 +373,24 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Sets the value for the specific element.
|
* Sets the value for the specific element.
|
||||||
* APIs that inherit BaseAPI should override this function
|
* APIs that inherit BaseAPI should override this function
|
||||||
|
*
|
||||||
|
* @param {string} _CMIElement
|
||||||
|
* @param {any} _value
|
||||||
*/
|
*/
|
||||||
setCMIValue(_CMIElement, _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(
|
_commonSetCMIValue(
|
||||||
methodName: String, scorm2004: boolean, CMIElement, value) {
|
methodName: String, scorm2004: boolean, CMIElement, value) {
|
||||||
if (!CMIElement || CMIElement === '') {
|
if (!CMIElement || CMIElement === '') {
|
||||||
@@ -393,7 +413,7 @@ export default class BaseAPI {
|
|||||||
if (scorm2004 && (attribute.substr(0, 8) === '{target=') &&
|
if (scorm2004 && (attribute.substr(0, 8) === '{target=') &&
|
||||||
(typeof refObject._isTargetValid == 'function')) {
|
(typeof refObject._isTargetValid == 'function')) {
|
||||||
_self.throwSCORMError(_self.#error_codes.READ_ONLY_ELEMENT);
|
_self.throwSCORMError(_self.#error_codes.READ_ONLY_ELEMENT);
|
||||||
} else if (!refObject.hasOwnProperty(attribute)) {
|
} else if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||||
_self.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
_self.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||||
} else {
|
} else {
|
||||||
if (_self.stringContains(CMIElement, '.correct_responses')) {
|
if (_self.stringContains(CMIElement, '.correct_responses')) {
|
||||||
@@ -412,7 +432,7 @@ export default class BaseAPI {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refObject.prototype === CMIArray) {
|
if (refObject instanceof CMIArray) {
|
||||||
const index = parseInt(structure[i + 1], 10);
|
const index = parseInt(structure[i + 1], 10);
|
||||||
|
|
||||||
// SCO is trying to set an item on an array
|
// SCO is trying to set an item on an array
|
||||||
@@ -448,24 +468,34 @@ export default class BaseAPI {
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract method for validating that a response is correct.
|
||||||
|
*
|
||||||
|
* @param {string} _CMIElement
|
||||||
|
* @param {*} _value
|
||||||
|
*/
|
||||||
validateCorrectResponse(_CMIElement, _value) {
|
validateCorrectResponse(_CMIElement, _value) {
|
||||||
return false;
|
// just a stub method
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or builds a new child element to add to the array.
|
* 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a value from the CMI Object
|
* Gets a value from the CMI Object
|
||||||
*
|
*
|
||||||
* @param methodName
|
* @param {string} methodName
|
||||||
* @param scorm2004
|
* @param {boolean} scorm2004
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
_commonGetCMIValue(methodName: String, scorm2004: boolean, CMIElement) {
|
_commonGetCMIValue(methodName: String, scorm2004: boolean, CMIElement) {
|
||||||
@@ -482,7 +512,7 @@ export default class BaseAPI {
|
|||||||
|
|
||||||
if (!scorm2004) {
|
if (!scorm2004) {
|
||||||
if (i === structure.length - 1) {
|
if (i === structure.length - 1) {
|
||||||
if (!refObject.hasOwnProperty(attribute)) {
|
if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||||
_self.throwSCORMError(101,
|
_self.throwSCORMError(101,
|
||||||
'getCMIValue did not find a value for: ' + CMIElement);
|
'getCMIValue did not find a value for: ' + CMIElement);
|
||||||
}
|
}
|
||||||
@@ -493,7 +523,7 @@ export default class BaseAPI {
|
|||||||
const target = String(attribute).
|
const target = String(attribute).
|
||||||
substr(8, String(attribute).length - 9);
|
substr(8, String(attribute).length - 9);
|
||||||
return refObject._isTargetValid(target);
|
return refObject._isTargetValid(target);
|
||||||
} else if (!refObject.hasOwnProperty(attribute)) {
|
} else if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||||
_self.throwSCORMError(401,
|
_self.throwSCORMError(401,
|
||||||
'The data model element passed to GetValue (' + CMIElement +
|
'The data model element passed to GetValue (' + CMIElement +
|
||||||
') is not a valid SCORM data model element.');
|
') 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
|
* Returns true if the API's current state is STATE_INITIALIZED
|
||||||
|
*
|
||||||
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
isInitialized() {
|
isInitialized() {
|
||||||
return _self.currentState === api_constants.STATE_INITIALIZED;
|
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
|
* Returns true if the API's current state is STATE_NOT_INITIALIZED
|
||||||
|
*
|
||||||
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
isNotInitialized() {
|
isNotInitialized() {
|
||||||
return _self.currentState === api_constants.STATE_NOT_INITIALIZED;
|
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
|
* Returns true if the API's current state is STATE_TERMINATED
|
||||||
|
*
|
||||||
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
isTerminated() {
|
isTerminated() {
|
||||||
return _self.currentState === api_constants.STATE_TERMINATED;
|
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
|
* Provides a mechanism for attaching to a specific SCORM event
|
||||||
*
|
*
|
||||||
* @param listenerName
|
* @param {string} listenerName
|
||||||
* @param callback
|
* @param {function} callback
|
||||||
*/
|
*/
|
||||||
on(listenerName: String, callback: function) {
|
on(listenerName: String, callback: function) {
|
||||||
if (!callback) return;
|
if (!callback) return;
|
||||||
@@ -571,9 +607,9 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Processes any 'on' listeners that have been created
|
* Processes any 'on' listeners that have been created
|
||||||
*
|
*
|
||||||
* @param functionName
|
* @param {string} functionName
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @param value
|
* @param {*} value
|
||||||
*/
|
*/
|
||||||
processListeners(functionName: String, CMIElement: String, value: any) {
|
processListeners(functionName: String, CMIElement: String, value: any) {
|
||||||
for (let i = 0; i < _self.listenerArray.length; i++) {
|
for (let i = 0; i < _self.listenerArray.length; i++) {
|
||||||
@@ -591,8 +627,8 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Throws a SCORM error
|
* Throws a SCORM error
|
||||||
*
|
*
|
||||||
* @param errorNumber
|
* @param {number} errorNumber
|
||||||
* @param message
|
* @param {string} message
|
||||||
*/
|
*/
|
||||||
throwSCORMError(errorNumber: number, message: String) {
|
throwSCORMError(errorNumber: number, message: String) {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
@@ -605,20 +641,34 @@ export default class BaseAPI {
|
|||||||
_self.lastErrorCode = String(errorNumber);
|
_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.
|
* Loads CMI data from a JSON object.
|
||||||
|
*
|
||||||
|
* @param {object} json
|
||||||
|
* @param {string} CMIElement
|
||||||
*/
|
*/
|
||||||
loadFromJSON(json, CMIElement) {
|
loadFromJSON(json, CMIElement) {
|
||||||
if (!_self.isNotInitialized()) {
|
if (!_self.isNotInitialized()) {
|
||||||
console.error(
|
console.error(
|
||||||
'loadFromJSON can only be called before the call to LMSInitialize.');
|
'loadFromJSON can only be called before the call to lmsInitialize.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMIElement = CMIElement || 'cmi';
|
CMIElement = CMIElement || 'cmi';
|
||||||
|
|
||||||
for (const key in json) {
|
for (const key in json) {
|
||||||
if (json.hasOwnProperty(key) && json[key]) {
|
if ({}.hasOwnProperty.call(json, key) && json[key]) {
|
||||||
const currentCMIElement = CMIElement + '.' + key;
|
const currentCMIElement = CMIElement + '.' + key;
|
||||||
const value = json[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() {
|
renderCMIToJSON() {
|
||||||
const cmi = _self.cmi;
|
const cmi = _self.cmi;
|
||||||
// Do we want/need to return fields that have no set value?
|
// 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.
|
* Check if the value matches the proper format. If not, throw proper error code.
|
||||||
*
|
*
|
||||||
* @param value
|
* @param {string} value
|
||||||
* @param regexPattern
|
* @param {string} regexPattern
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
checkValidFormat(value: String, regexPattern: String) {
|
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.
|
* Check if the value matches the proper range. If not, throw proper error code.
|
||||||
*
|
*
|
||||||
* @param value
|
* @param {*} value
|
||||||
* @param rangePattern
|
* @param {string} rangePattern
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
checkValidRange(value: any, rangePattern: String) {
|
checkValidRange(value: any, rangePattern: String) {
|
||||||
@@ -686,7 +741,7 @@ export default class BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Throws a SCORM error
|
* 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) {
|
scheduleCommit(when: number) {
|
||||||
_self.#timeout = new ScheduledCommit(this, when);
|
_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 {
|
class ScheduledCommit {
|
||||||
#API;
|
#API;
|
||||||
#cancelled: false;
|
#cancelled: false;
|
||||||
#timeout;
|
#timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ScheduledCommit
|
||||||
|
* @param {BaseAPI} API
|
||||||
|
* @param {number} when
|
||||||
|
*/
|
||||||
constructor(API: any, when: number) {
|
constructor(API: any, when: number) {
|
||||||
_self.#API = API;
|
_self.#API = API;
|
||||||
_self.#timeout = setTimeout(_self.#wrapper, when);
|
_self.#timeout = setTimeout(_self.#wrapper, when);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel any currently scheduled commit
|
||||||
|
*/
|
||||||
cancel() {
|
cancel() {
|
||||||
_self.#cancelled = true;
|
_self.#cancelled = true;
|
||||||
if (_self.#timeout) {
|
if (_self.#timeout) {
|
||||||
@@ -720,6 +786,9 @@ class ScheduledCommit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap the API commit call to check if the call has already been cancelled
|
||||||
|
*/
|
||||||
#wrapper = () => {
|
#wrapper = () => {
|
||||||
if (!_self.#cancelled) {
|
if (!_self.#cancelled) {
|
||||||
_self.#API.commit();
|
_self.#API.commit();
|
||||||
|
|||||||
@@ -13,134 +13,170 @@ import {scorm12_error_codes} from './constants/error_codes';
|
|||||||
import {scorm12_regex} from './regex';
|
import {scorm12_regex} from './regex';
|
||||||
|
|
||||||
const constants = scorm12_constants;
|
const constants = scorm12_constants;
|
||||||
|
let _self;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API class for SCORM 1.2
|
||||||
|
*/
|
||||||
export default class Scorm12API extends BaseAPI {
|
export default class Scorm12API extends BaseAPI {
|
||||||
|
/**
|
||||||
|
* Constructor for SCORM 1.2 API
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
super(scorm12_error_codes);
|
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 function from SCORM 1.2 Spec
|
||||||
*/
|
*
|
||||||
LMSInitialize() {
|
* @return {string} bool
|
||||||
return this.initialize('LMSInitialize', 'LMS was already initialized!',
|
*/
|
||||||
|
lmsInitialize() {
|
||||||
|
return _self.initialize('LMSInitialize', 'LMS was already initialized!',
|
||||||
'LMS is already finished!');
|
'LMS is already finished!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {string} bool
|
* LMSFinish function from SCORM 1.2 Spec
|
||||||
*/
|
*
|
||||||
LMSFinish() {
|
* @return {string} bool
|
||||||
return this.terminate('LMSFinish', false);
|
*/
|
||||||
|
lmsFinish() {
|
||||||
|
return _self.terminate('LMSFinish', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param CMIElement
|
* LMSGetValue function from SCORM 1.2 Spec
|
||||||
* @return {string}
|
*
|
||||||
*/
|
* @param {string} CMIElement
|
||||||
LMSGetValue(CMIElement) {
|
* @return {string}
|
||||||
return this.getValue('LMSGetValue', false, CMIElement);
|
*/
|
||||||
|
lmsGetValue(CMIElement) {
|
||||||
|
return _self.getValue('LMSGetValue', false, CMIElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param CMIElement
|
* LMSSetValue function from SCORM 1.2 Spec
|
||||||
* @param value
|
*
|
||||||
* @return {string}
|
* @param {string} CMIElement
|
||||||
*/
|
* @param {*} value
|
||||||
LMSSetValue(CMIElement, value) {
|
* @return {string}
|
||||||
return this.setValue('LMSSetValue', false, CMIElement, value);
|
*/
|
||||||
|
lmsSetValue(CMIElement, value) {
|
||||||
|
return _self.setValue('LMSSetValue', false, CMIElement, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orders LMS to store all content parameters
|
* LMSCommit function from SCORM 1.2 Spec
|
||||||
*
|
*
|
||||||
* @return {string} bool
|
* @return {string} bool
|
||||||
*/
|
*/
|
||||||
LMSCommit() {
|
lmsCommit() {
|
||||||
return this.commit('LMSCommit', false);
|
return _self.commit('LMSCommit', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns last error code
|
* LMSGetLastError function from SCORM 1.2 Spec
|
||||||
*
|
*
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetLastError() {
|
lmsGetLastError() {
|
||||||
return this.getLastError('LMSGetLastError');
|
return _self.getLastError('LMSGetLastError');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the errorNumber error description
|
* LMSGetErrorString function from SCORM 1.2 Spec
|
||||||
*
|
*
|
||||||
* @param CMIErrorCode
|
* @param {string} CMIErrorCode
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetErrorString(CMIErrorCode) {
|
lmsGetErrorString(CMIErrorCode) {
|
||||||
return this.getErrorString('LMSGetErrorString', CMIErrorCode);
|
return _self.getErrorString('LMSGetErrorString', CMIErrorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a comprehensive description of the errorNumber error.
|
* LMSGetDiagnostic function from SCORM 1.2 Spec
|
||||||
*
|
*
|
||||||
* @param CMIErrorCode
|
* @param {string} CMIErrorCode
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetDiagnostic(CMIErrorCode) {
|
lmsGetDiagnostic(CMIErrorCode) {
|
||||||
return this.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
return _self.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a value on the CMI Object
|
* Sets a value on the CMI Object
|
||||||
*
|
*
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @param value
|
* @param {*} value
|
||||||
* @return {string}
|
*/
|
||||||
*/
|
|
||||||
setCMIValue(CMIElement, value) {
|
setCMIValue(CMIElement, value) {
|
||||||
this._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
_self._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a value from the CMI Object
|
* Gets a value from the CMI Object
|
||||||
*
|
*
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
getCMIValue(CMIElement) {
|
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.
|
* Gets or builds a new child element to add to the array.
|
||||||
*
|
*
|
||||||
* @param CMIElement
|
* @param {string} CMIElement
|
||||||
* @param value
|
* @param {*} value
|
||||||
|
* @return {object}
|
||||||
*/
|
*/
|
||||||
getChildElement(CMIElement, value) {
|
getChildElement(CMIElement, value) {
|
||||||
let newChild;
|
let newChild;
|
||||||
|
|
||||||
if (this.stringContains(CMIElement, 'cmi.objectives')) {
|
if (_self.stringContains(CMIElement, 'cmi.objectives')) {
|
||||||
newChild = new CMIObjectivesObject(this);
|
newChild = new CMIObjectivesObject(this);
|
||||||
} else if (this.stringContains(CMIElement, '.correct_responses')) {
|
} else if (_self.stringContains(CMIElement, '.correct_responses')) {
|
||||||
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
||||||
} else if (this.stringContains(CMIElement, '.objectives')) {
|
} else if (_self.stringContains(CMIElement, '.objectives')) {
|
||||||
newChild = new CMIInteractionsObjectivesObject(this);
|
newChild = new CMIInteractionsObjectivesObject(this);
|
||||||
} else if (this.stringContains(CMIElement, 'cmi.interactions')) {
|
} else if (_self.stringContains(CMIElement, 'cmi.interactions')) {
|
||||||
newChild = new CMIInteractionsObject(this);
|
newChild = new CMIInteractionsObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newChild;
|
return newChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates Correct Response values
|
||||||
|
*
|
||||||
|
* @param {string} CMIElement
|
||||||
|
* @param {*} value
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
validateCorrectResponse(CMIElement, value) {
|
validateCorrectResponse(CMIElement, value) {
|
||||||
return true;
|
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) {
|
getLmsErrorMessageDetails(errorNumber, detail) {
|
||||||
let basicMessage = 'No Error';
|
let basicMessage = 'No Error';
|
||||||
let detailMessage = '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() {
|
getCurrentTotalTime() {
|
||||||
const timeRegex = new RegExp(scorm12_regex.CMITime);
|
const timeRegex = new RegExp(scorm12_regex.CMITime);
|
||||||
|
|
||||||
const totalTime = this.cmi.core.total_time;
|
const totalTime = _self.cmi.core.total_time;
|
||||||
const sessionTime = this.cmi.core.session_time;
|
const sessionTime = _self.cmi.core.session_time;
|
||||||
|
|
||||||
const totalSeconds = Utilities.getTimeAsSeconds(totalTime, timeRegex);
|
return Utilities.addHHMMSSTimeStrings(totalTime, sessionTime, timeRegex);
|
||||||
const sessionSeconds = Utilities.getTimeAsSeconds(sessionTime, timeRegex);
|
|
||||||
|
|
||||||
return Utilities.getSecondsAsHHMMSS(totalSeconds + sessionSeconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace the whole API with another
|
* Replace the whole API with another
|
||||||
*/
|
*
|
||||||
|
* @param {Scorm12API} newAPI
|
||||||
|
*/
|
||||||
replaceWithAnotherScormAPI(newAPI) {
|
replaceWithAnotherScormAPI(newAPI) {
|
||||||
// Data Model
|
// Data Model
|
||||||
this.cmi = newAPI.cmi;
|
_self.cmi = newAPI.cmi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ let _self;
|
|||||||
* API class for SCORM 2004
|
* API class for SCORM 2004
|
||||||
*/
|
*/
|
||||||
class Scorm2004API extends BaseAPI {
|
class Scorm2004API extends BaseAPI {
|
||||||
version: '1.0';
|
#version: '1.0';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for SCORM 2004 API
|
* Constructor for SCORM 2004 API
|
||||||
@@ -36,28 +36,36 @@ class Scorm2004API extends BaseAPI {
|
|||||||
_self.cmi = new CMI(_self);
|
_self.cmi = new CMI(_self);
|
||||||
_self.adl = new ADL(_self);
|
_self.adl = new ADL(_self);
|
||||||
|
|
||||||
// Rename functions to match 2004 Spec
|
// Rename functions to match 2004 Spec and expose to modules
|
||||||
_self.Initialize = _self.LMSInitialize;
|
_self.Initialize = _self.lmsInitialize;
|
||||||
_self.Terminate = _self.LMSTerminate;
|
_self.Terminate = _self.lmsTerminate;
|
||||||
_self.GetValue = _self.LMSGetValue;
|
_self.GetValue = _self.lmsGetValue;
|
||||||
_self.SetValue = _self.LMSSetValue;
|
_self.SetValue = _self.lmsSetValue;
|
||||||
_self.Commit = _self.LMSCommit;
|
_self.Commit = _self.lmsCommit;
|
||||||
_self.GetLastError = _self.LMSGetLastError;
|
_self.GetLastError = _self.lmsGetLastError;
|
||||||
_self.GetErrorString = _self.LMSGetErrorString;
|
_self.GetErrorString = _self.lmsGetErrorString;
|
||||||
_self.GetDiagnostic = _self.LMSGetDiagnostic;
|
_self.GetDiagnostic = _self.lmsGetDiagnostic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for #version
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
get version() {
|
||||||
|
return this.#version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {string} bool
|
* @return {string} bool
|
||||||
*/
|
*/
|
||||||
LMSInitialize() {
|
lmsInitialize() {
|
||||||
return _self.initialize('Initialize');
|
return _self.initialize('Initialize');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {string} bool
|
* @return {string} bool
|
||||||
*/
|
*/
|
||||||
LMSTerminate() {
|
lmsTerminate() {
|
||||||
return _self.terminate('Terminate', true);
|
return _self.terminate('Terminate', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +73,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
* @param {string} CMIElement
|
* @param {string} CMIElement
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetValue(CMIElement) {
|
lmsGetValue(CMIElement) {
|
||||||
return _self.getValue('GetValue', true, CMIElement);
|
return _self.getValue('GetValue', true, CMIElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +82,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
* @param {any} value
|
* @param {any} value
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSSetValue(CMIElement, value) {
|
lmsSetValue(CMIElement, value) {
|
||||||
return _self.setValue('SetValue', true, CMIElement, value);
|
return _self.setValue('SetValue', true, CMIElement, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +91,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
*
|
*
|
||||||
* @return {string} bool
|
* @return {string} bool
|
||||||
*/
|
*/
|
||||||
LMSCommit() {
|
lmsCommit() {
|
||||||
return _self.commit('Commit');
|
return _self.commit('Commit');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,27 +100,27 @@ class Scorm2004API extends BaseAPI {
|
|||||||
*
|
*
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetLastError() {
|
lmsGetLastError() {
|
||||||
return _self.getLastError('GetLastError');
|
return _self.getLastError('GetLastError');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the errorNumber error description
|
* Returns the errorNumber error description
|
||||||
*
|
*
|
||||||
* @param CMIErrorCode
|
* @param {(string|number)} CMIErrorCode
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetErrorString(CMIErrorCode) {
|
lmsGetErrorString(CMIErrorCode) {
|
||||||
return _self.getErrorString('GetErrorString', CMIErrorCode);
|
return _self.getErrorString('GetErrorString', CMIErrorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a comprehensive description of the errorNumber error.
|
* Returns a comprehensive description of the errorNumber error.
|
||||||
*
|
*
|
||||||
* @param CMIErrorCode
|
* @param {(string|number)} CMIErrorCode
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
LMSGetDiagnostic(CMIErrorCode) {
|
lmsGetDiagnostic(CMIErrorCode) {
|
||||||
return _self.getDiagnostic('GetDiagnostic', CMIErrorCode);
|
return _self.getDiagnostic('GetDiagnostic', CMIErrorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +168,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
const response_type = correct_responses[interaction_type];
|
const response_type = correct_responses[interaction_type];
|
||||||
let nodes = [];
|
let nodes = [];
|
||||||
if (response_type.delimiter !== '') {
|
if (response_type.delimiter !== '') {
|
||||||
nodes = value.split(response_type.delimiter);
|
nodes = String(value).split(response_type.delimiter);
|
||||||
} else {
|
} else {
|
||||||
nodes[0] = value;
|
nodes[0] = value;
|
||||||
}
|
}
|
||||||
@@ -191,7 +199,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Validate correct response.
|
* Validate correct response.
|
||||||
* @param {string} CMIElement
|
* @param {string} CMIElement
|
||||||
* @param {any} value
|
* @param {*} value
|
||||||
*/
|
*/
|
||||||
validateCorrectResponse(CMIElement, value) {
|
validateCorrectResponse(CMIElement, value) {
|
||||||
const parts = CMIElement.split('.');
|
const parts = CMIElement.split('.');
|
||||||
@@ -215,7 +223,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
response_type.limit) {
|
response_type.limit) {
|
||||||
let nodes = [];
|
let nodes = [];
|
||||||
if (response_type.delimiter !== '') {
|
if (response_type.delimiter !== '') {
|
||||||
nodes = value.split(response_type.delimiter);
|
nodes = String(value).split(response_type.delimiter);
|
||||||
} else {
|
} else {
|
||||||
nodes[0] = value;
|
nodes[0] = value;
|
||||||
}
|
}
|
||||||
@@ -258,8 +266,8 @@ class Scorm2004API extends BaseAPI {
|
|||||||
/**
|
/**
|
||||||
* Returns the message that corresponds to errorNumber.
|
* Returns the message that corresponds to errorNumber.
|
||||||
*
|
*
|
||||||
* @param {string,number} errorNumber
|
* @param {(string|number)} errorNumber
|
||||||
* @param {string} detail
|
* @param {boolean} detail
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getLmsErrorMessageDetails(errorNumber, detail) {
|
getLmsErrorMessageDetails(errorNumber, detail) {
|
||||||
@@ -276,6 +284,13 @@ class Scorm2004API extends BaseAPI {
|
|||||||
return detail ? detailMessage : basicMessage;
|
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) => {
|
#checkDuplicatedPattern = (correct_response, current_index, value) => {
|
||||||
let found = false;
|
let found = false;
|
||||||
const count = correct_response._count;
|
const count = correct_response._count;
|
||||||
@@ -287,6 +302,12 @@ class Scorm2004API extends BaseAPI {
|
|||||||
return found;
|
return found;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for a valid correct_response value
|
||||||
|
* @param {string} interaction_type
|
||||||
|
* @param {Array} nodes
|
||||||
|
* @param {*} value
|
||||||
|
*/
|
||||||
#checkCorrectResponseValue = (interaction_type, nodes, value) => {
|
#checkCorrectResponseValue = (interaction_type, nodes, value) => {
|
||||||
const response = correct_responses[interaction_type];
|
const response = correct_responses[interaction_type];
|
||||||
const formatRegex = new RegExp(response.format);
|
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) => {
|
#removeCorrectResponsePrefixes = (node) => {
|
||||||
let seenOrder = false;
|
let seenOrder = false;
|
||||||
let seenCase = false;
|
let seenCase = false;
|
||||||
@@ -404,11 +430,7 @@ class Scorm2004API extends BaseAPI {
|
|||||||
const totalTime = _self.cmi.total_time;
|
const totalTime = _self.cmi.total_time;
|
||||||
const sessionTime = _self.cmi.session_time;
|
const sessionTime = _self.cmi.session_time;
|
||||||
|
|
||||||
const durationRegex = scorm2004_regex.CMITimespan;
|
return Util.addTwoDurations(totalTime, sessionTime,
|
||||||
const totalSeconds = Util.getDurationAsSeconds(totalTime, durationRegex);
|
scorm2004_regex.CMITimespan);
|
||||||
const sessionSeconds = Util.getDurationAsSeconds(sessionTime,
|
|
||||||
durationRegex);
|
|
||||||
|
|
||||||
return Util.getSecondsAsISODuration(totalSeconds + sessionSeconds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,17 +39,18 @@ class CMIEvaluation extends BaseCMI {
|
|||||||
*/
|
*/
|
||||||
constructor(API) {
|
constructor(API) {
|
||||||
super(API);
|
super(API);
|
||||||
}
|
|
||||||
|
|
||||||
comments = new class extends CMIArray {
|
this.comments = new class extends CMIArray {
|
||||||
/**
|
/**
|
||||||
* Constructor for AICC Evaluation Comments object
|
* Constructor for AICC Evaluation Comments object
|
||||||
* @param {AICC} API
|
* @param {AICC} API
|
||||||
*/
|
*/
|
||||||
constructor(API) {
|
constructor(API) {
|
||||||
super(API, constants.comments_children, 402);
|
super(API, constants.comments_children,
|
||||||
}
|
scorm12_error_codes.INVALID_SET_VALUE);
|
||||||
};
|
}
|
||||||
|
}(API);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,6 +63,16 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
|
|||||||
*/
|
*/
|
||||||
constructor(API) {
|
constructor(API) {
|
||||||
super(API, constants.student_data_children);
|
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 = '';
|
#tries_during_lesson = '';
|
||||||
@@ -84,34 +95,20 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
|
|||||||
this.#tries_during_lesson = tries_during_lesson :
|
this.#tries_during_lesson = tries_during_lesson :
|
||||||
throwReadOnlyError();
|
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
|
* Class for AICC Tries
|
||||||
*/
|
*/
|
||||||
export class CMITriesObject extends BaseCMI {
|
export class CMITriesObject extends BaseCMI {
|
||||||
#API;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for AICC Tries object
|
* Constructor for AICC Tries object
|
||||||
* @param {AICC} API
|
* @param {AICC} API
|
||||||
*/
|
*/
|
||||||
constructor(API) {
|
constructor(API) {
|
||||||
super(API);
|
super(API);
|
||||||
this.#API = API;
|
|
||||||
_self = this;
|
this.score = new CMIScore(API);
|
||||||
}
|
}
|
||||||
|
|
||||||
#status = '';
|
#status = '';
|
||||||
@@ -152,8 +149,6 @@ export class CMITriesObject extends BaseCMI {
|
|||||||
this.#time = time;
|
this.#time = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
score = new CMIScore(_self.#API);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,7 +241,9 @@ export class NAV extends BaseCMI {
|
|||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
get event() {
|
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_constants} from '../constants/api_constants';
|
||||||
import {scorm12_error_codes} from '../constants/error_codes';
|
import {scorm12_error_codes} from '../constants/error_codes';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for API cmi objects
|
||||||
|
*/
|
||||||
export class BaseCMI {
|
export class BaseCMI {
|
||||||
jsonString = false;
|
jsonString = false;
|
||||||
API;
|
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 {
|
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) {
|
constructor(API, score_children?, score_range?, invalidErrorCode) {
|
||||||
super(API);
|
super(API);
|
||||||
|
|
||||||
this.#_children = score_children? score_children : scorm12_constants.score_children;
|
this.#_children = score_children ?
|
||||||
this.#_score_range = score_range? score_range : false;
|
score_children :
|
||||||
this.#_invalid_error_code = invalidErrorCode ? invalidErrorCode : scorm12_error_codes.INVALID_SET_VALUE;
|
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;
|
#_children;
|
||||||
#_score_range;
|
#_score_range;
|
||||||
#_invalid_error_code;
|
#_invalid_error_code;
|
||||||
#raw = '';
|
#raw = '';
|
||||||
#min = '';
|
#min = '';
|
||||||
#max = '100';
|
#max = '100';
|
||||||
|
|
||||||
get _children() {
|
/**
|
||||||
return this.#_children;
|
* Getter for _children
|
||||||
}
|
* @return {string}
|
||||||
set _children(_children) {
|
* @private
|
||||||
this.API.throwSCORMError(this.#_invalid_error_code);
|
*/
|
||||||
}
|
get _children() {
|
||||||
|
return this.#_children;
|
||||||
|
}
|
||||||
|
|
||||||
get raw() {
|
/**
|
||||||
return this.#raw;
|
* Setter for _children. Just throws an error.
|
||||||
}
|
* @param {string} _children
|
||||||
set raw(raw) {
|
* @private
|
||||||
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
|
*/
|
||||||
(!this.#_score_range || this.API.checkValidRange(raw, this.#_score_range))) {
|
set _children(_children) {
|
||||||
this.#raw = raw;
|
this.API.throwSCORMError(this.#_invalid_error_code);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get min() {
|
/**
|
||||||
return this.#min;
|
* Getter for #raw
|
||||||
}
|
* @return {string}
|
||||||
set min(min) {
|
*/
|
||||||
if (this.API.checkValidFormat(min, scorm12_constants.CMIDecimal) &&
|
get raw() {
|
||||||
(!this.#_score_range || this.API.checkValidRange(min, this.#_score_range))) {
|
return this.#raw;
|
||||||
this.#min = min;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get max() {
|
/**
|
||||||
return this.#max;
|
* Setter for #raw
|
||||||
}
|
* @param {string} raw
|
||||||
set max(max) {
|
*/
|
||||||
if (this.API.checkValidFormat(max, scorm12_constants.CMIDecimal) &&
|
set raw(raw) {
|
||||||
(!this.#_score_range || this.API.checkValidRange(max, this.#_score_range))) {
|
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
|
||||||
this.#max = max;
|
(!this.#_score_range ||
|
||||||
}
|
this.API.checkValidRange(raw, this.#_score_range))) {
|
||||||
|
this.#raw = raw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toJSON = () => {
|
/**
|
||||||
return {
|
* Getter for #min
|
||||||
'raw': this.raw,
|
* @return {string}
|
||||||
'min': this.min,
|
*/
|
||||||
'max': this.max,
|
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 {
|
export class CMIArray extends BaseCMI {
|
||||||
|
/**
|
||||||
|
* Constructor cmi *.n arrays
|
||||||
|
* @param {BaseAPI} API
|
||||||
|
* @param {string} children
|
||||||
|
* @param {number} errorCode
|
||||||
|
*/
|
||||||
constructor({API, children, errorCode}) {
|
constructor({API, children, errorCode}) {
|
||||||
super(API);
|
super(API);
|
||||||
this.#_children = children;
|
this.#_children = children;
|
||||||
@@ -80,30 +156,56 @@ export class CMIArray extends BaseCMI {
|
|||||||
this.childArray = [];
|
this.childArray = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
#errorCode;
|
#errorCode;
|
||||||
#_children;
|
#_children;
|
||||||
|
|
||||||
get _children() {
|
/**
|
||||||
return this.#_children;
|
* Getter for _children
|
||||||
}
|
* @return {*}
|
||||||
set _children(_children) {
|
* @private
|
||||||
this.API.throwSCORMError(this.#errorCode);
|
*/
|
||||||
}
|
get _children() {
|
||||||
|
return this.#_children;
|
||||||
|
}
|
||||||
|
|
||||||
get _count() {
|
/**
|
||||||
return this.childArray.length;
|
* Setter for _children. Just throws an error.
|
||||||
}
|
* @param {string} _children
|
||||||
set _count(_count) {
|
* @private
|
||||||
this.API.throwSCORMError(this.#errorCode);
|
*/
|
||||||
}
|
set _children(_children) {
|
||||||
|
this.API.throwSCORMError(this.#errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
toJSON = () => {
|
/**
|
||||||
this.jsonString = true;
|
* Getter for _count
|
||||||
const result = {};
|
* @return {number}
|
||||||
for (let i = 0; i < this.childArray.length; i++) {
|
* @private
|
||||||
result[i + ''] = this.childArray[i];
|
*/
|
||||||
}
|
get _count() {
|
||||||
delete this.jsonString;
|
return this.childArray.length;
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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': {
|
'301': {
|
||||||
basicMessage: 'Not initialized',
|
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': {
|
'401': {
|
||||||
basicMessage: 'Not implemented error',
|
basicMessage: 'Not implemented error',
|
||||||
|
|||||||
124
src/regex.js
124
src/regex.js
@@ -1,76 +1,76 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
export const scorm12_regex = {
|
export const scorm12_regex = {
|
||||||
CMIString256: '^.{0,255}$',
|
CMIString256: '^.{0,255}$',
|
||||||
CMIString4096: '^.{0,4096}$',
|
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})?$',
|
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,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$',
|
CMITimespan: '^([0-9]{2,}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$', // eslint-disable-line
|
||||||
CMIInteger: '^\\d+$',
|
CMIInteger: '^\\d+$',
|
||||||
CMISInteger: '^-?([0-9]+)$',
|
CMISInteger: '^-?([0-9]+)$',
|
||||||
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$',
|
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$', // eslint-disable-line
|
||||||
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
|
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
|
||||||
CMIFeedback: '^.{0,255}$', // This must be redefined
|
CMIFeedback: '^.{0,255}$', // This must be redefined
|
||||||
CMIIndex: '[._](\\d+).',
|
CMIIndex: '[._](\\d+).',
|
||||||
|
|
||||||
// Vocabulary Data Type Definition
|
// Vocabulary Data Type Definition
|
||||||
CMIStatus: '^passed$|^completed$|^failed$|^incomplete$|^browsed$',
|
CMIStatus: '^passed$|^completed$|^failed$|^incomplete$|^browsed$',
|
||||||
CMIStatus2: '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$',
|
CMIStatus2: '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$',
|
||||||
CMIExit: '^time-out$|^suspend$|^logout$|^$',
|
CMIExit: '^time-out$|^suspend$|^logout$|^$',
|
||||||
CMIType: '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$',
|
CMIType: '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$',
|
||||||
CMIResult: '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$',
|
CMIResult: '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$', // eslint-disable-line
|
||||||
NAVEvent: '^previous$|^continue$',
|
NAVEvent: '^previous$|^continue$',
|
||||||
|
|
||||||
// Data ranges
|
// Data ranges
|
||||||
score_range: '0#100',
|
score_range: '0#100',
|
||||||
audio_range: '-1#100',
|
audio_range: '-1#100',
|
||||||
speed_range: '-100#100',
|
speed_range: '-100#100',
|
||||||
weighting_range: '-100#100',
|
weighting_range: '-100#100',
|
||||||
text_range: '-1#1',
|
text_range: '-1#1',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const aicc_regex = {
|
export const aicc_regex = {
|
||||||
...scorm12_regex, ...{
|
...scorm12_regex, ...{
|
||||||
CMIIdentifier: '^\\w{1,255}$',
|
CMIIdentifier: '^\\w{1,255}$',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const scorm2004_regex = {
|
export const scorm2004_regex = {
|
||||||
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
|
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
|
||||||
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
|
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
|
||||||
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
|
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
|
||||||
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
|
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
|
||||||
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
|
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
|
||||||
CMILang: '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$',
|
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}$)?',
|
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})?\}))(.*?)$',
|
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})?)?$',
|
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}$)?',
|
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})?)?)?)?)?)?)?)?$',
|
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)?)?$',
|
CMITimespan: '^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$',
|
||||||
CMIInteger: '^\\d+$',
|
CMIInteger: '^\\d+$',
|
||||||
CMISInteger: '^-?([0-9]+)$',
|
CMISInteger: '^-?([0-9]+)$',
|
||||||
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
|
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
|
||||||
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
|
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
|
||||||
CMIShortIdentifier: '^[\\w\.]{1,250}$',
|
CMIShortIdentifier: '^[\\w\.]{1,250}$', // eslint-disable-line
|
||||||
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
|
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
|
||||||
CMIFeedback: '^.*$', // This must be redefined
|
CMIFeedback: '^.*$', // This must be redefined
|
||||||
CMIIndex: '[._](\\d+).',
|
CMIIndex: '[._](\\d+).',
|
||||||
CMIIndexStore: '.N(\\d+).',
|
CMIIndexStore: '.N(\\d+).',
|
||||||
|
|
||||||
// Vocabulary Data Type Definition
|
// Vocabulary Data Type Definition
|
||||||
CMICStatus: '^completed$|^incomplete$|^not attempted$|^unknown$',
|
CMICStatus: '^completed$|^incomplete$|^not attempted$|^unknown$',
|
||||||
CMISStatus: '^passed$|^failed$|^unknown$',
|
CMISStatus: '^passed$|^failed$|^unknown$',
|
||||||
CMIExit: '^time-out$|^suspend$|^logout$|^normal$|^$',
|
CMIExit: '^time-out$|^suspend$|^logout$|^normal$|^$',
|
||||||
CMIType: '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$',
|
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})?$',
|
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$',
|
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$',
|
NAVBoolean: '^unknown$|^true$|^false$',
|
||||||
NAVTarget: '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$',
|
NAVTarget: '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$',
|
||||||
|
|
||||||
// Data ranges
|
// Data ranges
|
||||||
scaled_range: '-1#1',
|
scaled_range: '-1#1',
|
||||||
audio_range: '0#*',
|
audio_range: '0#*',
|
||||||
speed_range: '0#*',
|
speed_range: '0#*',
|
||||||
text_range: '-1#1',
|
text_range: '-1#1',
|
||||||
progress_range: '0#1',
|
progress_range: '0#1',
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
export const SECONDS_PER_SECOND = 1;
|
export const SECONDS_PER_SECOND = 1.0;
|
||||||
export const SECONDS_PER_MINUTE = 60;
|
export const SECONDS_PER_MINUTE = 60;
|
||||||
export const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
export const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
||||||
export const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
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 dateObj = new Date(totalSeconds * 1000);
|
||||||
const minutes = dateObj.getUTCMinutes();
|
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') + ':' +
|
return hours.toString().padStart(2, '0') + ':' +
|
||||||
minutes.toString().padStart(2, '0') + ':' +
|
minutes.toString().padStart(2, '0') + ':' +
|
||||||
seconds.toString().padStart(2, '0');
|
seconds.toString().padStart(2, '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,9 +51,14 @@ export function getSecondsAsISODuration(seconds: Number) {
|
|||||||
let remainder = seconds;
|
let remainder = seconds;
|
||||||
|
|
||||||
designations.forEach(([sign, current_seconds]) => {
|
designations.forEach(([sign, current_seconds]) => {
|
||||||
const value = Math.floor(remainder / current_seconds);
|
let value = Math.floor(remainder / current_seconds);
|
||||||
|
|
||||||
remainder = 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) {
|
if (value) {
|
||||||
duration += `${value}${sign}`;
|
duration += `${value}${sign}`;
|
||||||
@@ -104,10 +110,45 @@ export function getDurationAsSeconds(duration: String, durationRegex: RegExp) {
|
|||||||
anchor.setHours(anchor.getHours() + Number(hours || 0));
|
anchor.setHours(anchor.getHours() + Number(hours || 0));
|
||||||
anchor.setMinutes(anchor.getMinutes() + Number(minutes || 0));
|
anchor.setMinutes(anchor.getMinutes() + Number(minutes || 0));
|
||||||
anchor.setSeconds(anchor.getSeconds() + Number(seconds || 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;
|
const milliseconds = Number(Number(seconds) % 1).toFixed(6) * 1000.0;
|
||||||
anchor.setMilliseconds(anchor.getMilliseconds() + milliseconds);
|
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 {expect} from 'chai';
|
||||||
import {describe, it} from "mocha";
|
import {describe, it} from 'mocha';
|
||||||
import * as Utilities from '../src/utilities';
|
import * as Utilities from '../src/utilities';
|
||||||
import {scorm12_regex, scorm2004_regex} from "../src/regex";
|
import {scorm12_regex, scorm2004_regex} from '../src/regex';
|
||||||
|
|
||||||
describe('Utility Tests', () => {
|
describe('Utility Tests', () => {
|
||||||
describe('function getSecondsAsHHMMSS()', () => {
|
describe('getSecondsAsHHMMSS()', () => {
|
||||||
it('10 returns 00:00:10', () => {
|
it('10 returns 00:00:10', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(10)
|
Utilities.getSecondsAsHHMMSS(10),
|
||||||
).to.equal('00:00:10');
|
).to.equal('00:00:10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('60 returns 00:01:00', () => {
|
it('60 returns 00:01:00', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(60)
|
Utilities.getSecondsAsHHMMSS(60),
|
||||||
).to.equal('00:01:00');
|
).to.equal('00:01:00');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('3600 returns 01:00:00', () => {
|
it('3600 returns 01:00:00', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(3600)
|
Utilities.getSecondsAsHHMMSS(3600),
|
||||||
).to.equal('01:00:00');
|
).to.equal('01:00:00');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('70 returns 00:01:10', () => {
|
it('70 returns 00:01:10', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(70)
|
Utilities.getSecondsAsHHMMSS(70),
|
||||||
).to.equal('00:01:10');
|
).to.equal('00:01:10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('3670 returns 01:01:10', () => {
|
it('3670 returns 01:01:10', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(3670)
|
Utilities.getSecondsAsHHMMSS(3670),
|
||||||
).to.equal('01:01:10');
|
).to.equal('01:01:10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('90000 returns 25:00:00, check for hours greater than 24', () => {
|
it('90000 returns 25:00:00, check for hours greater than 24', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(90000)
|
Utilities.getSecondsAsHHMMSS(90000),
|
||||||
).to.equal('25:00:00');
|
).to.equal('25:00:00');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('-3600 returns 00:00:00, negative time not allowed in SCORM session times', () => {
|
it('-3600 returns 00:00:00, negative time not allowed in SCORM session times',
|
||||||
expect(
|
() => {
|
||||||
Utilities.getSecondsAsHHMMSS(-3600)
|
expect(
|
||||||
).to.equal('00:00:00');
|
Utilities.getSecondsAsHHMMSS(-3600),
|
||||||
});
|
).to.equal('00:00:00');
|
||||||
|
});
|
||||||
|
|
||||||
it('Empty seconds returns 00:00:00', () => {
|
it('Empty seconds returns 00:00:00', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsHHMMSS(null)
|
Utilities.getSecondsAsHHMMSS(null),
|
||||||
).to.equal('00:00:00');
|
).to.equal('00:00:00');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('function getSecondsAsISODuration()', () => {
|
describe('getSecondsAsISODuration()', () => {
|
||||||
it('10 returns P10S', () => {
|
it('10 returns P10S', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(10)
|
Utilities.getSecondsAsISODuration(10),
|
||||||
).to.equal('P10S');
|
).to.equal('P10S');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('60 returns P1M', () => {
|
it('60 returns P1M', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(60)
|
Utilities.getSecondsAsISODuration(60),
|
||||||
).to.equal('P1M');
|
).to.equal('P1M');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('3600 returns P1H', () => {
|
it('3600 returns P1H', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(3600)
|
Utilities.getSecondsAsISODuration(3600),
|
||||||
).to.equal('P1H');
|
).to.equal('P1H');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('70 returns P1M10S', () => {
|
it('70 returns P1M10S', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(70)
|
Utilities.getSecondsAsISODuration(70),
|
||||||
).to.equal('P1M10S');
|
).to.equal('P1M10S');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('3670 returns P1H1M10S', () => {
|
it('3670 returns P1H1M10S', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(3670)
|
Utilities.getSecondsAsISODuration(3670),
|
||||||
).to.equal('P1H1M10S');
|
).to.equal('P1H1M10S');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('90000 returns P1D1H', () => {
|
it('90000 returns P1D1H', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(90000)
|
Utilities.getSecondsAsISODuration(90000),
|
||||||
).to.equal('P1D1H');
|
).to.equal('P1D1H');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('90061 returns P1D1H1M1S', () => {
|
it('90061 returns P1D1H1M1S', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(90061)
|
Utilities.getSecondsAsISODuration(90061),
|
||||||
).to.equal('P1D1H1M1S');
|
).to.equal('P1D1H1M1S');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('-3600 returns P0S, negative time not allowed in SCORM session times', () => {
|
it('-3600 returns P0S, negative time not allowed in SCORM session times',
|
||||||
expect(
|
() => {
|
||||||
Utilities.getSecondsAsISODuration(-3600)
|
expect(
|
||||||
).to.equal('P0S');
|
Utilities.getSecondsAsISODuration(-3600),
|
||||||
});
|
).to.equal('P0S');
|
||||||
|
});
|
||||||
|
|
||||||
it('Empty seconds returns P0S', () => {
|
it('Empty seconds returns P0S', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getSecondsAsISODuration(null)
|
Utilities.getSecondsAsISODuration(null),
|
||||||
).to.equal('P0S');
|
).to.equal('P0S');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('function getTimeAsSeconds()', () => {
|
describe('getTimeAsSeconds()', () => {
|
||||||
it('00:00:10 returns 10', () => {
|
it('00:00:10 returns 10', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan),
|
||||||
).to.equal(10);
|
).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('00:01:10 returns 70', () => {
|
it('00:01:10 returns 70', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan),
|
||||||
).to.equal(70);
|
).to.equal(70);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('01:01:10 returns 3670', () => {
|
it('01:01:10 returns 3670', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan),
|
||||||
).to.equal(3670);
|
).to.equal(3670);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('100:00:00 returns 3670', () => {
|
it('100:00:00 returns 3670', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan),
|
||||||
).to.equal(360000);
|
).to.equal(360000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('-01:00:00 returns 0', () => {
|
it('-01:00:00 returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Number value returns 0', () => {
|
it('Number value returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('boolean value returns 0', () => {
|
it('boolean value returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Empty value returns 0', () => {
|
it('Empty value returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan)
|
Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).to.equal(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('function getDurationAsSeconds()', () => {
|
describe('getDurationAsSeconds()', () => {
|
||||||
it('P0S returns 0', () => {
|
it('P0S returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('P70S returns 70', () => {
|
it('P70S returns 70', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan),
|
||||||
).to.equal(70);
|
).to.equal(70);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PT1M10S returns 70', () => {
|
it('PT1M10S returns 70', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('PT1M10S', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('PT1M10S',
|
||||||
).to.equal(70);
|
scorm2004_regex.CMITimespan),
|
||||||
});
|
).to.equal(70);
|
||||||
|
});
|
||||||
|
|
||||||
it('P1D returns 86400', () => {
|
it('P1D returns 86400', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan),
|
||||||
).to.equal(86400);
|
).to.equal(86400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('P1M returns number of seconds for one month from now', () => {
|
it('P1M returns number of seconds for one month from now', () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
let oneMonthFromNow = new Date(now);
|
const oneMonthFromNow = new Date(now);
|
||||||
oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1);
|
oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('P1M', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('P1M', scorm2004_regex.CMITimespan),
|
||||||
).to.equal((oneMonthFromNow - now) / 1000.0);
|
).to.equal((oneMonthFromNow - now) / 1000.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('P1Y returns number of seconds for one year from now', () => {
|
it('P1Y returns number of seconds for one year from now', () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
let oneYearFromNow = new Date(now);
|
const oneYearFromNow = new Date(now);
|
||||||
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
|
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan),
|
||||||
).to.equal((oneYearFromNow - now) / 1000.0);
|
).to.equal((oneYearFromNow - now) / 1000.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid duration returns 0', () => {
|
it('Invalid duration returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Empty duration returns 0', () => {
|
it('Empty duration returns 0', () => {
|
||||||
expect(
|
expect(
|
||||||
Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan)
|
Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan),
|
||||||
).to.equal(0);
|
).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