|
1 | 1 | require 'rails_helper'
|
| 2 | +require_relative '../support/shared_examples/link_spec' |
2 | 3 |
|
3 |
| -RSpec.describe 'View Search Reslut' do |
| 4 | +RSpec.describe 'View Search Reslut', type: :system do |
4 | 5 | before do
|
5 | 6 | visit 'catalog/berkeley-s7038h'
|
6 | 7 | end
|
7 | 8 |
|
| 9 | + shared_examples 'download link invisible' do |text| |
| 10 | + it "it has no link #{text}" do |
| 11 | + expect(page).not_to have_link(text: text) |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + shared_examples 'download link visible' do |text, href, css_downloads| |
| 16 | + it "it has link #{text}" do |
| 17 | + expect(page).to have_link(text: text, href: href) |
| 18 | + end |
| 19 | + it 'is has download css attributes' do |
| 20 | + expect(page).to have_css(css_downloads[:location]) |
| 21 | + expect(page).to have_css(css_downloads[:style]) |
| 22 | + expect(page).to have_css(css_downloads[:type]) |
| 23 | + expect(page).to have_css(css_downloads[:id]) |
| 24 | + end |
| 25 | + end |
| 26 | + |
8 | 27 | it 'has the record title' do
|
9 | 28 | within('#document') do
|
10 | 29 | expect(find('h2')).to have_text('Intersections, San Benito County, California, 2016')
|
11 | 30 | end
|
12 | 31 | end
|
13 | 32 |
|
14 |
| - it 'displays the metadata link' do |
15 |
| - expect(page).to have_link('Metadata', href: '/catalog/berkeley-s7038h/metadata') |
16 |
| - end |
| 33 | + context 'has metadata link' do |
| 34 | + it 'displays the metadata link' do |
| 35 | + expect(page).to have_link('Metadata', href: '/catalog/berkeley-s7038h/metadata') |
| 36 | + end |
17 | 37 |
|
18 |
| - context 'when clicking the metadata link' do |
19 |
| - it 'triggers the modal', js: true do |
| 38 | + it 'clicking the metadata link, triggers the modal', js: true do |
20 | 39 | find('#metadataLink').click
|
21 | 40 |
|
22 | 41 | expect(page).to have_css('a.pill-metadata.nav-link.active',
|
|
33 | 52 | end
|
34 | 53 | end
|
35 | 54 |
|
36 |
| - context 'when downloading geodata' do |
| 55 | + context 'downloading button available' do |
37 | 56 | it 'displays the download button' do
|
38 | 57 | expect(page).to have_button('downloads-button')
|
39 | 58 | end
|
40 | 59 |
|
41 |
| - it 'clicking to show downloading options' do |
| 60 | + it_behaves_like 'download link invisible', 'Original Shapefile' |
| 61 | + it_behaves_like 'download link invisible', 'Export Shapefile' |
| 62 | + it_behaves_like 'download link invisible', 'Export KMZ' |
| 63 | + it_behaves_like 'download link invisible', 'Export GeoJSON' |
| 64 | + |
| 65 | + end |
| 66 | + context 'clicking button to display downloading links' do |
| 67 | + before do |
42 | 68 | find('#downloads-button').click
|
43 |
| - expect(page).to have_link(text: 'Original Shapefile', href: 'https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip') |
44 |
| - expect(page).to have_css('a[contenturl="https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip"]') |
45 |
| - expect(page).to have_css('a[data-download="trigger"]') |
46 |
| - expect(page).to have_css('a[data-download-type="direct"]') |
47 |
| - expect(page).to have_css('a[data-download-id="berkeley-s7038h"]') |
48 |
| - |
49 |
| - expect(page).to have_link(text: 'Export Shapefile', href: '') |
50 |
| - # expect(page).to have_link(text: 'Export KMZ') |
51 |
| - # expect(page).to have_link(text: 'Export GeoJSON') |
52 |
| - # |
53 |
| - find('a[data-download-type="direct"]').click |
54 |
| - # expect(File).to exist('/tmp/data.zip') |
55 |
| - expect(find('a[data-download-type="direct"]').text).to eq('Original Shapefile') |
56 | 69 | end
|
| 70 | + |
| 71 | + href = 'https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip' |
| 72 | + css_downloads = { location: 'a[contenturl="https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip"]', |
| 73 | + style: 'a[data-download="trigger"]', |
| 74 | + type: 'a[data-download-type="direct"]', |
| 75 | + id: 'a[data-download-id="berkeley-s7038h"]' } |
| 76 | + it_behaves_like 'download link visible', 'Original Shapefile', href, css_downloads |
| 77 | + |
| 78 | + href = '' |
| 79 | + css_downloads = { location: 'a[data-download-path="/download/berkeley-s7038h?type=shapefile"]', |
| 80 | + style: 'a[data-download="trigger"]', |
| 81 | + type: 'a[data-download-type="shapefile"]', |
| 82 | + id: 'a[data-download-id="berkeley-s7038h"]' } |
| 83 | + it_behaves_like 'download link visible', 'Export Shapefile', href, css_downloads |
| 84 | + |
| 85 | + css_downloads = { location: 'a[data-download-path="/download/berkeley-s7038h?type=kmz"]', |
| 86 | + style: 'a[data-download="trigger"]', |
| 87 | + type: 'a[data-download-type="kmz"]', |
| 88 | + id: 'a[data-download-id="berkeley-s7038h"]' } |
| 89 | + it_behaves_like 'download link visible', 'Export KMZ', href, css_downloads |
| 90 | + |
| 91 | + css_downloads = { location: 'a[data-download-path="/download/berkeley-s7038h?type=geojson"]', |
| 92 | + style: 'a[data-download="trigger"]', |
| 93 | + type: 'a[data-download-type="geojson"]', |
| 94 | + id: 'a[data-download-id="berkeley-s7038h"]' } |
| 95 | + it_behaves_like 'download link visible', 'Export GeoJSON', href, css_downloads |
| 96 | + |
57 | 97 | end
|
| 98 | + # end |
58 | 99 | end
|
| 100 | + |
| 101 | +# RSpec.shared_examples 'download link visible' do |page, text, href, css_downloads| |
| 102 | +# it "it has link #{text}" do |
| 103 | +# expect(page).to have_link(text: text, href: href) |
| 104 | +# end |
| 105 | + |
| 106 | +# it 'is has download css attributes' do |
| 107 | +# expect(page).to have_css(css_downloads[:location]) |
| 108 | +# expect(page).to have_css(css_downloads[:style]) |
| 109 | +# expect(page).to have_css(css_downloads[:type]) |
| 110 | +# expect(page).to have_css(css_downloads[:id]) |
| 111 | + |
| 112 | +# end |
| 113 | +# end |
| 114 | + |
| 115 | +# RSpec.shared_examples 'download link invisible' do |page, text| |
| 116 | +# it "it has no link #{text}" do |
| 117 | +# expect(page).not_to have_link(text: text) |
| 118 | +# end |
| 119 | + |
| 120 | +# end |
| 121 | + |
| 122 | +# <a data-download-path="/download/berkeley-s7038h?type=kmz" data-download="trigger" data-download-type="kmz" data-download-id="berkeley-s7038h" href="">Export KMZ</a> |
| 123 | + |
| 124 | +# it_behaves_like 'download link visible', page, 'Export Shapefile' |
| 125 | +# it_behaves_like 'download link visible', page, 'Export KMZ' |
| 126 | +# it_behaves_like 'download link visible', page, 'Export GeoJSON' |
| 127 | + |
| 128 | +# expect(page).to have_link(text: 'Original Shapefile', href: 'https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip') |
| 129 | +# expect(page).to have_css('a[contenturl="https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip"]') |
| 130 | +# expect(page).to have_css('a[data-download="trigger"]') |
| 131 | +# expect(page).to have_css('a[data-download-type="shapefile"]') |
| 132 | +# expect(page).to have_css('a[data-download-id="berkeley-s7038h"]') |
| 133 | + |
| 134 | +# expect(page).to have_link(text: 'Export Shapefile', href: '') |
| 135 | +# # expect(page).to have_link(text: 'Export KMZ') |
| 136 | +# expect(page).to have_link(text: 'Export GeoJSON') |
| 137 | +# |
| 138 | +# find('a[data-download-type="direct"]').click |
| 139 | +# # expect(File).to exist('/tmp/data.zip') |
| 140 | +# expect(find('a[data-download-type="direct"]').text).to eq('Original Shapefile') |
| 141 | +# end |
| 142 | + |
| 143 | +# <a data-download-path="/download/berkeley-s7038h?type=shapefile" |
| 144 | +# data-download="trigger" data-download-type="shapefile" |
| 145 | +# data-download-id="berkeley-s7038h" |
| 146 | +# href="">Export Shapefile</a> |
| 147 | + |
| 148 | +# it 'clicking button to show downloading options' do |
| 149 | +# find('#downloads-button').click |
| 150 | +# expect(page).to have_link(text: 'Original Shapefile', href: 'https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip') |
| 151 | +# expect(page).to have_css('a[contenturl="https://spatial.lib.berkeley.edu/public/berkeley-s7038h/data.zip"]') |
| 152 | +# expect(page).to have_css('a[data-download="trigger"]') |
| 153 | +# expect(page).to have_css('a[data-download-type="direct"]') |
| 154 | +# expect(page).to have_css('a[data-download-id="berkeley-s7038h"]') |
| 155 | + |
| 156 | +# expect(page).to have_link(text: 'Export Shapefile', href: '') |
| 157 | +# # expect(page).to have_link(text: 'Export KMZ') |
| 158 | +# # expect(page).to have_link(text: 'Export GeoJSON') |
| 159 | +# # |
| 160 | +# find('a[data-download-type="direct"]').click |
| 161 | +# # expect(File).to exist('/tmp/data.zip') |
| 162 | +# expect(find('a[data-download-type="direct"]').text).to eq('Original Shapefile') |
| 163 | +# end |
0 commit comments