fix: parse description/label as children (#300)
* fix: parse description/label as children * fix: bounce problem tag attributes to advanced
This commit is contained in:
@@ -28,6 +28,28 @@ export const nonQuestionKeys = [
|
||||
'textline',
|
||||
];
|
||||
|
||||
export const responseKeys = [
|
||||
'multiplechoiceresponse',
|
||||
'numericalresponse',
|
||||
'optionresponse',
|
||||
'stringresponse',
|
||||
'choiceresponse',
|
||||
'multiplechoiceresponse',
|
||||
'truefalseresponse',
|
||||
'optionresponse',
|
||||
'numericalresponse',
|
||||
'stringresponse',
|
||||
'customresponse',
|
||||
'symbolicresponse',
|
||||
'coderesponse',
|
||||
'externalresponse',
|
||||
'formularesponse',
|
||||
'schematicresponse',
|
||||
'imageresponse',
|
||||
'annotationresponse',
|
||||
'choicetextresponse',
|
||||
];
|
||||
|
||||
export const stripNonTextTags = ({ input, tag }) => {
|
||||
const stripedTags = {};
|
||||
Object.entries(input).forEach(([key, value]) => {
|
||||
@@ -313,12 +335,7 @@ export class OLXParser {
|
||||
};
|
||||
const builder = new XMLBuilder(options);
|
||||
const problemArray = _.get(this.questionData[0], problemType) || this.questionData;
|
||||
/* TODO: How do we uniquely identify the description?
|
||||
In order to parse description, there should be two states
|
||||
and settings should be introduced to edit the label and description.
|
||||
In turn editing the settings update the state and then it can be added to
|
||||
the parsed OLX.
|
||||
*/
|
||||
|
||||
const questionArray = [];
|
||||
problemArray.forEach(tag => {
|
||||
const tagName = Object.keys(tag)[0];
|
||||
@@ -327,6 +344,16 @@ export class OLXParser {
|
||||
throw new Error('Script Tag, reverting to Advanced Editor');
|
||||
}
|
||||
questionArray.push(tag);
|
||||
} else if (responseKeys.includes(tagName)) {
|
||||
/* <label> and <description> tags often are both valid olx as siblings or children of response type tags.
|
||||
They, however, do belong in the question, so we append them to the question.
|
||||
*/
|
||||
tag[tagName].forEach(subTag => {
|
||||
const subTagName = Object.keys(subTag)[0];
|
||||
if (subTagName === 'label' || subTagName === 'description') {
|
||||
questionArray.push(subTag);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
const questionString = builder.build(questionArray);
|
||||
@@ -428,6 +455,11 @@ export class OLXParser {
|
||||
if (_.isEmpty(this.problem)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (Object.keys(this.problem).some((key) => key.indexOf('@_') !== -1)) {
|
||||
throw new Error('Misc Attributes asscoiated with problem, opening in advanced editor');
|
||||
}
|
||||
|
||||
let answersObject = {};
|
||||
let additionalAttributes = {};
|
||||
let groupFeedbackList = [];
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
styledQuestionOLX,
|
||||
shuffleProblemOLX,
|
||||
scriptProblemOlX,
|
||||
labelDescriptionQuestionOLX,
|
||||
} from './mockData/olxTestData';
|
||||
import { ProblemTypeKeys } from '../../../data/constants/problem';
|
||||
|
||||
@@ -73,6 +74,18 @@ describe('Check OLXParser problem type', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('OLX Parser settings attributes on problem tags', () => {
|
||||
test('OLX with attributes on the problem tags should error out', () => {
|
||||
const olxparser = new OLXParser(labelDescriptionQuestionOLX.rawOLX);
|
||||
try {
|
||||
olxparser.getParsedOLXData();
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(Error);
|
||||
expect(e.message).toBe('Misc Attributes asscoiated with problem, opening in advanced editor');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Check OLXParser hints', () => {
|
||||
test('Test checkbox hints', () => {
|
||||
const olxparser = new OLXParser(checkboxesOLXWithFeedbackAndHintsOLX.rawOLX);
|
||||
@@ -198,6 +211,12 @@ describe('Check OLXParser for question parsing', () => {
|
||||
const question = olxparser.parseQuestions(problemType);
|
||||
expect(question).toBe(styledQuestionOLX.question);
|
||||
});
|
||||
test('Test OLX content with labels and descriptions inside reponse tag should parse correctly, appending the label/description to the question', () => {
|
||||
const olxparser = new OLXParser(labelDescriptionQuestionOLX.rawOLX);
|
||||
const problemType = olxparser.getProblemType();
|
||||
const question = olxparser.parseQuestions(problemType);
|
||||
expect(question).toBe(labelDescriptionQuestionOLX.question);
|
||||
});
|
||||
});
|
||||
|
||||
describe('OLXParser for problem with solution tag', () => {
|
||||
|
||||
@@ -671,3 +671,26 @@ export const shuffleProblemOLX = {
|
||||
</multiplechoiceresponse>
|
||||
</problem>`,
|
||||
};
|
||||
|
||||
export const labelDescriptionQuestionOLX = {
|
||||
rawOLX:
|
||||
`<problem display_name="Eggs b) - Choosing a System" markdown="null" max_attempts="3" weight="0.5">
|
||||
<p style="text-align: center;"><img height="274" width="" src="/static/boiling_eggs_water_system.png" alt="boiling eggs: water system"/></p>
|
||||
<multiplechoiceresponse>
|
||||
<label>Taking the system as just the <b>water</b>, as indicated by the red dashed line, what would be the correct expression for the first law of thermodynamics applied to this system?</label>
|
||||
<description>Watch out, boiling water is hot</description>
|
||||
<choicegroup type="MultipleChoice">
|
||||
<choice correct="true">( Delta E_text{water} = Q )</choice>
|
||||
<choice correct="false">( Delta E_text{water} = - W )</choice>
|
||||
<choice correct="false">( Delta E_text{water} = 0 )</choice>
|
||||
</choicegroup>
|
||||
</multiplechoiceresponse>
|
||||
<solution>
|
||||
<div class="detailed-solution">
|
||||
<h2>Explanation</h2>
|
||||
</div>
|
||||
</solution>
|
||||
</problem>`,
|
||||
|
||||
question: '<p style="text-align: center;"><img height="274" width="" src="/static/boiling_eggs_water_system.png" alt="boiling eggs: water system"></img></p><label>Taking the system as just the<b>water</b>, as indicated by the red dashed line, what would be the correct expression for the first law of thermodynamics applied to this system?</label><em>Watch out, boiling water is hot</em>',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user