fix: use only null in state for empty value
This commit is contained in:
@@ -15,16 +15,18 @@ export const parseScoringSettings = (metadata, defaultSettings) => {
|
||||
let scoring = {};
|
||||
|
||||
const attempts = popuplateItem({}, 'max_attempts', 'number', metadata);
|
||||
const initialAttempts = _.get(attempts, 'number', null);
|
||||
const defaultAttempts = _.get(defaultSettings, 'max_attempts', null);
|
||||
attempts.unlimited = false;
|
||||
|
||||
// isFinite checks if value is a finite primitive number.
|
||||
if (!_.isFinite(_.get(attempts, 'number', null))) {
|
||||
attempts.number = _.get(defaultSettings, 'max_attempts', null);
|
||||
if (!_.isFinite(initialAttempts) || initialAttempts === defaultAttempts) {
|
||||
// set number to null in any case as lms will pick default value if it exists.
|
||||
attempts.number = null;
|
||||
}
|
||||
|
||||
// if above statement was true and no default was found, set unlimited to true
|
||||
if (_.isNil(attempts.number)) {
|
||||
attempts.number = '';
|
||||
// if both block number and default number are null set unlimited to true.
|
||||
if (_.isNil(initialAttempts) && _.isNil(defaultAttempts)) {
|
||||
attempts.unlimited = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('Test Settings to State Parser', () => {
|
||||
|
||||
test('Test score settings attempts missing with default max_attempts', () => {
|
||||
const scoreSettings = parseScoringSettings(singleSelectWithHints.metadata, defaultSettings);
|
||||
expect(scoreSettings.attempts).toStrictEqual({ number: 1, unlimited: false });
|
||||
expect(scoreSettings.attempts).toStrictEqual({ number: null, unlimited: false });
|
||||
});
|
||||
|
||||
test('Test negative attempts in score', () => {
|
||||
@@ -47,12 +47,12 @@ describe('Test Settings to State Parser', () => {
|
||||
|
||||
test('Test score settings missing with default', () => {
|
||||
const settings = parseSettings(singleSelectWithHints.metadata, defaultSettings);
|
||||
expect(settings.scoring).toStrictEqual({ attempts: { number: 1, unlimited: false } });
|
||||
expect(settings.scoring).toStrictEqual({ attempts: { number: null, unlimited: false } });
|
||||
});
|
||||
|
||||
test('Test score settings missing with null default', () => {
|
||||
const settings = parseSettings(singleSelectWithHints.metadata, { max_attempts: null });
|
||||
expect(settings.scoring).toStrictEqual({ attempts: { number: '', unlimited: true } });
|
||||
expect(settings.scoring).toStrictEqual({ attempts: { number: null, unlimited: true } });
|
||||
});
|
||||
|
||||
test('Test invalid randomization', () => {
|
||||
|
||||
@@ -356,7 +356,7 @@ export const singleSelectWithHints = {
|
||||
scoring: {
|
||||
attempts: {
|
||||
unlimited: true,
|
||||
number: '',
|
||||
number: null,
|
||||
},
|
||||
},
|
||||
timeBetween: 0,
|
||||
|
||||
Reference in New Issue
Block a user