Skip to content

Commit 1d25a82

Browse files
Updated tests to look for buttons inside of forms instead of anchor elements
1 parent 6801a95 commit 1d25a82

18 files changed

+48
-45
lines changed

spec/requests/admin/ndbn_members_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
html = Nokogiri::HTML(response.body)
2121

2222
expect(html.css("h1").text).to eq("NDBN Member Upload")
23-
expect(html.css("input[type=file]").count).to eq(1)
24-
expect(html.css("button[type=submit]").count).to eq(1)
23+
24+
expect(html.css("form[action='/admin/ndbn_members/upload_csv']").count).to eq(1)
25+
expect(html.css("form[action='/admin/ndbn_members/upload_csv'] input[type=file]").count).to eq(1)
26+
expect(html.css("form[action='/admin/ndbn_members/upload_csv'] button[type=submit]").count).to eq(1)
2527

2628
expect(html.css("th").map(&:text)).to match_array(["NDBN Member Number", "Member Name"])
2729
expect(html.css("tbody tr td").map(&:text)).to match_array(["123", "A Baby Center"])

spec/requests/distributions_requests_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
get distributions_path
8888
page = Nokogiri::HTML(response.body)
8989
edit = page.at_css("a[href='#{edit_distribution_path(id: distribution.id)}']")
90-
reclaim = page.at_css("a.btn-danger[href='#{distribution_path(id: distribution.id)}']")
90+
reclaim = page.at_css("form[action='#{distribution_path(id: distribution.id)}'] .btn-danger")
9191
expect(edit.attr("class")).not_to match(/disabled/)
9292
expect(reclaim.attr("class")).not_to match(/disabled/)
9393
expect(response.body).not_to match(/Has Inactive Items/)
@@ -102,7 +102,7 @@
102102
get distributions_path
103103
page = Nokogiri::HTML(response.body)
104104
edit = page.at_css("a[href='#{edit_distribution_path(id: distribution.id)}']")
105-
reclaim = page.at_css("a.btn-danger[href='#{distribution_path(id: distribution.id)}']")
105+
reclaim = page.at_css("form[action='#{distribution_path(id: distribution.id)}'] .btn-danger")
106106
expect(edit.attr("class")).to match(/disabled/)
107107
expect(reclaim.attr("class")).to match(/disabled/)
108108
expect(response.body).to match(/Has Inactive Items/)

spec/requests/donation_sites_requests_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
page = Nokogiri::HTML(response.body)
2525
expect(response.body).to include("An Active Site")
2626
expect(response.body).not_to include("An Inactive Site")
27-
button1 = page.css(".btn[href='/donation_sites/#{active_donation_site.id}/deactivate']")
27+
button1 = page.css("form[action='/donation_sites/#{active_donation_site.id}/deactivate'] .btn")
2828
expect(button1.text.strip).to eq("Deactivate")
2929
expect(button1.attr('class')).not_to match(/disabled/)
3030
end
@@ -39,12 +39,12 @@
3939
expect(response.body).to include("An Inactive Site")
4040

4141
# Active donation site should have deactivate button
42-
button1 = page.css(".btn[href='/donation_sites/#{active_donation_site.id}/deactivate']")
42+
button1 = page.css("form[action='/donation_sites/#{active_donation_site.id}/deactivate'] .btn")
4343
expect(button1.text.strip).to eq("Deactivate")
4444
expect(button1.attr('class')).not_to match(/disabled/)
4545

4646
# Inactive donation site should have reactivate button
47-
button2 = page.css(".btn[href='/donation_sites/#{inactive_donation_site.id}/reactivate']")
47+
button2 = page.css("form[action='/donation_sites/#{inactive_donation_site.id}/reactivate'] .btn")
4848
expect(button2.text.strip).to eq("Restore")
4949
expect(button2.attr('class')).not_to match(/disabled/)
5050
end

