From 87aaa7f3ff4505662ab8a4d746be28bb0fbc7f35 Mon Sep 17 00:00:00 2001 From: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com> Date: Tue, 7 Feb 2023 20:04:16 -0500 Subject: [PATCH] fix: add empty answer to problem without answers (#235) --- .../ProblemEditor/data/OLXParser.js | 10 +++++++++- .../ProblemEditor/data/OLXParser.test.js | 6 ++++++ .../data/mockData/olxTestData.js | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 4c6f76b72..561b365c4 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -59,7 +59,15 @@ export class OLXParser { let data = {}; const widget = _.get(this.problem, `${problemType}.${widgetName}`); const choice = _.get(widget, option); - if (_.isArray(choice)) { + if (_.isEmpty(choice)) { + answers.push( + { + id: indexToLetterMap[answers.length], + title: '', + correct: true, + }, + ); + } else if (_.isArray(choice)) { choice.forEach((element, index) => { const title = element['#text']; const correct = eval(element['@_correct'].toLowerCase()); diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index d32088f6e..c0c8b4bab 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -6,6 +6,7 @@ import { numericInputWithFeedbackAndHintsOLX, numericInputWithFeedbackAndHintsOLXException, textInputWithFeedbackAndHintsOLX, + multipleChoiceWithoutAnswers, multipleChoiceWithFeedbackAndHintsOLX, textInputWithFeedbackAndHintsOLXWithMultipleAnswers, advancedProblemOlX, @@ -88,6 +89,11 @@ describe('Check OLXParser hints', () => { }); describe('Check OLXParser for answer parsing', () => { + test('Test check single select with empty answers', () => { + const olxparser = new OLXParser(multipleChoiceWithoutAnswers.rawOLX); + const answer = olxparser.parseMultipleChoiceAnswers('multiplechoiceresponse', 'choicegroup', 'choice'); + expect(answer).toEqual(multipleChoiceWithoutAnswers.data); + }); test('Test checkbox answer', () => { const olxparser = new OLXParser(checkboxesOLXWithFeedbackAndHintsOLX.rawOLX); const answer = olxparser.parseMultipleChoiceAnswers('choiceresponse', 'checkboxgroup', 'choice'); diff --git a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js index 90b3837d3..2c6da1e90 100644 --- a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js +++ b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js @@ -138,6 +138,26 @@ an incorrect answer You can specify optional export const checkboxesOLXWithFeedbackAndHintsOLX = getCheckboxesOLXWithFeedbackAndHintsOLX({}); +export const multipleChoiceWithoutAnswers = { + rawOLX: ` + + + + + + + `, + data: { + answers: [ + { + id: 'A', + title: '', + correct: true, + }, + ], + }, +}; + export const dropdownOLXWithFeedbackAndHintsOLX = { rawOLX: `