forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSisButtonViewSpec.coffee
More file actions
206 lines (180 loc) · 7.53 KB
/
Copy pathSisButtonViewSpec.coffee
File metadata and controls
206 lines (180 loc) · 7.53 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#
# Copyright (C) 2016 - 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 [
'jquery'
'compiled/views/SisButtonView'
'Backbone'
], ($, SisButtonView, Backbone) ->
class AssignmentStub extends Backbone.Model
url: '/fake'
postToSIS: (postToSisBoolean) =>
return @get 'post_to_sis' unless arguments.length > 0
@set 'post_to_sis', postToSisBoolean
name: (newName) =>
return @get 'name' unless arguments.length > 0
@set 'name', newName
maxNameLength: =>
return ENV.MAX_NAME_LENGTH
dueAt: (date) =>
return @get 'due_at' unless arguments.length > 0
@set 'due_at', date
sisIntegrationSettingsEnabled: =>
return ENV.SIS_INTEGRATION_SETTINGS_ENABLED
class QuizStub extends Backbone.Model
url: '/fake'
postToSIS: (postToSisBoolean) =>
return @get 'post_to_sis' unless arguments.length > 0
@set 'post_to_sis', postToSisBoolean
name: (newName) =>
return @get 'title' unless arguments.length > 0
@set 'title', newName
maxNameLength: =>
return ENV.MAX_NAME_LENGTH
dueAt: (date) =>
return @get 'due_at' unless arguments.length > 0
@set 'due_at', date
sisIntegrationSettingsEnabled: =>
return ENV.SIS_INTEGRATION_SETTINGS_ENABLED
QUnit.module 'SisButtonView',
setup: ->
@assignment = new AssignmentStub()
@quiz = new QuizStub()
@quiz.set('toggle_post_to_sis_url', '/some_other_url')
test 'properly populates initial settings', ->
@assignment.set('post_to_sis', true)
@quiz.set('post_to_sis', false)
@view1 = new SisButtonView(model: @assignment, sisName: 'SIS')
@view2 = new SisButtonView(model: @quiz, sisName: 'SIS')
@view1.render()
@view2.render()
equal @view1.$input.attr('title'), 'Sync to SIS enabled. Click to toggle.'
equal @view2.$input.attr('title'), 'Sync to SIS disabled. Click to toggle.'
test 'properly populates initial settings with custom SIS name', ->
@assignment.set('post_to_sis', true)
@quiz.set('post_to_sis', false)
@view1 = new SisButtonView(model: @assignment, sisName: 'PowerSchool')
@view2 = new SisButtonView(model: @quiz, sisName: 'PowerSchool')
@view1.render()
@view2.render()
equal @view1.$input.attr('title'), 'Sync to PowerSchool enabled. Click to toggle.'
equal @view2.$input.attr('title'), 'Sync to PowerSchool disabled. Click to toggle.'
test 'properly toggles model sis status when clicked', ->
ENV.MAX_NAME_LENGTH = 256
@assignment.set('post_to_sis', false)
@assignment.set('name', 'Too Much Tuna')
@view = new SisButtonView(model: @assignment)
@view.render()
@view.$el.click()
ok @assignment.postToSIS()
@view.$el.click()
ok !@assignment.postToSIS()
test 'model does not save if there are name length errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
@assignment.set('post_to_sis', false)
@assignment.set('name', 'Too Much Tuna')
@view = new SisButtonView(model: @assignment, maxNameLengthRequired: true)
@view.render()
@view.$el.click()
ok !@assignment.postToSIS()
test 'model saves if there are name length errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is false', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
@assignment.set('post_to_sis', false)
@assignment.set('name', 'Too Much Tuna')
@view = new SisButtonView(model: @assignment, maxNameLengthRequired: false)
@view.render()
@view.$el.click()
ok @assignment.postToSIS()
test 'model does not save if there are name length errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
@quiz.set('post_to_sis', false)
@quiz.set('title', 'Too Much Tuna')
@view = new SisButtonView(model: @quiz, maxNameLengthRequired: true)
@view.render()
@view.$el.click()
ok !@quiz.postToSIS()
test 'model saves if there are name length errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is false', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
@quiz.set('post_to_sis', false)
@quiz.set('title', 'Too Much Tuna')
@view = new SisButtonView(model: @quiz, maxNameLengthRequired: false)
@view.render()
@view.$el.click()
ok @quiz.postToSIS()
test 'model does not save if there are due date errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
@assignment.set('post_to_sis', false)
@assignment.set('name', 'Too Much Tuna')
@view = new SisButtonView(model: @assignment, dueDateRequired: true)
@view.render()
@view.$el.click()
ok !@assignment.postToSIS()
test 'model saves if there are due date errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is false', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
@assignment.set('post_to_sis', false)
@assignment.set('name', 'Too Much Tuna')
@view = new SisButtonView(model: @assignment, dueDateRequired: true)
@view.render()
@view.$el.click()
ok @assignment.postToSIS()
test 'model does not save if there are due date errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
@quiz.set('post_to_sis', false)
@quiz.set('title', 'Too Much Tuna')
@view = new SisButtonView(model: @quiz, dueDateRequired: true)
@view.render()
@view.$el.click()
ok !@quiz.postToSIS()
test 'model saves if there are due date errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is false', ->
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
@quiz.set('post_to_sis', false)
@quiz.set('title', 'Too Much Tuna')
@view = new SisButtonView(model: @quiz, dueDateRequired: true)
@view.render()
@view.$el.click()
ok @quiz.postToSIS()
test 'does not override dates', ->
ENV.MAX_NAME_LENGTH = 256
@assignment.set('name', 'Gil Faizon')
saveStub = @stub(@assignment, 'save').callsFake(() ->)
@view = new SisButtonView(model: @assignment)
@view.render()
@view.$el.click()
ok saveStub.calledWith(override_dates: false)
test 'properly saves model with a custom url if present', ->
ENV.MAX_NAME_LENGTH = 256
@quiz.set('title', 'George St. Geegland')
@stub @quiz, 'save', (attributes, options) ->
ok options['url'], '/some_other_url'
@quiz.set('post_to_sis', false)
@view = new SisButtonView(model: @quiz)
@view.render()
@view.$el.click()
ok @quiz.postToSIS()
test 'properly associates button label via aria-describedby', ->
@assignment.set('id', '1')
@view = new SisButtonView(model: @assignment)
@view.render()
equal @view.$input.attr('aria-describedby'), 'sis-status-label-1'
equal @view.$label.attr('id'), 'sis-status-label-1'