Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: switch to advanced editor for partial credit support #386

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>`
}