forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubmissionCellSpec.coffee
More file actions
472 lines (372 loc) · 20.8 KB
/
Copy pathSubmissionCellSpec.coffee
File metadata and controls
472 lines (372 loc) · 20.8 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
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#
# 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/gradezilla/SubmissionCell'
'str/htmlEscape'
'jquery'
'jsx/shared/helpers/numberHelper'
'compiled/gradezilla/GradebookTranslations'
], (SubmissionCell, htmlEscape, $, numberHelper, GRADEBOOK_TRANSLATIONS) ->
dangerousHTML= '"><img src=/ onerror=alert(document.cookie);>'
escapedDangerousHTML = htmlEscape dangerousHTML
QUnit.module "SubmissionCell",
setup: ->
@pointsPossible = 100
@opts =
item:
'whatever': {}
column:
field: 'whatever'
object:
points_possible: @pointsPossible
container: $('#fixtures')[0]
@cell = new SubmissionCell @opts
teardown: -> $('#fixtures').empty()
test "#applyValue escapes html in passed state", ->
item = whatever: {grade: '1'}
state = dangerousHTML
@stub @cell, 'postValue'
@cell.applyValue(item,state)
equal item.whatever.grade, escapedDangerousHTML
test "#applyValue calls flashWarning", ->
@stub @cell, 'postValue'
flashWarningStub = @stub $, 'flashWarning'
@cell.applyValue(@opts.item, '150')
ok flashWarningStub.calledOnce
test "#applyValue calls numberHelper with points possible", ->
numberHelperStub = @stub(numberHelper, 'parse').withArgs(@pointsPossible)
@stub @cell, 'postValue'
@cell.applyValue(@opts.item, '10')
strictEqual numberHelperStub.callCount, 1
test "#applyValue calls numberHelper with state", ->
state = '10'
numberHelperStub = @stub(numberHelper, 'parse').withArgs(state)
@stub @cell, 'postValue'
@cell.applyValue(@opts.item, state)
strictEqual numberHelperStub.callCount, 1
test "#loadValue escapes html", ->
@opts.item.whatever.grade = dangerousHTML
@cell.loadValue()
equal @cell.$input.val(), escapedDangerousHTML
equal @cell.$input[0].defaultValue, escapedDangerousHTML
test "#class.formatter rounds numbers if they are numbers", ->
@stub(SubmissionCell.prototype, 'cellWrapper').withArgs('0.67').returns('ok')
formattedResponse = SubmissionCell.formatter(0, 0, { grade: 0.666 }, {}, {})
equal formattedResponse, 'ok'
test "#class.formatter gives the value to the formatter if submission.grade isnt a parseable number", ->
@stub(SubmissionCell.prototype, 'cellWrapper').withArgs('happy').returns('ok')
formattedResponse = SubmissionCell.formatter(0, 0, { grade: 'happy' }, {}, {})
equal formattedResponse, 'ok'
test "#class.formatter adds a percent symbol for assignments with a percent grading_type", ->
@stub(SubmissionCell.prototype, 'cellWrapper').withArgs("73%").returns('ok')
formattedResponse = SubmissionCell.formatter(0, 0, { grade: 73 }, { grading_type: "percent" }, {})
equal formattedResponse, 'ok'
test "#class.formatter, isInactive adds grayed-out", ->
student = { isInactive: true }
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 'happy'}, { }, student)
notEqual submissionCellResponse.indexOf("grayed-out"), -1
test "#class.formatter, isLocked: true adds grayed-out", ->
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 73 }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("grayed-out") > -1
test "#class.formatter, isLocked: true adds cannot_edit", ->
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 73 }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("cannot_edit") > -1
test "#class.formatter, isLocked: false doesn't add grayed-out", ->
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 73 }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("grayed-out"), -1
test "#class.formatter, isLocked: false doesn't add cannot_edit", ->
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 73 }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("cannot_edit"), -1
test "#class.formatter, tooltip adds your text to the special classes", ->
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 73 }, {}, {}, { tooltip: "dora_the_explorer" })
ok submissionCellResponse.indexOf("dora_the_explorer") > -1
test "#class.formatter, isInactive: false doesn't add grayed-out", ->
student = { isInactive: false }
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 10 }, { }, student)
equal submissionCellResponse.indexOf("grayed-out"), -1
test "#class.formatter, isConcluded adds grayed-out", ->
student = { isConcluded: true }
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 10 }, { }, student)
notEqual submissionCellResponse.indexOf("grayed-out"), -1
test "#class.formatter, isConcluded doesn't have grayed-out", ->
student = { isConcluded: false }
submissionCellResponse = SubmissionCell.formatter(0, 0, { grade: 10 }, { }, student)
equal submissionCellResponse.indexOf("grayed-out"), -1
test "#letter_grade.formatter, shows EX when submission is excused", ->
@stub(SubmissionCell.prototype, 'cellWrapper').withArgs('EX').returns('ok')
formattedResponse = SubmissionCell.letter_grade.formatter(0, 0, {excused:true}, {}, {})
equal formattedResponse, 'ok'
test "#letter_grade.formatter, shows the score and letter grade", ->
@stub(SubmissionCell.prototype, 'cellWrapper').withArgs('F<span class=\'letter-grade-points\'>0</span>').returns('ok')
formattedResponse = SubmissionCell.letter_grade.formatter(0, 0, {grade: 'F', score: 0 }, {}, {})
equal formattedResponse, 'ok'
test "#letter_grade.formatter, shows the letter grade", ->
@stub(SubmissionCell.prototype, 'cellWrapper').withArgs('B').returns('ok')
formattedResponse = SubmissionCell.letter_grade.formatter(0, 0, {grade: 'B'}, {}, {})
equal formattedResponse, 'ok'
test "#letter_grade.formatter, isLocked: true adds grayed-out", ->
submissionCellResponse = SubmissionCell.letter_grade.formatter(0, 0, { grade: "A" }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("grayed-out") > -1
test "#letter_grade.formatter, isLocked: true adds cannot_edit", ->
submissionCellResponse = SubmissionCell.letter_grade.formatter(0, 0, { grade: "A" }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("cannot_edit") > -1
test "#letter_grade.formatter, isLocked: false doesn't add grayed-out", ->
submissionCellResponse = SubmissionCell.letter_grade.formatter(0, 0, { grade: "A" }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("grayed-out"), -1
test "#letter_grade.formatter, isLocked: false doesn't add cannot_edit", ->
submissionCellResponse = SubmissionCell.letter_grade.formatter(0, 0, { grade: "A" }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("cannot_edit"), -1
test "#letter_grade.formatter, tooltip adds your text to the special classes", ->
submissionCellResponse = SubmissionCell.letter_grade.formatter(0, 0, { grade: "A" }, {}, {}, { tooltip: "dora_the_explorer" })
ok submissionCellResponse.indexOf("dora_the_explorer") > -1
test "#gpa_scale.formatter, isLocked: true adds grayed-out", ->
submissionCellResponse = SubmissionCell.gpa_scale.formatter(0, 0, { grade: 3.2 }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("grayed-out") > -1
test "#gpa_scale.formatter, isLocked: true adds cannot_edit", ->
submissionCellResponse = SubmissionCell.gpa_scale.formatter(0, 0, { grade: 3.2 }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("cannot_edit") > -1
test "#gpa_scale.formatter, isLocked: false doesn't add grayed-out", ->
submissionCellResponse = SubmissionCell.gpa_scale.formatter(0, 0, { grade: 3.2 }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("grayed-out"), -1
test "#gpa_scale.formatter, isLocked: false doesn't add cannot_edit", ->
submissionCellResponse = SubmissionCell.gpa_scale.formatter(0, 0, { grade: 3.2 }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("cannot_edit"), -1
test "#gpa_scale.formatter, tooltip adds your text to the special classes", ->
submissionCellResponse = SubmissionCell.gpa_scale.formatter(0, 0, { grade: 3.2 }, {}, {}, { tooltip: "dora_the_explorer" })
ok submissionCellResponse.indexOf("dora_the_explorer") > -1
test "#pass_fail.formatter, isLocked: true adds grayed-out", ->
submissionCellResponse = SubmissionCell.pass_fail.formatter(0, 0, { grade: "complete" }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("grayed-out") > -1
test "#pass_fail.formatter, isLocked: true adds cannot_edit", ->
submissionCellResponse = SubmissionCell.pass_fail.formatter(0, 0, { grade: "complete" }, {}, {}, { isLocked: true })
ok submissionCellResponse.indexOf("cannot_edit") > -1
test "#pass_fail.formatter, isLocked: false doesn't add grayed-out", ->
submissionCellResponse = SubmissionCell.pass_fail.formatter(0, 0, { grade: "complete" }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("grayed-out"), -1
test "#pass_fail.formatter, isLocked: false doesn't add cannot_edit", ->
submissionCellResponse = SubmissionCell.pass_fail.formatter(0, 0, { grade: "complete" }, {}, {}, { isLocked: false })
equal submissionCellResponse.indexOf("cannot_edit"), -1
test "#pass_fail.formatter, tooltip adds your text to the special classes", ->
submissionCellResponse = SubmissionCell.pass_fail.formatter(0, 0, { grade: "complete" }, {}, {}, { tooltip: "dora_the_explorer" })
ok submissionCellResponse.indexOf("dora_the_explorer") > -1
QUnit.module "Pass/Fail SubmissionCell",
setup: ->
opts =
item:
foo: {}
column:
field: 'foo'
object:
points_possible: 100
assignment: {}
container: $('#fixtures')[0]
@cell = new SubmissionCell.pass_fail opts
@cell.$input = $("<button><i></i></button>")
teardown: -> $('#fixtures').empty()
test "#pass_fail#transitionValue changes the aria-label to match the currently selected option", ->
@cell.transitionValue('fail')
equal @cell.$input.attr('aria-label'), 'fail'
test "#pass_fail#transitionValue updates the icon class", ->
@cell.transitionValue('pass')
ok @cell.$input.find('i').hasClass('icon-check')
QUnit.module ".styles"
test "when submission and assignment are empty, return nothing", ->
deepEqual SubmissionCell.styles(), []
test "when submission is dropped it returns dropped", ->
deepEqual SubmissionCell.styles({ drop: true }), ["dropped"]
test "when submission is not dropped it returns nothing", ->
deepEqual SubmissionCell.styles({ drop: false }), []
test "when submission's 'drop' property is undefined it returns nothing", ->
deepEqual SubmissionCell.styles({ drop: undefined }), []
test "when submission is excused it returns dropped", ->
deepEqual SubmissionCell.styles({ excused: true }), ["excused"]
test "when submission is not excused it returns nothing", ->
deepEqual SubmissionCell.styles({ excused: false }), []
test "when submission's 'excused' property is undefined it returns nothing", ->
deepEqual SubmissionCell.styles({ excused: undefined }), []
test "when submission's grade does not match the current submission it returns resubmitted", ->
deepEqual SubmissionCell.styles({ grade_matches_current_submission: false }), ["resubmitted"]
test "when submission's grade matches the current submission it returns resubmitted", ->
deepEqual SubmissionCell.styles({ grade_matches_current_submission: true }), []
test "when submission's 'grade_matches_current_submission' property is undefined it returns nothing", ->
deepEqual SubmissionCell.styles({ grade_matches_current_submission: undefined }), []
test "when a submission is missing it returns missing", ->
deepEqual SubmissionCell.styles({ missing: true }), ["missing"]
test "when a submission is not missing it returns nothing", ->
deepEqual SubmissionCell.styles({ missing: false }), []
test "when a submission's 'missing' property is undefined it returns nothing", ->
deepEqual SubmissionCell.styles({ missing: undefined }), []
test "when a submission is late it returns late", ->
deepEqual SubmissionCell.styles({ late: true }), ["late"]
test "when a submission is not late it returns nothing", ->
deepEqual SubmissionCell.styles({ late: false }), []
test "when a submission's 'late' property is undefined it return nothing", ->
deepEqual SubmissionCell.styles({ late: undefined }), []
test "when an assignment's is ungraded it returns ungraded", ->
assignment = {}
deepEqual SubmissionCell.styles(assignment, { submission_types: ["not_graded"] }), ["ungraded"]
test "when an assignment's is not ungraded it returns nothing", ->
assignment = {}
deepEqual SubmissionCell.styles(assignment, { submission_types: ['online_text_entry'] }), []
test "when an assignment's type is undefined it return nothing", ->
assignment = {}
deepEqual SubmissionCell.styles(assignment, { submission_types: undefined }), []
test "when an assignment is muted it returns muted", ->
assignment = {}
deepEqual SubmissionCell.styles(assignment, { muted: true }), ["muted"]
test "when an assignment is not muted it returns nothing", ->
assignment = {}
deepEqual SubmissionCell.styles(assignment, { muted: false }), []
test "when an assignment submission's 'mute' property is undefined it return nothing", ->
assignment = {}
deepEqual SubmissionCell.styles(assignment, { muted: undefined }), []
test "when a submission has a type it is returned", ->
deepEqual SubmissionCell.styles({ submission_type: "fake_type" }), ["fake_type"]
test "when a submission has no type it returns nothing", ->
deepEqual SubmissionCell.styles({ submission_type: '' }), []
test "when a submission's submitions_type is undefined it return nothing", ->
deepEqual SubmissionCell.styles({ submission_type: undefined }), []
test "when a submission is late, ungraded, muted and has a submission type", ->
submission =
late: true
submission_type: "online_text_entry"
assignment =
submission_types: ["not_graded"]
muted: true
deepEqual SubmissionCell.styles(submission, assignment), [
'late',
'ungraded',
'muted',
'online_text_entry'
]
test "when a submission is both dropped and excused, dropped takes priority", ->
deepEqual SubmissionCell.styles({ drop: true, excused: true }), ['dropped']
test "when a submission is both excused and resubmitted, excused takes priority", ->
deepEqual SubmissionCell.styles({ excused: true, grade_matches_current_submission: false }), ['excused']
test "when a submission is both resubmitted and missing, missing takes priority", ->
deepEqual SubmissionCell.styles({ grade_matches_current_submission: false, late: true }), ['resubmitted']
test "when a submission is both missing and late, missing takes priority", ->
deepEqual SubmissionCell.styles({ missing: true, late: true }), ['missing']
test "when all criteria are present, the styles are dropped, ungraded, muted, and the submission_type", ->
submission =
drop: true
excused: true
grade_matches_current_submission: false
missing: true
late: true
submission_type: "online_text_entry"
assignment =
submission_types: ["not_graded"]
muted: true
deepEqual SubmissionCell.styles(submission, assignment), [
"dropped",
"ungraded",
"muted",
"online_text_entry"
]
QUnit.module ".tooltips"
test "given nothing, it returns nothing", ->
deepEqual SubmissionCell.tooltips(), []
test "given all criteria, everything is present", ->
submission =
drop: true
excused: true
grade_matches_current_submission: false
missing: true
late: true
submission_type: "online_url"
assignment =
submission_types: ["not_graded"]
muted: true
deepEqual SubmissionCell.tooltips(submission, assignment), [
"dropped",
"excused",
"resubmitted",
"missing",
"late",
"ungraded"
"muted",
"online_url"
]
test "given a dropped submission, it returns dropped", ->
deepEqual SubmissionCell.tooltips({ drop: true }), ["dropped"]
test "given an excused submission, it returns excused", ->
deepEqual SubmissionCell.tooltips({ excused: true }), ["excused"]
test "given a resubmitted submission, it returns resubmitted", ->
deepEqual SubmissionCell.tooltips({ grade_matches_current_submission: false }), ["resubmitted"]
test "given a missing submission, it returns missing", ->
deepEqual SubmissionCell.tooltips({ missing: true }), ["missing"]
test "given a late submission, it returns late", ->
deepEqual SubmissionCell.tooltips({ late: true }), ["late"]
test "given an ungraded assignment, it returns ungraded", ->
deepEqual SubmissionCell.tooltips({}, { submission_types: ["not_graded"] }), ["ungraded"]
test "given a muted assignment, it returns muted", ->
deepEqual SubmissionCell.tooltips({}, { muted: true }), ["muted"]
QUnit.module "#cellWrapper",
setup: ->
@fixtures = document.querySelector('#fixtures')
params: ->
item:
'whatever':
id: '1'
submission_type: "online_text_entry"
column:
field: 'whatever'
teardown: ->
@fixtures.innerHTML = ''
test "if student is inactive, styles include 'grayed-out'", ->
cell = (new SubmissionCell(@params())).cellWrapper('', { student: { isInactive: true } })
@fixtures.innerHTML = cell
strictEqual @fixtures.querySelectorAll('div.grayed-out').length, 1
test "if student is concluded, styles include 'grayed-out'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { student: { isConcluded: true } })
strictEqual @fixtures.querySelectorAll('div.grayed-out').length, 1
test "if isLocked, styles include 'grayed-out'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { isLocked: true })
strictEqual @fixtures.querySelectorAll('div.grayed-out').length, 1
test "if student is inactive, tooltips include 'grayed-out'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { student: { isInactive: true } })
strictEqual @fixtures.querySelectorAll('div.grayed-out').length, 1
test "if student is concluded, styles include 'grayed-out'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { student: { isConcluded: true } })
strictEqual @fixtures.querySelectorAll('div.grayed-out').length, 1
test "if locked, styles include 'grayed-out'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { isLocked: true })
strictEqual @fixtures.querySelectorAll('div.grayed-out').length, 1
test "if student is concluded, styles include 'cannot_edit'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { student: { isConcluded: true } })
strictEqual @fixtures.querySelectorAll('div.cannot_edit').length, 1
test "if is locked, styles include 'cannot_edit'", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { isLocked: true })
strictEqual @fixtures.querySelectorAll('div.cannot_edit').length, 1
test "if it has tooltip key, styles include that value", ->
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { tooltip: 'fake-tooltip' })
strictEqual @fixtures.querySelectorAll('div.fake-tooltip').length, 1
test "if it has tooltip key, tooltips includes that value", ->
key = 'in_closed_grading_period'
@fixtures.innerHTML = (new SubmissionCell(@params())).cellWrapper('', { tooltip: key })
ok @fixtures.querySelector('.gradebook-tooltip').innerText.includes(
GRADEBOOK_TRANSLATIONS["submission_tooltip_#{key}"]
)
test "if it has turnitin data, styles includes 'turnitin'", ->
params = @params()
params.item.whatever.turnitin_data = { submission_1: 'none' }
@fixtures.innerHTML = (new SubmissionCell(params)).cellWrapper('')
strictEqual @fixtures.querySelectorAll('div.turnitin').length, 1
test "if no turnitin data, styles do not includes 'turnitin'", ->
@fixtures.innerHTML = (new SubmissionCell(@params()).cellWrapper(''))
strictEqual @fixtures.querySelectorAll('div.turnitin').length, 0