canvas-lms/spec/coffeescripts/submitAssignmentHelperSpec.js

108 lines
3.3 KiB
JavaScript
Raw Normal View History

/*
* 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 {
recordEulaAgreement,
verifyPledgeIsChecked
} from 'ui/features/submit_assignment/jquery/helper.js'
import $ from 'jquery'
QUnit.module('SubmitAssignmentHelper', {
teardown() {
let ENV
$('#fixtures').html('')
ENV = null
}
})
test('Sets the input value to the current time if checked is true for all eula inputs', () => {
const now = new Date()
const clock = sinon.useFakeTimers(now.getTime())
const inputHtml = `\
<input type='checkbox' name='test' class='checkbox-test'></input>
<input type='checkbox' name='test two' class='checkbox-test'></input>\
`
$('#fixtures').append(inputHtml)
recordEulaAgreement('.checkbox-test', true)
const inputs = document.querySelectorAll('.checkbox-test')
for (const val of inputs) {
equal(val.value, now.getTime())
}
return clock.restore()
})
test('Clears the value if the input is not checked', () => {
const now = new Date()
const clock = sinon.useFakeTimers(now.getTime())
const inputHtml = `\
<input type='checkbox' name='test' class='checkbox-test'></input>
<input type='checkbox' name='test two' class='checkbox-test'></input>\
`
$('#fixtures').append(inputHtml)
recordEulaAgreement('.checkbox-test', false)
const inputs = document.querySelectorAll('.checkbox-test')
for (const val of inputs) {
equal(val.value, '')
}
return clock.restore()
})
Add EULA timestamp to LTI tool file submissions closes: PLAT-3109 Test Plan: * Verify you can still create an online_upload submission via API withouth specifying a eula timestamp * Install a plagiarism detection tool * Install https://lti-tool-provider-example.herokuapp.com/xml_builder using all placements * Create a single assignment with submission types 'onine upload' and 'text entry.' The assignment should be associated with the plagiarism detection tool File Upload & Text Entry - As a student visit the assignment. Click the 'File Upload' tab and upload a file. - Verify the tool's EULA is displayed by a checkbox - Verify the checkbox must be clicked before submitting - Verify the page allows submitting once the checkbox is clicked. LTI Homework Submission Placement - Click the LTI submission tab - Go through the content item flow and return a File Item - Verify a link to the plagiarism tool's EULA is shown. - Verify the checkbox must be clicked before submitting - Verify submission is successful once box is checked * For all submission types verify the the `eula_agreement_timestamp` is set in the DB in the submission's 'turnitin_data' (i.e. turnitin_data: {:eula_agreement_timestamp=>"1522430904822"}) * Verify if the plagiarism detection tool has no EULA offered the checkbox does not appear in the LTI submission tab. Change-Id: Idb08d3c5d37c8c05ebf075f3c95c33c4c531aabf Reviewed-on: https://gerrit.instructure.com/145314 Tested-by: Jenkins Reviewed-by: Nathan Mills <nathanm@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Jesse Poulos <jpoulos@instructure.com>
2018-03-30 01:06:29 +08:00
test('returns true if checkbox does not exist', () => {
ok(verifyPledgeIsChecked($('#does_not_exist')))
})
test('returns true if the checkbox exists and is checked', () => {
const checkbox = document.createElement('input')
checkbox.type = 'checkbox'
checkbox.checked = true
checkbox.id = 'test-checkbox'
document.getElementById('fixtures').appendChild(checkbox)
ok(verifyPledgeIsChecked($('#test-checkbox')))
})
test('returns false if the checkbox exists and is not checked', () => {
const checkbox = document.createElement('input')
checkbox.type = 'checkbox'
checkbox.checked = false
checkbox.id = 'test-checkbox'
document.getElementById('fixtures').appendChild(checkbox)
notOk(verifyPledgeIsChecked($('#test-checkbox')))
})
test('alerts the user is the checkbox is not checked', () => {
const errorMessage =
'You must agree to the submission pledge before you can submit this assignment.'
Add EULA timestamp to LTI tool file submissions closes: PLAT-3109 Test Plan: * Verify you can still create an online_upload submission via API withouth specifying a eula timestamp * Install a plagiarism detection tool * Install https://lti-tool-provider-example.herokuapp.com/xml_builder using all placements * Create a single assignment with submission types 'onine upload' and 'text entry.' The assignment should be associated with the plagiarism detection tool File Upload & Text Entry - As a student visit the assignment. Click the 'File Upload' tab and upload a file. - Verify the tool's EULA is displayed by a checkbox - Verify the checkbox must be clicked before submitting - Verify the page allows submitting once the checkbox is clicked. LTI Homework Submission Placement - Click the LTI submission tab - Go through the content item flow and return a File Item - Verify a link to the plagiarism tool's EULA is shown. - Verify the checkbox must be clicked before submitting - Verify submission is successful once box is checked * For all submission types verify the the `eula_agreement_timestamp` is set in the DB in the submission's 'turnitin_data' (i.e. turnitin_data: {:eula_agreement_timestamp=>"1522430904822"}) * Verify if the plagiarism detection tool has no EULA offered the checkbox does not appear in the LTI submission tab. Change-Id: Idb08d3c5d37c8c05ebf075f3c95c33c4c531aabf Reviewed-on: https://gerrit.instructure.com/145314 Tested-by: Jenkins Reviewed-by: Nathan Mills <nathanm@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Jesse Poulos <jpoulos@instructure.com>
2018-03-30 01:06:29 +08:00
const alertSpy = sinon.spy()
const original_alert = window.alert
window.alert = alertSpy
const checkbox = document.createElement('input')
checkbox.type = 'checkbox'
checkbox.checked = false
checkbox.id = 'test-checkbox'
document.getElementById('fixtures').appendChild(checkbox)
verifyPledgeIsChecked($('#test-checkbox'))
ok(alertSpy.calledWith(errorMessage))
window.alert = original_alert
})