Skip to content

Commit e25b608

Browse files
Fixed problem when entering one million items for donation (#5155)
1 parent 6ab47ef commit e25b608

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/javascript/utils/donations.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ $(function() {
108108
)
109109

110110
const large_donation_boundary = 100000;
111-
$(document).on("submit", "form#new_donation", (e, _) =>
111+
$(document).on("click", "form#new_donation button[type='submit']", (e, _) =>
112112
$(".quantity").each(function(_, q) {
113113
const quantity = parseInt(q.value, 10);
114114
if (quantity > large_donation_boundary) {
115-
confirm(
115+
const answer_confirm = confirm(
116116
`${quantity} items is a large donation! Are you sure you want to submit?`
117-
);
117+
)
118+
answer_confirm === false && e.preventDefault();
118119
}
119120
})
120121
);

spec/system/donation_system_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,20 @@
431431
end.to change { Donation.count }.by(1)
432432
end
433433

434+
it "Remains on the page when the user cancels a large donation", js: true do
435+
select Donation::SOURCES[:misc], from: "donation_source"
436+
select StorageLocation.first.name, from: "donation_storage_location_id"
437+
select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id"
438+
fill_in "donation_line_items_attributes_0_quantity", with: "1000000"
439+
440+
dismiss_confirm do
441+
click_button "Save"
442+
end
443+
444+
expect(page).to have_current_path(new_donation_path)
445+
expect(page).to have_button("Save")
446+
end
447+
434448
it "Requires quantity to be numeric" do
435449
select Donation::SOURCES[:misc], from: "donation_source"
436450
select StorageLocation.first.name, from: "donation_storage_location_id"

0 commit comments

Comments
 (0)