From 746cd7cc28563f1556a7ad3ad21afc2d1d91f431 Mon Sep 17 00:00:00 2001 From: Ken Clary Date: Thu, 9 Feb 2023 14:47:29 -0500 Subject: [PATCH] feat: multiple numericalresponse tags no longer special-cased against going to the advanced editor. TNL-10426. --- .../ProblemEditor/data/OLXParser.js | 34 +------ .../ProblemEditor/data/OLXParser.test.js | 23 ++--- .../ProblemEditor/data/ReactStateOLXParser.js | 5 - .../data/ReactStateOLXParser.test.js | 8 -- .../data/mockData/olxTestData.js | 97 ++++--------------- 5 files changed, 37 insertions(+), 130 deletions(-) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 561b365c4..44d70e73a 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -226,28 +226,6 @@ export class OLXParser { parseNumericResponse() { const { numericalresponse } = this.problem; - let answers = []; - let subAnswers = []; - let data = {}; - // TODO: Find a way to add answers using additional_answers v/s numericalresponse - if (_.isArray(numericalresponse)) { - numericalresponse.forEach((numericalAnswer) => { - subAnswers = this.parseNumericResponseObject(numericalAnswer, answers.length); - answers = _.concat(answers, subAnswers); - }); - } else { - subAnswers = this.parseNumericResponseObject(numericalresponse, answers.length); - answers = _.concat(answers, subAnswers); - } - - data = { - answers, - }; - - return data; - } - - parseNumericResponseObject(numericalresponse, answerOffset) { let answerFeedback = ''; const answers = []; let responseParam = {}; @@ -261,7 +239,7 @@ export class OLXParser { }; } answers.push({ - id: indexToLetterMap[answers.length + answerOffset], + id: indexToLetterMap[answers.length], title: numericalresponse['@_answer'], correct: true, selectedFeedback: feedback, @@ -274,7 +252,7 @@ export class OLXParser { additionalAnswer.forEach((newAnswer) => { answerFeedback = this.getFeedback(newAnswer); answers.push({ - id: indexToLetterMap[answers.length + answerOffset], + id: indexToLetterMap[answers.length], title: newAnswer['@_answer'], correct: true, selectedFeedback: answerFeedback, @@ -283,13 +261,13 @@ export class OLXParser { } else { answerFeedback = this.getFeedback(additionalAnswer); answers.push({ - id: indexToLetterMap[answers.length + answerOffset], + id: indexToLetterMap[answers.length], title: additionalAnswer['@_answer'], correct: true, selectedFeedback: answerFeedback, }); } - return answers; + return { answers }; } parseQuestions(problemType) { @@ -386,10 +364,8 @@ export class OLXParser { return ProblemTypeKeys.ADVANCED; } // make sure compound problems are treated as advanced - // TODO: Find a way to add answers using additional_answers v/s numericalresponse if ((problemTypeKeys.length > 1) - || (problemTypeKeys[0] !== ProblemTypeKeys.NUMERIC // multiple numeric problems are really just multiple answers - && _.isArray(this.problem[problemTypeKeys[0]]) + || (_.isArray(this.problem[problemTypeKeys[0]]) && this.problem[problemTypeKeys[0]].length > 1)) { return ProblemTypeKeys.ADVANCED; } diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index c0c8b4bab..9041ead4d 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -4,13 +4,14 @@ import { getCheckboxesOLXWithFeedbackAndHintsOLX, dropdownOLXWithFeedbackAndHintsOLX, numericInputWithFeedbackAndHintsOLX, - numericInputWithFeedbackAndHintsOLXException, textInputWithFeedbackAndHintsOLX, multipleChoiceWithoutAnswers, multipleChoiceWithFeedbackAndHintsOLX, textInputWithFeedbackAndHintsOLXWithMultipleAnswers, advancedProblemOlX, multipleProblemOlX, + multipleProblemTwoOlX, + multipleProblemThreeOlX, blankProblemOLX, blankQuestionOLX, styledQuestionOLX, @@ -53,6 +54,16 @@ describe('Check OLXParser problem type', () => { const problemType = olxparser.getProblemType(); expect(problemType).toBe(ProblemTypeKeys.ADVANCED); }); + test('Test Advanced Problem Type by multiples, second example', () => { + const olxparser = new OLXParser(multipleProblemTwoOlX.rawOLX); + const problemType = olxparser.getProblemType(); + expect(problemType).toBe(ProblemTypeKeys.ADVANCED); + }); + test('Test Advanced Problem Type by multiples, third example', () => { + const olxparser = new OLXParser(multipleProblemThreeOlX.rawOLX); + const problemType = olxparser.getProblemType(); + expect(problemType).toBe(ProblemTypeKeys.ADVANCED); + }); test('Test Blank Problem Type', () => { const olxparser = new OLXParser(blankProblemOLX.rawOLX); const problemType = olxparser.getProblemType(); @@ -124,11 +135,6 @@ describe('Check OLXParser for answer parsing', () => { const answer = olxparser.parseNumericResponse(); expect(answer).toEqual(numericInputWithFeedbackAndHintsOLX.data); }); - test('Test numerical response answers exception', () => { - const olxparser = new OLXParser(numericInputWithFeedbackAndHintsOLXException.rawOLX); - const answer = olxparser.parseNumericResponse(); - expect(answer).toEqual(numericInputWithFeedbackAndHintsOLXException.data); - }); }); describe('Check OLXParser for question parsing', () => { @@ -157,11 +163,6 @@ describe('Check OLXParser for question parsing', () => { const question = olxparser.parseQuestions('numericalresponse'); expect(question).toEqual(numericInputWithFeedbackAndHintsOLX.question); }); - test('Test numerical response question exception', () => { - const olxparser = new OLXParser(numericInputWithFeedbackAndHintsOLXException.rawOLX); - const question = olxparser.parseQuestions('numericalresponse'); - expect(question).toEqual(numericInputWithFeedbackAndHintsOLXException.question); - }); test('Test OLX with no question content should have empty string for question', () => { const olxparser = new OLXParser(blankQuestionOLX.rawOLX); const problemType = olxparser.getProblemType(); diff --git a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js index 4197d2f0a..0f7681335 100644 --- a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js +++ b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js @@ -258,11 +258,6 @@ class ReactStateOLXParser { let answerObject = {}; const additionalAnswers = []; let firstCorrectAnswerParsed = false; - /* - TODO: Need to figure out how to add multiple numericalresponse, - the parser right now converts all the other right answers into - additional answers. - */ answers.forEach((answer) => { const correcthint = this.getAnswerHints(answer); if (this.hasAttributeWithValue(answer, 'title')) { diff --git a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js index 6c98ba99d..6ea378195 100644 --- a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js @@ -3,7 +3,6 @@ import { checkboxesOLXWithFeedbackAndHintsOLX, dropdownOLXWithFeedbackAndHintsOLX, numericInputWithFeedbackAndHintsOLX, - numericInputWithFeedbackAndHintsOLXException, textInputWithFeedbackAndHintsOLX, multipleChoiceWithFeedbackAndHintsOLX, textInputWithFeedbackAndHintsOLXWithMultipleAnswers, @@ -46,13 +45,6 @@ describe('Check React Sate OLXParser problem', () => { const buildOLX = stateParser.buildOLX(); expect(buildOLX.replace(/\s/g, '')).toEqual(numericInputWithFeedbackAndHintsOLX.buildOLX.replace(/\s/g, '')); }); - test('Test numerical response with feedback and hints problem type with exception', () => { - const olxparser = new OLXParser(numericInputWithFeedbackAndHintsOLXException.rawOLX); - const problem = olxparser.getParsedOLXData(); - const stateParser = new ReactStateOLXParser({ problem }); - const buildOLX = stateParser.buildOLX(); - expect(buildOLX.replace(/\s/g, '')).toEqual(numericInputWithFeedbackAndHintsOLXException.buildOLX.replace(/\s/g, '')); - }); test('Test string response with feedback and hints, multiple answers', () => { const olxparser = new OLXParser(textInputWithFeedbackAndHintsOLXWithMultipleAnswers.rawOLX); const problem = olxparser.getParsedOLXData(); diff --git a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js index 2c6da1e90..5333bdc58 100644 --- a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js +++ b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js @@ -523,83 +523,6 @@ export const textInputWithFeedbackAndHintsOLXWithMultipleAnswers = { `, }; -export const numericInputWithFeedbackAndHintsOLXException = { - rawOLX: ` -

You can use this template as a guide to the simple editor markdown and OLX markup to use for numerical input with hints and feedback problems. Edit this component to replace this template with your own assessment.

- - - You can add an optional tip or note related to the prompt like this. - - - - - - - You can specify optional feedback like this, which appears after this answer is submitted. - - - - This is one feedback! - - - - - You can add an optional hint like this. Problems that have a hint include a hint button, and this text appears the first time learners select the button. - If you add more than one hint, a different hint appears each time learners select the hint button. - -
`, - data: { - answers: [ - { - id: 'A', - title: '300', - correct: true, - selectedFeedback: '', - }, - { - id: 'B', - title: '100', - correct: true, - selectedFeedback: 'You can specify optional feedback like this, which appears after this answer is submitted.', - tolerance: '5', - }, - { - id: 'C', - title: '200', - correct: true, - selectedFeedback: '', - tolerance: '4', - }, - { - id: 'D', - title: '500', - correct: true, - selectedFeedback: 'This is one feedback!', - }, - ], - }, - question: '

You can use this template as a guide to the simple editor markdown and OLX markup to use for numerical input with hints and feedback problems. Edit this component to replace this template with your own assessment.

You can add an optional tip or note related to the prompt like this.', - buildOLX: ` -

You can use this template as a guide to the simple editor markdown and OLX markup to use for numerical input with hints and feedback problems. Edit this component to replace this template with your own assessment.

- - You can add an optional tip or note related to the prompt like this. - - - You can specify optional feedback like this, which appears after this answer is submitted. - - - - This is one feedback! - - - - - You can add an optional hint like this. Problems that have a hint include a hint button, and this text appears the first time learners select the button. - If you add more than one hint, a different hint appears each time learners select the hint button. - -
-`, -}; export const advancedProblemOlX = { rawOLX: ` @@ -621,6 +544,26 @@ export const multipleProblemOlX = { `, }; +export const multipleProblemTwoOlX = { + rawOLX: ` + + + + + + +`, +}; +export const multipleProblemThreeOlX = { + rawOLX: ` + + + + + + +`, +}; export const blankProblemOLX = { rawOLX: '', };