Merge branch 'master' of https://github.com/jcputney/scorm-again
This commit is contained in:
@@ -3,6 +3,7 @@ import {describe, it} from 'mocha';
|
||||
import Scorm12API from '../src/Scorm12API';
|
||||
import * as h from './api_helpers';
|
||||
import {scorm12_error_codes} from '../src/constants/error_codes';
|
||||
import {scorm12_values} from '../src/constants/field_values';
|
||||
|
||||
const api = (settings = {}) => {
|
||||
const API = new Scorm12API(settings);
|
||||
@@ -16,6 +17,27 @@ const apiInitialized = (settings = {}) => {
|
||||
};
|
||||
|
||||
describe('SCORM 1.2 API Tests', () => {
|
||||
describe('LMSSetValue()', () => {
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.core.score.raw',
|
||||
validValues: scorm12_values.validScoreRange,
|
||||
invalidValues: scorm12_values.invalidScoreRange,
|
||||
});
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.core.score.min',
|
||||
validValues: scorm12_values.validScoreRange,
|
||||
invalidValues: scorm12_values.invalidScoreRange,
|
||||
});
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.core.score.max',
|
||||
validValues: scorm12_values.validScoreRange,
|
||||
invalidValues: scorm12_values.invalidScoreRange,
|
||||
});
|
||||
});
|
||||
|
||||
describe('setCMIValue()', () => {
|
||||
describe('Invalid Sets - Should Always Fail', () => {
|
||||
h.checkSetCMIValue({
|
||||
@@ -280,7 +302,7 @@ describe('SCORM 1.2 API Tests', () => {
|
||||
scorm12API.cmi.core.session_time = '23:59:59';
|
||||
const cmiExport = scorm12API.renderCommitCMI(true);
|
||||
expect(
|
||||
cmiExport.cmi.core.total_time
|
||||
cmiExport.cmi.core.total_time,
|
||||
).to.equal('36:34:55');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,33 @@ const apiInitialized = () => {
|
||||
};
|
||||
|
||||
describe('SCORM 2004 API Tests', () => {
|
||||
describe('SetValue()', () => {
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.score.scaled',
|
||||
validValues: scorm2004_values.validScaledRange,
|
||||
invalidValues: scorm2004_values.invalidScaledRange,
|
||||
});
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.score.raw',
|
||||
validValues: scorm2004_values.validScoreRange,
|
||||
invalidValues: scorm2004_values.invalidScoreRange,
|
||||
});
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.score.min',
|
||||
validValues: scorm2004_values.validScoreRange,
|
||||
invalidValues: scorm2004_values.invalidScoreRange,
|
||||
});
|
||||
h.checkValidValues({
|
||||
api: apiInitialized(),
|
||||
fieldName: 'cmi.score.max',
|
||||
validValues: scorm2004_values.validScoreRange,
|
||||
invalidValues: scorm2004_values.invalidScoreRange,
|
||||
});
|
||||
});
|
||||
|
||||
describe('setCMIValue()', () => {
|
||||
describe('Invalid Sets - Should Always Fail', () => {
|
||||
h.checkSetCMIValue({
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
import {describe, it} from 'mocha';
|
||||
import {expect} from 'chai';
|
||||
|
||||
export const checkValidValues = (
|
||||
{
|
||||
api,
|
||||
fieldName,
|
||||
validValues,
|
||||
invalidValues,
|
||||
}) => {
|
||||
describe(`Field: ${fieldName}`, () => {
|
||||
for (const idx in validValues) {
|
||||
if ({}.hasOwnProperty.call(validValues, idx)) {
|
||||
it(`Should successfully write '${validValues[idx]}' to ${fieldName}`,
|
||||
() => {
|
||||
expect(api.lmsSetValue(fieldName, validValues[idx])).
|
||||
to.equal('true');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const idx in invalidValues) {
|
||||
if ({}.hasOwnProperty.call(invalidValues, idx)) {
|
||||
it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`,
|
||||
() => {
|
||||
expect(api.lmsSetValue(fieldName, invalidValues[idx])).
|
||||
to.equal('false');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const checkLMSSetValue = (
|
||||
{
|
||||
api,
|
||||
|
||||
@@ -592,7 +592,7 @@ describe('SCORM 1.2 CMI Tests', () => {
|
||||
).
|
||||
to.
|
||||
equal(
|
||||
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","entry":"","total_time":"00:00:00","lesson_mode":"normal","exit":"","session_time":"00:00:00","score":{"raw":"","min":"","max":"100"}},"objectives":{"0":{"id":"","status":"","score":{"raw":"","min":"","max":"100"}}},"student_data":{"mastery_score":"","max_time_allowed":"","time_limit_action":""},"student_preference":{"audio":"","language":"","speed":"","text":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}}}');
|
||||
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","entry":"","lesson_mode":"normal","exit":"","session_time":"00:00:00","score":{"raw":"","min":"","max":"100"}},"objectives":{"0":{"id":"","status":"","score":{"raw":"","min":"","max":"100"}}},"student_data":{"mastery_score":"","max_time_allowed":"","time_limit_action":""},"student_preference":{"audio":"","language":"","speed":"","text":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}}}');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ describe('SCORM 2004 CMI Tests', () => {
|
||||
).
|
||||
to.
|
||||
equal(
|
||||
'{"comments_from_learner":{},"comments_from_lms":{},"completion_status":"unknown","completion_threshold":"","credit":"credit","entry":"","exit":"","interactions":{"0":{"id":"","type":"","objectives":{},"timestamp":"","weighting":"","learner_response":"","result":"","latency":"","description":"","correct_responses":{}}},"launch_data":"","learner_id":"","learner_name":"","learner_preference":{"audio_level":"1","language":"","delivery_speed":"1","audio_captioning":"0"},"location":"","max_time_allowed":"","mode":"normal","objectives":{"0":{"id":"","success_status":"unknown","completion_status":"unknown","progress_measure":"","description":"","score":{"scaled":"","raw":"","min":"","max":""}}},"progress_measure":"","scaled_passing_score":"","score":{"scaled":"","raw":"","min":"","max":""},"session_time":"PT0H0M0S","success_status":"unknown","suspend_data":"","time_limit_action":"continue,no message","total_time":"PT0S"}');
|
||||
'{"comments_from_learner":{},"comments_from_lms":{},"completion_status":"unknown","completion_threshold":"","credit":"credit","entry":"","exit":"","interactions":{"0":{"id":"","type":"","objectives":{},"timestamp":"","weighting":"","learner_response":"","result":"","latency":"","description":"","correct_responses":{}}},"launch_data":"","learner_id":"","learner_name":"","learner_preference":{"audio_level":"1","language":"","delivery_speed":"1","audio_captioning":"0"},"location":"","max_time_allowed":"","mode":"normal","objectives":{"0":{"id":"","success_status":"unknown","completion_status":"unknown","progress_measure":"","description":"","score":{"scaled":"","raw":"","min":"","max":""}}},"progress_measure":"","scaled_passing_score":"","score":{"scaled":"","raw":"","min":"","max":""},"session_time":"PT0H0M0S","success_status":"unknown","suspend_data":"","time_limit_action":"continue,no message"}');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -712,7 +712,7 @@ describe('SCORM 2004 CMI Tests', () => {
|
||||
).
|
||||
to.
|
||||
equal(
|
||||
'{"comments_from_learner":{},"comments_from_lms":{},"completion_status":"unknown","completion_threshold":"","credit":"credit","entry":"","exit":"","interactions":{"0":{"id":"","type":"","objectives":{},"timestamp":"","weighting":"","learner_response":"","result":"","latency":"","description":"","correct_responses":{}}},"launch_data":"","learner_id":"","learner_name":"","learner_preference":{"audio_level":"1","language":"","delivery_speed":"1","audio_captioning":"0"},"location":"","max_time_allowed":"","mode":"normal","objectives":{"0":{"id":"","success_status":"unknown","completion_status":"unknown","progress_measure":"","description":"","score":{"scaled":"","raw":"","min":"","max":""}}},"progress_measure":"","scaled_passing_score":"","score":{"scaled":"","raw":"","min":"","max":""},"session_time":"PT0H0M0S","success_status":"unknown","suspend_data":"","time_limit_action":"continue,no message","total_time":"PT0S"}');
|
||||
'{"comments_from_learner":{},"comments_from_lms":{},"completion_status":"unknown","completion_threshold":"","credit":"credit","entry":"","exit":"","interactions":{"0":{"id":"","type":"","objectives":{},"timestamp":"","weighting":"","learner_response":"","result":"","latency":"","description":"","correct_responses":{}}},"launch_data":"","learner_id":"","learner_name":"","learner_preference":{"audio_level":"1","language":"","delivery_speed":"1","audio_captioning":"0"},"location":"","max_time_allowed":"","mode":"normal","objectives":{"0":{"id":"","success_status":"unknown","completion_status":"unknown","progress_measure":"","description":"","score":{"scaled":"","raw":"","min":"","max":""}}},"progress_measure":"","scaled_passing_score":"","score":{"scaled":"","raw":"","min":"","max":""},"session_time":"PT0H0M0S","success_status":"unknown","suspend_data":"","time_limit_action":"continue,no message"}');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ export const scorm12_values = {
|
||||
'time-out',
|
||||
'suspend',
|
||||
'logout',
|
||||
'',
|
||||
],
|
||||
invalidExit: [
|
||||
'close',
|
||||
@@ -132,7 +133,12 @@ export const scorm12_values = {
|
||||
validScoreRange: [
|
||||
'1',
|
||||
'50.25',
|
||||
'70',
|
||||
'100',
|
||||
1,
|
||||
50.25,
|
||||
70,
|
||||
100,
|
||||
],
|
||||
invalidScoreRange: [
|
||||
'invalid',
|
||||
@@ -224,6 +230,7 @@ export const scorm2004_values = {
|
||||
'suspend',
|
||||
'logout',
|
||||
'normal',
|
||||
'',
|
||||
],
|
||||
invalidExit: [
|
||||
'close',
|
||||
|
||||
@@ -224,9 +224,9 @@ describe('Utility Tests', () => {
|
||||
describe('addTwoDurations()', () => {
|
||||
it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => {
|
||||
expect(
|
||||
Utilities.addTwoDurations('PT1H5M30.5S', 'PT15M10S',
|
||||
Utilities.addTwoDurations('PT1H5M30.5S', 'PT15M30S',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal('PT1H20M40.5S');
|
||||
).to.equal('PT1H21M0.5S');
|
||||
});
|
||||
it('P1Y364D plus P2DT1H45M52S equals P732DT1H45M52S', () => {
|
||||
expect(
|
||||
@@ -251,9 +251,9 @@ describe('Utility Tests', () => {
|
||||
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',
|
||||
Utilities.addHHMMSSTimeStrings('01:05:30.5', '00:15:30',
|
||||
scorm12_regex.CMITimespan),
|
||||
).to.equal('01:20:40.5');
|
||||
).to.equal('01:21:00.5');
|
||||
});
|
||||
it('17496:00:00 plus 49:35:52 equals 17545:35:52', () => {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user