Skip to content

Commit 83508dc

Browse files
authored
Merge pull request #5317 from Benjamin-Couey/3689-check-double-clicks-on-submit
3689 check double clicks on submit
2 parents 46a569b + 86b6a84 commit 83508dc

File tree

9 files changed

+99
-41
lines changed

9 files changed

+99
-41
lines changed

app/helpers/ui_helper.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ def _link_to(link, options = {}, properties = {})
162162
text = options[:text]
163163
size = options[:size]
164164
type = options[:type]
165+
166+
properties[:data] ||= {}
167+
properties[:data][:disable_with] ||= "Please wait..."
168+
165169
if options[:data].present?
166-
properties[:data] ||= {}
167170
properties[:data].merge!(options[:data])
168171
end
169172
properties[:title] = options[:title] if options[:title].present?
@@ -180,7 +183,7 @@ def _link_to(link, options = {}, properties = {})
180183
end
181184
end
182185

183-
def _button_to(options = {}, other_properties = {})
186+
def _button_to(options = {}, properties = {})
184187
submit_type = options[:submit_type] || "submit"
185188
id = options[:id]
186189
type = options[:type]
@@ -189,7 +192,10 @@ def _button_to(options = {}, other_properties = {})
189192
text = options[:text]
190193
align = options[:align]
191194

192-
button_tag({ type: submit_type, id: id, class: "btn btn-#{type} btn-#{size} #{align}" }.merge(other_properties)) do
195+
properties[:data] ||= {}
196+
properties[:data][:disable_with] ||= "Please wait..."
197+
198+
button_tag({ type: submit_type, id: id, class: "btn btn-#{type} btn-#{size} #{align}" }.merge(properties)) do
193199
fa_icon icon, text: text
194200
end
195201
end

app/views/partner_users/_user.html.erb

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

app/views/partner_users/_users.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
</td>
5050
<td class='d-flex flex-column'>
5151
<% unless user.invitation_accepted_at %>
52-
<%= button_to resend_invitation_partner_user_path(partner, user), method: :post, class: "btn btn-warning btn-xs mb-2" do %>
52+
<%= button_to resend_invitation_partner_user_path(partner, user), method: :post, data: { disable_with: "Please wait..." }, class: "btn btn-warning btn-xs mb-2" do %>
5353
<i class="fa fa-envelope"></i> Resend Invitation
5454
<% end %>
5555
<% end %>
56-
<%= button_to reset_password_partner_user_path(partner, user), method: :post, data: { confirm: "Are you sure?" }, class: "btn btn-info btn-xs mb-2" do %>
56+
<%= button_to reset_password_partner_user_path(partner, user), method: :post, data: { confirm: "Are you sure?", disable_with: "Please wait..." }, class: "btn btn-info btn-xs mb-2" do %>
5757
<i class="fa fa-key"></i> Reset Password
5858
<% end %>
59-
<%= button_to partner_user_path(partner, user), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-xs" do %>
59+
<%= button_to partner_user_path(partner, user), method: :delete, data: { confirm: "Are you sure?", disable_with: "Please wait..." }, class: "btn btn-danger btn-xs" do %>
6060
<i class="fa fa-ban"></i> Remove Access
6161
<% end %>
6262

app/views/partners/_partner_row.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<% when "awaiting_review" %>
4040
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Applicant's Profile", icon: "check", type: "warning" } %>
4141
<% when "approved" %>
42-
<%= button_to recertify_partner_partner_path(partner_row), data: { confirm: "Recertify partner #{partner_row.name}?"}, class: "btn btn-xs bg-red" do %>
42+
<%= button_to recertify_partner_partner_path(partner_row), data: { confirm: "Recertify partner #{partner_row.name}?", disable_with: "Please wait..."}, class: "btn btn-xs bg-red" do %>
4343
<i class="fa fa-refresh"></i> Request Recertification
4444
<% end %>
4545
<% when "deactivated" %>

app/views/requests/_request_row.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</td>
2323
<td class="text-right">
2424
<%= view_button_to request_path(request_row) %>
25-
<%= button_to 'Cancel', new_request_cancelation_path(request_id: request_row.id), method: :get, class: 'btn btn-danger btn-xs' %>
25+
<%= button_to 'Cancel', new_request_cancelation_path(request_id: request_row.id), method: :get, data: { disable_with: "Please wait..." }, class: 'btn btn-danger btn-xs' %>
2626
<%= print_button_to print_picklist_request_path(request_row), { format: :pdf, text: "Print", size: "xs" } %>
2727
</td>
2828
</tr>

app/views/requests/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<%= view_button_to(distribution_path(@request.distribution), {text: "View Associated Distribution", size: "md"}) if @request.distribution %>
111111
<%= print_button_to print_picklist_request_path(@request), { format: :pdf, text: "Print", size: "md" } %>
112112
<%= button_to 'Cancel', new_request_cancelation_path(request_id: @request.id),
113-
method: :get, form_class: 'd-inline', class: 'btn btn-danger btn-md' %>
113+
method: :get, data: { disable_with: "Please wait..." }, form_class: 'd-inline', class: 'btn btn-danger btn-md' %>
114114
</div>
115115
</div>
116116
</div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Simulates the user double clicking on an element specified by a css_selector
2+
# by using the API provided by Ferrum to manipulate the browser directly.
3+
#
4+
# @param css_selector [String] The CSS selector for the element to be double clicked.
5+
#
6+
# @example Usage
7+
# # Make sure the element is there
8+
# expect(page.find('a.btn.btn-success.btn-md[href*="/picked_up"]')).to have_content("Distribution Complete")
9+
#
10+
# # Double click it
11+
# ferrum_double_click('a.btn.btn-success.btn-md[href*="/picked_up"]')
12+
#
13+
# # Assert something based on the double click.
14+
def ferrum_double_click(css_selector)
15+
node = Capybara.page.driver.browser.at_css(css_selector)
16+
x, y = node.find_position
17+
mouse = node.page.mouse
18+
mouse.move(x:, y:)
19+
mouse.down
20+
mouse.up
21+
sleep(0.05)
22+
mouse.down
23+
mouse.up
24+
end

spec/system/distribution_system_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,4 +887,41 @@
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

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)