From 9847b0f1ebe401f72e5349fa9dfc36e2ec99e640 Mon Sep 17 00:00:00 2001 From: Jonathan Putney Date: Fri, 26 Jun 2020 12:07:06 -0400 Subject: [PATCH] Fixing an issue with double digit interaction counts --- src/AICC.js | 6 +++--- src/BaseAPI.js | 2 +- src/Scorm12API.js | 8 ++++---- src/Scorm2004API.js | 12 ++++++------ test/Scorm12API.spec.js | 7 ++++++- test/Scorm2004API.spec.js | 9 +++++++++ 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/AICC.js b/src/AICC.js index 9f74b09..4203127 100644 --- a/src/AICC.js +++ b/src/AICC.js @@ -41,13 +41,13 @@ export default class AICC extends Scorm12API { let newChild = super.getChildElement(CMIElement, value, foundFirstIndex); if (!newChild) { - if (this.stringMatches(CMIElement, 'cmi\\.evaluation\\.comments\\.\\d')) { + if (this.stringMatches(CMIElement, 'cmi\\.evaluation\\.comments\\.\\d+')) { newChild = new CMIEvaluationCommentsObject(); } else if (this.stringMatches(CMIElement, - 'cmi\\.student_data\\.tries\\.\\d')) { + 'cmi\\.student_data\\.tries\\.\\d+')) { newChild = new CMITriesObject(); } else if (this.stringMatches(CMIElement, - 'cmi\\.student_data\\.attempt_records\\.\\d')) { + 'cmi\\.student_data\\.attempt_records\\.\\d+')) { newChild = new CMIAttemptRecordsObject(); } } diff --git a/src/BaseAPI.js b/src/BaseAPI.js index bc0582f..fc4800f 100644 --- a/src/BaseAPI.js +++ b/src/BaseAPI.js @@ -531,7 +531,7 @@ export default class BaseAPI { } else if (!this._checkObjectHasProperty(refObject, attribute)) { this.throwSCORMError(invalidErrorCode, invalidErrorMessage); } else { - if (this.stringMatches(CMIElement, '\\.correct_responses\\.\\d')) { + if (this.stringMatches(CMIElement, '\\.correct_responses\\.\\d+')) { this.validateCorrectResponse(CMIElement, value); } diff --git a/src/Scorm12API.js b/src/Scorm12API.js index 41961be..84cf98c 100644 --- a/src/Scorm12API.js +++ b/src/Scorm12API.js @@ -171,16 +171,16 @@ export default class Scorm12API extends BaseAPI { getChildElement(CMIElement, value, foundFirstIndex) { let newChild; - if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d')) { + if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d+')) { newChild = new CMIObjectivesObject(); } else if (foundFirstIndex && this.stringMatches(CMIElement, - 'cmi\\.interactions\\.\\d\\.correct_responses\\.\\d')) { + 'cmi\\.interactions\\.\\d+\\.correct_responses\\.\\d+')) { newChild = new CMIInteractionsCorrectResponsesObject(); } else if (foundFirstIndex && this.stringMatches(CMIElement, - 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) { + 'cmi\\.interactions\\.\\d+\\.objectives\\.\\d+')) { newChild = new CMIInteractionsObjectivesObject(); } else if (!foundFirstIndex && - this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) { + this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d+')) { newChild = new CMIInteractionsObject(); } diff --git a/src/Scorm2004API.js b/src/Scorm2004API.js index 1b49a5b..37ff890 100644 --- a/src/Scorm2004API.js +++ b/src/Scorm2004API.js @@ -187,10 +187,10 @@ export default class Scorm2004API extends BaseAPI { getChildElement(CMIElement, value, foundFirstIndex) { let newChild; - if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d')) { + if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d+')) { newChild = new CMIObjectivesObject(); } else if (foundFirstIndex && this.stringMatches(CMIElement, - 'cmi\\.interactions\\.\\d\\.correct_responses\\.\\d')) { + 'cmi\\.interactions\\.\\d+\\.correct_responses\\.\\d+')) { const parts = CMIElement.split('.'); const index = Number(parts[2]); const interaction = this.cmi.interactions.childArray[index]; @@ -233,16 +233,16 @@ export default class Scorm2004API extends BaseAPI { newChild = new CMIInteractionsCorrectResponsesObject(); } } else if (foundFirstIndex && this.stringMatches(CMIElement, - 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) { + 'cmi\\.interactions\\.\\d+\\.objectives\\.\\d+')) { newChild = new CMIInteractionsObjectivesObject(); } else if (!foundFirstIndex && - this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) { + this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d+')) { newChild = new CMIInteractionsObject(); } else if (this.stringMatches(CMIElement, - 'cmi\\.comments_from_learner\\.\\d')) { + 'cmi\\.comments_from_learner\\.\\d+')) { newChild = new CMICommentsObject(); } else if (this.stringMatches(CMIElement, - 'cmi\\.comments_from_lms\\.\\d')) { + 'cmi\\.comments_from_lms\\.\\d+')) { newChild = new CMICommentsObject(true); } diff --git a/test/Scorm12API.spec.js b/test/Scorm12API.spec.js index ca0b6c5..4c971b2 100644 --- a/test/Scorm12API.spec.js +++ b/test/Scorm12API.spec.js @@ -282,7 +282,12 @@ describe('SCORM 1.2 API Tests', () => { }); h.checkLMSSetValue({ api: apiInitialized(), - fieldName: 'cmi.interactions.0.correct_responses.0.pattern', + fieldName: 'cmi.interactions.0.objectives.0.id', + valueToTest: 'AAA', + }); + h.checkLMSSetValue({ + api: apiInitialized(), + fieldName: 'cmi.interactions.10.correct_responses.0.pattern', valueToTest: 't', }); }); diff --git a/test/Scorm2004API.spec.js b/test/Scorm2004API.spec.js index cd6ee95..a087e69 100644 --- a/test/Scorm2004API.spec.js +++ b/test/Scorm2004API.spec.js @@ -305,6 +305,15 @@ describe('SCORM 2004 API Tests', () => { String(scorm2004API.lmsGetLastError()) ).to.equal(String(0)); }); + it('should allow cmi.interactions.10.correct_responses.0.pattern to be set - T/F', + () => { + const scorm2004API = apiInitialized(); + scorm2004API.setCMIValue('cmi.interactions.0.type', 'true-false'); + scorm2004API.setCMIValue('cmi.interactions.0.correct_responses.0.pattern', 'true'); + expect( + String(scorm2004API.lmsGetLastError()) + ).to.equal(String(0)); + }); it('should allow cmi.interactions.0.correct_responses.0.pattern to be set - choice', () => { const scorm2004API = apiInitialized();