Skip to content

Commit 8fd5bf1

Browse files
committed
add rspec system tests
1 parent 5742eda commit 8fd5bf1

File tree

7 files changed

+155
-83
lines changed

7 files changed

+155
-83
lines changed

spec/features/click_login_link_spec.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

spec/rails_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#
9292
# The different available types are documented in the features, such as in
9393
# https://relishapp.com/rspec/rspec-rails/docs
94-
config.infer_spec_type_from_file_location!
94+
# config.infer_spec_type_from_file_location!
9595

9696
# Filter lines from Rails gems in backtraces.
9797
config.filter_rails_from_backtrace!
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
RSpec.shared_examples 'download link visible' do |text, href, css_downloads|
2+
it "it has link #{text}" do
3+
expect(page).to have_link(text: text, href: href)
4+
end
5+
6+
it 'is has download css attributes' do
7+
expect(page).to have_css(css_downloads[:location])
8+
expect(page).to have_css(css_downloads[:style])
9+
expect(page).to have_css(css_downloads[:type])
10+
expect(page).to have_css(css_downloads[:id])
11+
12+
end
13+
end
14+
15+
RSpec.shared_examples 'download link invisible' do |text|
16+
it "it has no link #{text}" do
17+
expect(page).not_to have_link(text: text)
18+
end
19+
20+
end

spec/system/application_system_spec.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,32 @@
11
require 'rails_helper'
22

3-
RSpec.describe 'View Institution Catalog' do
3+
RSpec.describe 'View Institution Catalog', type: :system do
44
before do
55
visit '/'
6-
# click_link('University of California Berkeley')
76
end
87

98
it 'view home page title' do
109
expect(page).to have_title('UC Berkeley GeoData Repository')
1110
end
1211

13-
it 'display UC Berkeley link' do
12+
it 'display UC Berkeley collection link' do
1413
expect(page).to have_link('University of California Berkeley')
1514
end
1615

17-
context 'click UC Berkeley link to show result page' do
16+
context 'click UC Berkeley collection link to display UC Berkley collection page' do
1817
before do
1918
click_link('University of California Berkeley')
2019
end
2120

2221
it 'display record number' do
23-
a = find('.page-entries').text.split[-1].to_i
24-
expect(a).to be > 3
25-
# expect(find('.page-entries')).to have_content('1 - 4 of 4')
22+
expect(find('.page-entries'))
23+
24+
total_record_num = find('.page-entries').text.split[-1].strip.to_i
25+
expect(total_record_num).to be > 3
2626
end
2727

2828
it 'display active provider - UC Berkeley' do
2929
expect(find('.card.facet-limit.blacklight-schema_provider_s.facet-limit-active')).to have_content('University of California Berkeley')
3030
end
31-
# expect(page.find_link(href: '/')).first.to be_visible
32-
# print page.html
33-
# expect(page.find('svg', title: 'University Of California Berkeley')).to be_visible
34-
# expect(page).to have_css('blacklight-catalog.blacklight-catalog-index')
35-
36-
# expect(page).to have_title('UC Berkeley GeoData Repository')
37-
# Capybara.using_wait_time(10) do
38-
# expect(page).to have_css('card.facet-limit.blacklight-schema_provider_s.facet-limit-active')
39-
# end
40-
# within('.card.facet-limit.blacklight-schema_provider_s.facet-limit-active') do
41-
# expect(page).to have_css('svg title', text: 'BBB')
42-
# expect(page).to have_css('svg[aria-label="University Of California Berkeley"] title', text: 'BBB')
43-
44-
# end
4531
end
4632
end

spec/system/public_record_spec.rb

Lines changed: 126 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
require 'rails_helper'
2+
require_relative '../support/shared_examples/link_spec'
23

3-
RSpec.describe 'View Search Reslut' do
4+
RSpec.describe 'View Search Reslut', type: :system do
45
before do
56
visit 'catalog/berkeley-s7038h'
67
end
78

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+
827
it 'has the record title' do
928
within('#document') do
1029
expect(find('h2')).to have_text('Intersections, San Benito County, California, 2016')
1130
end
1231
end
1332

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
1737

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
2039
find('#metadataLink').click
2140

2241
expect(page).to have_css('a.pill-metadata.nav-link.active',
@@ -33,26 +52,112 @@
3352
end
3453
end
3554

36-
context 'when downloading geodata' do
55+
context 'downloading button available' do
3756
it 'displays the download button' do
3857
expect(page).to have_button('downloads-button')
3958
end
4059

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
4268
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')
5669
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+
5797
end
98+
# end
5899
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

spec/system/restrict_record_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22

33
# RSpec.describe 'View Restricted Data', type: :system do
4-
RSpec.describe 'View Restricted Data' do
4+
RSpec.describe 'View Restricted Data', type: :system do
55
let(:app_hostname) { IPSocket.getaddress(Socket.gethostname) }
66
let(:cas_url) { "/cas/login?service=http://#{app_hostname}:3000/users/auth/calnet/callback?url=http://#{app_hostname}:3000/catalog/berkeley-s7b12n" }
77
before do

0 commit comments

Comments
 (0)