fix: droppable must be less than total (#31972)
This commit is contained in:
@@ -61,9 +61,9 @@ define(['backbone', 'underscore', 'gettext'], function(Backbone, _, gettext) {
|
||||
errors.drop_count = gettext('Please enter non-negative integer.');
|
||||
} else attrs.drop_count = intDropCount;
|
||||
}
|
||||
if (_.has(attrs, 'min_count') && _.has(attrs, 'drop_count') && !_.has(errors, 'min_count') && !_.has(errors, 'drop_count') && attrs.drop_count > attrs.min_count) {
|
||||
if (_.has(attrs, 'min_count') && _.has(attrs, 'drop_count') && !_.has(errors, 'min_count') && !_.has(errors, 'drop_count') && attrs.drop_count >= attrs.min_count) {
|
||||
var template = _.template(
|
||||
gettext('Cannot drop more <%- types %> assignments than are assigned.')
|
||||
gettext('You must have at least one undroppable <%- types %> assignment.')
|
||||
);
|
||||
errors.drop_count = template({types: attrs.type});
|
||||
}
|
||||
|
||||
@@ -41,6 +41,21 @@ define(["js/models/settings/course_grader"], CourseGrader =>
|
||||
expect(errors.min_count).toBe('Please enter an integer greater than 0.');
|
||||
expect(errors.drop_count).toBe('Please enter non-negative integer.');
|
||||
});
|
||||
|
||||
it("gives validation error if drop_count is not less than min_count", function() {
|
||||
const model = new CourseGrader();
|
||||
const type = 'Homework'
|
||||
let errors = model.validate({min_count: 3, drop_count: 2, type: type}, {validate:true});
|
||||
expect(errors).toBeUndefined();
|
||||
|
||||
errors = model.validate({min_count: 3, drop_count: 3, type: type}, {validate:true});
|
||||
expect(errors.min_count).toBeUndefined();
|
||||
expect(errors.drop_count).toBe('You must have at least one undroppable Homework assignment.');
|
||||
|
||||
errors = model.validate({min_count: 3, drop_count: 4, type: type}, {validate:true});
|
||||
expect(errors.min_count).toBeUndefined();
|
||||
expect(errors.drop_count).toBe('You must have at least one undroppable Homework assignment.');
|
||||
});
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user