Skip to content

Commit

Permalink
Merge pull request #386 from open-craft/navin/partial-credit
Browse files Browse the repository at this point in the history
fix: switch to advanced editor for partial credit support
  • Loading branch information
kenclary authored Sep 20, 2023
2 parents 773812c + e3f5bbf commit eb320ab
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/editors/containers/ProblemEditor/data/OLXParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 = {};
Expand Down
36 changes: 36 additions & 0 deletions src/editors/containers/ProblemEditor/data/OLXParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import {
advancedProblemOlX,
multipleTextInputProblemOlX,
multipleNumericProblemOlX,
multiSelectPartialCredit,
NumericAndTextInputProblemOlX,
blankProblemOLX,
blankQuestionOLX,
styledQuestionOLX,
shuffleProblemOLX,
scriptProblemOlX,
singleSelectPartialCredit,
labelDescriptionQuestionOLX,
htmlEntityTestOLX,
numberParseTestOLX,
numericalProblemPartialCredit,
solutionExplanationTest,
solutionExplanationWithoutDivTest,
tablesInRichTextTest,
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
40 changes: 40 additions & 0 deletions src/editors/containers/ProblemEditor/data/mockData/olxTestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,3 +1112,43 @@ export const parseOutExplanationTests = {
<p>solution meat</p>
`
};

export const multiSelectPartialCredit = {
rawOLX: `<problem>
<choiceresponse partial_credit="EDC">
<label>Which of the following is a fruit?</label>
<description>Select all that apply.</description>
<checkboxgroup>
<choice correct="true">apple</choice>
<choice correct="true">pumpkin</choice>
<choice correct="false">potato</choice>
<choice correct="true">tomato</choice>
</checkboxgroup>
</choiceresponse>
</problem>`
}

export const singleSelectPartialCredit = {
rawOLX: `<problem>
<multiplechoiceresponse partial_credit="points">
<label>What Apple device competed with the portable CD player?</label>
<choicegroup type="MultipleChoice">
<choice correct="false">The iPad</choice>
<choice correct="false">Napster</choice>
<choice correct="true">The iPod</choice>
<choice correct="partial" point_value="0.25">The vegetable peeler</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>`
}

export const numericalProblemPartialCredit = {
rawOLX: `<problem>
<numericalresponse answer="9.3*10^7" partial_credit="close">
<label>How many miles away from Earth is the sun?</label>
<description>Use scientific notation to answer.</description>
<formulaequationinput/>
<responseparam type="tolerance" default="1%" partial_range="3"/>
</numericalresponse>
</problem>`
}

0 comments on commit eb320ab

Please sign in to comment.