Commit 1f3e1218 by Awais Jibran

Fix empty file description in ORA response

parent 4ceb210b
......@@ -626,6 +626,10 @@ describe("OpenAssessment.ResponseView", function() {
function getFileUploadField() {
return $(view.element).find('.file__upload').first();
}
function expectFileUploadButton(disabled) {
view.checkFilesDescriptions();
expect(getFileUploadField().is(':disabled')).toEqual(disabled);
}
spyOn(view, 'updateFilesDescriptionsFields').and.callThrough();
var files = [{type: 'image/jpeg', size: 1024, name: 'picture1.jpg', data: ''},
......@@ -634,26 +638,36 @@ describe("OpenAssessment.ResponseView", function() {
expect(getFileUploadField().is(':disabled')).toEqual(true);
expect(view.updateFilesDescriptionsFields).toHaveBeenCalledWith(files, undefined, 'image');
var firstDescriptionField1 = $(view.element).find('.file__description__0').first();
var firstDescriptionField2 = $(view.element).find('.file__description__1').first();
// set the first description field (the second is still empty)
// Only set the first description field and the second field remain empty.
// and check that upload button is disabled
var firstDescriptionField1 = $(view.element).find('.file__description__0').first();
$(firstDescriptionField1).val('test');
view.checkFilesDescriptions();
expect(getFileUploadField().is(':disabled')).toEqual(true);
$(firstDescriptionField1).val('test1');
$(firstDescriptionField2).val('');
expectFileUploadButton(true);
// set the second description field (now both descriptions are not empty)
// Set the second description field to be only spaces (given first description has value).
// and check that upload button is disabled
$(firstDescriptionField2).val(' ');
expectFileUploadButton(true)
// Set the both description fields to contain only spaces.
// and check that upload button is disabled
$(firstDescriptionField1).val(' ');
$(firstDescriptionField2).val(' ');
expectFileUploadButton(true)
// set the both description field to contain non empty values.
// and check that upload button is enabled
var firstDescriptionField2 = $(view.element).find('.file__description__1').first();
$(firstDescriptionField1).val('test1');
$(firstDescriptionField2).val('test2');
view.checkFilesDescriptions();
expect(getFileUploadField().is(':disabled')).toEqual(false);
expectFileUploadButton(false)
// remove value in the first upload field
// and check that upload button is disabled
$(firstDescriptionField1).val('');
view.checkFilesDescriptions();
expect(getFileUploadField().is(':disabled')).toEqual(true);
expectFileUploadButton(true)
});
it("removes description fields after files upload", function() {
......
......@@ -666,7 +666,7 @@ OpenAssessment.ResponseView.prototype = {
var filesDescriptions = [];
$(this.element).find('.file__description').each(function() {
var filesDescriptionVal = $(this).val();
var filesDescriptionVal = $.trim($(this).val());
if (filesDescriptionVal) {
filesDescriptions.push(filesDescriptionVal);
} else {
......
......@@ -400,24 +400,20 @@ class SubmissionMixin(object):
"""
urls = []
if 'file_keys' in submission['answer']:
keys = submission['answer'].get('file_keys', [])
file_keys = submission['answer'].get('file_keys', [])
descriptions = submission['answer'].get('files_descriptions', [])
for idx, key in enumerate(keys):
url = self._get_url_by_file_key(key)
if url:
description = ''
try:
description = descriptions[idx]
except IndexError:
pass
urls.append((url, description))
for idx, key in enumerate(file_keys):
file_download_url = self._get_url_by_file_key(key)
if file_download_url:
file_description = descriptions[idx].strip() if idx < len(descriptions) else ''
urls.append((file_download_url, file_description))
else:
break
elif 'file_key' in submission['answer']:
key = submission['answer'].get('file_key', '')
url = self._get_url_by_file_key(key)
if url:
urls.append((url, ''))
file_download_url = self._get_url_by_file_key(key)
if file_download_url:
urls.append((file_download_url, ''))
return urls
@staticmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment