Moving field values to test src

This commit is contained in:
Jonathan Putney
2020-01-09 09:36:08 -05:00
parent 8d8831954e
commit d460053cbb
10 changed files with 29 additions and 32 deletions

View File

@@ -106,6 +106,8 @@ export default class BaseAPI {
if (this.checkState(checkTerminated, if (this.checkState(checkTerminated,
this.#error_codes.TERMINATION_BEFORE_INIT, this.#error_codes.TERMINATION_BEFORE_INIT,
this.#error_codes.MULTIPLE_TERMINATION)) { this.#error_codes.MULTIPLE_TERMINATION)) {
this.currentState = global_constants.STATE_TERMINATED;
const result = this.storeData(true); const result = this.storeData(true);
if (result.errorCode && result.errorCode > 0) { if (result.errorCode && result.errorCode > 0) {
this.throwSCORMError(result.errorCode); this.throwSCORMError(result.errorCode);
@@ -114,7 +116,7 @@ export default class BaseAPI {
result.result : global_constants.SCORM_FALSE; result.result : global_constants.SCORM_FALSE;
if (checkTerminated) this.lastErrorCode = 0; if (checkTerminated) this.lastErrorCode = 0;
this.currentState = global_constants.STATE_TERMINATED;
returnValue = global_constants.SCORM_TRUE; returnValue = global_constants.SCORM_TRUE;
this.processListeners(callbackName); this.processListeners(callbackName);
} }
@@ -906,7 +908,8 @@ export default class BaseAPI {
*/ */
scheduleCommit(when: number) { scheduleCommit(when: number) {
this.#timeout = new ScheduledCommit(this, when); this.#timeout = new ScheduledCommit(this, when);
this.apiLog('scheduleCommit', '', 'scheduled', global_constants.LOG_LEVEL_DEBUG); this.apiLog('scheduleCommit', '', 'scheduled',
global_constants.LOG_LEVEL_DEBUG);
} }
/** /**

View File

@@ -473,10 +473,6 @@ export default class Scorm2004API extends BaseAPI {
renderCommitCMI(terminateCommit: boolean) { renderCommitCMI(terminateCommit: boolean) {
const cmiExport = this.renderCMIToJSONObject(); const cmiExport = this.renderCMIToJSONObject();
if (terminateCommit) {
cmiExport.cmi.total_time = this.cmi.getCurrentTotalTime();
}
const result = []; const result = [];
const flattened = Utilities.flatten(cmiExport); const flattened = Utilities.flatten(cmiExport);
switch (this.settings.dataCommitFormat) { switch (this.settings.dataCommitFormat) {

View File

@@ -526,7 +526,7 @@ class CMICore extends BaseCMI {
'credit': this.credit, 'credit': this.credit,
'lesson_status': this.lesson_status, 'lesson_status': this.lesson_status,
'entry': this.entry, 'entry': this.entry,
'total_time': this.total_time, 'total_time': this.getCurrentTotalTime(),
'lesson_mode': this.lesson_mode, 'lesson_mode': this.lesson_mode,
'exit': this.exit, 'exit': this.exit,
'session_time': this.session_time, 'session_time': this.session_time,

View File

@@ -103,7 +103,7 @@ export class CMI extends BaseCMI {
#success_status = 'unknown'; #success_status = 'unknown';
#suspend_data = ''; #suspend_data = '';
#time_limit_action = 'continue,no message'; #time_limit_action = 'continue,no message';
#total_time = '0'; #total_time = '';
/** /**
* 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
@@ -538,7 +538,7 @@ export class CMI extends BaseCMI {
'success_status': this.success_status, 'success_status': this.success_status,
'suspend_data': this.suspend_data, 'suspend_data': this.suspend_data,
'time_limit_action': this.time_limit_action, 'time_limit_action': this.time_limit_action,
'total_time': this.total_time, 'total_time': this.getCurrentTotalTime(),
}; };
delete this.jsonString; delete this.jsonString;
return result; return result;

View File

@@ -1,7 +1,5 @@
// @flow // @flow
import {scorm12_values, scorm2004_values} from './field_values';
export const scorm12_regex = { export const scorm12_regex = {
CMIString256: '^.{0,255}$', CMIString256: '^.{0,255}$',
CMIString4096: '^.{0,4096}$', CMIString4096: '^.{0,4096}$',
@@ -15,11 +13,11 @@ export const scorm12_regex = {
CMIIndex: '[._](\\d+).', CMIIndex: '[._](\\d+).',
// Vocabulary Data Type Definition // Vocabulary Data Type Definition
CMIStatus: '^(' + scorm12_values.validLessonStatus.join('|') + ')$', CMIStatus: '^(passed|completed|failed|incomplete|browsed)$',
CMIStatus2: '^(' + scorm12_values.validLessonStatus.join('|') + '|not attempted)$', CMIStatus2: '^(passed|completed|failed|incomplete|browsed|not attempted)$',
CMIExit: '^(' + scorm12_values.validExit.join('|') + '|)$', CMIExit: '^(time-out|suspend|logout|)$',
CMIType: '^(' + scorm12_values.validType.join('|') + ')$', CMIType: '^(true-false|choice|fill-in|matching|performance|sequencing|likert|numeric)$',
CMIResult: '^(' + scorm12_values.validResult.join('|') + '|([0-9]{0,3})?(\\.[0-9]*)?)$', // eslint-disable-line CMIResult: '^(correct|wrong|unanticipated|neutral|([0-9]{0,3})?(\\.[0-9]*)?)$', // eslint-disable-line
NAVEvent: '^(previous|continue)$', NAVEvent: '^(previous|continue)$',
// Data ranges // Data ranges
@@ -60,12 +58,12 @@ export const scorm2004_regex = {
CMIIndexStore: '.N(\\d+).', CMIIndexStore: '.N(\\d+).',
// Vocabulary Data Type Definition // Vocabulary Data Type Definition
CMICStatus: '^(' + scorm2004_values.validCStatus.join('|') + ')$', CMICStatus: '^(completed|incomplete|not attempted|unknown)$',
CMISStatus: '^(' + scorm2004_values.validSStatus.join('|') + ')$', CMISStatus: '^(passed|failed|unknown)$',
CMIExit: '^(' + scorm2004_values.validExit.join('|') + ')$', CMIExit: '^(time-out|suspend|logout|normal)$',
CMIType: '^(' + scorm2004_values.validType.join('|') + ')$', CMIType: '^(true-false|choice|fill-in|long-fill-in|matching|performance|sequencing|likert|numeric|other)$',
CMIResult: '^(' + scorm2004_values.validResult.join('|') + '|-?([0-9]{1,4})(\\.[0-9]{1,18})?)$', CMIResult: '^(correct|wrong|unanticipated|neutral|-?([0-9]{1,4})(\\.[0-9]{1,18})?)$',
NAVEvent: '^(' + scorm2004_values.validNavRequest.join('|') + '|\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump)$', // eslint-disable-line NAVEvent: '^(previous|continue|exit|exitAll|abandon|abandonAll|suspendAll|\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump)$', // eslint-disable-line
NAVBoolean: '^(unknown|true|false$)', NAVBoolean: '^(unknown|true|false$)',
NAVTarget: '^(previous|continue|choice.{target=\\S{0,200}[a-zA-Z0-9]})$', NAVTarget: '^(previous|continue|choice.{target=\\S{0,200}[a-zA-Z0-9]})$',

View File

@@ -3,7 +3,7 @@ import {describe, it} from 'mocha';
import * as h from './api_helpers'; import * as h from './api_helpers';
import {scorm2004_error_codes} from '../src/constants/error_codes'; import {scorm2004_error_codes} from '../src/constants/error_codes';
import Scorm2004API from '../src/Scorm2004API'; import Scorm2004API from '../src/Scorm2004API';
import {scorm2004_values} from '../src/constants/field_values'; import {scorm2004_values} from './field_values';
const api = () => { const api = () => {
const API = new Scorm2004API(); const API = new Scorm2004API();

View File

@@ -13,7 +13,7 @@ import {
NAV, NAV,
} from '../../src/cmi/scorm12_cmi'; } from '../../src/cmi/scorm12_cmi';
import {expect} from 'chai'; import {expect} from 'chai';
import {scorm12_values} from '../../src/constants/field_values'; import {scorm12_values} from '../field_values';
const invalid_set = scorm12_error_codes.INVALID_SET_VALUE; const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
const type_mismatch = scorm12_error_codes.TYPE_MISMATCH; const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
@@ -520,7 +520,7 @@ describe('AICC CMI Tests', () => {
). ).
to. to.
equal( equal(
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","entry":"","total_time":"","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":"","tries":{"0":{"status":"","time":"","score":{"raw":"","min":"","max":"100"}}}},"student_preference":{"audio":"","language":"","speed":"","text":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}},"evaluation":{"comments":{"0":{"content":"","location":"","time":""}}}}'); '{"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":"","tries":{"0":{"status":"","time":"","score":{"raw":"","min":"","max":"100"}}}},"student_preference":{"audio":"","language":"","speed":"","text":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}},"evaluation":{"comments":{"0":{"content":"","location":"","time":""}}}}');
}); });
}); });

View File

@@ -10,7 +10,7 @@ import {
CMIObjectivesObject, CMIObjectivesObject,
} from '../../src/cmi/scorm12_cmi'; } from '../../src/cmi/scorm12_cmi';
import * as h from '../cmi_helpers'; import * as h from '../cmi_helpers';
import {scorm12_values} from '../../src/constants/field_values'; import {scorm12_values} from '../field_values';
const invalid_set = scorm12_error_codes.INVALID_SET_VALUE; const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
const type_mismatch = scorm12_error_codes.TYPE_MISMATCH; const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
@@ -592,7 +592,7 @@ describe('SCORM 1.2 CMI Tests', () => {
). ).
to. to.
equal( equal(
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","entry":"","total_time":"","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":"","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":{}}}}');
}); });
}); });

View File

@@ -12,7 +12,7 @@ import {
} from '../../src/cmi/scorm2004_cmi'; } from '../../src/cmi/scorm2004_cmi';
import * as h from '../cmi_helpers'; import * as h from '../cmi_helpers';
import {expect} from 'chai'; import {expect} from 'chai';
import {scorm2004_values} from '../../src/constants/field_values'; import {scorm2004_values} from '../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;
@@ -234,7 +234,7 @@ describe('SCORM 2004 CMI Tests', () => {
h.checkReadAndWrite({ h.checkReadAndWrite({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.total_time', fieldName: 'cmi.total_time',
expectedValue: '0', expectedValue: '',
}); });
/** /**
@@ -402,7 +402,7 @@ describe('SCORM 2004 CMI Tests', () => {
). ).
to. to.
equal( 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":"0"}'); '{"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"}');
}); });
}); });
@@ -543,7 +543,7 @@ describe('SCORM 2004 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.total_time', fieldName: 'cmi.total_time',
expectedValue: '0', expectedValue: '',
expectedError: read_only, expectedError: read_only,
}); });
@@ -712,7 +712,7 @@ describe('SCORM 2004 CMI Tests', () => {
). ).
to. to.
equal( 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":"0"}'); '{"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"}');
}); });
}); });