Fixes and additional test cases
This commit is contained in:
@@ -837,14 +837,6 @@ export default class BaseAPI {
|
|||||||
'The storeData method has not been implemented');
|
'The storeData method has not been implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the current total time as total_time + session_time
|
|
||||||
* APIs that inherit BaseAPI should override this function
|
|
||||||
*/
|
|
||||||
getCurrentTotalTime() {
|
|
||||||
this.cmi.getCurrentTotalTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the request to the LMS
|
* Send the request to the LMS
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ export default class Scorm12API extends BaseAPI {
|
|||||||
const cmiExport = this.renderCMIToJSONObject();
|
const cmiExport = this.renderCMIToJSONObject();
|
||||||
|
|
||||||
if (terminateCommit) {
|
if (terminateCommit) {
|
||||||
cmiExport.cmi.core.total_time = this.getCurrentTotalTime();
|
cmiExport.cmi.core.total_time = this.cmi.getCurrentTotalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|||||||
@@ -439,17 +439,17 @@ export default class Scorm2004API extends BaseAPI {
|
|||||||
* @return {object|Array}
|
* @return {object|Array}
|
||||||
*/
|
*/
|
||||||
renderCommitCMI(terminateCommit: boolean) {
|
renderCommitCMI(terminateCommit: boolean) {
|
||||||
const cmi = this.renderCMIToJSONObject();
|
const cmiExport = this.renderCMIToJSONObject();
|
||||||
|
|
||||||
if (terminateCommit) {
|
if (terminateCommit) {
|
||||||
cmi.total_time = this.getCurrentTotalTime();
|
cmiExport.cmi.total_time = this.cmi.getCurrentTotalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
const flattened = Utilities.flatten(cmi);
|
const flattened = Utilities.flatten(cmiExport);
|
||||||
switch (this.settings.dataCommitFormat) {
|
switch (this.settings.dataCommitFormat) {
|
||||||
case 'flattened':
|
case 'flattened':
|
||||||
return Utilities.flatten(cmi);
|
return Utilities.flatten(cmiExport);
|
||||||
case 'params':
|
case 'params':
|
||||||
for (const item in flattened) {
|
for (const item in flattened) {
|
||||||
if ({}.hasOwnProperty.call(flattened, item)) {
|
if ({}.hasOwnProperty.call(flattened, item)) {
|
||||||
@@ -459,7 +459,7 @@ export default class Scorm2004API extends BaseAPI {
|
|||||||
return result;
|
return result;
|
||||||
case 'json':
|
case 'json':
|
||||||
default:
|
default:
|
||||||
return cmi;
|
return cmiExport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ export default class Scorm2004API extends BaseAPI {
|
|||||||
*/
|
*/
|
||||||
storeData(terminateCommit: boolean) {
|
storeData(terminateCommit: boolean) {
|
||||||
if (terminateCommit) {
|
if (terminateCommit) {
|
||||||
if (this.cmi.lesson_mode === 'normal') {
|
if (this.cmi.mode === 'normal') {
|
||||||
if (this.cmi.credit === 'credit') {
|
if (this.cmi.credit === 'credit') {
|
||||||
if (this.cmi.completion_threshold && this.cmi.progress_measure) {
|
if (this.cmi.completion_threshold && this.cmi.progress_measure) {
|
||||||
if (this.cmi.progress_measure >= this.cmi.completion_threshold) {
|
if (this.cmi.progress_measure >= this.cmi.completion_threshold) {
|
||||||
@@ -493,7 +493,8 @@ export default class Scorm2004API extends BaseAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let navRequest = false;
|
let navRequest = false;
|
||||||
if (this.adl.nav.request !== (this.startingData?.adl?.nav?.request || '')) {
|
if (this.adl.nav.request !== (this.startingData?.adl?.nav?.request) &&
|
||||||
|
this.adl.nav.request !== '_none_') {
|
||||||
this.adl.nav.request = encodeURIComponent(this.adl.nav.request);
|
this.adl.nav.request = encodeURIComponent(this.adl.nav.request);
|
||||||
navRequest = true;
|
navRequest = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,11 +223,14 @@ export class CMIScore extends BaseCMI {
|
|||||||
* @return {{min: string, max: string, raw: string}}
|
* @return {{min: string, max: string, raw: string}}
|
||||||
*/
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
this.jsonString = true;
|
||||||
|
const result = {
|
||||||
'raw': this.raw,
|
'raw': this.raw,
|
||||||
'min': this.min,
|
'min': this.min,
|
||||||
'max': this.max,
|
'max': this.max,
|
||||||
};
|
};
|
||||||
|
delete this.jsonString;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,23 @@ function check2004ValidRange(value: any, rangePattern: String) {
|
|||||||
* Class representing cmi object for SCORM 2004
|
* Class representing cmi object for SCORM 2004
|
||||||
*/
|
*/
|
||||||
export class CMI extends BaseCMI {
|
export class CMI extends BaseCMI {
|
||||||
|
/**
|
||||||
|
* Constructor for the SCORM 2004 cmi object
|
||||||
|
* @param {boolean} initialized
|
||||||
|
*/
|
||||||
|
constructor(initialized: boolean) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.learner_preference = new CMILearnerPreference();
|
||||||
|
this.score = new Scorm2004CMIScore();
|
||||||
|
this.comments_from_learner = new CMICommentsFromLearner();
|
||||||
|
this.comments_from_lms = new CMICommentsFromLMS();
|
||||||
|
this.interactions = new CMIInteractions();
|
||||||
|
this.objectives = new CMIObjectives();
|
||||||
|
|
||||||
|
if (initialized) this.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
#_version = '1.0';
|
#_version = '1.0';
|
||||||
#_children = constants.cmi_children;
|
#_children = constants.cmi_children;
|
||||||
#completion_status = 'unknown';
|
#completion_status = 'unknown';
|
||||||
@@ -88,23 +105,6 @@ export class CMI extends BaseCMI {
|
|||||||
#time_limit_action = 'continue,no message';
|
#time_limit_action = 'continue,no message';
|
||||||
#total_time = '0';
|
#total_time = '0';
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the SCORM 2004 cmi object
|
|
||||||
* @param {boolean} initialized
|
|
||||||
*/
|
|
||||||
constructor(initialized: boolean) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.learner_preference = new CMILearnerPreference();
|
|
||||||
this.score = new Scorm2004CMIScore();
|
|
||||||
this.comments_from_learner = new CMICommentsFromLearner();
|
|
||||||
this.comments_from_lms = new CMICommentsFromLMS();
|
|
||||||
this.interactions = new CMIInteractions();
|
|
||||||
this.objectives = new CMIObjectives();
|
|
||||||
|
|
||||||
if (initialized) this.initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the API has been initialized after the CMI has been created
|
* Called when the API has been initialized after the CMI has been created
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -272,6 +272,19 @@ describe('SCORM 1.2 API Tests', () => {
|
|||||||
).to.equal('student_2');
|
).to.equal('student_2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('renderCommitCMI()', () => {
|
||||||
|
it('should calculate total time when terminateCommit passed',
|
||||||
|
() => {
|
||||||
|
const scorm12API = api();
|
||||||
|
scorm12API.cmi.core.total_time = '12:34:56';
|
||||||
|
scorm12API.cmi.core.session_time = '23:59:59';
|
||||||
|
const cmiExport = scorm12API.renderCommitCMI(true);
|
||||||
|
expect(
|
||||||
|
cmiExport.cmi.core.total_time
|
||||||
|
).to.equal('36:34:55');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('storeData()', () => {
|
describe('storeData()', () => {
|
||||||
it('should set cmi.core.lesson_status to "completed"', () => {
|
it('should set cmi.core.lesson_status to "completed"', () => {
|
||||||
const scorm12API = api();
|
const scorm12API = api();
|
||||||
|
|||||||
@@ -287,4 +287,56 @@ describe('SCORM 2004 API Tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('renderCommitCMI()', () => {
|
||||||
|
it('should calculate total time when terminateCommit passed',
|
||||||
|
() => {
|
||||||
|
const scorm2004API = api();
|
||||||
|
scorm2004API.cmi.total_time = 'PT12H34M56S';
|
||||||
|
scorm2004API.cmi.session_time = 'PT23H59M59S';
|
||||||
|
const cmiExport = scorm2004API.renderCommitCMI(true);
|
||||||
|
expect(
|
||||||
|
cmiExport.cmi.total_time
|
||||||
|
).to.equal('P1DT12H34M55S');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('storeData()', () => {
|
||||||
|
it('should set cmi.completion_status to "completed"',
|
||||||
|
() => {
|
||||||
|
const scorm2004API = api();
|
||||||
|
scorm2004API.cmi.credit = 'credit';
|
||||||
|
scorm2004API.cmi.completion_threshold = '0.6';
|
||||||
|
scorm2004API.cmi.progress_measure = '0.75';
|
||||||
|
scorm2004API.storeData(true);
|
||||||
|
expect(scorm2004API.cmi.completion_status).to.equal('completed');
|
||||||
|
});
|
||||||
|
it('should set cmi.completion_status to "incomplete"',
|
||||||
|
() => {
|
||||||
|
const scorm2004API = api();
|
||||||
|
scorm2004API.cmi.credit = 'credit';
|
||||||
|
scorm2004API.cmi.completion_threshold = '0.7';
|
||||||
|
scorm2004API.cmi.progress_measure = '0.6';
|
||||||
|
scorm2004API.storeData(true);
|
||||||
|
expect(scorm2004API.cmi.completion_status).to.equal('incomplete');
|
||||||
|
});
|
||||||
|
it('should set cmi.success_status to "passed"',
|
||||||
|
() => {
|
||||||
|
const scorm2004API = api();
|
||||||
|
scorm2004API.cmi.credit = 'credit';
|
||||||
|
scorm2004API.cmi.score.scaled = '0.7';
|
||||||
|
scorm2004API.cmi.scaled_passing_score = '0.6';
|
||||||
|
scorm2004API.storeData(true);
|
||||||
|
expect(scorm2004API.cmi.success_status).to.equal('passed');
|
||||||
|
});
|
||||||
|
it('should set cmi.success_status to "failed"',
|
||||||
|
() => {
|
||||||
|
const scorm2004API = api();
|
||||||
|
scorm2004API.cmi.credit = 'credit';
|
||||||
|
scorm2004API.cmi.score.scaled = '0.6';
|
||||||
|
scorm2004API.cmi.scaled_passing_score = '0.7';
|
||||||
|
scorm2004API.storeData(true);
|
||||||
|
expect(scorm2004API.cmi.success_status).to.equal('failed');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user