Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Oct 24, 2024
1 parent 14d43f5 commit bece3a5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
5 changes: 1 addition & 4 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,25 @@


$(document).ready(function () {

$('.dropdown-toggle').dropdown();

// disable in browser form validations
$('form').find('input').removeAttr('required');


$('.theses .options a').click(function (e) {
e.preventDefault();
$(this).tab('show');
$(".theses .options a").removeClass("active")
$(this).addClass("active")
})

});

$(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();
if($.inArray(ext, allowed) == -1) {
alert('File extension "' + ext + '" is not allowed for this upload.');
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);
Expand Down
16 changes: 14 additions & 2 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@ class Document < ApplicationRecord
LICENCE_FILE_EXT = [ '.pdf' ].freeze

#### ADDITIONAL METHODS
def allowed_extensions
list = SUPPLEMENTAL_FILE_EXT
def allowed_extensions
list = PRIMARY_FILE_EXT

case document_type
when 'primary'
list = PRIMARY_FILE_EXT
when 'supplemental'
list = SUPPLEMENTAL_FILE_EXT
when 'licence'
list = LICENCE_FILE_EXT
when 'embargo'
list = EMBARGO_FILE_EXT
end

return list
end

Expand Down
28 changes: 28 additions & 0 deletions test/models/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,32 @@ class DocumentTest < ActiveSupport::TestCase
assert_equal 4, Document.supplemental.count, 'The should be 4 supplemental documents'
assert_equal 2, Document.primary.count, 'There should be 5 primary documents'
end

should 'allowed_extensions should match document usage' do
d = Document.new

d.usage = 'thesis'
d.supplemental = false
assert_equal Document::PRIMARY_FILE_EXT, d.allowed_extensions

d.usage = 'thesis'
d.supplemental = true
assert_equal Document::SUPPLEMENTAL_FILE_EXT, d.allowed_extensions

d.usage = 'licence'
d.supplemental = false
assert_equal Document::LICENCE_FILE_EXT, d.allowed_extensions

d.usage = 'licence'
d.supplemental = true
assert_equal Document::LICENCE_FILE_EXT, d.allowed_extensions

d.usage = 'embargo'
d.supplemental = false
assert_equal Document::EMBARGO_FILE_EXT, d.allowed_extensions

d.usage = 'embargo'
d.supplemental = true
assert_equal Document::EMBARGO_FILE_EXT, d.allowed_extensions
end
end
3 changes: 3 additions & 0 deletions test/system/app_settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ 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'
Expand Down Expand Up @@ -195,10 +196,12 @@ 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"
Expand Down
12 changes: 10 additions & 2 deletions test/system/students_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class StudentsTest < ApplicationSystemTestCase
end

## Page 2 and 3 tests
should "upload primary file" do
should "upload files" do
@thesis = FactoryGirl.create(:thesis)
login_as(@thesis.student)
visit root_url
Expand Down Expand Up @@ -262,6 +262,9 @@ 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/)
Expand All @@ -282,7 +285,6 @@ 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)
Expand Down Expand Up @@ -319,6 +321,9 @@ 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")
Expand Down Expand Up @@ -359,6 +364,9 @@ 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."
Expand Down
11 changes: 11 additions & 0 deletions test/system/theses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ 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/)
Expand All @@ -204,6 +205,7 @@ 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")
Expand All @@ -228,6 +230,7 @@ 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")
Expand All @@ -239,6 +242,7 @@ 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")
Expand All @@ -251,6 +255,7 @@ 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

Expand All @@ -266,6 +271,7 @@ 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"

Expand All @@ -279,6 +285,7 @@ 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"
Expand All @@ -290,10 +297,12 @@ 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/)

Expand All @@ -309,10 +318,12 @@ 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/)

Expand Down

0 comments on commit bece3a5

Please sign in to comment.