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
68 lines (53 loc) · 2.17 KB
/
Copy pathMessageStudentsDialogSpec.coffee
File metadata and controls
68 lines (53 loc) · 2.17 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
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'