Commit 4cb03f43 by zubiar-arbi

Grading types should not allow empty field for "Total Number" and "Number of Droppable"

STUD-988
parent 23dc10d0
...@@ -18,3 +18,10 @@ define ["js/models/settings/course_grader"], (CourseGrader) -> ...@@ -18,3 +18,10 @@ define ["js/models/settings/course_grader"], (CourseGrader) ->
expect(model.get('weight')).toBe(7) expect(model.get('weight')).toBe(7)
expect(model.get('min_count')).toBe(3) expect(model.get('min_count')).toBe(3)
expect(model.get('drop_count')).toBe(1) expect(model.get('drop_count')).toBe(1)
it "gives validation error if min_count is less than 1 or drop_count is NaN", ->
model = new CourseGrader()
errors = model.validate({min_count: 0, drop_count: ''}, {validate:true})
expect(errors.min_count).toBe('Please enter an integer greater than 0.')
expect(errors.drop_count).toBe('Please enter an integer.')
...@@ -50,16 +50,18 @@ var CourseGrader = Backbone.Model.extend({ ...@@ -50,16 +50,18 @@ var CourseGrader = Backbone.Model.extend({
} }
}} }}
if (_.has(attrs, 'min_count')) { if (_.has(attrs, 'min_count')) {
if (!isFinite(attrs.min_count) || /\D+/.test(attrs.min_count)) { var intMinCount = parseInt(attrs.min_count, 10);
errors.min_count = gettext("Please enter an integer."); if (!isFinite(intMinCount) || /\D+/.test(intMinCount) || intMinCount < 1) {
errors.min_count = gettext("Please enter an integer greater than 0.");
} }
else attrs.min_count = parseInt(attrs.min_count, 10); else attrs.min_count = intMinCount;
} }
if (_.has(attrs, 'drop_count')) { if (_.has(attrs, 'drop_count')) {
if (!isFinite(attrs.drop_count) || /\D+/.test(attrs.drop_count)) { var intDropCount = parseInt(attrs.drop_count, 10);
if (!isFinite(intDropCount) || /\D+/.test(intDropCount) || isNaN(intDropCount)) {
errors.drop_count = gettext("Please enter an integer."); errors.drop_count = gettext("Please enter an integer.");
} }
else attrs.drop_count = parseInt(attrs.drop_count, 10); else attrs.drop_count = intDropCount;
} }
if (_.has(attrs, 'min_count') && _.has(attrs, 'drop_count') && attrs.drop_count > attrs.min_count) { if (_.has(attrs, 'min_count') && _.has(attrs, 'drop_count') && attrs.drop_count > attrs.min_count) {
errors.drop_count = _.template( errors.drop_count = _.template(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment