Skip to content

Commit 8467700

Browse files
Added tests to verify that double clicking on buttons does not cause repeated requests
1 parent 5c2612a commit 8467700

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

spec/system/distribution_system_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,4 +887,43 @@
887887

888888
expect(page).to have_content("This distribution has been marked as being completed!")
889889
end
890+
891+
it "Double clicking distribution complete does not result in the distribution attemping to be completed twice" do
892+
visit new_distribution_path
893+
item = View::Inventory.new(organization.id).items_for_location(storage_location.id).first.db_item
894+
TestInventory.create_inventory(organization,
895+
{
896+
storage_location.id => { item.id => 20 }
897+
})
898+
899+
select "Test Partner", from: "Partner"
900+
select "Test Storage Location", from: "From storage location"
901+
choose "Delivery"
902+
select item.name, from: "distribution_line_items_attributes_0_item_id"
903+
fill_in "distribution_line_items_attributes_0_quantity", with: 15
904+
905+
click_button "Save"
906+
907+
within "#distributionConfirmationModal" do
908+
click_button "Yes, it's correct"
909+
end
910+
911+
# Make sure the button is there before trying to double click it
912+
expect(page.find('a.btn.btn-success.btn-md[href*="/picked_up"]')).to have_content("Distribution Complete")
913+
914+
# Double click on the Distribution complete button
915+
ferrum_double_click('a.btn.btn-success.btn-md[href*="/picked_up"]')
916+
917+
# Capybara will be quick to determine that a screen doesn't have content.
918+
# Make some positive assertions that only appears on the new screen to make
919+
# sure it's loaded before asserting something isn't there.
920+
expect(page).not_to have_content("Distribution Complete")
921+
expect(page).to have_content("Complete")
922+
923+
# If it tries to mark the distribution as completed twice, the second time
924+
# will fail (the distribution is already complete) and show this error
925+
expect(page).not_to have_content("Sorry, we encountered an error when trying to mark this distribution as being completed")
926+
end
890927
end
928+
929+

spec/system/partner_system_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@
3030

3131
expect(partner_awaiting_approval.reload.approved?).to eq(true)
3232
end
33+
34+
it 'Double clicking approval button does not result in the partner attemping to be approved twice' do
35+
visit partners_path
36+
37+
assert page.has_content? partner_awaiting_approval.name
38+
click_on "Review Applicant's Profile"
39+
40+
# Make sure the button is there before trying to double click it
41+
expect(page.find('a.btn.btn-success.btn-md[href*="/approve_application"]')).to have_content("Approve Partner")
42+
43+
# Double click on the Distribution complete button
44+
ferrum_double_click('a.btn.btn-success.btn-md[href*="/approve_application"]')
45+
46+
# Capybara will be quick to determine that a screen doesn't have content.
47+
# Make some positive assertions that only appears on the new screen to make
48+
# sure it's loaded before asserting something isn't there.
49+
expect(page).to have_content("Partner Agencies for")
50+
51+
# If it tries to mark the partner as approved twice, the second time
52+
# will fail (the partner is already approved) and show this error
53+
expect(page).not_to have_content('Failed to approve partner because: ["partner is not waiting for approval"]')
54+
# TODO: Verify multiple emails aren't sent?
55+
end
3356
end
3457

3558
context 'when the approval does not succeed' do

0 commit comments

Comments
 (0)