Fixing eslint issues, and still working on test cases

This commit is contained in:
Jonathan Putney
2019-11-11 15:05:02 -05:00
parent 5dae5ca0ae
commit 2f5c9804c9
19 changed files with 3667 additions and 1718 deletions

View File

@@ -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);
});
});
});

View 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});
});
});
});

View File

@@ -1,220 +1,277 @@
import { expect } from 'chai';
import {describe, it} from "mocha";
import * as Utilities from '../src/utilities';
import {scorm12_regex, scorm2004_regex} from "../src/regex";
import {expect} from 'chai';
import {describe, it} from 'mocha';
import * as Utilities from '../src/utilities';
import {scorm12_regex, scorm2004_regex} from '../src/regex';
describe('Utility Tests', () => {
describe('function getSecondsAsHHMMSS()', () => {
it('10 returns 00:00:10', () => {
expect(
Utilities.getSecondsAsHHMMSS(10)
).to.equal('00:00:10');
});
describe('getSecondsAsHHMMSS()', () => {
it('10 returns 00:00:10', () => {
expect(
Utilities.getSecondsAsHHMMSS(10),
).to.equal('00:00:10');
});
it('60 returns 00:01:00', () => {
expect(
Utilities.getSecondsAsHHMMSS(60)
).to.equal('00:01:00');
});
it('60 returns 00:01:00', () => {
expect(
Utilities.getSecondsAsHHMMSS(60),
).to.equal('00:01:00');
});
it('3600 returns 01:00:00', () => {
expect(
Utilities.getSecondsAsHHMMSS(3600)
).to.equal('01:00:00');
});
it('3600 returns 01:00:00', () => {
expect(
Utilities.getSecondsAsHHMMSS(3600),
).to.equal('01:00:00');
});
it('70 returns 00:01:10', () => {
expect(
Utilities.getSecondsAsHHMMSS(70)
).to.equal('00:01:10');
});
it('70 returns 00:01:10', () => {
expect(
Utilities.getSecondsAsHHMMSS(70),
).to.equal('00:01:10');
});
it('3670 returns 01:01:10', () => {
expect(
Utilities.getSecondsAsHHMMSS(3670)
).to.equal('01:01:10');
});
it('3670 returns 01:01:10', () => {
expect(
Utilities.getSecondsAsHHMMSS(3670),
).to.equal('01:01:10');
});
it('90000 returns 25:00:00, check for hours greater than 24', () => {
expect(
Utilities.getSecondsAsHHMMSS(90000)
).to.equal('25:00:00');
});
it('90000 returns 25:00:00, check for hours greater than 24', () => {
expect(
Utilities.getSecondsAsHHMMSS(90000),
).to.equal('25:00:00');
});
it('-3600 returns 00:00:00, negative time not allowed in SCORM session times', () => {
expect(
Utilities.getSecondsAsHHMMSS(-3600)
).to.equal('00:00:00');
});
it('-3600 returns 00:00:00, negative time not allowed in SCORM session times',
() => {
expect(
Utilities.getSecondsAsHHMMSS(-3600),
).to.equal('00:00:00');
});
it('Empty seconds returns 00:00:00', () => {
expect(
Utilities.getSecondsAsHHMMSS(null)
).to.equal('00:00:00');
});
});
it('Empty seconds returns 00:00:00', () => {
expect(
Utilities.getSecondsAsHHMMSS(null),
).to.equal('00:00:00');
});
});
describe('function getSecondsAsISODuration()', () => {
it('10 returns P10S', () => {
expect(
Utilities.getSecondsAsISODuration(10)
).to.equal('P10S');
});
describe('getSecondsAsISODuration()', () => {
it('10 returns P10S', () => {
expect(
Utilities.getSecondsAsISODuration(10),
).to.equal('P10S');
});
it('60 returns P1M', () => {
expect(
Utilities.getSecondsAsISODuration(60)
).to.equal('P1M');
});
it('60 returns P1M', () => {
expect(
Utilities.getSecondsAsISODuration(60),
).to.equal('P1M');
});
it('3600 returns P1H', () => {
expect(
Utilities.getSecondsAsISODuration(3600)
).to.equal('P1H');
});
it('3600 returns P1H', () => {
expect(
Utilities.getSecondsAsISODuration(3600),
).to.equal('P1H');
});
it('70 returns P1M10S', () => {
expect(
Utilities.getSecondsAsISODuration(70)
).to.equal('P1M10S');
});
it('70 returns P1M10S', () => {
expect(
Utilities.getSecondsAsISODuration(70),
).to.equal('P1M10S');
});
it('3670 returns P1H1M10S', () => {
expect(
Utilities.getSecondsAsISODuration(3670)
).to.equal('P1H1M10S');
});
it('3670 returns P1H1M10S', () => {
expect(
Utilities.getSecondsAsISODuration(3670),
).to.equal('P1H1M10S');
});
it('90000 returns P1D1H', () => {
expect(
Utilities.getSecondsAsISODuration(90000)
).to.equal('P1D1H');
});
it('90000 returns P1D1H', () => {
expect(
Utilities.getSecondsAsISODuration(90000),
).to.equal('P1D1H');
});
it('90061 returns P1D1H1M1S', () => {
expect(
Utilities.getSecondsAsISODuration(90061)
).to.equal('P1D1H1M1S');
});
it('90061 returns P1D1H1M1S', () => {
expect(
Utilities.getSecondsAsISODuration(90061),
).to.equal('P1D1H1M1S');
});
it('-3600 returns P0S, negative time not allowed in SCORM session times', () => {
expect(
Utilities.getSecondsAsISODuration(-3600)
).to.equal('P0S');
});
it('-3600 returns P0S, negative time not allowed in SCORM session times',
() => {
expect(
Utilities.getSecondsAsISODuration(-3600),
).to.equal('P0S');
});
it('Empty seconds returns P0S', () => {
expect(
Utilities.getSecondsAsISODuration(null)
).to.equal('P0S');
});
});
it('Empty seconds returns P0S', () => {
expect(
Utilities.getSecondsAsISODuration(null),
).to.equal('P0S');
});
});
describe('function getTimeAsSeconds()', () => {
it('00:00:10 returns 10', () => {
expect(
Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan)
).to.equal(10);
});
describe('getTimeAsSeconds()', () => {
it('00:00:10 returns 10', () => {
expect(
Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan),
).to.equal(10);
});
it('00:01:10 returns 70', () => {
expect(
Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan)
).to.equal(70);
});
it('00:01:10 returns 70', () => {
expect(
Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan),
).to.equal(70);
});
it('01:01:10 returns 3670', () => {
expect(
Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan)
).to.equal(3670);
});
it('01:01:10 returns 3670', () => {
expect(
Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan),
).to.equal(3670);
});
it('100:00:00 returns 3670', () => {
expect(
Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan)
).to.equal(360000);
});
it('100:00:00 returns 3670', () => {
expect(
Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan),
).to.equal(360000);
});
it('-01:00:00 returns 0', () => {
expect(
Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan)
).to.equal(0);
});
it('-01:00:00 returns 0', () => {
expect(
Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan),
).to.equal(0);
});
it('Number value returns 0', () => {
expect(
Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan)
).to.equal(0);
});
it('Number value returns 0', () => {
expect(
Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan),
).to.equal(0);
});
it('boolean value returns 0', () => {
expect(
Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan)
).to.equal(0);
});
it('boolean value returns 0', () => {
expect(
Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan),
).to.equal(0);
});
it('Empty value returns 0', () => {
expect(
Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan)
).to.equal(0);
});
});
it('Empty value returns 0', () => {
expect(
Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan),
).to.equal(0);
});
});
describe('function getDurationAsSeconds()', () => {
it('P0S returns 0', () => {
expect(
Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan)
).to.equal(0);
});
describe('getDurationAsSeconds()', () => {
it('P0S returns 0', () => {
expect(
Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan),
).to.equal(0);
});
it('P70S returns 70', () => {
expect(
Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan)
).to.equal(70);
});
it('P70S returns 70', () => {
expect(
Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan),
).to.equal(70);
});
it('PT1M10S returns 70', () => {
expect(
Utilities.getDurationAsSeconds('PT1M10S', scorm2004_regex.CMITimespan)
).to.equal(70);
});
it('PT1M10S returns 70', () => {
expect(
Utilities.getDurationAsSeconds('PT1M10S',
scorm2004_regex.CMITimespan),
).to.equal(70);
});
it('P1D returns 86400', () => {
expect(
Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan)
).to.equal(86400);
});
it('P1D returns 86400', () => {
expect(
Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan),
).to.equal(86400);
});
it('P1M returns number of seconds for one month from now', () => {
const now = new Date();
let oneMonthFromNow = new Date(now);
oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1);
it('P1M returns number of seconds for one month from now', () => {
const now = new Date();
const oneMonthFromNow = new Date(now);
oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1);
expect(
Utilities.getDurationAsSeconds('P1M', scorm2004_regex.CMITimespan)
).to.equal((oneMonthFromNow - now) / 1000.0);
});
expect(
Utilities.getDurationAsSeconds('P1M', scorm2004_regex.CMITimespan),
).to.equal((oneMonthFromNow - now) / 1000.0);
});
it('P1Y returns number of seconds for one year from now', () => {
const now = new Date();
let oneYearFromNow = new Date(now);
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
it('P1Y returns number of seconds for one year from now', () => {
const now = new Date();
const oneYearFromNow = new Date(now);
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
expect(
Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan)
).to.equal((oneYearFromNow - now) / 1000.0);
});
expect(
Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan),
).to.equal((oneYearFromNow - now) / 1000.0);
});
it('Invalid duration returns 0', () => {
expect(
Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan)
).to.equal(0);
});
it('Invalid duration returns 0', () => {
expect(
Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan),
).to.equal(0);
});
it('Empty duration returns 0', () => {
expect(
Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan)
).to.equal(0);
});
});
});
it('Empty duration returns 0', () => {
expect(
Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan),
).to.equal(0);
});
});
describe('addTwoDurations()', () => {
it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => {
expect(
Utilities.addTwoDurations('P1H5M30.5S', 'PT15M10S',
scorm2004_regex.CMITimespan),
).to.equal('P1H20M40.5S');
});
it('P1Y364D plus P2D1H45M52S equals P732D1H45M52S', () => {
expect(
Utilities.addTwoDurations('P1Y364D', 'P2D1H45M52S',
scorm2004_regex.CMITimespan),
).to.equal('P732D1H45M52S');
});
it('Invalid plus valid equals valid', () => {
expect(
Utilities.addTwoDurations('NOT A VALID DURATION', 'P1H30M45S',
scorm2004_regex.CMITimespan),
).to.equal('P1H30M45S');
});
it('Valid plus invalid equals valid', () => {
expect(
Utilities.addTwoDurations('P1H30M45S', 'NOT A VALID DURATION',
scorm2004_regex.CMITimespan),
).to.equal('P1H30M45S');
});
});
describe('addHHMMSSTimeStrings()', () => {
it('01:05:30.5 plus 00:15:10 equals 01:20:40.5', () => {
expect(
Utilities.addHHMMSSTimeStrings('01:05:30.5', '00:15:10',
scorm12_regex.CMITimespan),
).to.equal('01:20:40.5');
});
it('17496:00:00 plus 49:35:52 equals 17545:35:52', () => {
expect(
Utilities.addHHMMSSTimeStrings('17496:00:00', '49:35:52',
scorm12_regex.CMITimespan),
).to.equal('17545:35:52');
});
it('Invalid plus valid equals valid', () => {
expect(
Utilities.addHHMMSSTimeStrings('-00:15:10', '01:05:30.5',
scorm12_regex.CMITimespan),
).to.equal('01:05:30.5');
});
it('Valid plus invalid equals valid', () => {
expect(
Utilities.addHHMMSSTimeStrings('01:05:30.5', 'NOT A VALID DURATION',
scorm12_regex.CMITimespan),
).to.equal('01:05:30.5');
});
});
});