Merge pull request #187 from openedx/kenclary/TNL-10324

fix: match new frontend behavior with legacy behavior (zero problem attempts is zero attempts, null attempts is infinite); negative values disallowed and forced to zero. TNL-10324.
This commit is contained in:
kenclary
2023-01-12 10:40:47 -05:00
committed by GitHub
2 changed files with 29 additions and 5 deletions

View File

@@ -113,14 +113,14 @@ export const resetCardHooks = (updateSettings) => {
export const scoringCardHooks = (scoring, updateSettings) => {
const handleMaxAttemptChange = (event) => {
let unlimitedAttempts = true;
let unlimitedAttempts = false;
let attemptNumber = parseInt(event.target.value);
if (_.isNaN(attemptNumber)) {
attemptNumber = null;
unlimitedAttempts = true;
} else if (attemptNumber < 0) {
attemptNumber = 0;
}
if (attemptNumber > 0) {
unlimitedAttempts = false;
}
updateSettings({ scoring: { ...scoring, attempts: { number: attemptNumber, unlimited: unlimitedAttempts } } });
};

View File

@@ -178,7 +178,31 @@ describe('Problem settings hooks', () => {
const value = 0;
output.handleMaxAttemptChange({ target: { value } });
expect(updateSettings)
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: value, unlimited: true } } });
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: value, unlimited: false } } });
});
test('test handleMaxAttemptChange set attempts to null value', () => {
const value = null;
output.handleMaxAttemptChange({ target: { value } });
expect(updateSettings)
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: true } } });
});
test('test handleMaxAttemptChange set attempts to empty string', () => {
const value = '';
output.handleMaxAttemptChange({ target: { value } });
expect(updateSettings)
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: true } } });
});
test('test handleMaxAttemptChange set attempts to non-numeric value', () => {
const value = 'abc';
output.handleMaxAttemptChange({ target: { value } });
expect(updateSettings)
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: null, unlimited: true } } });
});
test('test handleMaxAttemptChange set attempts to negative value', () => {
const value = -1;
output.handleMaxAttemptChange({ target: { value } });
expect(updateSettings)
.toHaveBeenCalledWith({ scoring: { ...scoring, attempts: { number: 0, unlimited: false } } });
});
test('test handleWeightChange', () => {
const value = 2;