forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentIndexSpec.coffee
More file actions
135 lines (107 loc) · 4.09 KB
/
Copy pathAssignmentIndexSpec.coffee
File metadata and controls
135 lines (107 loc) · 4.09 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
define [
'Backbone'
'compiled/models/AssignmentGroup'
'compiled/models/Course'
'compiled/collections/AssignmentGroupCollection'
'compiled/views/assignments/AssignmentGroupListView'
'compiled/views/assignments/IndexView'
'compiled/views/assignments/ToggleShowByView'
'jquery'
'helpers/fakeENV'
'helpers/jquery.simulate'
], (Backbone, AssignmentGroup, Course, AssignmentGroupCollection, AssignmentGroupListView, IndexView, ToggleShowByView, $, fakeENV) ->
fixtures = $('#fixtures')
assignmentGroups = null
assignmentIndex = () ->
$('<div id="content"></div>').appendTo fixtures
course = new Course {id: 1}
group1 = new AssignmentGroup
name: "Group 1"
assignments: [{id: 1, name: 'Foo Name'}, {id: 2, name: 'Bar Title'}]
group2 = new AssignmentGroup
name: "Group 2"
assignments: [{id: 1, name: 'Baz Title'}, {id: 2, name: 'Qux Name'}]
assignmentGroups = new AssignmentGroupCollection [group1, group2],
course: course
assignmentGroupsView = new AssignmentGroupListView
collection: assignmentGroups
course: course
showByView = false
if !ENV.PERMISSIONS.manage
showByView = new ToggleShowByView
course: course
assignmentGroups: assignmentGroups
app = new IndexView
assignmentGroupsView: assignmentGroupsView
collection: assignmentGroups
createGroupView: false
assignmentSettingsView: false
showByView: showByView
app.render()
QUnit.module 'assignmentIndex',
setup: ->
fakeENV.setup(PERMISSIONS: {manage: true})
@enable_spy = @spy(IndexView.prototype, 'enableSearch')
teardown: ->
fakeENV.teardown()
assignmentGroups = null
fixtures.empty()
test 'should filter by search term', ->
view = assignmentIndex()
$('#search_term').val('foo')
view.filterResults()
equal view.$el.find('.assignment').not('.hidden').length, 1
$('#search_term').val('BooBerry')
view.filterResults()
equal view.$el.find('.assignment').not('.hidden').length, 0
$('#search_term').val('name')
view.filterResults()
equal view.$el.find('.assignment').not('.hidden').length, 2
test 'should have search disabled on render', ->
view = assignmentIndex()
ok view.$('#search_term').is(':disabled')
test 'should enable search on assignmentGroup reset', ->
view = assignmentIndex()
assignmentGroups.reset()
ok !view.$('#search_term').is(':disabled')
test 'enable search handler should only fire on the first reset', ->
view = assignmentIndex()
assignmentGroups.reset()
ok @enable_spy.calledOnce
#reset a second time and make sure it was still only called once
assignmentGroups.reset()
ok @enable_spy.calledOnce
test 'should show modules column', ->
view = assignmentIndex()
[a1, a2] = assignmentGroups.assignments()
a1.set 'modules', ['One', 'Two']
a2.set 'modules', ['Three']
ok view.$("#assignment_1 .modules .tooltip_link").text().match(/Multiple Modules/)
ok view.$("#assignment_1 .modules").text().match(/One\s+Two/)
ok view.$("#assignment_2 .modules").text().match(/Three Module/)
test "should show 'Add Quiz/Test' button if quiz lti is enabled", ->
ENV.PERMISSIONS.manage_course = true
ENV.QUIZ_LTI_ENABLED = true
view = assignmentIndex()
$button = view.$('.new_quiz_lti')
equal $button.length, 1
ok /\?quiz_lti$/.test $button.attr('href')
test "should not show 'Add Quiz/Test' button if quiz lti is not enabled", ->
ENV.PERMISSIONS.manage_course = true
ENV.QUIZ_LTI_ENABLED = false
view = assignmentIndex()
equal $('.new_quiz_lti').length, 0
QUnit.module 'student index view',
setup: ->
fakeENV.setup(PERMISSIONS: {manage: false})
teardown: ->
fakeENV.teardown()
assignmentGroups = null
fixtures.empty()
test 'should clear search on toggle', ->
clear_spy = @spy(IndexView.prototype, 'clearSearch')
view = assignmentIndex()
view.$('#search_term').val('something')
view.showByView.toggleShowBy({preventDefault: -> })
equal view.$('#search_term').val(), ""
ok clear_spy.called