More tests and fixes

This commit is contained in:
Jonathan Putney
2019-11-14 16:07:42 -05:00
parent caa5977a4b
commit 929176fb3e
14 changed files with 385 additions and 238 deletions

View File

@@ -17,8 +17,8 @@ export default class AICC extends Scorm12API {
constructor() { constructor() {
super(); super();
this.cmi = new CMI(this); this.cmi = new CMI();
this.nav = new NAV(this); this.nav = new NAV();
} }
/** /**

View File

@@ -609,7 +609,6 @@ export default class BaseAPI {
this.throwSCORMError(203); this.throwSCORMError(203);
} }
} }
return;
} else { } else {
return refObject; return refObject;
} }
@@ -776,6 +775,14 @@ export default class BaseAPI {
return JSON.parse(JSON.stringify(cmi)); return JSON.parse(JSON.stringify(cmi));
} }
/**
* Gets the current total time as total_time + session_time
* APIs that inherit BaseAPI should override this function
*/
getCurrentTotalTime() {
this.cmi.getCurrentTotalTime();
}
/** /**
* Throws a SCORM error * Throws a SCORM error
* *

View File

@@ -24,7 +24,7 @@ export default class Scorm12API extends BaseAPI {
constructor() { constructor() {
super(scorm12_error_codes); super(scorm12_error_codes);
this.cmi = new CMI(this); this.cmi = new CMI();
// Rename functions to match 1.2 Spec and expose to modules // Rename functions to match 1.2 Spec and expose to modules
this.LMSInitialize = this.lmsInitialize; this.LMSInitialize = this.lmsInitialize;
this.LMSFinish = this.lmsFinish; this.LMSFinish = this.lmsFinish;
@@ -192,20 +192,6 @@ export default class Scorm12API extends BaseAPI {
return detail ? detailMessage : basicMessage; return detail ? detailMessage : basicMessage;
} }
/**
* Adds the current session time to the existing total time.
*
* @return {string}
*/
getCurrentTotalTime() {
const timeRegex = new RegExp(scorm12_regex.CMITime);
const totalTime = this.cmi.core.total_time;
const sessionTime = this.cmi.core.session_time;
return Utilities.addHHMMSSTimeStrings(totalTime, sessionTime, timeRegex);
}
/** /**
* Replace the whole API with another * Replace the whole API with another
* *

View File

@@ -30,8 +30,8 @@ export default class Scorm2004API extends BaseAPI {
constructor() { constructor() {
super(scorm2004_error_codes); super(scorm2004_error_codes);
this.cmi = new CMI(this); this.cmi = new CMI();
this.adl = new ADL(this); this.adl = new ADL();
// Rename functions to match 2004 Spec and expose to modules // Rename functions to match 2004 Spec and expose to modules
this.Initialize = this.lmsInitialize; this.Initialize = this.lmsInitialize;
@@ -420,17 +420,4 @@ export default class Scorm2004API extends BaseAPI {
this.cmi = newAPI.cmi; this.cmi = newAPI.cmi;
this.adl = newAPI.adl; this.adl = newAPI.adl;
} }
/**
* Adds the current session time to the existing total time.
*
* @return {string} ISO8601 Duration
*/
getCurrentTotalTime() {
const totalTime = this.cmi.total_time;
const sessionTime = this.cmi.session_time;
return Util.addTwoDurations(totalTime, sessionTime,
scorm2004_regex.CMITimespan);
}
} }

View File

