diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index b5467b838..39b43ef71 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -72,6 +72,10 @@ export class OLXParser { const answers = []; let data = {}; const widget = _.get(this.problem, `${problemType}.${widgetName}`); + const permissableTags = ['choice', '@_type', 'compoundhint', 'option', '#text']; + if (_.keys(widget).some((tag) => !permissableTags.includes(tag))) { + throw new Error('Misc Tags, reverting to Advanced Editor'); + } const choice = _.get(widget, option); const isComplexAnswer = [ProblemTypeKeys.SINGLESELECT, ProblemTypeKeys.MULTISELECT].includes(problemType); if (_.isEmpty(choice)) { diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index 21468bd83..99b4580f8 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -15,6 +15,7 @@ import { blankProblemOLX, blankQuestionOLX, styledQuestionOLX, + shuffleProblemOLX, } from './mockData/olxTestData'; import { ProblemTypeKeys } from '../../../data/constants/problem'; @@ -110,6 +111,23 @@ describe('Check OLXParser for answer parsing', () => { const answer = olxparser.parseMultipleChoiceAnswers('choiceresponse', 'checkboxgroup', 'choice'); expect(answer).toEqual(checkboxesOLXWithFeedbackAndHintsOLX.data); }); + + test('Test checkbox answer', () => { + const olxparser = new OLXParser(checkboxesOLXWithFeedbackAndHintsOLX.rawOLX); + const answer = olxparser.parseMultipleChoiceAnswers('choiceresponse', 'checkboxgroup', 'choice'); + expect(answer).toEqual(checkboxesOLXWithFeedbackAndHintsOLX.data); + }); + + test('Test checkboxs with extraneous tags error out', () => { + const olxparser = new OLXParser(shuffleProblemOLX.rawOLX); + try { + olxparser.parseMultipleChoiceAnswers('choiceresponse', 'checkboxgroup', 'choice'); + } catch (e) { + expect(e).toBeInstanceOf(Error); + expect(e.message).toBe('Misc Tags, reverting to Advanced Editor'); + } + }); + test('Test dropdown answer', () => { const olxparser = new OLXParser(dropdownOLXWithFeedbackAndHintsOLX.rawOLX); const answer = olxparser.parseMultipleChoiceAnswers('optionresponse', 'optioninput', 'option'); diff --git a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js index 3cbd61a92..89bde5b7f 100644 --- a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js +++ b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js @@ -607,3 +607,17 @@ export const styledQuestionOLX = { `, question: '
test
', }; + +export const shuffleProblemOLX = { + rawOLX: `