fix: more correct parsing of settings, for scoring; use empty string instead of null for empty attempts. TNL-10433.
This commit is contained in:
@@ -15,11 +15,15 @@ export const parseScoringSettings = (metadata) => {
|
||||
let scoring = {};
|
||||
|
||||
let attempts = popuplateItem({}, 'max_attempts', 'number', metadata);
|
||||
if (!_.isEmpty(attempts)) {
|
||||
const unlimited = _.isNaN(attempts.number);
|
||||
attempts = { ...attempts, unlimited };
|
||||
scoring = { ...scoring, attempts };
|
||||
if (_.isEmpty(attempts) || _.isNaN(attempts.number)) {
|
||||
attempts = { unlimited: true, number: '' };
|
||||
} else {
|
||||
attempts.unlimited = false;
|
||||
if (attempts.number < 0) {
|
||||
attempts.number = 0;
|
||||
}
|
||||
}
|
||||
scoring = { ...scoring, attempts };
|
||||
|
||||
scoring = popuplateItem(scoring, 'weight', 'weight', metadata);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
dropdownWithFeedbackHints,
|
||||
numericWithHints,
|
||||
textInputWithHints,
|
||||
singleSelectWithHints,
|
||||
singleSelectWithHints, negativeAttempts,
|
||||
} from './mockData/problemTestData';
|
||||
|
||||
describe('Test Settings to State Parser', () => {
|
||||
@@ -33,13 +33,18 @@ describe('Test Settings to State Parser', () => {
|
||||
});
|
||||
|
||||
test('Test score settings attempts missing', () => {
|
||||
const scoreSettings = parseScoringSettings(textInputWithHints.metadata);
|
||||
expect(scoreSettings.attempts).toBeUndefined();
|
||||
const scoreSettings = parseScoringSettings(singleSelectWithHints.metadata);
|
||||
expect(scoreSettings.attempts).toStrictEqual(singleSelectWithHints.state.settings.scoring.attempts);
|
||||
});
|
||||
|
||||
test('Test negative attempts in score', () => {
|
||||
const scoreSettings = parseScoringSettings(negativeAttempts.metadata);
|
||||
expect(scoreSettings.attempts).toStrictEqual(negativeAttempts.state.settings.scoring.attempts);
|
||||
});
|
||||
|
||||
test('Test score settings missing', () => {
|
||||
const settings = parseSettings(singleSelectWithHints.metadata);
|
||||
expect(settings.scoring).toBeUndefined();
|
||||
expect(settings.scoring).toStrictEqual(singleSelectWithHints.state.settings.scoring);
|
||||
});
|
||||
|
||||
test('Test invalid randomization', () => {
|
||||
|
||||
@@ -359,10 +359,9 @@ export const singleSelectWithHints = {
|
||||
},
|
||||
],
|
||||
scoring: {
|
||||
weight: 0,
|
||||
attempts: {
|
||||
unlimited: true,
|
||||
number: null,
|
||||
number: '',
|
||||
},
|
||||
},
|
||||
timeBetween: 0,
|
||||
@@ -387,3 +386,38 @@ export const singleSelectWithHints = {
|
||||
`,
|
||||
},
|
||||
};
|
||||
|
||||
export const negativeAttempts = {
|
||||
state: {
|
||||
rawOLX: '<problem>\n <numericalresponse answer="100">\n <responseparam type="tolerance" default="5"/>\n <formulaequationinput/>\n </numericalresponse>\n</problem>\n',
|
||||
problemType: 'TEXTINPUT',
|
||||
question: '',
|
||||
answers: [
|
||||
{
|
||||
id: 'A',
|
||||
title: '100 +-5',
|
||||
correct: true,
|
||||
},
|
||||
],
|
||||
groupFeedbackList: [],
|
||||
settings: {
|
||||
scoring: {
|
||||
weight: 2.5,
|
||||
attempts: {
|
||||
unlimited: false,
|
||||
number: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
metadata: {
|
||||
markdown: `
|
||||
=100 +-5 {{You can specify optional feedback like this, which appears after this answer is submitted.}}
|
||||
`,
|
||||
weight: 2.5,
|
||||
max_attempts: -1,
|
||||
rerandomize: 'invalid_input',
|
||||
showanswer: 'invalid_input',
|
||||
attempts_before_showanswer_button: 2,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user