feat: parse out explanation text (#358)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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 <p>Explanation</p>', () => {
|
||||
const olxparser = new OLXParser(parseOutExplanationTests.rawOLX);
|
||||
const problemType = olxparser.getProblemType();
|
||||
const explanation = olxparser.getSolutionExplanation(problemType);
|
||||
expect(explanation).toBe(parseOutExplanationTests.solutionExplanation);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1090,3 +1090,25 @@ export const tablesInRichTextTest = {
|
||||
In which of the following observations does the C-value paradox apply? Select all that apply.
|
||||
</p>`,
|
||||
};
|
||||
|
||||
export const parseOutExplanationTests = {
|
||||
rawOLX: `<problem>
|
||||
<multiplechoiceresponse>
|
||||
<choicegroup>
|
||||
</choicegroup>
|
||||
<solution>
|
||||
<p>Explanation</p>
|
||||
<p>
|
||||
Explanation
|
||||
</p>
|
||||
<p>solution meat</p>
|
||||
</solution>
|
||||
</multiplechoiceresponse>
|
||||
<demandhint></demandhint>
|
||||
</problem>`,
|
||||
solutionExplanation: `
|
||||
|
||||
|
||||
<p>solution meat</p>
|
||||
`
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user