From 9b2d4e36b33c84ecfbdc150ddfbc1a1f2edf9ae1 Mon Sep 17 00:00:00 2001 From: Liz Abinante Date: Wed, 13 Nov 2013 12:53:44 -0600 Subject: [PATCH] adds validation for name to assignment quick add fixes CNVS-9495 test plan: - with draft state enabled - from assignment index page as a teacher - click quick add button for assignment - save without title - verify that the error message renders - also verify that you can save assignment with a title from quick add window Change-Id: If7359af56656b9e3dd6a33b9db9d6638c8b3f175 Reviewed-on: https://gerrit.instructure.com/26281 Tested-by: Jenkins Reviewed-by: Cameron Matheson QA-Review: Caleb Guanzon Product-Review: Simon Williams --- .../assignments/CreateAssignmentView.coffee | 16 +++++++++++++- .../CreateAssignmentViewSpec.coffee | 22 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/coffeescripts/views/assignments/CreateAssignmentView.coffee b/app/coffeescripts/views/assignments/CreateAssignmentView.coffee index bca0c9fad99..149456704cc 100644 --- a/app/coffeescripts/views/assignments/CreateAssignmentView.coffee +++ b/app/coffeescripts/views/assignments/CreateAssignmentView.coffee @@ -4,9 +4,10 @@ define [ 'compiled/views/DialogFormView' 'jst/assignments/CreateAssignment' 'jst/EmptyDialogFormWrapper' + 'i18n!assignments' 'jquery' 'jquery.instructure_date_and_time' -], (_, Assignment, DialogFormView, template, wrapper, $) -> +], (_, Assignment, DialogFormView, template, wrapper, I18n, $) -> class CreateAssignmentView extends DialogFormView defaults: @@ -88,3 +89,16 @@ define [ newAssignmentUrl: -> ENV.URLS.new_assignment_url + + validateBeforeSave: (data, errors) -> + errors = @_validateTitle data, errors + errors + + _validateTitle: (data, errors) -> + frozenTitle = _.contains(@model.frozenAttributes(), "title") + + if !frozenTitle and (!data.name or $.trim(data.name.toString()).length == 0) + errors["name"] = [ + message: I18n.t 'name_is_required', 'Name is required!' + ] + errors \ No newline at end of file diff --git a/spec/coffeescripts/views/assignments/CreateAssignmentViewSpec.coffee b/spec/coffeescripts/views/assignments/CreateAssignmentViewSpec.coffee index f7ba308583b..7afb089bc44 100644 --- a/spec/coffeescripts/views/assignments/CreateAssignmentViewSpec.coffee +++ b/spec/coffeescripts/views/assignments/CreateAssignmentViewSpec.coffee @@ -17,6 +17,9 @@ define [ assignment2 = -> new Assignment(buildAssignment2()) + assignment3 = -> + new Assignment(buildAssignment3()) + buildAssignment1 = -> date1 = "due_at":"2013-08-28T23:59:00-06:00" @@ -44,6 +47,15 @@ define [ "position":2 ) + buildAssignment3 = -> + buildAssignment( + "id":4 + "name":"" + "due_at":"2013-08-23T23:59:00-06:00" + "points_possible":10 + "position":3 + ) + buildAssignment = (options) -> options ?= {} @@ -82,6 +94,7 @@ define [ setup: -> @assignment1 = assignment1() @assignment2 = assignment2() + @assignment3 = assignment3() @group = assignmentGroup() test "initialize generates a new assignment for creation", -> @@ -191,3 +204,12 @@ define [ $.fn.datetime_field.restore() DialogFormView.prototype.openAgain.restore() + test "requires name to save assignment", -> + view = createView(@assignment3) + data = + name: "" + errors = view.validateBeforeSave(data, []) + + ok errors["name"] + equal errors["name"].length, 1 + equal errors["name"][0]["message"], "Name is required!" \ No newline at end of file