spec/requests/donations_requests_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
get donation_path(donation.id)
252252
page = Nokogiri::HTML(response.body)
253253
edit = page.at_css("a[href='#{edit_donation_path(donation.id)}']")
254-
delete = page.at_css("a.btn-danger[href='#{donation_path(donation.id)}']")
254+
delete = page.at_css("form[action='#{donation_path(donation.id)}'] .btn-danger")
255255
expect(edit.attr("class")).to match(/disabled/)
256256
expect(delete.attr("class")).to match(/disabled/)
257257
expect(response.body).to match(/please make the following items active: #{item.name}/)

spec/requests/items_requests_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@
243243
expect(response.body).to include("NODEACTIVATE")
244244
expect(response.body).to include("NODELETE")
245245
expect(response.body).not_to include("NOSIR")
246-
button1 = page.css(".btn.btn-danger[href='/items/#{item.id}']")
246+
button1 = page.css("form[action='/items/#{item.id}'] .btn.btn-danger")
247247
expect(button1.text.strip).to eq("Delete")
248-
button2 = page.css(".btn[href='/items/#{non_delete_item.id}/deactivate']")
248+
button2 = page.css("form[action='/items/#{non_delete_item.id}/deactivate'] .btn")
249249
expect(button2.text.strip).to eq("Deactivate")
250250
expect(button2.attr('class')).not_to match(/disabled/)
251-
button3 = page.css(".btn[href='/items/#{non_deactivate_item.id}/deactivate']")
251+
button3 = page.css("form[action='/items/#{non_deactivate_item.id}/deactivate'] .btn")
252252
expect(button3.text.strip).to eq("Deactivate")
253253
expect(button3.attr('class')).to match(/disabled/)
254254
end

spec/requests/purchases_requests_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
get purchase_path(purchase.id)
376376
page = Nokogiri::HTML(response.body)
377377
edit = page.at_css("a[href='#{edit_purchase_path(purchase.id)}']")
378-
delete = page.at_css("a.btn-danger[href='#{purchase_path(purchase.id)}']")
378+
delete = page.at_css("form[action='#{purchase_path(purchase.id)}'] .btn-danger")
379379
expect(edit.attr("class")).to match(/disabled/)
380380
expect(delete.attr("class")).to match(/disabled/)
381381
expect(response.body).to match(/please make the following items active: #{item.name}/)

spec/requests/storage_locations_requests_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
it "shows a deactivate button" do
7272
get storage_locations_path(format: response_format)
7373
page = Nokogiri::HTML(response.body)
74-
deactivate_link = page.at_css("a[href='#{storage_location_deactivate_path(storage_location)}']")
74+
deactivate_link = page.at_css("form[action='#{storage_location_deactivate_path(storage_location)}'] button")
7575
expect(deactivate_link.attr("class")).not_to match(/disabled/)
7676
end
7777
end
@@ -85,7 +85,7 @@
8585
it "shows a disabled deactivate button" do
8686
get storage_locations_path(format: response_format)
8787
page = Nokogiri::HTML(response.body)
88-
deactivate_link = page.at_css("a[href='#{storage_location_deactivate_path(storage_location)}']")
88+
deactivate_link = page.at_css("form[action='#{storage_location_deactivate_path(storage_location)}'] button")
8989
expect(deactivate_link.attr("class")).to match(/disabled/)
9090
end
9191
end

spec/system/audit_system_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
expect(page).to have_content(audit_quantity)
8888

8989
accept_confirm do
90-
click_link "Finalize Audit"
90+
click_button "Finalize Audit"
9191
end
9292
expect(page.find(".alert-info")).to have_content "Audit is Finalized"
9393

@@ -209,7 +209,7 @@
209209
expect(page).to have_content("Delete Audit")
210210
expect do
211211
accept_confirm do
212-
click_link "Delete Audit"
212+
click_button "Delete Audit"
213213
end
214214
expect(page).to have_content("Audit is successfully deleted.")
215215
end.to change { Audit.count }.by(-1)
@@ -257,7 +257,7 @@
257257
expect(page).to have_content("Delete Audit")
258258
expect do
259259
accept_confirm do
260-
click_link "Delete Audit"
260+
click_button "Delete Audit"
261261
end
262262
expect(page).to have_content("Audit is successfully deleted.")
263263
end.to change { Audit.count }.by(-1)
@@ -269,7 +269,7 @@
269269
expect(page).to have_content("Finalize Audit")
270270
expect do
271271
accept_confirm do
272-
click_link "Finalize Audit"
272+
click_button "Finalize Audit"
273273
end
274274
expect(page).to have_content("Audit is Finalized.")
275275
end.to change { Audit.finalized.count }.by(1)
@@ -284,7 +284,7 @@
284284
expect(page).to have_content("Finalize Audit")
285285
expect do
286286
accept_confirm do
287-
click_link "Finalize Audit"
287+
click_button "Finalize Audit"
288288
end
289289
expect(page).to have_content("Audit is Finalized.")
290290
end.to change { storage_location.size }.by(quantity - item_quantity)
@@ -295,7 +295,7 @@
295295
visit subject
296296
expect(page).to have_content("Finalize Audit")
297297
accept_confirm do
298-
click_link "Finalize Audit"
298+
click_button "Finalize Audit"
299299
end
300300
expect(page).not_to have_content("Resume Audit")
301301
expect(page).not_to have_content("Delete Audit")
@@ -309,7 +309,7 @@
309309
visit subject
310310
expect(page).to have_content("Finalize Audit")
311311
accept_confirm do
312-
click_link "Finalize Audit"
312+
click_button "Finalize Audit"
313313
end
314314
expect(page).not_to have_content("Delete Audit")
315315
# Actual Deletion(`delete :destroy`) Check is done in audits_controller_spec
@@ -332,7 +332,7 @@
332332
visit subject
333333
expect do
334334
accept_confirm do
335-
click_link "Finalize Audit"
335+
click_button "Finalize Audit"
336336
end
337337
expect(page).to have_content("Audit is Finalized.")
338338
end.to change { storage_location.size }.by(quantity - item_quantity)

spec/system/authorization_system_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
visit new_distribution_path
4747
select "Test Partner", from: "Partner"
4848
select "Test Storage Location", from: "From storage location"
49-
first('input[name="authenticity_token"]', visible: false).set("NOTAVALIDCSRFTOKEN")
49+
first('form[action="/distributions"] input[name="authenticity_token"]', visible: false).set("NOTAVALIDCSRFTOKEN")
5050
page.execute_script("$(\"meta[name='csrf-token']\").attr('content', 'NOTAVALIDCSRFTOKEN');")
5151
click_button "Save"
5252
expect(current_path).to eql new_distribution_path

spec/system/barcode_item_system_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
visit subject
7878
expect(page).to have_content("barcode_to_delete")
79-
click_link "Delete"
79+
click_button "Delete"
8080
expect(page).to have_content("Barcode deleted!")
8181
expect(page).not_to have_content("barcode_to_delete")
8282
end
@@ -87,7 +87,7 @@
8787

8888
visit subject
8989
expect(page).to have_content(b_item.value)
90-
ferrum_double_click('a.btn.btn-danger.btn-xs[href*="/barcode_items/"]')
90+
ferrum_double_click('form[action*="/barcode_items/"] .btn.btn-danger.btn-xs')
9191
expect(page).to have_content("Barcode deleted!")
9292
expect(page).not_to have_content("barcode_to_delete")
9393
expect(page).not_to have_content("Sorry, you don't have permission to delete this barcode.")

0 commit comments

Comments
 (0)