forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageStudentsDialogSpec.coffee
More file actions
85 lines (69 loc) · 2.83 KB
/
Copy pathMessageStudentsDialogSpec.coffee
File metadata and controls
85 lines (69 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# Copyright (C) 2013 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
define [
'compiled/views/MessageStudentsDialog'
'jquery'
'underscore'
], (MessageStudentsDialog,$,_) ->
QUnit.module "MessageStudentsDialog",
setup: ->
@testData =
context: 'The Quiz'
recipientGroups: [
{
name: 'have taken the quiz'
recipients: [ {id: 1, short_name: 'bob'}]
}
{
name: "haven't taken the quiz"
recipients: [ {id: 2, short_name: 'alice'} ]
}
]
@dialog = new MessageStudentsDialog @testData
@dialog.render()
$('#fixtures').append @dialog.$el
teardown: ->
@dialog.remove()
$('#fixtures').empty()
test "#initialize", ->
deepEqual @dialog.recipientGroups, @testData.recipientGroups,
'saves recipientGroups'
deepEqual @dialog.recipients, @testData.recipientGroups[0].recipients,
'saves first recipientGroups recipients to be displayed'
ok @dialog.options.title.match(@testData.context), 'saves the title to be displayed'
ok @dialog.model, 'creates conversation automatically'
test "updates list of recipients when dropdown changes", ->
@dialog.$recipientGroupName.val("haven't taken the quiz").trigger 'change'
html = @dialog.$el.html()
ok html.match('alice'), 'updated with the new list of recipients'
ok !html.match('bob'), "doesn't contain old list of recipients"
test "#getFormValues returns correct values", ->
messageBody = 'Students please take your quiz, dang it!'
@dialog.$messageBody.val messageBody
json = @dialog.getFormData()
{body,recipients} = json
strictEqual json.body, messageBody, 'includes message body'
strictEqual json.recipientGroupName, undefined,
"doesn't include recipientGroupName"
deepEqual json.recipients,
_.pluck(@testData.recipientGroups[0].recipients, 'id'),
'includes list of ids'
test "validateBeforeSave", ->
errors = @dialog.validateBeforeSave({body: ''},{})
ok errors.body[0].message, 'validates empty body'
errors = @dialog.validateBeforeSave({body: 'take your dang quiz'},{recipients: []})
ok errors.recipientGroupName[0].message, 'validates when sending to empty list of users'