Skip to content

Commit

Permalink
added download test case + copybara configuration for downloading files
Browse files Browse the repository at this point in the history
  • Loading branch information
DevAdm committed Aug 14, 2024
1 parent af5e6be commit fe36163
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 48 deletions.
24 changes: 20 additions & 4 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
require 'test_helper'

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400], options: {
browser: :remote,
url: "http://#{ENV.fetch('SELENIUM_SERVER')}:4444"
}
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] do |options|
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

# Add preferences
options.add_preference(:download, {
prompt_for_download: false,
default_directory: File.join(Rails.root, 'tmp')
})

# Remote driver setup
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: "http://#{ENV.fetch('SELENIUM_SERVER')}:4444",
options: options
)
end
end

def setup
user = FactoryGirl.create(:user)
Expand Down
9 changes: 8 additions & 1 deletion test/helpers/system_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ def select_chosen_option(dropdown_selector, option_text)
end
assert_selector "#{dropdown_selector} .chosen-single", text: option_text
end
end

def wait_for_download(filename)
loop do
break if File.exist?(filename)
sleep 1
end
end
end
2 changes: 1 addition & 1 deletion test/system/students_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class StudentsTest < ApplicationSystemTestCase

# Yorkspace Licence
assert page.has_selector?('#thesis_yorkspace_licence_agreement', visible: true), "#thesis_yorkspace_licence_agreement not found."
checkbox = find('#thesis_yorkspace_licence_agreement')
checkbox = find('#thesis_yorkspace_licence_agreement', visible: true)
assert_not checkbox.disabled?
click_link('View YorkSpace Licence Agreement')
assert page.has_selector?('#yorkspace-licence', visible: true), "#yorkspace-licence not found."
Expand Down
51 changes: 9 additions & 42 deletions test/system/theses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@
require 'helpers/system_test_helper'

class ThesesTest < ApplicationSystemTestCase
include SystemTestHelper # Include the SystemTestHelper module here

setup do
FactoryGirl.create(:user, role: User::ADMIN)
FactoryGirl.create(:user, role: User::MANAGER)
@thesis_01 = FactoryGirl.create(:thesis, degree_name: 'IMBA', degree_level: 'Master\'s')
@thesis_02 = FactoryGirl.create(:thesis, status: Thesis::UNDER_REVIEW)
end

def wait_for_download(filename, timeout: 30)
Timeout.timeout(timeout) do
loop do
break if File.exist?(filename)
sleep 1
end
end
end

test "be able to download report" do
user = FactoryGirl.create(:user, role: User::ADMIN)
login_as(user)
Expand All @@ -28,9 +21,10 @@ def wait_for_download(filename, timeout: 30)
click_link("Under Review Theses")
assert_selector 'a', text: 'Download Excel'
click_link("Download Excel")
filename = "tmp/test-screenshots/theses_report.xlsx"
wait_for_download(filename, timeout: 30)
filename = "tmp/theses_report.xlsx"
wait_for_download(filename)
assert File.exist?(filename), "Expected file #{filename} to be downloaded"
File.delete("tmp/theses_report.xlsx")
end

test 'Assign a thesis to ME and unassign this' do
Expand Down Expand Up @@ -176,17 +170,6 @@ def wait_for_download(filename, timeout: 30)
assert_selector(".name", text: /\.pdf/)
end

should "not be able to upload invalid primary document file type" do
visit root_url
click_link(@thesis_01.title)

click_on("Upload Primary File")
attach_file("document_file", Rails.root.join('test/fixtures/files/theses_report.zip'))
click_button('Upload')

assert_selector(".invalid-feedback", text: "Primary file must be a PDF")
end

should "not upload primary document with incorrect file format" do
visit root_url
click_link(@thesis_01.title)
Expand All @@ -208,14 +191,14 @@ def wait_for_download(filename, timeout: 30)
fill_in("Non-YorkU Email Address", with: "#{@thesis_01.student.username}@mailinator.com")
click_on("Continue")

fill_in(".thesis_abstract", with: "Abstract Test")
fill_in("Abstract", with: "Abstract Test")
click_on("Continue")

click_on("Upload Supplementary Files")
attach_file("document_file", Rails.root.join('test/fixtures/files/zip-file.zip'))
click_button('Upload')

assert_selector(".invalid-feedback", text: "Supplementary file be valid format")
assert_selector(".invalid-feedback", text: "File Supplemental file must be a valid file type")
end

should "not upload supplmentary document with incorrect file format as admin" do
Expand All @@ -226,7 +209,7 @@ def wait_for_download(filename, timeout: 30)
attach_file("document_file", Rails.root.join('test/fixtures/files/zip-file.zip'))
click_button('Upload')

assert_selector(".invalid-feedback", text: "Supplementary file be valid format")
assert_selector(".invalid-feedback", text: "File Supplemental file must be a valid file type")
end

should "be able to upload supplementary document by admin/staff" do
Expand All @@ -240,22 +223,6 @@ def wait_for_download(filename, timeout: 30)
assert_selector(".supplemental", text: /_supplemental_/) #Supplemental

end

<<<<<<< HEAD
should "not be able to upload invalid supplementary document file type" do
visit root_url
click_link(@thesis_01.title)

click_on("Upload Supplementary Files")
assert_selector "h1", text: "Upload Supplementary File", visible: :all
attach_file("document_file", Rails.root.join('test/fixtures/files/theses_report.zip'))
click_button('Upload')
assert_selector(".invalid-feedback", text: "Supplemental file must be a valid file type") #Supplemental

end
=======
>>>>>>> 751a97d (new tests)

###########################################################
##### TESTS WILL NEED BE UPDATED WITH NEW FILE NAMES ######
###########################################################
Expand Down Expand Up @@ -302,7 +269,7 @@ def wait_for_download(filename, timeout: 30)
click_link("Delete this file?")
page.accept_alert

assert_selector "p", text: "There is no primary file or document attached to this thesis/dissertation."
assert_selector "p", text: "There are no primary files or documents attached to this thesis/dissertation."
end

should "update supplementary file" do
Expand Down

0 comments on commit fe36163

Please sign in to comment.