remove unused submission cell code
New Gradebook no longer uses this anywhere. refs GRADE-932 test plan: * ensure Jenkins passes Change-Id: I73ecccfd031a352863fa69e70c3a5963cf081089 Reviewed-on: https://gerrit.instructure.com/143011 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com> QA-Review: Keith T. Garner <kgarner@instructure.com>
This commit is contained in:
parent
e25768453e
commit
15d8b35bc2
|
@ -1,332 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 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'
|
||||
'underscore'
|
||||
'i18n!gradebook'
|
||||
'jsx/shared/helpers/numberHelper'
|
||||
'jsx/gradebook/shared/helpers/GradeFormatHelper'
|
||||
'../gradezilla/GradebookTranslations'
|
||||
'jsx/grading/helpers/OutlierScoreHelper'
|
||||
'str/htmlEscape'
|
||||
'../gradezilla/Turnitin'
|
||||
'../util/round'
|
||||
'jquery.ajaxJSON'
|
||||
'jquery.instructure_misc_helpers' # raw
|
||||
], ($, _, I18n, numberHelper, GradeFormatHelper, GRADEBOOK_TRANSLATIONS,
|
||||
{ default: OutlierScoreHelper }, htmlEscape, {extractDataTurnitin}, round) ->
|
||||
|
||||
class SubmissionCell
|
||||
|
||||
constructor: (@opts) ->
|
||||
@init()
|
||||
|
||||
init: () ->
|
||||
submission = @opts.item[@opts.column.field]
|
||||
@$wrapper = $(@cellWrapper("<input #{@ariaLabelTemplate(submission.submission_type)} class='grade'/>")).appendTo(@opts.container)
|
||||
@$input = @$wrapper.find('input').focus().select()
|
||||
|
||||
destroy: () ->
|
||||
@$input.remove()
|
||||
|
||||
focus: () ->
|
||||
@$input.focus()
|
||||
|
||||
loadValue: () ->
|
||||
@val = if @opts.item[@opts.column.field].excused
|
||||
I18n.t('Excused')
|
||||
else
|
||||
submission = @opts.item[@opts.column.field]
|
||||
grade = submission.entered_grade || submission.grade || ""
|
||||
formattedGrade = GradeFormatHelper.formatGrade(grade, { gradingType: submission.gradingType })
|
||||
@val = htmlEscape(formattedGrade)
|
||||
@$input.val(@val)
|
||||
@$input[0].defaultValue = @val
|
||||
@$input.select() if @$input.get(0) == document.activeElement
|
||||
|
||||
serializeValue: () ->
|
||||
@$input.val()
|
||||
|
||||
applyValue: (item, state) ->
|
||||
submission = item[@opts.column.field]
|
||||
if state.toUpperCase() == "EX"
|
||||
submission.excused = true
|
||||
else
|
||||
submission.grade = htmlEscape state
|
||||
pointsPossible = numberHelper.parse(@opts.column.object.points_possible)
|
||||
score = numberHelper.parse(state)
|
||||
outlierScoreHelper = new OutlierScoreHelper(score, pointsPossible)
|
||||
$.flashWarning(outlierScoreHelper.warningMessage()) if outlierScoreHelper.hasWarning()
|
||||
@wrapper?.remove()
|
||||
@postValue(item, state)
|
||||
|
||||
postValue: (item, state) ->
|
||||
submission = item[@opts.column.field]
|
||||
url = @opts.grid.getOptions().change_grade_url
|
||||
url = url.replace(":assignment", submission.assignment_id).replace(":submission", submission.user_id)
|
||||
data = if state.toUpperCase() == "EX"
|
||||
{"submission[excuse]": true}
|
||||
else
|
||||
{"submission[posted_grade]": GradeFormatHelper.delocalizeGrade(state)}
|
||||
$.ajaxJSON url, "PUT", data, @onUpdateSuccess, @onUpdateError
|
||||
|
||||
onUpdateSuccess: (submission) ->
|
||||
$.publish('submissions_updated', [submission.all_submissions])
|
||||
|
||||
onUpdateError: ->
|
||||
$.flashError(GRADEBOOK_TRANSLATIONS.submission_update_error)
|
||||
|
||||
isValueChanged: () ->
|
||||
@val != @$input.val()
|
||||
|
||||
validate: () ->
|
||||
{ valid: true, msg: null }
|
||||
|
||||
# default formatter (points, percent)
|
||||
@formatter: (row, col, submission, assignment, student, opts = {}) ->
|
||||
if submission.excused
|
||||
grade = I18n.t("Excused")
|
||||
else
|
||||
grade = GradeFormatHelper.formatGrade(
|
||||
submission.grade,
|
||||
{
|
||||
gradingType: assignment?.grading_type,
|
||||
precision: round.DEFAULT
|
||||
}
|
||||
)
|
||||
|
||||
this.prototype.cellWrapper(grade, {
|
||||
needsGrading: opts.needsGrading,
|
||||
submission: submission,
|
||||
assignment: assignment,
|
||||
editable: false,
|
||||
student: student,
|
||||
isLocked: !!opts.isLocked,
|
||||
tooltip: opts.tooltip
|
||||
})
|
||||
|
||||
cellWrapper: (innerContents, options = {}) ->
|
||||
opts = $.extend({}, {
|
||||
classes: '',
|
||||
editable: true,
|
||||
student: {
|
||||
isInactive: false,
|
||||
isConcluded: false,
|
||||
},
|
||||
isLocked: false
|
||||
}, options)
|
||||
opts.submission ||= @opts.item[@opts.column.field]
|
||||
opts.assignment ||= @opts.column.object
|
||||
opts.editable = false if opts.student.isConcluded
|
||||
submission_type = opts.submission.submission_type if opts.submission?.submission_type || null
|
||||
styles = SubmissionCell.styles(opts.submission, opts.assignment)
|
||||
|
||||
styles.push("grayed-out") if opts.student.isInactive || opts.student.isConcluded || opts.isLocked
|
||||
styles.push("cannot_edit") if opts.student.isConcluded || opts.isLocked
|
||||
if opts.tooltip
|
||||
styles.push(opts.tooltip)
|
||||
tooltips.push(opts.tooltip)
|
||||
|
||||
opts.classes += ' no_grade_yet ' unless opts.submission.grade && opts.submission.workflow_state != 'pending_review'
|
||||
innerContents = '<i class="icon-not-graded"></i>' if opts.needsGrading
|
||||
innerContents ?= '–'
|
||||
|
||||
if turnitin = extractDataTurnitin(opts.submission)
|
||||
styles.push('turnitin')
|
||||
innerContents += "<span class='gradebook-cell-turnitin #{htmlEscape turnitin.state}-score' />"
|
||||
|
||||
"""
|
||||
<div class="gradebook-cell #{htmlEscape if opts.editable then 'gradebook-cell-editable focus' else ''} #{htmlEscape opts.classes} #{htmlEscape styles.join(' ')}">
|
||||
#{$.raw innerContents}
|
||||
</div>
|
||||
"""
|
||||
|
||||
ariaLabelTemplate: (submission_type) ->
|
||||
label = GRADEBOOK_TRANSLATIONS["submission_tooltip_#{submission_type}"]
|
||||
if label?
|
||||
"aria-label='#{label}'"
|
||||
else
|
||||
""
|
||||
|
||||
@styles: (submission = {}, assignment = {}) ->
|
||||
classes = []
|
||||
|
||||
# only one of these can be present for styling
|
||||
if submission.drop
|
||||
classes.push('dropped')
|
||||
else if submission.excused
|
||||
classes.push('excused')
|
||||
else if submission.grade_matches_current_submission == false
|
||||
classes.push('resubmitted')
|
||||
else if submission.missing
|
||||
classes.push('missing')
|
||||
else if submission.late
|
||||
classes.push('late')
|
||||
|
||||
classes.push('ungraded') if ''+assignment.submission_types is "not_graded"
|
||||
classes.push('muted') if assignment.muted
|
||||
classes.push(submission.submission_type) if submission.submission_type
|
||||
classes
|
||||
|
||||
class SubmissionCell.out_of extends SubmissionCell
|
||||
init: () ->
|
||||
submission = @opts.item[@opts.column.field]
|
||||
@$wrapper = $(@cellWrapper("""
|
||||
<div class="overflow-wrapper">
|
||||
<div class="grade-and-outof-wrapper">
|
||||
<input type="text" #{@ariaLabelTemplate(submission.submission_type)} class="grade"/>
|
||||
<span class="outof">
|
||||
<span class="divider">/</span>
|
||||
#{htmlEscape(I18n.n(@opts.column.object.points_possible))}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
""", { classes: 'gradebook-cell-out-of-formatter' })).appendTo(@opts.container)
|
||||
@$input = @$wrapper.find('input').focus().select()
|
||||
|
||||
class SubmissionCell.letter_grade extends SubmissionCell
|
||||
# Letter Grade formatter
|
||||
@formatter: (row, col, submission, assignment, student, opts={}) ->
|
||||
innerContents = if submission.excused
|
||||
I18n.t("Excused")
|
||||
else if submission.score?
|
||||
"#{htmlEscape submission.grade}<span class='letter-grade-points'>#{htmlEscape(I18n.n(submission.score))}</span>"
|
||||
else
|
||||
submission.grade
|
||||
|
||||
SubmissionCell.prototype.cellWrapper(innerContents, {submission: submission, assignment: assignment, editable: false, student: student, isLocked: !!opts.isLocked, tooltip: opts.tooltip})
|
||||
|
||||
class SubmissionCell.gpa_scale extends SubmissionCell
|
||||
# GPA Scale formatter
|
||||
@formatter: (row, col, submission, assignment, student, opts={}) ->
|
||||
innerContents = if submission.excused
|
||||
I18n.t("Excused")
|
||||
else
|
||||
submission.grade
|
||||
|
||||
SubmissionCell.prototype.cellWrapper(innerContents, {submission: submission, assignment: assignment, editable: false, student: student, classes: "gpa_scale_cell", isLocked: !!opts.isLocked, tooltip: opts.tooltip})
|
||||
|
||||
passFailMessage = (text) ->
|
||||
switch text
|
||||
when 'EX' then GRADEBOOK_TRANSLATIONS.submission_excused
|
||||
when '' then GRADEBOOK_TRANSLATIONS.submission_blank
|
||||
else GRADEBOOK_TRANSLATIONS["submission_#{text}"]
|
||||
|
||||
iconClassFromSubmission = (submission) ->
|
||||
{ pass: 'icon-check', complete: 'icon-check', fail: 'icon-x', incomplete: 'icon-x' }[submission.rawGrade] || 'icon-undefined'
|
||||
|
||||
class SubmissionCell.pass_fail extends SubmissionCell
|
||||
|
||||
states = ['pass', 'fail', '']
|
||||
STATE_MAPPING =
|
||||
pass: 'pass'
|
||||
complete: 'pass'
|
||||
fail: 'fail'
|
||||
incomplete: 'fail'
|
||||
|
||||
classFromSubmission = (submission) ->
|
||||
if submission.excused
|
||||
# this can never occur, since excused submissions have no grade
|
||||
# and ungraded submissions do not use htmlFromSubmission
|
||||
"EX"
|
||||
else
|
||||
STATE_MAPPING[submission.rawGrade] || ''
|
||||
|
||||
checkboxButtonTemplate = (iconClass) ->
|
||||
if _.isEmpty(iconClass)
|
||||
'–'
|
||||
else
|
||||
"""
|
||||
<i class="#{htmlEscape iconClass}" role="presentation"></i>
|
||||
"""
|
||||
|
||||
# Complete/Incomplete (pass_fail) cell formatter and editor
|
||||
# only used by formatter for graded submissions
|
||||
htmlFromSubmission: (options={}) ->
|
||||
cssClass = classFromSubmission(options.submission)
|
||||
iconClass = iconClassFromSubmission(options.submission)
|
||||
editable = if options.editable
|
||||
'editable'
|
||||
else
|
||||
''
|
||||
SubmissionCell::cellWrapper("""
|
||||
<button
|
||||
data-value="#{htmlEscape(options.submission.entered_grade || '')}"
|
||||
class="Button Button--icon-action gradebook-checkbox gradebook-checkbox-#{htmlEscape cssClass} #{htmlEscape(editable)}"
|
||||
type="button"
|
||||
aria-label="#{htmlEscape cssClass}">
|
||||
<span class="screenreader-only">#{htmlEscape(passFailMessage(cssClass))}</span>
|
||||
#{checkboxButtonTemplate(iconClass)}
|
||||
</button>
|
||||
""", options)
|
||||
|
||||
# Complete/Incomplete (pass_fail) formatter
|
||||
@formatter: (row, col, submission, assignment, student, opts={}) ->
|
||||
return SubmissionCell.formatter.apply(this, arguments) unless submission.grade?
|
||||
pass_fail::htmlFromSubmission({
|
||||
submission, assignment, editable: false, isLocked: opts.isLocked, tooltip: opts.tooltip, needsGrading: opts.needsGrading
|
||||
})
|
||||
|
||||
init: () ->
|
||||
classes = 'Grid__AssignmentRowCell__PassFailInput'
|
||||
@$wrapper = $(@cellWrapper(undefined, { classes }))
|
||||
@$wrapper = $(@htmlFromSubmission({
|
||||
classes,
|
||||
submission: @opts.item[@opts.column.field],
|
||||
assignment: @opts.column.object,
|
||||
editable: true})
|
||||
).appendTo(@opts.container)
|
||||
@$input = @$wrapper.find('.gradebook-checkbox')
|
||||
.bind('click', (event) =>
|
||||
event.preventDefault()
|
||||
currentValue = @$input.data('value')
|
||||
if currentValue is 'complete'
|
||||
newValue = 'incomplete'
|
||||
else if currentValue is 'incomplete'
|
||||
newValue = ''
|
||||
else
|
||||
newValue = 'complete'
|
||||
@transitionValue(newValue)
|
||||
).focus()
|
||||
|
||||
destroy: () ->
|
||||
@$wrapper.remove()
|
||||
|
||||
transitionValue: (newValue) ->
|
||||
@$input
|
||||
.removeClass('gradebook-checkbox-pass gradebook-checkbox-fail')
|
||||
.addClass('gradebook-checkbox-' + classFromSubmission(rawGrade: newValue))
|
||||
.attr('aria-label', passFailMessage(STATE_MAPPING[newValue]))
|
||||
.data('value', newValue)
|
||||
@$input.find('i')
|
||||
.removeClass()
|
||||
.addClass(iconClassFromSubmission(rawGrade: newValue))
|
||||
|
||||
loadValue: () ->
|
||||
submission = @opts.item[@opts.column.field]
|
||||
@val = submission.entered_grade || submission.grade || ""
|
||||
|
||||
serializeValue: () ->
|
||||
@$input.data('value')
|
||||
|
||||
isValueChanged: () ->
|
||||
@val != @$input.data('value')
|
||||
|
||||
class SubmissionCell.points extends SubmissionCell
|
||||
|
||||
SubmissionCell
|
|
@ -1,689 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
import SubmissionCell from 'compiled/gradezilla/SubmissionCell'
|
||||
import htmlEscape from 'str/htmlEscape'
|
||||
import $ from 'jquery'
|
||||
import numberHelper from 'jsx/shared/helpers/numberHelper'
|
||||
import GRADEBOOK_TRANSLATIONS from 'compiled/gradezilla/GradebookTranslations'
|
||||
|
||||
const dangerousHTML = '"><img src=/ onerror=alert(document.cookie);>'
|
||||
const escapedDangerousHTML = htmlEscape(dangerousHTML)
|
||||
|
||||
QUnit.module('SubmissionCell', {
|
||||
setup() {
|
||||
this.pointsPossible = 100
|
||||
this.opts = {
|
||||
item: {whatever: {}},
|
||||
column: {
|
||||
field: 'whatever',
|
||||
object: {points_possible: this.pointsPossible}
|
||||
},
|
||||
container: $('#fixtures')[0]
|
||||
}
|
||||
this.cell = new SubmissionCell(this.opts)
|
||||
},
|
||||
teardown() {
|
||||
$('#fixtures').empty()
|
||||
}
|
||||
})
|
||||
|
||||
test('#applyValue escapes html in passed state', function() {
|
||||
const item = {whatever: {grade: '1'}}
|
||||
const state = dangerousHTML
|
||||
this.stub(this.cell, 'postValue')
|
||||
this.cell.applyValue(item, state)
|
||||
equal(item.whatever.grade, escapedDangerousHTML)
|
||||
})
|
||||
|
||||
test('#applyValue calls flashWarning', function() {
|
||||
this.stub(this.cell, 'postValue')
|
||||
const flashWarningStub = this.stub($, 'flashWarning')
|
||||
this.cell.applyValue(this.opts.item, '150')
|
||||
ok(flashWarningStub.calledOnce)
|
||||
})
|
||||
|
||||
test('#applyValue calls numberHelper with points possible', function() {
|
||||
const numberHelperStub = this.stub(numberHelper, 'parse').withArgs(this.pointsPossible)
|
||||
this.stub(this.cell, 'postValue')
|
||||
this.cell.applyValue(this.opts.item, '10')
|
||||
strictEqual(numberHelperStub.callCount, 1)
|
||||
})
|
||||
|
||||
test('#applyValue calls numberHelper with state', function() {
|
||||
const state = '10'
|
||||
const numberHelperStub = this.stub(numberHelper, 'parse').withArgs(state)
|
||||
this.stub(this.cell, 'postValue')
|
||||
this.cell.applyValue(this.opts.item, state)
|
||||
strictEqual(numberHelperStub.callCount, 1)
|
||||
})
|
||||
|
||||
test('#loadValue escapes html', function() {
|
||||
this.opts.item.whatever.grade = dangerousHTML
|
||||
this.cell.loadValue()
|
||||
equal(this.cell.$input.val(), escapedDangerousHTML)
|
||||
equal(this.cell.$input[0].defaultValue, escapedDangerousHTML)
|
||||
})
|
||||
|
||||
test('#loadValue uses entered_grade when available', function() {
|
||||
this.opts.item.whatever.grade = '100'
|
||||
this.opts.item.whatever.entered_grade = '110'
|
||||
this.cell.loadValue()
|
||||
equal(this.cell.$input.val(), '110')
|
||||
equal(this.cell.$input[0].defaultValue, '110')
|
||||
})
|
||||
|
||||
test('#class.formatter rounds numbers if they are numbers', function() {
|
||||
this.stub(SubmissionCell.prototype, 'cellWrapper')
|
||||
.withArgs('0.67')
|
||||
.returns('ok')
|
||||
const 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', function() {
|
||||
this.stub(SubmissionCell.prototype, 'cellWrapper')
|
||||
.withArgs('happy')
|
||||
.returns('ok')
|
||||
const formattedResponse = SubmissionCell.formatter(0, 0, {grade: 'happy'}, {}, {})
|
||||
equal(formattedResponse, 'ok')
|
||||
})
|
||||
|
||||
test('#class.formatter adds a percent symbol for assignments with a percent grading_type', function() {
|
||||
this.stub(SubmissionCell.prototype, 'cellWrapper')
|
||||
.withArgs('73%')
|
||||
.returns('ok')
|
||||
const formattedResponse = SubmissionCell.formatter(
|
||||
0,
|
||||
0,
|
||||
{grade: 73},
|
||||
{grading_type: 'percent'},
|
||||
{}
|
||||
)
|
||||
equal(formattedResponse, 'ok')
|
||||
})
|
||||
|
||||
test('#class.formatter, isInactive adds grayed-out', () => {
|
||||
const student = {isInactive: true}
|
||||
const submissionCellResponse = SubmissionCell.formatter(0, 0, {grade: 'happy'}, {}, student)
|
||||
notEqual(submissionCellResponse.indexOf('grayed-out'), -1)
|
||||
})
|
||||
|
||||
test('#class.formatter, isLocked: true adds grayed-out', () => {
|
||||
const submissionCellResponse = SubmissionCell.formatter(
|
||||
0,
|
||||
0,
|
||||
{grade: 73},
|
||||
{},
|
||||
{},
|
||||
{isLocked: true}
|
||||
)
|
||||
ok(submissionCellResponse.indexOf('grayed-out') > -1)
|
||||
})
|
||||
|
||||
test('#class.formatter, isLocked: true adds cannot_edit', () => {
|
||||
const 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", () => {
|
||||
const 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", () => {
|
||||
const submissionCellResponse = SubmissionCell.formatter(
|
||||
0,
|
||||
0,
|
||||
{grade: 73},
|
||||
{},
|
||||
{},
|
||||
{isLocked: false}
|
||||
)
|
||||
equal(submissionCellResponse.indexOf('cannot_edit'), -1)
|
||||
})
|
||||
|
||||
test("#class.formatter, isInactive: false doesn't add grayed-out", () => {
|
||||
const student = {isInactive: false}
|
||||
const submissionCellResponse = SubmissionCell.formatter(0, 0, {grade: 10}, {}, student)
|
||||
equal(submissionCellResponse.indexOf('grayed-out'), -1)
|
||||
})
|
||||
|
||||
test('#class.formatter, isConcluded adds grayed-out', () => {
|
||||
const student = {isConcluded: true}
|
||||
const submissionCellResponse = SubmissionCell.formatter(0, 0, {grade: 10}, {}, student)
|
||||
notEqual(submissionCellResponse.indexOf('grayed-out'), -1)
|
||||
})
|
||||
|
||||
test("#class.formatter, isConcluded doesn't have grayed-out", () => {
|
||||
const student = {isConcluded: false}
|
||||
const submissionCellResponse = SubmissionCell.formatter(0, 0, {grade: 10}, {}, student)
|
||||
equal(submissionCellResponse.indexOf('grayed-out'), -1)
|
||||
})
|
||||
|
||||
test('#letter_grade.formatter, shows Excused when submission is excused', function() {
|
||||
this.stub(SubmissionCell.prototype, 'cellWrapper')
|
||||
.withArgs('Excused')
|
||||
.returns('ok')
|
||||
const formattedResponse = SubmissionCell.letter_grade.formatter(0, 0, {excused: true}, {}, {})
|
||||
equal(formattedResponse, 'ok')
|
||||
})
|
||||
|
||||
test('#letter_grade.formatter, shows the score and letter grade', function() {
|
||||
this.stub(SubmissionCell.prototype, 'cellWrapper')
|
||||
.withArgs("F<span class='letter-grade-points'>0</span>")
|
||||
.returns('ok')
|
||||
const formattedResponse = SubmissionCell.letter_grade.formatter(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
grade: 'F',
|
||||
score: 0
|
||||
},
|
||||
{},
|
||||
{}
|
||||
)
|
||||
equal(formattedResponse, 'ok')
|
||||
})
|
||||
|
||||
test('#letter_grade.formatter, shows the letter grade', function() {
|
||||
this.stub(SubmissionCell.prototype, 'cellWrapper')
|
||||
.withArgs('B')
|
||||
.returns('ok')
|
||||
const formattedResponse = SubmissionCell.letter_grade.formatter(0, 0, {grade: 'B'}, {}, {})
|
||||
equal(formattedResponse, 'ok')
|
||||
})
|
||||
|
||||
test('#letter_grade.formatter, isLocked: true adds grayed-out', () => {
|
||||
const 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', () => {
|
||||
const 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", () => {
|
||||
const 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", () => {
|
||||
const submissionCellResponse = SubmissionCell.letter_grade.formatter(
|
||||
0,
|
||||
0,
|
||||
{grade: 'A'},
|
||||
{},
|
||||
{},
|
||||
{isLocked: false}
|
||||
)
|
||||
equal(submissionCellResponse.indexOf('cannot_edit'), -1)
|
||||
})
|
||||
|
||||
test('#gpa_scale.formatter, isLocked: true adds grayed-out', () => {
|
||||
const 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', () => {
|
||||
const 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", () => {
|
||||
const 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", () => {
|
||||
const submissionCellResponse = SubmissionCell.gpa_scale.formatter(
|
||||
0,
|
||||
0,
|
||||
{grade: 3.2},
|
||||
{},
|
||||
{},
|
||||
{isLocked: false}
|
||||
)
|
||||
equal(submissionCellResponse.indexOf('cannot_edit'), -1)
|
||||
})
|
||||
|
||||
test('#pass_fail.formatter, isLocked: true adds grayed-out', () => {
|
||||
const 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', () => {
|
||||
const 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", () => {
|
||||
const 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", () => {
|
||||
const submissionCellResponse = SubmissionCell.pass_fail.formatter(
|
||||
0,
|
||||
0,
|
||||
{grade: 'complete'},
|
||||
{},
|
||||
{},
|
||||
{isLocked: false}
|
||||
)
|
||||
equal(submissionCellResponse.indexOf('cannot_edit'), -1)
|
||||
})
|
||||
|
||||
test('#pass_fail.formatter, uses rawGrade to determine cssClass', () => {
|
||||
const submissionCellResponse = SubmissionCell.pass_fail.formatter(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
grade: 'completo',
|
||||
rawGrade: 'complete'
|
||||
},
|
||||
{},
|
||||
{}
|
||||
)
|
||||
ok(submissionCellResponse.indexOf('gradebook-checkbox-pass') > -1)
|
||||
})
|
||||
|
||||
test('#pass_fail.formatter, uses rawGrade to determine iconClass', () => {
|
||||
const submissionCellResponse = SubmissionCell.pass_fail.formatter(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
grade: 'completo',
|
||||
rawGrade: 'complete'
|
||||
},
|
||||
{},
|
||||
{}
|
||||
)
|
||||
ok(submissionCellResponse.indexOf('icon-check') > -1)
|
||||
})
|
||||
|
||||
QUnit.module('Pass/Fail SubmissionCell', {
|
||||
getCell(overrides = {}) {
|
||||
const opts = {
|
||||
item: {
|
||||
foo: {
|
||||
...overrides.foo
|
||||
}
|
||||
},
|
||||
column: {
|
||||
field: 'foo',
|
||||
object: {points_possible: 100}
|
||||
},
|
||||
assignment: {},
|
||||
container: $('#fixtures')[0]
|
||||
}
|
||||
this.cell = new SubmissionCell.pass_fail(opts)
|
||||
},
|
||||
teardown() {
|
||||
$('#fixtures').empty()
|
||||
}
|
||||
})
|
||||
|
||||
test('#pass_fail#htmlFromSubmission sets the data value for the button to entered_grade when it is complete', function() {
|
||||
this.getCell({foo: {entered_grade: 'complete'}})
|
||||
strictEqual(this.cell.$input.data('value'), 'complete')
|
||||
})
|
||||
|
||||
test('#pass_fail#htmlFromSubmission sets the data value for the button to entered_grade when it is incomplete', function() {
|
||||
this.getCell({foo: {entered_grade: 'incomplete'}})
|
||||
strictEqual(this.cell.$input.data('value'), 'incomplete')
|
||||
})
|
||||
|
||||
test('#pass_fail#transitionValue changes the aria-label to match the currently selected option', function() {
|
||||
this.getCell()
|
||||
this.cell.$input = $('<button><i></i></button>')
|
||||
this.cell.transitionValue('incomplete')
|
||||
equal(this.cell.$input.attr('aria-label'), 'fail')
|
||||
})
|
||||
|
||||
test('#pass_fail#transitionValue updates the icon class', function() {
|
||||
this.getCell()
|
||||
this.cell.$input = $('<button><i></i></button>')
|
||||
this.cell.transitionValue('complete')
|
||||
ok(this.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", () => {
|
||||
const assignment = {}
|
||||
deepEqual(SubmissionCell.styles(assignment, {submission_types: ['not_graded']}), ['ungraded'])
|
||||
})
|
||||
|
||||
test("when an assignment's is not ungraded it returns nothing", () => {
|
||||
const assignment = {}
|
||||
deepEqual(SubmissionCell.styles(assignment, {submission_types: ['online_text_entry']}), [])
|
||||
})
|
||||
|
||||
test("when an assignment's type is undefined it return nothing", () => {
|
||||
const assignment = {}
|
||||
deepEqual(SubmissionCell.styles(assignment, {submission_types: undefined}), [])
|
||||
})
|
||||
|
||||
test('when an assignment is muted it returns muted', () => {
|
||||
const assignment = {}
|
||||
deepEqual(SubmissionCell.styles(assignment, {muted: true}), ['muted'])
|
||||
})
|
||||
|
||||
test('when an assignment is not muted it returns nothing', () => {
|
||||
const assignment = {}
|
||||
deepEqual(SubmissionCell.styles(assignment, {muted: false}), [])
|
||||
})
|
||||
|
||||
test("when an assignment submission's 'mute' property is undefined it return nothing", () => {
|
||||
const 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', () => {
|
||||
const submission = {
|
||||
late: true,
|
||||
submission_type: 'online_text_entry'
|
||||
}
|
||||
const 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', () => {
|
||||
const submission = {
|
||||
drop: true,
|
||||
excused: true,
|
||||
grade_matches_current_submission: false,
|
||||
missing: true,
|
||||
late: true,
|
||||
submission_type: 'online_text_entry'
|
||||
}
|
||||
const assignment = {
|
||||
submission_types: ['not_graded'],
|
||||
muted: true
|
||||
}
|
||||
deepEqual(SubmissionCell.styles(submission, assignment), [
|
||||
'dropped',
|
||||
'ungraded',
|
||||
'muted',
|
||||
'online_text_entry'
|
||||
])
|
||||
})
|
||||
|
||||
QUnit.module('#cellWrapper', {
|
||||
setup() {
|
||||
this.fixtures = document.querySelector('#fixtures')
|
||||
},
|
||||
params() {
|
||||
return {
|
||||
item: {
|
||||
whatever: {
|
||||
id: '1',
|
||||
submission_type: 'online_text_entry'
|
||||
}
|
||||
},
|
||||
column: {
|
||||
field: 'whatever',
|
||||
object: {id: '42'}
|
||||
}
|
||||
}
|
||||
},
|
||||
teardown() {
|
||||
this.fixtures.innerHTML = ''
|
||||
}
|
||||
})
|
||||
|
||||
test("if student is inactive, styles include 'grayed-out'", function() {
|
||||
const cell = new SubmissionCell(this.params()).cellWrapper('', {student: {isInactive: true}})
|
||||
this.fixtures.innerHTML = cell
|
||||
strictEqual(this.fixtures.querySelectorAll('div.grayed-out').length, 1)
|
||||
})
|
||||
|
||||
test("if student is concluded, styles include 'grayed-out'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {
|
||||
student: {isConcluded: true}
|
||||
})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.grayed-out').length, 1)
|
||||
})
|
||||
|
||||
test("if isLocked, styles include 'grayed-out'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {isLocked: true})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.grayed-out').length, 1)
|
||||
})
|
||||
|
||||
test("if student is inactive, tooltips include 'grayed-out'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {
|
||||
student: {isInactive: true}
|
||||
})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.grayed-out').length, 1)
|
||||
})
|
||||
|
||||
test("if student is concluded, styles include 'grayed-out'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {
|
||||
student: {isConcluded: true}
|
||||
})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.grayed-out').length, 1)
|
||||
})
|
||||
|
||||
test("if locked, styles include 'grayed-out'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {isLocked: true})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.grayed-out').length, 1)
|
||||
})
|
||||
|
||||
test("if student is concluded, styles include 'cannot_edit'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {
|
||||
student: {isConcluded: true}
|
||||
})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.cannot_edit').length, 1)
|
||||
})
|
||||
|
||||
test("if is locked, styles include 'cannot_edit'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('', {isLocked: true})
|
||||
strictEqual(this.fixtures.querySelectorAll('div.cannot_edit').length, 1)
|
||||
})
|
||||
|
||||
test("if it has turnitin data, styles includes 'turnitin'", function() {
|
||||
const params = this.params()
|
||||
params.item.whatever.turnitin_data = {submission_1: 'none'}
|
||||
this.fixtures.innerHTML = new SubmissionCell(params).cellWrapper('')
|
||||
strictEqual(this.fixtures.querySelectorAll('div.turnitin').length, 1)
|
||||
})
|
||||
|
||||
test("if no turnitin data, styles do not includes 'turnitin'", function() {
|
||||
this.fixtures.innerHTML = new SubmissionCell(this.params()).cellWrapper('')
|
||||
strictEqual(this.fixtures.querySelectorAll('div.turnitin').length, 0)
|
||||
})
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import SubmissionCell from 'compiled/gradezilla/SubmissionCell';
|
||||
import AssignmentRowCell from 'jsx/gradezilla/default_gradebook/components/AssignmentRowCell';
|
||||
|
||||
QUnit.module('AssignmentRowCell', (suiteHooks) => {
|
||||
|
|
Loading…
Reference in New Issue