Skip to content

Commit 9b2d4e3

Browse files
committed
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 <jenkins@instructure.com> Reviewed-by: Cameron Matheson <cameron@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
1 parent 12077de commit 9b2d4e3

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

app/coffeescripts/views/assignments/CreateAssignmentView.coffee

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ define [
44
'compiled/views/DialogFormView'
55
'jst/assignments/CreateAssignment'
66
'jst/EmptyDialogFormWrapper'
7+
'i18n!assignments'
78
'jquery'
89
'jquery.instructure_date_and_time'
9-
], (_, Assignment, DialogFormView, template, wrapper, $) ->
10+
], (_, Assignment, DialogFormView, template, wrapper, I18n, $) ->
1011

1112
class CreateAssignmentView extends DialogFormView
1213
defaults:
@@ -88,3 +89,16 @@ define [
8889

8990
newAssignmentUrl: ->
9091
ENV.URLS.new_assignment_url
92+
93+
validateBeforeSave: (data, errors) ->
94+
errors = @_validateTitle data, errors
95+
errors
96+
97+
_validateTitle: (data, errors) ->
98+
frozenTitle = _.contains(@model.frozenAttributes(), "title")
99+
100+
if !frozenTitle and (!data.name or $.trim(data.name.toString()).length == 0)
101+
errors["name"] = [
102+
message: I18n.t 'name_is_required', 'Name is required!'
103+
]
104+
errors

spec/coffeescripts/views/assignments/CreateAssignmentViewSpec.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ define [
1717
assignment2 = ->
1818
new Assignment(buildAssignment2())
1919

20+
assignment3 = ->
21+
new Assignment(buildAssignment3())
22+
2023
buildAssignment1 = ->
2124
date1 =
2225
"due_at":"2013-08-28T23:59:00-06:00"
@@ -44,6 +47,15 @@ define [
4447
"position":2
4548
)
4649

50+
buildAssignment3 = ->
51+
buildAssignment(
52+
"id":4
53+
"name":""
54+
"due_at":"2013-08-23T23:59:00-06:00"
55+
"points_possible":10
56+
"position":3
57+
)
58+
4759
buildAssignment = (options) ->
4860
options ?= {}
4961

@@ -82,6 +94,7 @@ define [
8294
setup: ->
8395
@assignment1 = assignment1()
8496
@assignment2 = assignment2()
97+
@assignment3 = assignment3()
8598
@group = assignmentGroup()
8699

87100
test "initialize generates a new assignment for creation", ->
@@ -191,3 +204,12 @@ define [
191204
$.fn.datetime_field.restore()
192205
DialogFormView.prototype.openAgain.restore()
193206

207+
test "requires name to save assignment", ->
208+
view = createView(@assignment3)
209+
data =
210+
name: ""
211+
errors = view.validateBeforeSave(data, [])
212+
213+
ok errors["name"]
214+
equal errors["name"].length, 1
215+
equal errors["name"][0]["message"], "Name is required!"

0 commit comments

Comments
 (0)