From e3f5bbfe0ca9e0886cc4e3f7ae92aae68001eadf Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Mon, 11 Sep 2023 19:26:42 +0200 Subject: [PATCH] fix: switch to advanced editor for partial credit support This commit reverts to advanced editor when partial_credit attribute is added to multichoice, single select and numerical problems. Without this change, the partial_credit attribute is removed from the problem on the next edit. --- .../ProblemEditor/data/OLXParser.js | 6 +++ .../ProblemEditor/data/OLXParser.test.js | 36 +++++++++++++++++ .../data/mockData/olxTestData.js | 40 +++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 4e10ccc03..59e851eff 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -181,6 +181,9 @@ export class OLXParser { if (_.keys(widget).some((tag) => !permissableTags.includes(tag))) { throw new Error('Misc Tags, reverting to Advanced Editor'); } + if (_.get(this.problem, `${problemType}.@_partial_credit`)) { + throw new Error('Partial credit not supported by GUI, reverting to Advanced Editor'); + } const choice = _.get(widget, option); const isComplexAnswer = RichTextProblems.includes(problemType); if (_.isEmpty(choice)) { @@ -401,6 +404,9 @@ export class OLXParser { 'correcthint', ); const { numericalresponse } = this.problem; + if (_.get(numericalresponse, '@_partial_credit')) { + throw new Error('Partial credit not supported by GUI, reverting to Advanced Editor'); + } let answerFeedback = ''; const answers = []; let responseParam = {}; diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index 410fa85eb..65a42eaba 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -11,15 +11,18 @@ import { advancedProblemOlX, multipleTextInputProblemOlX, multipleNumericProblemOlX, + multiSelectPartialCredit, NumericAndTextInputProblemOlX, blankProblemOLX, blankQuestionOLX, styledQuestionOLX, shuffleProblemOLX, scriptProblemOlX, + singleSelectPartialCredit, labelDescriptionQuestionOLX, htmlEntityTestOLX, numberParseTestOLX, + numericalProblemPartialCredit, solutionExplanationTest, solutionExplanationWithoutDivTest, tablesInRichTextTest, @@ -42,6 +45,9 @@ const multipleNumericOlxParser = new OLXParser(multipleNumericProblemOlX.rawOLX) const numericAndTextInputOlxParser = new OLXParser(NumericAndTextInputProblemOlX.rawOLX); const labelDescriptionQuestionOlxParser = new OLXParser(labelDescriptionQuestionOLX.rawOLX); const shuffleOlxParser = new OLXParser(shuffleProblemOLX.rawOLX); +const multiSelectPartialCreditOlxParser = new OLXParser(multiSelectPartialCredit.rawOLX); +const singleSelectPartialCreditParser = new OLXParser(singleSelectPartialCredit.rawOLX); +const numericalProblemPartialCreditParser = new OLXParser(numericalProblemPartialCredit.rawOLX); describe('OLXParser', () => { describe('throws error and redirects to advanced editor', () => { @@ -71,6 +77,36 @@ describe('OLXParser', () => { expect(() => olxparser.parseQuestions('numericalresponse')).toThrow(new Error('Script Tag, reverting to Advanced Editor')); }); }); + describe('when multi select problem finds partial_credit attribute', () => { + it('should throw error and contain message regarding opening advanced editor', () => { + try { + multiSelectPartialCreditOlxParser.getParsedOLXData(); + } catch (e) { + expect(e).toBeInstanceOf(Error); + expect(e.message).toBe('Partial credit not supported by GUI, reverting to Advanced Editor'); + } + }); + }); + describe('when multi select problem finds partial_credit attribute', () => { + it('should throw error and contain message regarding opening advanced editor', () => { + try { + numericalProblemPartialCreditParser.getParsedOLXData(); + } catch (e) { + expect(e).toBeInstanceOf(Error); + expect(e.message).toBe('Partial credit not supported by GUI, reverting to Advanced Editor'); + } + }); + }); + describe('when multi select problem finds partial_credit attribute', () => { + it('should throw error and contain message regarding opening advanced editor', () => { + try { + singleSelectPartialCreditParser.getParsedOLXData(); + } catch (e) { + expect(e).toBeInstanceOf(Error); + expect(e.message).toBe('Partial credit not supported by GUI, reverting to Advanced Editor'); + } + }); + }); }); describe('getProblemType()', () => { describe('given a blank problem', () => { diff --git a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js index a6d53ce29..79d4b9cbf 100644 --- a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js +++ b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js @@ -1112,3 +1112,43 @@ export const parseOutExplanationTests = {

solution meat

` }; + +export const multiSelectPartialCredit = { + rawOLX: ` + + + Select all that apply. + + apple + pumpkin + potato + tomato + + + ` +} + +export const singleSelectPartialCredit = { + rawOLX: ` + + + + The iPad + Napster + The iPod + The vegetable peeler + + + ` +} + +export const numericalProblemPartialCredit = { + rawOLX: ` + + + Use scientific notation to answer. + + + + ` +}