@@ -10,6 +10,7 @@ import {scorm12_constants} from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes'; import {scorm12_error_codes} from '../constants/error_codes';
import {scorm12_regex} from '../constants/regex'; import {scorm12_regex} from '../constants/regex';
import {ValidationError} from '../exceptions'; import {ValidationError} from '../exceptions';
import * as Utilities from '../utilities';
const constants = scorm12_constants; const constants = scorm12_constants;
const regex = scorm12_regex; const regex = scorm12_regex;
@@ -244,6 +245,15 @@ export class CMI extends BaseCMI {
this.#comments_from_lms = comments_from_lms : this.#comments_from_lms = comments_from_lms :
throwReadOnlyError(); throwReadOnlyError();
} }
/**
* Adds the current session time to the existing total time.
*
* @return {string}
*/
getCurrentTotalTime() {
return this.core.getCurrentTotalTime();
}
} }
/** /**
@@ -475,6 +485,19 @@ class CMICore extends BaseCMI {
} }
} }
/**
* Adds the current session time to the existing total time.
*
* @return {string}
*/
getCurrentTotalTime() {
return Utilities.addHHMMSSTimeStrings(
this.#total_time,
this.#session_time,
new RegExp(scorm12_regex.CMITimespan)
);
}
/** /**
* toJSON for cmi.core * toJSON for cmi.core
* *

View File

@@ -11,6 +11,7 @@ import {scorm2004_regex} from '../constants/regex';
import {scorm2004_error_codes} from '../constants/error_codes'; import {scorm2004_error_codes} from '../constants/error_codes';
import {learner_responses} from '../constants/response_constants'; import {learner_responses} from '../constants/response_constants';
import {ValidationError} from '../exceptions'; import {ValidationError} from '../exceptions';
import * as Util from '../utilities';
const constants = scorm2004_constants; const constants = scorm2004_constants;
const regex = scorm2004_regex; const regex = scorm2004_regex;
@@ -466,6 +467,19 @@ export class CMI extends BaseCMI {
!this.initialized ? this.#total_time = total_time : throwReadOnlyError(); !this.initialized ? this.#total_time = total_time : throwReadOnlyError();
} }
/**
* Adds the current session time to the existing total time.
*
* @return {string} ISO8601 Duration
*/
getCurrentTotalTime() {
return Util.addTwoDurations(
this.#total_time,
this.#session_time,
scorm2004_regex.CMITimespan,
);
}
/** /**
* toJSON for cmi * toJSON for cmi
* *

View File

@@ -44,7 +44,7 @@ export function getSecondsAsHHMMSS(totalSeconds: Number) {
export function getSecondsAsISODuration(seconds: Number) { export function getSecondsAsISODuration(seconds: Number) {
// SCORM spec does not deal with negative durations, give zero back // SCORM spec does not deal with negative durations, give zero back
if (!seconds || seconds <= 0) { if (!seconds || seconds <= 0) {
return 'P0S'; return 'PT0S';
} }
let duration = 'P'; let duration = 'P';
@@ -61,6 +61,11 @@ export function getSecondsAsISODuration(seconds: Number) {
} }
if (value) { if (value) {
if ((duration.indexOf('D') > 0 ||
sign === 'H' || sign === 'M' || sign === 'S') &&
duration.indexOf('T') === -1) {
duration += 'T';
}
duration += `${value}${sign}`; duration += `${value}${sign}`;
} }
}); });

View File

@@ -11,7 +11,7 @@ const api = () => {
return API; return API;
}; };
const apiInitialized = () => { const apiInitialized = () => {
const API = api(true); const API = api();
API.lmsInitialize(); API.lmsInitialize();
return API; return API;
}; };

View File

@@ -0,0 +1,17 @@
import {describe, it} from 'mocha';
import {expect} from 'chai';
import BaseAPI from '../src/BaseAPI';
import {BaseCMI} from '../src/cmi/common';
describe('Abstract Class Tests', () => {
it('BaseAPI should not be instantiated', () => {
expect(
() => new BaseAPI(),
).to.throw('Cannot construct BaseAPI instances directly');
});
it('BaseCMI should not be instantiated', () => {
expect(
() => new BaseCMI(),
).to.throw('Cannot construct BaseCMI instances directly');
});
});

View File

@@ -17,13 +17,78 @@ const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT; const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT;
const read_only = scorm12_error_codes.READ_ONLY_ELEMENT; const read_only = scorm12_error_codes.READ_ONLY_ELEMENT;
const cmi = () => {
return new CMI();
};
const cmiInitialized = () => {
const obj = new CMI();
obj.initialize();
return obj;
};
const interaction = () => {
return new CMIInteractionsObject();
};
const interactionInitialized = () => {
const cmi = new CMIInteractionsObject();
cmi.initialize();
return cmi;
};
const interactionObjective = () => {
return new CMIInteractionsObjectivesObject();
};
const correctResponse = () => {
return new CMIInteractionsCorrectResponsesObject();
};
const objective = () => {
return new CMIObjectivesObject();
};
describe('SCORM 1.2 CMI Tests', () => { describe('SCORM 1.2 CMI Tests', () => {
describe('getCurrentTotalTime()', () => {
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: '00:00:00',
sessionTime: '00:15:45',
expectedTotal: '00:15:45',
totalFieldName: 'cmi.core.total_time',
sessionFieldName: 'cmi.core.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: '00:01:00',
sessionTime: '00:15:45',
expectedTotal: '00:16:45',
totalFieldName: 'cmi.core.total_time',
sessionFieldName: 'cmi.core.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: '00:01:00',
sessionTime: '00:00:00',
expectedTotal: '00:01:00',
totalFieldName: 'cmi.core.total_time',
sessionFieldName: 'cmi.core.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: '25:01:00',
sessionTime: '13:00:00',
expectedTotal: '38:01:00',
totalFieldName: 'cmi.core.total_time',
sessionFieldName: 'cmi.core.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: '48:01:45',
sessionTime: '13:00:16',
expectedTotal: '61:02:01',
totalFieldName: 'cmi.core.total_time',
sessionFieldName: 'cmi.core.session_time',
});
});
describe('CMI Spec Tests', () => { describe('CMI Spec Tests', () => {
describe('Pre-Initialize Tests', () => { describe('Pre-Initialize Tests', () => {
const cmi = () => {
return new CMI();
};
/** /**
* Base CMI Properties * Base CMI Properties
*/ */
@@ -279,46 +344,40 @@ describe('SCORM 1.2 CMI Tests', () => {
}); });
describe('Post-Initialize Tests', () => { describe('Post-Initialize Tests', () => {
const cmi = () => {
const obj = new CMI();
obj.initialize();
return obj;
};
/** /**
* Base CMI Properties * Base CMI Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi._version', fieldName: 'cmi._version',
expectedValue: '3.4', expectedValue: '3.4',
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi._children', fieldName: 'cmi._children',
expectedValue: scorm12_constants.cmi_children, expectedValue: scorm12_constants.cmi_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.suspend_data', fieldName: 'cmi.suspend_data',
limit: 4096, limit: 4096,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.launch_data', fieldName: 'cmi.launch_data',
expectedError: read_only, expectedError: read_only,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.comments', fieldName: 'cmi.comments',
limit: 4096, limit: 4096,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.comments_from_lms', fieldName: 'cmi.comments_from_lms',
expectedError: read_only, expectedError: read_only,
}); });
@@ -327,77 +386,77 @@ describe('SCORM 1.2 CMI Tests', () => {
* cmi.core Properties * cmi.core Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core._children', fieldName: 'cmi.core._children',
expectedValue: scorm12_constants.core_children, expectedValue: scorm12_constants.core_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.student_id', fieldName: 'cmi.core.student_id',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.student_name', fieldName: 'cmi.core.student_name',
expectedError: read_only, expectedError: read_only,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.lesson_location', fieldName: 'cmi.core.lesson_location',
limit: 255, limit: 255,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.credit', fieldName: 'cmi.core.credit',
expectedError: read_only, expectedError: read_only,
}); });
h.checkRead({ h.checkRead({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.lesson_status', fieldName: 'cmi.core.lesson_status',
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.lesson_status', fieldName: 'cmi.core.lesson_status',
validValues: scorm12_values.validLessonStatus, validValues: scorm12_values.validLessonStatus,
invalidValues: scorm12_values.invalidLessonStatus, invalidValues: scorm12_values.invalidLessonStatus,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.entry', fieldName: 'cmi.core.entry',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.total_time', fieldName: 'cmi.core.total_time',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.lesson_mode', fieldName: 'cmi.core.lesson_mode',
expectedValue: 'normal', expectedValue: 'normal',
expectedError: read_only, expectedError: read_only,
}); });
h.checkWrite({ h.checkWrite({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.exit', fieldName: 'cmi.core.exit',
valueToTest: 'suspend', valueToTest: 'suspend',
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.exit', fieldName: 'cmi.core.exit',
validValues: scorm12_values.validExit, validValues: scorm12_values.validExit,
invalidValues: scorm12_values.invalidExit, invalidValues: scorm12_values.invalidExit,
}); });
h.checkWriteOnly({ h.checkWriteOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.session_time', fieldName: 'cmi.core.session_time',
valueToTest: '00:00:00', valueToTest: '00:00:00',
expectedError: write_only, expectedError: write_only,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.session_time', fieldName: 'cmi.core.session_time',
validValues: scorm12_values.validHHMMSS, validValues: scorm12_values.validHHMMSS,
invalidValues: scorm12_values.invalidHHMMSS, invalidValues: scorm12_values.invalidHHMMSS,
@@ -407,25 +466,25 @@ describe('SCORM 1.2 CMI Tests', () => {
* cmi.core.score Properties * cmi.core.score Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.score._children', fieldName: 'cmi.core.score._children',
expectedValue: scorm12_constants.score_children, expectedValue: scorm12_constants.score_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.score.raw', fieldName: 'cmi.core.score.raw',
validValues: scorm12_values.validScoreRange, validValues: scorm12_values.validScoreRange,
invalidValues: scorm12_values.invalidScoreRange, invalidValues: scorm12_values.invalidScoreRange,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.score.min', fieldName: 'cmi.core.score.min',
validValues: scorm12_values.validScoreRange, validValues: scorm12_values.validScoreRange,
invalidValues: scorm12_values.invalidScoreRange, invalidValues: scorm12_values.invalidScoreRange,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.core.score.max', fieldName: 'cmi.core.score.max',
validValues: scorm12_values.validScoreRange, validValues: scorm12_values.validScoreRange,
invalidValues: scorm12_values.invalidScoreRange, invalidValues: scorm12_values.invalidScoreRange,
@@ -435,13 +494,13 @@ describe('SCORM 1.2 CMI Tests', () => {
* cmi.objectives Properties * cmi.objectives Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._children', fieldName: 'cmi.objectives._children',
expectedValue: scorm12_constants.objectives_children, expectedValue: scorm12_constants.objectives_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._count', fieldName: 'cmi.objectives._count',
expectedValue: 0, expectedValue: 0,
expectedError: invalid_set, expectedError: invalid_set,
@@ -451,23 +510,23 @@ describe('SCORM 1.2 CMI Tests', () => {
* cmi.student_data Properties * cmi.student_data Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_data._children', fieldName: 'cmi.student_data._children',
expectedValue: scorm12_constants.student_data_children, expectedValue: scorm12_constants.student_data_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_data.mastery_score', fieldName: 'cmi.student_data.mastery_score',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_data.max_time_allowed', fieldName: 'cmi.student_data.max_time_allowed',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_data.time_limit_action', fieldName: 'cmi.student_data.time_limit_action',
expectedError: read_only, expectedError: read_only,
}); });
@@ -476,31 +535,31 @@ describe('SCORM 1.2 CMI Tests', () => {
* cmi.student_preference Properties * cmi.student_preference Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_preference._children', fieldName: 'cmi.student_preference._children',
expectedValue: scorm12_constants.student_preference_children, expectedValue: scorm12_constants.student_preference_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_preference.audio', fieldName: 'cmi.student_preference.audio',
validValues: scorm12_values.valid0To100Range.concat(['-1']), validValues: scorm12_values.valid0To100Range.concat(['-1']),
invalidValues: scorm12_values.invalid0To100Range, invalidValues: scorm12_values.invalid0To100Range,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_preference.language', fieldName: 'cmi.student_preference.language',
limit: 255, limit: 255,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_preference.speed', fieldName: 'cmi.student_preference.speed',
validValues: scorm12_values.validSpeedRange, validValues: scorm12_values.validSpeedRange,
invalidValues: scorm12_values.invalidSpeedRange, invalidValues: scorm12_values.invalidSpeedRange,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.student_preference.text', fieldName: 'cmi.student_preference.text',
validValues: scorm12_values.validIntegerScaledRange, validValues: scorm12_values.validIntegerScaledRange,
invalidValues: scorm12_values.invalidIntegerScaledRange, invalidValues: scorm12_values.invalidIntegerScaledRange,
@@ -510,20 +569,20 @@ describe('SCORM 1.2 CMI Tests', () => {
* cmi.interactions Properties * cmi.interactions Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.interactions._children', fieldName: 'cmi.interactions._children',
expectedValue: scorm12_constants.interactions_children, expectedValue: scorm12_constants.interactions_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.interactions._count', fieldName: 'cmi.interactions._count',
expectedValue: 0, expectedValue: 0,
expectedError: invalid_set, expectedError: invalid_set,
}); });
it('should export JSON', () => { it('should export JSON', () => {
const cmiObj = cmi(); const cmiObj = cmiInitialized();
cmiObj.objectives.childArray.push(new CMIObjectivesObject()); cmiObj.objectives.childArray.push(new CMIObjectivesObject());
cmiObj.interactions.childArray.push(new CMIInteractionsObject()); cmiObj.interactions.childArray.push(new CMIInteractionsObject());
expect( expect(
@@ -536,15 +595,6 @@ describe('SCORM 1.2 CMI Tests', () => {
}); });
describe('CMIInteractionsObject Tests', () => { describe('CMIInteractionsObject Tests', () => {
const interaction = () => {
return new CMIInteractionsObject();
};
const interactionInitialized = () => {
const cmi = new CMIInteractionsObject();
cmi.initialize();
return cmi;
};
/** /**
* cmi.interactions.n object * cmi.interactions.n object
*/ */
@@ -655,10 +705,6 @@ describe('SCORM 1.2 CMI Tests', () => {
}); });
describe('CMIInteractionsObjectivesObject Tests', () => { describe('CMIInteractionsObjectivesObject Tests', () => {
const interactionObjective = () => {
return new CMIInteractionsObjectivesObject();
};
/** /**
* cmi.interactions.n.objectives.n object * cmi.interactions.n.objectives.n object
*/ */
@@ -676,9 +722,6 @@ describe('SCORM 1.2 CMI Tests', () => {
}); });
describe('CMIInteractionsCorrectResponsesObject Tests', () => { describe('CMIInteractionsCorrectResponsesObject Tests', () => {
const correctResponse = () => {
return new CMIInteractionsCorrectResponsesObject();
};
/** /**
* cmi.interactions.n.correct_responses.n object * cmi.interactions.n.correct_responses.n object
@@ -698,10 +741,6 @@ describe('SCORM 1.2 CMI Tests', () => {
}); });
describe('CMIObjectivesObject Tests', () => { describe('CMIObjectivesObject Tests', () => {
const objective = () => {
return new CMIObjectivesObject();
};
/** /**
* cmi.objectives.n object * cmi.objectives.n object
*/ */

View File

@@ -5,7 +5,7 @@ import {
ADL, ADL,
CMI, CMI,
CMICommentsObject, CMICommentsObject,
CMICommentsFromLMSObject, CMIInteractionsCorrectResponsesObject, CMIInteractionsCorrectResponsesObject,
CMIInteractionsObject, CMIInteractionsObject,
CMIInteractionsObjectivesObject, CMIInteractionsObjectivesObject,
CMIObjectivesObject, CMIObjectivesObject,
@@ -16,16 +16,99 @@ import {scorm2004_values} from '../../src/constants/field_values';
const read_only = scorm2004_error_codes.READ_ONLY_ELEMENT; const read_only = scorm2004_error_codes.READ_ONLY_ELEMENT;
const write_only = scorm2004_error_codes.WRITE_ONLY_ELEMENT; const write_only = scorm2004_error_codes.WRITE_ONLY_ELEMENT;
const invalid_set = scorm2004_error_codes.INVALID_SET_VALUE;
const type_mismatch = scorm2004_error_codes.TYPE_MISMATCH; const type_mismatch = scorm2004_error_codes.TYPE_MISMATCH;
const cmi = () => {
return new CMI();
};
const cmiInitialized = () => {
const cmiObj = new CMI();
cmiObj.initialize();
return cmiObj;
};
const comments = () => {
return new CMICommentsObject();
};
const lmsComments = () => {
return new CMICommentsObject(true);
};
const lmsCommentsInitialized = () => {
const cmi = lmsComments();
cmi.initialize();
return cmi;
};
const interaction = () => {
return new CMIInteractionsObject();
};
const interactionInitialized = () => {
const cmi = new CMIInteractionsObject();
cmi.initialize();
return cmi;
};
const objective = () => {
return new CMIObjectivesObject();
};
const objectiveInitialized = () => {
const cmi = new CMIObjectivesObject();
cmi.initialize();
return cmi;
};
const interactionObjective = () => {
return new CMIInteractionsObjectivesObject();
};
const correctResponse = () => {
return new CMIInteractionsCorrectResponsesObject();
};
const adl = () => {
return new ADL();
};
describe('SCORM 2004 CMI Tests', () => { describe('SCORM 2004 CMI Tests', () => {
describe('getCurrentTotalTime()', () => {
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: 'PT0S',
sessionTime: 'PT15M45S',
expectedTotal: 'PT15M45S',
totalFieldName: 'cmi.total_time',
sessionFieldName: 'cmi.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: 'PT60S',
sessionTime: 'PT15M45S',
expectedTotal: 'PT16M45S',
totalFieldName: 'cmi.total_time',
sessionFieldName: 'cmi.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: 'PT60S',
sessionTime: 'PT0S',
expectedTotal: 'PT1M',
totalFieldName: 'cmi.total_time',
sessionFieldName: 'cmi.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: 'PT25H1M0S',
sessionTime: 'PT13H',
expectedTotal: 'P1DT14H1M',
totalFieldName: 'cmi.total_time',
sessionFieldName: 'cmi.session_time',
});
h.checkGetCurrentTotalTime({
cmi: cmi(),
startingTotal: 'PT48H1M45S',
sessionTime: 'PT13H16S',
expectedTotal: 'P2DT13H2M1S',
totalFieldName: 'cmi.total_time',
sessionFieldName: 'cmi.session_time',
});
});
describe('CMI Spec Tests', () => { describe('CMI Spec Tests', () => {
describe('Pre-Initialize Tests', () => { describe('Pre-Initialize Tests', () => {
const cmi = () => {
return new CMI();
};
/** /**
* Base CMI Properties * Base CMI Properties
*/ */
@@ -324,147 +407,141 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('Post-Initialize Tests', () => { describe('Post-Initialize Tests', () => {
const cmi = () => {
const cmiObj = new CMI();
cmiObj.initialize();
return cmiObj;
};
/** /**
* Base CMI Properties * Base CMI Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi._version', fieldName: 'cmi._version',
expectedValue: '1.0', expectedValue: '1.0',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi._children', fieldName: 'cmi._children',
expectedValue: scorm2004_constants.cmi_children, expectedValue: scorm2004_constants.cmi_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.completion_status', fieldName: 'cmi.completion_status',
expectedError: type_mismatch, expectedError: type_mismatch,
validValues: scorm2004_values.validCStatus, validValues: scorm2004_values.validCStatus,
invalidValues: scorm2004_values.invalidCStatus, invalidValues: scorm2004_values.invalidCStatus,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.completion_threshold', fieldName: 'cmi.completion_threshold',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.credit', fieldName: 'cmi.credit',
expectedValue: 'credit', expectedValue: 'credit',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.entry', fieldName: 'cmi.entry',
expectedError: read_only, expectedError: read_only,
}); });
h.checkWriteOnly({ h.checkWriteOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.exit', fieldName: 'cmi.exit',
expectedError: write_only, expectedError: write_only,
valueToTest: 'time-out', valueToTest: 'time-out',
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.exit', fieldName: 'cmi.exit',
validValues: scorm2004_values.validExit, validValues: scorm2004_values.validExit,
invalidValues: scorm2004_values.invalidExit, invalidValues: scorm2004_values.invalidExit,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.launch_data', fieldName: 'cmi.launch_data',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_id', fieldName: 'cmi.learner_id',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_name', fieldName: 'cmi.learner_name',
expectedError: read_only, expectedError: read_only,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.location', fieldName: 'cmi.location',
limit: 1000, limit: 1000,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.max_time_allowed', fieldName: 'cmi.max_time_allowed',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.mode', fieldName: 'cmi.mode',
expectedValue: 'normal', expectedValue: 'normal',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.max_time_allowed', fieldName: 'cmi.max_time_allowed',
expectedError: read_only, expectedError: read_only,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.progress_measure', fieldName: 'cmi.progress_measure',
validValues: scorm2004_values.valid0To1Range, validValues: scorm2004_values.valid0To1Range,
invalidValues: scorm2004_values.invalid0To1Range, invalidValues: scorm2004_values.invalid0To1Range,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.scaled_passing_score', fieldName: 'cmi.scaled_passing_score',
expectedError: read_only, expectedError: read_only,
}); });
h.checkWriteOnly({ h.checkWriteOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.session_time', fieldName: 'cmi.session_time',
valueToTest: 'P0S', valueToTest: 'P0S',
expectedError: write_only, expectedError: write_only,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.session_time', fieldName: 'cmi.session_time',
validValues: scorm2004_values.validISO8601Durations, validValues: scorm2004_values.validISO8601Durations,
invalidValues: scorm2004_values.invalidISO8601Durations, invalidValues: scorm2004_values.invalidISO8601Durations,
}); });
h.checkRead({ h.checkRead({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.success_status', fieldName: 'cmi.success_status',
expectedValue: 'unknown', expectedValue: 'unknown',
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.success_status', fieldName: 'cmi.success_status',
validValues: scorm2004_values.validSStatus, validValues: scorm2004_values.validSStatus,
invalidValues: scorm2004_values.invalidSStatus, invalidValues: scorm2004_values.invalidSStatus,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.suspend_data', fieldName: 'cmi.suspend_data',
limit: 64000, limit: 64000,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.time_limit_action', fieldName: 'cmi.time_limit_action',
expectedValue: 'continue,no message', expectedValue: 'continue,no message',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.total_time', fieldName: 'cmi.total_time',
expectedValue: '0', expectedValue: '0',
expectedError: read_only, expectedError: read_only,
@@ -474,19 +551,19 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.learner_preference Properties * cmi.learner_preference Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_preference._children', fieldName: 'cmi.learner_preference._children',
expectedValue: scorm2004_constants.student_preference_children, expectedValue: scorm2004_constants.student_preference_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_preference.audio_level', fieldName: 'cmi.learner_preference.audio_level',
validValues: scorm2004_values.valid0To100Range, validValues: scorm2004_values.valid0To100Range,
invalidValues: scorm2004_values.invalid0To100Range, invalidValues: scorm2004_values.invalid0To100Range,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_preference.language', fieldName: 'cmi.learner_preference.language',
validValues: [ validValues: [
'en', 'en',
@@ -500,13 +577,13 @@ describe('SCORM 2004 CMI Tests', () => {
], ],
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_preference.delivery_speed', fieldName: 'cmi.learner_preference.delivery_speed',
validValues: scorm2004_values.valid0To100Range, validValues: scorm2004_values.valid0To100Range,
invalidValues: scorm2004_values.invalid0To100Range, invalidValues: scorm2004_values.invalid0To100Range,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.learner_preference.audio_captioning', fieldName: 'cmi.learner_preference.audio_captioning',
validValues: scorm2004_values.validIntegerScaledRange, validValues: scorm2004_values.validIntegerScaledRange,
invalidValues: scorm2004_values.invalidIntegerScaledRange, invalidValues: scorm2004_values.invalidIntegerScaledRange,
@@ -516,13 +593,13 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.objectives Properties * cmi.objectives Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._children', fieldName: 'cmi.objectives._children',
expectedValue: scorm2004_constants.objectives_children, expectedValue: scorm2004_constants.objectives_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._count', fieldName: 'cmi.objectives._count',
expectedValue: 0, expectedValue: 0,
expectedError: read_only, expectedError: read_only,
@@ -532,31 +609,31 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.score Properties * cmi.score Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.score._children', fieldName: 'cmi.score._children',
expectedValue: scorm2004_constants.score_children, expectedValue: scorm2004_constants.score_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.score.scaled', fieldName: 'cmi.score.scaled',
validValues: scorm2004_values.validScaledRange, validValues: scorm2004_values.validScaledRange,
invalidValues: scorm2004_values.invalidScaledRange, invalidValues: scorm2004_values.invalidScaledRange,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.score.raw', fieldName: 'cmi.score.raw',
validValues: scorm2004_values.validScoreRange, validValues: scorm2004_values.validScoreRange,
invalidValues: scorm2004_values.invalidScoreRange, invalidValues: scorm2004_values.invalidScoreRange,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.score.min', fieldName: 'cmi.score.min',
validValues: scorm2004_values.validScoreRange, validValues: scorm2004_values.validScoreRange,
invalidValues: scorm2004_values.invalidScoreRange, invalidValues: scorm2004_values.invalidScoreRange,
}); });
h.checkValidValues({ h.checkValidValues({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.score.max', fieldName: 'cmi.score.max',
validValues: scorm2004_values.validScoreRange, validValues: scorm2004_values.validScoreRange,
invalidValues: scorm2004_values.invalidScoreRange, invalidValues: scorm2004_values.invalidScoreRange,
@@ -566,13 +643,13 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.comments_from_learner Properties * cmi.comments_from_learner Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.comments_from_learner._children', fieldName: 'cmi.comments_from_learner._children',
expectedValue: scorm2004_constants.comments_children, expectedValue: scorm2004_constants.comments_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.comments_from_learner._count', fieldName: 'cmi.comments_from_learner._count',
expectedValue: 0, expectedValue: 0,
expectedError: read_only, expectedError: read_only,
@@ -582,13 +659,13 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.comments_from_lms Properties * cmi.comments_from_lms Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.comments_from_lms._children', fieldName: 'cmi.comments_from_lms._children',
expectedValue: scorm2004_constants.comments_children, expectedValue: scorm2004_constants.comments_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.comments_from_lms._count', fieldName: 'cmi.comments_from_lms._count',
expectedValue: 0, expectedValue: 0,
expectedError: read_only, expectedError: read_only,
@@ -598,13 +675,13 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.interactions Properties * cmi.interactions Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.interactions._children', fieldName: 'cmi.interactions._children',
expectedValue: scorm2004_constants.interactions_children, expectedValue: scorm2004_constants.interactions_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.interactions._count', fieldName: 'cmi.interactions._count',
expectedValue: 0, expectedValue: 0,
expectedError: read_only, expectedError: read_only,
@@ -614,20 +691,20 @@ describe('SCORM 2004 CMI Tests', () => {
* cmi.objectives Properties * cmi.objectives Properties
*/ */
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._children', fieldName: 'cmi.objectives._children',
expectedValue: scorm2004_constants.objectives_children, expectedValue: scorm2004_constants.objectives_children,
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._count', fieldName: 'cmi.objectives._count',
expectedValue: 0, expectedValue: 0,
expectedError: read_only, expectedError: read_only,
}); });
it('should export JSON', () => { it('should export JSON', () => {
const cmiObj = cmi(); const cmiObj = cmiInitialized();
cmiObj.objectives.childArray.push(new CMIObjectivesObject()); cmiObj.objectives.childArray.push(new CMIObjectivesObject());
cmiObj.interactions.childArray.push(new CMIInteractionsObject()); cmiObj.interactions.childArray.push(new CMIInteractionsObject());
expect( expect(
@@ -640,10 +717,6 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('CMICommentsObject Tests', () => { describe('CMICommentsObject Tests', () => {
const comments = () => {
return new CMICommentsObject();
};
/** /**
* cmi.comments_from_learner.n object * cmi.comments_from_learner.n object
*/ */
@@ -682,62 +755,53 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('CMICommentsFromLMSObject Tests', () => { describe('CMICommentsFromLMSObject Tests', () => {
const comments = () => {
return new CMICommentsObject(true);
};
const commentsInitialized = () => {
const cmi = new CMICommentsObject(true);
cmi.initialize();
return cmi;
};
/** /**
* cmi.comments_from_lms.n object * cmi.comments_from_lms.n object
*/ */
h.checkValidValues({ h.checkValidValues({
cmi: comments(), cmi: lmsComments(),
fieldName: 'cmi.comment', fieldName: 'cmi.comment',
validValues: scorm2004_values.validComment, validValues: scorm2004_values.validComment,
invalidValues: scorm2004_values.invalidComment, invalidValues: scorm2004_values.invalidComment,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
cmi: comments(), cmi: lmsComments(),
fieldName: 'cmi.location', fieldName: 'cmi.location',
expectedError: type_mismatch, expectedError: type_mismatch,
limit: 250, limit: 250,
}); });
h.checkReadAndWrite({ h.checkReadAndWrite({
cmi: comments(), cmi: lmsComments(),
fieldName: 'cmi.timestamp', fieldName: 'cmi.timestamp',
valueToTest: scorm2004_values.validTimestamps[0], valueToTest: scorm2004_values.validTimestamps[0],
}); });
h.checkValidValues({ h.checkValidValues({
cmi: comments(), cmi: lmsComments(),
fieldName: 'cmi.timestamp', fieldName: 'cmi.timestamp',
validValues: scorm2004_values.validTimestamps, validValues: scorm2004_values.validTimestamps,
invalidValues: scorm2004_values.invalidTimestamps, invalidValues: scorm2004_values.invalidTimestamps,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: commentsInitialized(), cmi: lmsCommentsInitialized(),
fieldName: 'cmi.comment', fieldName: 'cmi.comment',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: commentsInitialized(), cmi: lmsCommentsInitialized(),
fieldName: 'cmi.location', fieldName: 'cmi.location',
expectedError: read_only, expectedError: read_only,
}); });
h.checkReadOnly({ h.checkReadOnly({
cmi: commentsInitialized(), cmi: lmsCommentsInitialized(),
fieldName: 'cmi.timestamp', fieldName: 'cmi.timestamp',
expectedError: read_only, expectedError: read_only,
}); });
it('should export JSON', () => { it('should export JSON', () => {
const cmi = comments(); const cmi = lmsComments();
expect( expect(
JSON.stringify(cmi), JSON.stringify(cmi),
).to.equal('{"comment":"","location":"","timestamp":""}'); ).to.equal('{"comment":"","location":"","timestamp":""}');
@@ -745,15 +809,6 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('CMIInteractionsObject Tests', () => { describe('CMIInteractionsObject Tests', () => {
const interaction = () => {
return new CMIInteractionsObject();
};
const interactionInitialized = () => {
const cmi = new CMIInteractionsObject();
cmi.initialize();
return cmi;
};
/** /**
* cmi.interactions.n object * cmi.interactions.n object
*/ */
@@ -853,15 +908,6 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('CMIObjectivesObject Tests', () => { describe('CMIObjectivesObject Tests', () => {
const objective = () => {
return new CMIObjectivesObject();
};
const objectiveInitialized = () => {
const cmi = new CMIObjectivesObject();
cmi.initialize();
return cmi;
};
/** /**
* cmi.objectives.n object * cmi.objectives.n object
*/ */
@@ -954,10 +1000,6 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('CMIInteractionsObjectivesObject Tests', () => { describe('CMIInteractionsObjectivesObject Tests', () => {
const interactionObjective = () => {
return new CMIInteractionsObjectivesObject();
};
/** /**
* cmi.interactions.n.objectives.n object * cmi.interactions.n.objectives.n object
*/ */
@@ -975,10 +1017,6 @@ describe('SCORM 2004 CMI Tests', () => {
}); });
describe('CMIInteractionsCorrectResponsesObject Tests', () => { describe('CMIInteractionsCorrectResponsesObject Tests', () => {
const correctResponse = () => {
return new CMIInteractionsCorrectResponsesObject();
};
/** /**
* cmi.interactions.n.correct_responses.n object * cmi.interactions.n.correct_responses.n object
*/ */
@@ -997,10 +1035,6 @@ describe('SCORM 2004 CMI Tests', () => {
describe('ADL Tests', () => { describe('ADL Tests', () => {
describe('ADLNav Tests', () => { describe('ADLNav Tests', () => {
const adl = () => {
return new ADL();
};
/** /**
* cmi.interactions.n.correct_responses.n object * cmi.interactions.n.correct_responses.n object
*/ */

View File

@@ -140,3 +140,22 @@ export const checkValidValues = (
} }
}); });
}; };
export const checkGetCurrentTotalTime = (
{
cmi: cmi,
totalFieldName,
sessionFieldName,
startingTotal,
sessionTime,
expectedTotal,
}) => {
it(`Should return ${expectedTotal} with a starting time of ${startingTotal} and a session time of ${sessionTime}`,
() => {
eval(`${totalFieldName} = '${startingTotal}'`);
eval(`${sessionFieldName} = '${sessionTime}'`);
expect(
cmi.getCurrentTotalTime(),
).to.equal(expectedTotal);
});
};

16
test/exceptions.spec.js Normal file
View File

@@ -0,0 +1,16 @@
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {ValidationError} from '../src/exceptions';
describe('Exception Tests', () => {
it('ValidationException should return message string', () => {
expect(
new ValidationError(0).message,
).to.equal('0');
});
it('ValidationException should return errorCode number', () => {
expect(
new ValidationError(0).errorCode,
).to.equal(0);
});
});

View File

@@ -56,59 +56,59 @@ describe('Utility Tests', () => {
}); });
describe('getSecondsAsISODuration()', () => { describe('getSecondsAsISODuration()', () => {
it('10 returns P10S', () => { it('10 returns PT10S', () => {
expect( expect(
Utilities.getSecondsAsISODuration(10), Utilities.getSecondsAsISODuration(10),
).to.equal('P10S'); ).to.equal('PT10S');
}); });
it('60 returns P1M', () => { it('60 returns PT1M', () => {
expect( expect(
Utilities.getSecondsAsISODuration(60), Utilities.getSecondsAsISODuration(60),
).to.equal('P1M'); ).to.equal('PT1M');
}); });
it('3600 returns P1H', () => { it('3600 returns PT1H', () => {
expect( expect(
Utilities.getSecondsAsISODuration(3600), Utilities.getSecondsAsISODuration(3600),
).to.equal('P1H'); ).to.equal('PT1H');
}); });
it('70 returns P1M10S', () => { it('70 returns PT1M10S', () => {
expect( expect(
Utilities.getSecondsAsISODuration(70), Utilities.getSecondsAsISODuration(70),
).to.equal('P1M10S'); ).to.equal('PT1M10S');
}); });
it('3670 returns P1H1M10S', () => { it('3670 returns PT1H1M10S', () => {
expect( expect(
Utilities.getSecondsAsISODuration(3670), Utilities.getSecondsAsISODuration(3670),
).to.equal('P1H1M10S'); ).to.equal('PT1H1M10S');
}); });
it('90000 returns P1D1H', () => { it('90000 returns P1DT1H', () => {
expect( expect(
Utilities.getSecondsAsISODuration(90000), Utilities.getSecondsAsISODuration(90000),
).to.equal('P1D1H'); ).to.equal('P1DT1H');
}); });
it('90061 returns P1D1H1M1S', () => { it('90061 returns P1DT1H1M1S', () => {
expect( expect(
Utilities.getSecondsAsISODuration(90061), Utilities.getSecondsAsISODuration(90061),
).to.equal('P1D1H1M1S'); ).to.equal('P1DT1H1M1S');
}); });
it('-3600 returns P0S, negative time not allowed in SCORM session times', it('-3600 returns PT0S, negative time not allowed in SCORM session times',
() => { () => {
expect( expect(
Utilities.getSecondsAsISODuration(-3600), Utilities.getSecondsAsISODuration(-3600),
).to.equal('P0S'); ).to.equal('PT0S');
}); });
it('Empty seconds returns P0S', () => { it('Empty seconds returns PT0S', () => {
expect( expect(
Utilities.getSecondsAsISODuration(null), Utilities.getSecondsAsISODuration(null),
).to.equal('P0S'); ).to.equal('PT0S');
}); });
}); });
@@ -224,27 +224,27 @@ describe('Utility Tests', () => {
describe('addTwoDurations()', () => { describe('addTwoDurations()', () => {
it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => { it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => {
expect( expect(
Utilities.addTwoDurations('P1H5M30.5S', 'PT15M10S', Utilities.addTwoDurations('PT1H5M30.5S', 'PT15M10S',
scorm2004_regex.CMITimespan), scorm2004_regex.CMITimespan),
).to.equal('P1H20M40.5S'); ).to.equal('PT1H20M40.5S');
}); });
it('P1Y364D plus P2D1H45M52S equals P732D1H45M52S', () => { it('P1Y364D plus P2DT1H45M52S equals P732DT1H45M52S', () => {
expect( expect(
Utilities.addTwoDurations('P1Y364D', 'P2D1H45M52S', Utilities.addTwoDurations('P1Y364D', 'P2DT1H45M52S',
scorm2004_regex.CMITimespan), scorm2004_regex.CMITimespan),
).to.equal('P732D1H45M52S'); ).to.equal('P732DT1H45M52S');
}); });
it('Invalid plus valid equals valid', () => { it('Invalid plus valid equals valid', () => {
expect( expect(
Utilities.addTwoDurations('NOT A VALID DURATION', 'P1H30M45S', Utilities.addTwoDurations('NOT A VALID DURATION', 'PT1H30M45S',
scorm2004_regex.CMITimespan), scorm2004_regex.CMITimespan),
).to.equal('P1H30M45S'); ).to.equal('PT1H30M45S');
}); });
it('Valid plus invalid equals valid', () => { it('Valid plus invalid equals valid', () => {
expect( expect(
Utilities.addTwoDurations('P1H30M45S', 'NOT A VALID DURATION', Utilities.addTwoDurations('PT1H30M45S', 'NOT A VALID DURATION',
scorm2004_regex.CMITimespan), scorm2004_regex.CMITimespan),
).to.equal('P1H30M45S'); ).to.equal('PT1H30M45S');
}); });
}); });