From 436fdfc470cdfcb4f8ed0642790bd8ad2e0af255 Mon Sep 17 00:00:00 2001 From: Raymond Zhou <56318341+rayzhou-bit@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:05:31 -0400 Subject: [PATCH] feat: parse out explanation text (#358) --- .../ProblemEditor/data/OLXParser.js | 6 +++-- .../ProblemEditor/data/OLXParser.test.js | 7 ++++++ .../data/mockData/olxTestData.js | 22 +++++++++++++++++++ src/editors/data/services/cms/mockApi.js | 16 +------------- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 4d0acaa10..4e10ccc03 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -529,13 +529,15 @@ export class OLXParser { const solutionArray = []; if (divBody && divBody.div) { divBody.div.forEach(tag => { - if (_.get(Object.values(tag)[0][0], '#text', null) !== 'Explanation') { + const tagText = _.get(Object.values(tag)[0][0], '#text', ''); + if (tagText.toString().trim() !== 'Explanation') { solutionArray.push(tag); } }); } else { solutionBody.solution.forEach(tag => { - if (_.get(Object.values(tag)[0][0], '#text', null) !== 'Explanation') { + const tagText = _.get(Object.values(tag)[0][0], '#text', ''); + if (tagText.toString().trim() !== 'Explanation') { solutionArray.push(tag); } }); diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index 49eedeaef..410fa85eb 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -23,6 +23,7 @@ import { solutionExplanationTest, solutionExplanationWithoutDivTest, tablesInRichTextTest, + parseOutExplanationTests, } from './mockData/olxTestData'; import { ProblemTypeKeys } from '../../../data/constants/problem'; @@ -327,5 +328,11 @@ describe('OLXParser', () => { const explanation = olxparser.getSolutionExplanation(problemType); expect(explanation).toBe(solutionExplanationWithoutDivTest.solutionExplanation); }); + it('should parse out

Explanation

', () => { + const olxparser = new OLXParser(parseOutExplanationTests.rawOLX); + const problemType = olxparser.getProblemType(); + const explanation = olxparser.getSolutionExplanation(problemType); + expect(explanation).toBe(parseOutExplanationTests.solutionExplanation); + }); }); }); diff --git a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js index 01983ca88..a6d53ce29 100644 --- a/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js +++ b/src/editors/containers/ProblemEditor/data/mockData/olxTestData.js @@ -1090,3 +1090,25 @@ export const tablesInRichTextTest = { In which of the following observations does the C-value paradox apply? Select all that apply.

`, }; + +export const parseOutExplanationTests = { + rawOLX: ` + + + + +

Explanation

+

+ Explanation +

+

solution meat

+
+
+ +
`, + solutionExplanation: ` + + +

solution meat

+ ` +}; diff --git a/src/editors/data/services/cms/mockApi.js b/src/editors/data/services/cms/mockApi.js index 06a8a9b54..e7939239e 100644 --- a/src/editors/data/services/cms/mockApi.js +++ b/src/editors/data/services/cms/mockApi.js @@ -36,21 +36,7 @@ export const fetchBlockById = ({ blockId, studioEndpointUrl }) => { } else if (blockId === 'problem-block-id') { data = { data: ` - -

What is the content of the register x2 after executing the following three lines of instructions?

-

Address          assembly instructions
0x0              addi x1, x0, 1
0x4              slli x2, x1, 4
0x8              sub x1, x2, x1

- - answerA - answerB - - -
-

Explanation

-

Address          assembly instructions    comment
0x0              addi x1, x0, 1           x1 = 0x1
0x4              slli x2, x1, 4           x2 = x1 << 4 = 0x10
0x8              sub x1, x2, x1           x1 = x2 - x1 = 0x10 - 0x01 = 0xf

-
-
-
-
`, + `, display_name: 'Dropdown', metadata: { markdown: `You can use this template as a guide to the simple editor markdown and OLX markup to use for dropdown problems. Edit this component to replace this template with your own assessment.