Skip to content

Commit

Permalink
refactor test code etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhoubk committed Jan 16, 2025
1 parent 5bc29f9 commit 6bad469
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 48 deletions.
11 changes: 5 additions & 6 deletions spec/features/download_zipfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def wait_for_download(zip_file_path, timeout: 5)

loop do
elapsed_time = Time.current - start_time
raise "Timeout waiting for downloading #{zip_file_path}" if elapsed_time > timeout
raise "Error: Timeout waiting for downloading #{zip_file_path}" if elapsed_time > timeout
return true if File.exist?(zip_file_path)

sleep 1
Expand All @@ -45,15 +45,14 @@ def wait_for_download(zip_file_path, timeout: 5)
find_link('Original Shapefile').click
download_completed = wait_for_download(zip_file_path)
if download_completed
expect(File.exist?(zip_file_path)).to be_truthy, "Download completed but data.zip file not found: #{zip_file_path}"
expect(File.exist?(zip_file_path)).to be_truthy, "Error: Downloaded data.zip file not found: #{zip_file_path}"
Zip::File.open(zip_file_path) do |zip_file|
file_names = zip_file.map(&:name)
puts "Contents: #{file_names}"
expect(file_names).to include('SanBenito_Intersections_2016.shp'), 'SanBenito_Intersections_2016.shp not found in data.zip'
expect(file_names).to include('SanBenito_Intersections_2016.shp'), 'Error: SanBenito_Intersections_2016.shp not found in data.zip'
end
else
expect(File.exist?(crdownload_file)).to be_truthy, "Download not completed and incompleted data.zip.crdownload file found: #{crdownload_file}"
expect(File.size(crdownload_file)).to be > 130_000, 'Incompleted data.zip.crdownload file size <= 130000'
expect(File.exist?(crdownload_file)).to be_truthy, "Error: Download not completed and incompleted data.zip.crdownload file found: #{crdownload_file}"
expect(File.size(crdownload_file)).to be > 130_000, 'Error: Incompleted data.zip.crdownload file size <= 130000'
end
end
end
Expand Down
41 changes: 3 additions & 38 deletions spec/system/public_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
visit 'catalog/berkeley-s7038h'
end

it 'has the record title' do
it 'Record title' do
within('#document') do
expect(find('h2')).to have_text('Intersections, San Benito County, California, 2016')
end
end

context 'has metadata link' do
context 'metadata link' do
it 'displays the metadata link' do
expect(page).to have_link('Metadata', href: '/catalog/berkeley-s7038h/metadata')
end
Expand All @@ -29,7 +29,7 @@
end
end

context 'downloading button available' do
context 'downloading button' do
it 'displays the download button' do
expect(page).to have_button('downloads-button')
end
Expand All @@ -39,39 +39,4 @@
it_behaves_like 'download link invisible', 'Export GeoJSON'
end

# context 'downloading links available' do
# before do
# find('#downloads-button').click
# end

# href = 'https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip'
# css_downloads = { location: 'a[contenturl="https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip"]',
# style: 'a[data-download="trigger"]',
# type: 'a[data-download-type="direct"]',
# id: 'a[data-download-id="berkeley-s7038h"]' }
# it_behaves_like 'download link visible', 'Original Shapefile', href, css_downloads

# href = ''
# css_downloads[:location] = 'a[data-download-path="/download/berkeley-s7038h?type=shapefile"]'
# css_downloads[:type] = 'a[data-download-type="shapefile"]'
# it_behaves_like 'download link visible', 'Export Shapefile', href, css_downloads

# css_downloads[:location] = 'a[data-download-path="/download/berkeley-s7038h?type=kmz"]'
# css_downloads[:type] = 'a[data-download-type="kmz"]'
# it_behaves_like 'download link visible', 'Export KMZ', href, css_downloads

# css_downloads[:location] = 'a[data-download-path="/download/berkeley-s7038h?type=geojson"]'
# css_downloads[:type] = 'a[data-download-type="geojson"]'
# it_behaves_like 'download link visible', 'Export GeoJSON', href, css_downloads
# end
#
context 'downloading links available' do
before do
find('#downloads-button').click
end
it 'displays the download button' do
find_link('Original Shapefile').click
# sleep(10)
end
end
end
11 changes: 7 additions & 4 deletions spec/system/restricted_access_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
visit '/catalog/berkeley-s7b12n'
end

def decoded_url(url)
uri = URI.parse(url)
decoded_query = URI.decode_www_form_component(uri.query)
URI.decode_www_form_component("#{uri.path}?#{decoded_query}")
end

it 'display login to view and download link' do
expect(page).to have_link('Login to View and Download')
end

it 'open calnet login page when clicking login to view and download link' do
find('.btn.btn-default').click
raw_url = page.current_url
uri = URI.parse(raw_url)
decoded_query = URI.decode_www_form_component(uri.query)
decoded_path_and_query = URI.decode_www_form_component("#{uri.path}?#{decoded_query}")
decoded_path_and_query = decoded_url(page.current_url)
expect(decoded_path_and_query).to eq(cas_url)
end
end

0 comments on commit 6bad469

Please sign in to comment.