test: fix related test cases
This commit is contained in:
@@ -126,12 +126,11 @@ export const scoringCardHooks = (scoring, updateSettings, defaultValue) => {
|
||||
let attemptNumber = parseInt(event.target.value);
|
||||
const { value } = event.target;
|
||||
// TODO: impove below condition handling
|
||||
if (_.isNaN(attemptNumber)) {
|
||||
if (_.isNaN(attemptNumber) || _.isNil(attemptNumber)) {
|
||||
attemptNumber = null;
|
||||
if (value === '' && !_.isNil(defaultValue)) {
|
||||
attemptNumber = null;
|
||||
setAttemptDisplayValue(`${defaultValue} (Default)`);
|
||||
} else if (_.isNil(defaultValue)) {
|
||||
attemptNumber = null;
|
||||
unlimitedAttempts = true;
|
||||
}
|
||||
} else if (attemptNumber <= 0) {
|
||||
|
||||
@@ -155,13 +155,13 @@ describe('Problem settings hooks', () => {
|
||||
output.handleUnlimitedChange({ target: { checked: true } });
|
||||
expect(state.setState[state.keys.attemptDisplayValue]).toHaveBeenCalledWith('');
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: '', unlimited: true } } });
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: true } } });
|
||||
});
|
||||
test('test handleUnlimitedChange sets attempts.unlimited to false when unchecked', () => {
|
||||
output.handleUnlimitedChange({ target: { checked: false } });
|
||||
expect(state.setState[state.keys.attemptDisplayValue]).toHaveBeenCalledWith(`${defaultValue} (Default)`);
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: defaultValue, unlimited: false } } });
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: false } } });
|
||||
});
|
||||
test('test handleMaxAttemptChange', () => {
|
||||
const value = 6;
|
||||
@@ -175,30 +175,30 @@ describe('Problem settings hooks', () => {
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: value, unlimited: false } } });
|
||||
});
|
||||
test('test handleMaxAttemptChange set attempts to null value', () => {
|
||||
test('test handleMaxAttemptChange set attempts to null value when default max_attempts is present', () => {
|
||||
const value = null;
|
||||
output.handleMaxAttemptChange({ target: { value } });
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: '', unlimited: true } } });
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: false } } });
|
||||
});
|
||||
test('test handleMaxAttemptChange set attempts to default value', () => {
|
||||
test('test handleMaxAttemptChange set attempts to null when default value is inputted', () => {
|
||||
const value = '1 (Default)';
|
||||
output.handleMaxAttemptChange({ target: { value } });
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: 1, unlimited: false } } });
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: false } } });
|
||||
});
|
||||
test('test handleMaxAttemptChange set attempts to non-numeric value', () => {
|
||||
const value = 'abc';
|
||||
output.handleMaxAttemptChange({ target: { value } });
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: '', unlimited: true } } });
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: false } } });
|
||||
});
|
||||
test('test handleMaxAttemptChange set attempts to empty value', () => {
|
||||
const value = '';
|
||||
output.handleMaxAttemptChange({ target: { value } });
|
||||
expect(state.setState[state.keys.attemptDisplayValue]).toHaveBeenCalledWith(`${defaultValue} (Default)`);
|
||||
expect(updateSettings)
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: 1, unlimited: false } } });
|
||||
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: false } } });
|
||||
});
|
||||
test('test handleMaxAttemptChange set attempts to negative value', () => {
|
||||
const value = -1;
|
||||
|
||||
@@ -49,6 +49,7 @@ exports[`ScoringCard snapshot snapshot: scoring setting card 1`] = `
|
||||
<Form.Checkbox
|
||||
checked={false}
|
||||
className="mt-3 decoration-control-label"
|
||||
disabled={true}
|
||||
>
|
||||
<div
|
||||
className="x-small"
|
||||
@@ -123,6 +124,7 @@ exports[`ScoringCard snapshot snapshot: scoring setting card max attempts 1`] =
|
||||
<Form.Checkbox
|
||||
checked={true}
|
||||
className="mt-3 decoration-control-label"
|
||||
disabled={true}
|
||||
>
|
||||
<div
|
||||
className="x-small"
|
||||
@@ -197,6 +199,7 @@ exports[`ScoringCard snapshot snapshot: scoring setting card zero zero weight 1`
|
||||
<Form.Checkbox
|
||||
checked={false}
|
||||
className="mt-3 decoration-control-label"
|
||||
disabled={true}
|
||||
>
|
||||
<div
|
||||
className="x-small"
|
||||
|
||||
@@ -16,7 +16,7 @@ export const parseScoringSettings = (metadata, defaultSettings) => {
|
||||
|
||||
let attempts = popuplateItem({}, 'max_attempts', 'number', metadata);
|
||||
// TODO: impove below condition handling
|
||||
if ((_.isEmpty(attempts) || _.isNaN(attempts.number)) && _.isNaN(defaultSettings.max_attempts)) {
|
||||
if ((_.isEmpty(attempts) || _.isNaN(attempts.number)) && (_.isEmpty(defaultSettings) || _.isNaN(defaultSettings.max_attempts))) {
|
||||
attempts = { unlimited: true, number: '' };
|
||||
} else if (!_.isEmpty(attempts) && !_.isNaN(attempts.number)) {
|
||||
attempts.unlimited = false;
|
||||
|
||||
@@ -8,39 +8,40 @@ import {
|
||||
} from './mockData/problemTestData';
|
||||
|
||||
describe('Test Settings to State Parser', () => {
|
||||
const defaultSettings = { max_attempts: 1 };
|
||||
test('Test all fields populated', () => {
|
||||
const settings = parseSettings(checklistWithFeebackHints.metadata);
|
||||
const settings = parseSettings(checklistWithFeebackHints.metadata, defaultSettings);
|
||||
const { hints, ...settingsPayload } = checklistWithFeebackHints.state.settings;
|
||||
expect(settings).toStrictEqual(settingsPayload);
|
||||
});
|
||||
|
||||
test('Test score settings', () => {
|
||||
const scoreSettings = parseScoringSettings(checklistWithFeebackHints.metadata);
|
||||
const scoreSettings = parseScoringSettings(checklistWithFeebackHints.metadata, defaultSettings);
|
||||
expect(scoreSettings).toStrictEqual(checklistWithFeebackHints.state.settings.scoring);
|
||||
});
|
||||
|
||||
test('Test score settings zero attempts', () => {
|
||||
const scoreSettings = parseScoringSettings(numericWithHints.metadata);
|
||||
const scoreSettings = parseScoringSettings(numericWithHints.metadata, defaultSettings);
|
||||
expect(scoreSettings).toStrictEqual(numericWithHints.state.settings.scoring);
|
||||
});
|
||||
|
||||
test('Test score settings attempts missing', () => {
|
||||
const scoreSettings = parseScoringSettings(singleSelectWithHints.metadata);
|
||||
test('Test score settings attempts missing with no default max_attempts', () => {
|
||||
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);
|
||||
const scoreSettings = parseScoringSettings(negativeAttempts.metadata, defaultSettings);
|
||||
expect(scoreSettings.attempts).toStrictEqual(negativeAttempts.state.settings.scoring.attempts);
|
||||
});
|
||||
|
||||
test('Test score settings missing', () => {
|
||||
const settings = parseSettings(singleSelectWithHints.metadata);
|
||||
test('Test score settings missing with no default', () => {
|
||||
const settings = parseSettings(singleSelectWithHints.metadata, {});
|
||||
expect(settings.scoring).toStrictEqual(singleSelectWithHints.state.settings.scoring);
|
||||
});
|
||||
|
||||
test('Test invalid randomization', () => {
|
||||
const settings = parseSettings(numericWithHints.metadata);
|
||||
const settings = parseSettings(numericWithHints.metadata, defaultSettings);
|
||||
expect(settings.randomization).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -55,12 +56,12 @@ describe('Test Settings to State Parser', () => {
|
||||
});
|
||||
|
||||
test('Test empty metadata', () => {
|
||||
const scoreSettings = parseSettings({});
|
||||
const scoreSettings = parseSettings({}, defaultSettings);
|
||||
expect(scoreSettings).toStrictEqual({});
|
||||
});
|
||||
|
||||
test('Test null metadata', () => {
|
||||
const scoreSettings = parseSettings(null);
|
||||
const scoreSettings = parseSettings(null, defaultSettings);
|
||||
expect(scoreSettings).toStrictEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user