fix missing file upload question answers

closes QO-714

flag=none

test plan:
- create an OAAT old quiz with file upload questions
- upload a file and click Next before file upload is done
- a confirm box is pop up with warning messages

Change-Id: Ib34838463a8965c50a44f174364d4e5b8de9c58f
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/261751
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Stephen Kacsmark <skacsmark@instructure.com>
QA-Review: Mark McDermott <mmcdermott@instructure.com>
Product-Review: Susan Sorensen <susan.sorensen@instructure.com>
This commit is contained in:
Han Yan 2021-03-28 18:15:56 -05:00
parent 5c39a6938c
commit 11a685b524
4 changed files with 28 additions and 2 deletions

View File

@ -31,7 +31,8 @@ export default class FileUploadQuestion extends View {
'.file-upload': '$fileUpload',
'.file-upload-btn': '$fileDialogButton',
'.attachment-id': '$attachmentID',
'.file-upload-box': '$fileUploadBox'
'.file-upload-box': '$fileUploadBox',
'#fileupload_in_progress': '$fileUploadInprogress'
}
this.prototype.events = {
@ -50,6 +51,7 @@ export default class FileUploadQuestion extends View {
if ((val = this.$fileUpload.val())) {
this.removeFileStatusMessage()
this.model.set('file', this.$fileUpload[0])
this.$fileUploadInprogress.val(true)
const dfrd = this.model.save(null, {success: this.processAttachment.bind(this)})
return this.$fileUploadBox.disableWhileLoading(dfrd)
}
@ -80,6 +82,7 @@ export default class FileUploadQuestion extends View {
// For now we'll just process the first one.
processAttachment(attachment) {
this.$attachmentID.val(this.model.id).trigger('change')
this.$fileUploadInprogress.val(false)
this.$fileUploadBox.addClass('file-upload-box-with-file')
this.render()
this.$fileUploadBox

View File

@ -74,6 +74,7 @@
name="question_<%= question[:id] %>[]"
value="<%= attachment_id_for(question) %>"/>
<% end %>
<input type="hidden" id="fileupload_in_progress" value="false"/>
<% end %>
</div>

View File

@ -721,7 +721,7 @@ $(function() {
.delegate(':text,textarea,select', 'change', function(event, update) {
const $this = $(this)
if ($this.hasClass('numerical_question_input')) {
var val = numberHelper.parse($this.val())
const val = numberHelper.parse($this.val())
$this.val(isNaN(val) ? '' : I18n.n(val.toFixed(4), {strip_insignificant_zeros: true}))
}
if ($this.hasClass('precision_question_input')) {
@ -910,6 +910,13 @@ $(function() {
}
}
if ($('#fileupload_in_progress[value="true"]', $questions).length !== 0) {
warningMessage = I18n.t(
'confirms.file_upload_in_progress',
'File upload is in progress. You may lose your answer before it is complete.'
)
}
if (warningMessage != undefined && !quizSubmission.submitting) {
const result = confirm(warningMessage)
if (!result) {

View File

@ -35,6 +35,7 @@ QUnit.module('FileUploadQuestionView', {
$('<input value="C:\\fakepath\\file.upload.zip" class="file-upload hidden" />').appendTo(
this.view.$el
)
$('<input type="hidden" id="fileupload_in_progress" value="false"/>').appendTo(this.view.$el)
this.view.$el.appendTo('#fixtures')
this.view.render()
},
@ -45,11 +46,25 @@ QUnit.module('FileUploadQuestionView', {
}
})
test('#checkForFileChange set file upload status to in_progress', function() {
$('#fileupload_in_progress').val(false)
const spy = sinon.stub(this.model, 'save')
ok($('#fileupload_in_progress').val(), 'false')
this.view.$fileUpload.val('C:\\fakepath\\file.upload.zip')
this.view.checkForFileChange($.Event('keydown', {keyCode: 64}))
ok($('#fileupload_in_progress').val(), 'true')
spy.reset()
spy.restore()
})
test('#processAttachment fires "attachmentManipulationComplete" event', function() {
$('#fileupload_in_progress').val(true)
const spy = sinon.spy(this.view, 'trigger')
notOk(spy.called, 'precondition')
ok($('#fileupload_in_progress').val(), 'true')
this.view.processAttachment()
ok(spy.calledWith('attachmentManipulationComplete'))
ok($('#fileupload_in_progress').val(), 'false')
this.view.trigger.restore()
})