diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 811368b..e3ee9ec 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -37,15 +37,19 @@ $(document).ready(function () { }) }); -$(document).on('change', 'form.file-upload input.file', function() { - if ($(this).val()) { - var allowed = $(this).data('ext').split(','); - var ext = '.' + $(this).val().split('.').pop().toLowerCase(); +$(document).on('click', '#file_upload_button', function(e) { + file = $(this).parents('form:first').find('input:file'); + if (file.val()) { + var allowed = file.data('ext').split(','); + var ext = '.' + file.val().split('.').pop().toLowerCase(); if($.inArray(ext, allowed) == -1) { alert('File extension ' + ext + ' is not allowed.'); - $(this).parents('form:first').find('input:submit').prop('disabled', true); } else { - $(this).parents('form:first').find('input:submit').prop('disabled', false); + return true; } + } else { + alert('Please choose a file to upload.'); } + e.preventDefault(); + return false; }); \ No newline at end of file diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index e6f8539..afa257a 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -42,7 +42,7 @@ html: { multipart: true, class: "file-upload" } do |f| %> <%= f.hidden_field :usage, value: @document.usage %> <%= f.hidden_field :supplemental, value: @document.supplemental %> - <%= f.button :submit, "Upload", class: "btn btn-primary file-upload", disabled: true %> + <%= f.button :submit, "Upload", class: "btn btn-primary file-upload", id: "file_upload_button", disabled: false %> <% if (defined? modal).nil? || !modal %> <% if current_user.role == User::STUDENT && @document.usage == 'licence' %> diff --git a/test/system/app_settings_test.rb b/test/system/app_settings_test.rb index 5b58a77..fe2dfc3 100644 --- a/test/system/app_settings_test.rb +++ b/test/system/app_settings_test.rb @@ -155,7 +155,6 @@ class AppSettingsTest < ApplicationSystemTestCase click_link('Continue') click_link_or_button('Upload Primary Thesis File') attach_file('document_file', Rails.root.join('test/fixtures/files/pdf-document.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') click_link('Continue') assert_selector 'div.student-view.fitted.submit > div', text: 'Review Licence Info Text Test' @@ -196,12 +195,10 @@ class AppSettingsTest < ApplicationSystemTestCase click_link('Continue') click_link_or_button('Upload Primary Thesis File') attach_file('document_file', Rails.root.join('test/fixtures/files/pdf-document.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') click_link('Continue') click_link_or_button('Upload Licence File') attach_file('document_file', Rails.root.join('test/fixtures/files/pdf-document.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') check 'thesis_lac_licence_agreement' assert_selector "input[type=checkbox][id=thesis_lac_licence_agreement]:checked" diff --git a/test/system/students_test.rb b/test/system/students_test.rb index 91b9fb0..1ed898b 100644 --- a/test/system/students_test.rb +++ b/test/system/students_test.rb @@ -226,7 +226,7 @@ class StudentsTest < ApplicationSystemTestCase end ## Page 2 and 3 tests - should "upload files" do + should "upload primary file" do @thesis = FactoryGirl.create(:thesis) login_as(@thesis.student) visit root_url @@ -262,9 +262,6 @@ class StudentsTest < ApplicationSystemTestCase assert_not(page.has_css?("p", text: "Smith_Jane_E_2014_PhD.pdf"), "Should not show 'example text' as per Spring 2024 requirements") attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") - click_button('Upload') assert_selector(".name", text: /\.pdf/) @@ -285,6 +282,7 @@ class StudentsTest < ApplicationSystemTestCase assert checkbox.checked?, "#thesis_lac_licence_agreement checkbox is not checked." + # Yorkspace Licence assert page.has_selector?('#thesis_yorkspace_licence_agreement', visible: true), "#thesis_yorkspace_licence_agreement not found." checkbox = find('#thesis_yorkspace_licence_agreement', visible: true) @@ -321,9 +319,6 @@ class StudentsTest < ApplicationSystemTestCase click_link_or_button('Upload Licence File') attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") - click_button('Upload') click_button("Accept and Continue") @@ -364,9 +359,6 @@ class StudentsTest < ApplicationSystemTestCase ## Upload a file not accepted format. e.g. ruby .rb attach_file("document_file", Rails.root.join('test/factories/thesis.rb')) - - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") - click_button('Upload') assert page.has_selector?('#supplementary-help-info', visible: true), "#supplementary-help-info not found." diff --git a/test/system/theses_test.rb b/test/system/theses_test.rb index 3f93842..c175b35 100644 --- a/test/system/theses_test.rb +++ b/test/system/theses_test.rb @@ -193,7 +193,6 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Primary Thesis File") attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".name", text: /\.pdf/) @@ -205,7 +204,6 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Primary Thesis File") attach_file("document_file", Rails.root.join('test/fixtures/files/image-example.jpg')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".invalid-feedback", text: "Primary file must be a PDF") @@ -230,7 +228,6 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Supplementary Thesis Files") attach_file("document_file", Rails.root.join('test/fixtures/files/zip-file.zip')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".invalid-feedback", text: "File Supplemental file must be a valid file type") @@ -242,7 +239,6 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Supplementary Thesis Files") attach_file("document_file", Rails.root.join('test/fixtures/files/zip-file.zip')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".invalid-feedback", text: "File Supplemental file must be a valid file type") @@ -255,7 +251,6 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Supplementary Thesis Files") assert_selector "h2", text: "Upload Supplementary Thesis File", visible: :all attach_file("document_file", Rails.root.join('test/fixtures/files/pdf-document.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".supplemental", text: /_supplemental_/) #Supplemental @@ -271,7 +266,6 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Licence Agreements") assert_selector "h2", text: "Upload Licence File", visible: :all attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_not_empty find('.licence-file').text, "The .licence-file element is empty, no file" @@ -285,7 +279,6 @@ class ThesesTest < ApplicationSystemTestCase assert_selector "h2", text: "Upload Embargo Documents", visible: :all attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_not_empty find('.embargo-file').text, "The .embargo-file element is empty, no file" @@ -297,12 +290,10 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Primary Thesis File") attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') click_link("Replace") attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".name", text: /\.pdf/) @@ -318,12 +309,10 @@ class ThesesTest < ApplicationSystemTestCase click_on("Upload Supplementary Thesis Files") attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') click_link("Replace") attach_file("document_file", Rails.root.join('test/fixtures/files/Tony_Rich_E_2012_Phd.pdf')) - execute_script("$('#document_file').parents('form:first').find('input:submit').prop('disabled', false);") click_button('Upload') assert_selector(".name", text: /\.pdf/)