forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSisButtonViewSpec.js
400 lines (361 loc) · 14 KB
/
SisButtonViewSpec.js
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
* 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/>.
*/
import $ from 'jquery'
import SisButtonView from '@canvas/sis/backbone/views/SisButtonView.coffee'
import Backbone from '@canvas/backbone'
class AssignmentStub extends Backbone.Model {
constructor() {
super(...arguments)
this.postToSIS = this.postToSIS.bind(this)
this.name = this.name.bind(this)
this.dueAt = this.dueAt.bind(this)
this.allDates = this.allDates.bind(this)
}
postToSIS(postToSisBoolean) {
if (!(arguments.length > 0)) {
return this.get('post_to_sis')
}
return this.set('post_to_sis', postToSisBoolean)
}
name(newName) {
if (!(arguments.length > 0)) {
return this.get('name')
}
return this.set('name', newName)
}
maxNameLength() {
return ENV.MAX_NAME_LENGTH
}
dueAt(date) {
if (!(arguments.length > 0)) {
return this.get('due_at')
}
return this.set('due_at', date)
}
allDates(alldate) {
if (!(arguments.length > 0)) {
return this.get('all_dates')
}
return this.set('all_dates', alldate)
}
sisIntegrationSettingsEnabled() {
return ENV.SIS_INTEGRATION_SETTINGS_ENABLED
}
}
AssignmentStub.prototype.url = '/fake'
class QuizStub extends Backbone.Model {
constructor() {
super(...arguments)
this.postToSIS = this.postToSIS.bind(this)
this.name = this.name.bind(this)
this.dueAt = this.dueAt.bind(this)
this.allDates = this.allDates.bind(this)
}
postToSIS(postToSisBoolean) {
if (!(arguments.length > 0)) {
return this.get('post_to_sis')
}
return this.set('post_to_sis', postToSisBoolean)
}
name(newName) {
if (!(arguments.length > 0)) {
return this.get('title')
}
return this.set('title', newName)
}
maxNameLength() {
return ENV.MAX_NAME_LENGTH
}
dueAt(date) {
if (!(arguments.length > 0)) {
return this.get('due_at')
}
return this.set('due_at', date)
}
allDates(alldate) {
if (!(arguments.length > 0)) {
return this.get('all_dates')
}
return this.set('all_dates', alldate)
}
sisIntegrationSettingsEnabled() {
return ENV.SIS_INTEGRATION_SETTINGS_ENABLED
}
}
QuizStub.prototype.url = '/fake'
QUnit.module('SisButtonView', {
setup() {
this.assignment = new AssignmentStub({id: 1})
this.quiz = new QuizStub({id: 1, assignment_id: 2})
}
})
test('properly populates initial settings', function() {
this.assignment.set('post_to_sis', true)
this.quiz.set('post_to_sis', false)
this.view1 = new SisButtonView({model: this.assignment, sisName: 'SIS'})
this.view2 = new SisButtonView({model: this.quiz, sisName: 'SIS'})
this.view1.render()
this.view2.render()
equal(this.view1.$input.attr('title'), 'Sync to SIS enabled. Click to toggle.')
equal(this.view2.$input.attr('title'), 'Sync to SIS disabled. Click to toggle.')
})
test('properly populates initial settings with custom SIS name', function() {
this.assignment.set('post_to_sis', true)
this.quiz.set('post_to_sis', false)
this.view1 = new SisButtonView({model: this.assignment, sisName: 'PowerSchool'})
this.view2 = new SisButtonView({model: this.quiz, sisName: 'PowerSchool'})
this.view1.render()
this.view2.render()
equal(this.view1.$input.attr('title'), 'Sync to PowerSchool enabled. Click to toggle.')
equal(this.view2.$input.attr('title'), 'Sync to PowerSchool disabled. Click to toggle.')
})
test('properly toggles model sis status when clicked', function() {
ENV.MAX_NAME_LENGTH = 256
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.view = new SisButtonView({model: this.assignment})
this.view.render()
this.view.$el.click()
ok(this.assignment.postToSIS())
this.view.$el.click()
ok(!this.assignment.postToSIS())
})
test('model does not save if there are name length errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.view = new SisButtonView({model: this.assignment, maxNameLengthRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.assignment.postToSIS())
})
test('model saves if there are name length errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is false', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.view = new SisButtonView({model: this.assignment, maxNameLengthRequired: false})
this.view.render()
this.view.$el.click()
ok(this.assignment.postToSIS())
})
test('model does not save if there are name length errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.view = new SisButtonView({model: this.quiz, maxNameLengthRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.quiz.postToSIS())
})
test('model saves if there are name length errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is false', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.view = new SisButtonView({model: this.quiz, maxNameLengthRequired: false})
this.view.render()
this.view.$el.click()
ok(this.quiz.postToSIS())
})
test('model does not save if there are due date errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.view = new SisButtonView({model: this.assignment, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.assignment.postToSIS())
})
test('model saves if there are overrides but not base due date for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.assignment.set('all_dates', [{dueAt: 'Test'}, {dueAt: 'Test2'}])
this.assignment.set('due_at', null)
this.view = new SisButtonView({model: this.assignment, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(this.assignment.postToSIS())
})
test('model does not save if there are no due date overrides and no base due date for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.assignment.set('all_dates', [])
this.assignment.set('due_at', null)
this.view = new SisButtonView({model: this.assignment, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.assignment.postToSIS())
})
test('model does not save if there is only one due date override and no base due date for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.assignment.set('all_dates', [{dueAt: 'Test'}, {dueAt: null}])
this.assignment.set('due_at', null)
this.view = new SisButtonView({model: this.assignment, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.assignment.postToSIS())
})
test('model does not save if there are no due dates on overrides assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.assignment.set('all_dates', [{dueAt: null}, {dueAt: null}])
this.assignment.set('due_at', 'I am a date')
this.view = new SisButtonView({model: this.assignment, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.assignment.postToSIS())
})
test('model saves if there are overrides but not base due date for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.quiz.set('all_dates', [{dueAt: 'Test'}, {dueAt: 'Test2'}])
this.quiz.set('due_at', null)
this.view = new SisButtonView({model: this.quiz, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(this.quiz.postToSIS())
})
test('model does not save if there are no due date overrides and no base due date for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.quiz.set('all_dates', [])
this.quiz.set('due_at', null)
this.view = new SisButtonView({model: this.quiz, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.quiz.postToSIS())
})
test('model does not save if there is only one due date override and no base due date for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.quiz.set('all_dates', [{dueAt: 'Test'}, {dueAt: null}])
this.quiz.set('due_at', null)
this.view = new SisButtonView({model: this.quiz, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.quiz.postToSIS())
})
test('model saves if there are no due date overrides and base for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.quiz.set('all_dates', [{dueAt: null}, {dueAt: null}])
this.quiz.set('due_at', 'I am a date')
this.view = new SisButtonView({model: this.quiz, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.quiz.postToSIS())
})
test('model saves if there are due date errors for assignment AND SIS_INTEGRATION_SETTINGS_ENABLED is false', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
this.assignment.set('post_to_sis', false)
this.assignment.set('name', 'Too Much Tuna')
this.view = new SisButtonView({model: this.assignment, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(this.assignment.postToSIS())
})
test('model does not save if there are due date errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is true', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = true
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.view = new SisButtonView({model: this.quiz, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(!this.quiz.postToSIS())
})
test('model saves if there are due date errors for quiz AND SIS_INTEGRATION_SETTINGS_ENABLED is false', function() {
ENV.MAX_NAME_LENGTH = 5
ENV.SIS_INTEGRATION_SETTINGS_ENABLED = false
this.quiz.set('post_to_sis', false)
this.quiz.set('title', 'Too Much Tuna')
this.view = new SisButtonView({model: this.quiz, dueDateRequired: true})
this.view.render()
this.view.$el.click()
ok(this.quiz.postToSIS())
})
test('toggles post_to_sis for an assignment', function() {
ENV.MAX_NAME_LENGTH = 256
ENV.COURSE_ID = 1001
this.assignment.set('name', 'Gil Faizon')
this.assignment.set('post_to_sis', true)
const saveStub = sandbox.stub($, 'ajaxJSON')
this.view = new SisButtonView({model: this.assignment})
this.view.render()
this.view.$el.click()
ok(
saveStub.calledWith('/api/v1/courses/1001/assignments/1', 'PUT', {
assignment: {override_dates: false, post_to_sis: false}
})
)
ok(!this.assignment.postToSIS())
})
test('toggles post_to_sis for a quiz', function() {
ENV.MAX_NAME_LENGTH = 256
ENV.COURSE_ID = 1001
this.quiz.set('title', 'George St. Geegland')
this.quiz.set('post_to_sis', false)
const saveStub = sandbox.stub($, 'ajaxJSON')
this.view = new SisButtonView({model: this.quiz})
this.view.render()
this.view.$el.click()
ok(
saveStub.calledWith('/api/v1/courses/1001/assignments/2', 'PUT', {
assignment: {override_dates: false, post_to_sis: true}
})
)
ok(this.quiz.postToSIS())
})
test('properly associates button label via aria-describedby', function() {
this.assignment.set('id', '1')
this.view = new SisButtonView({model: this.assignment})
this.view.render()
equal(this.view.$input.attr('aria-describedby'), 'sis-status-label-1')
equal(this.view.$label.attr('id'), 'sis-status-label-1')
})
test('properly toggles aria-pressed value based on post_to_sis', function() {
this.assignment.set('post_to_sis', true)
this.view = new SisButtonView({model: this.assignment})
this.view.render()
equal(this.view.$label.attr('aria-pressed'), 'true')
sandbox.stub($, 'ajaxJSON').callsFake((url, method, data, success) => success(data.assignment))
this.view.$el.click()
equal(this.view.$label.attr('aria-pressed'), 'false')
})