mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Add some debounce and an onwheel hack to product add to basket field
Debounce ensures we don't get a million requests if the up/down buttons are clicked rapidly. The onwheel hack adds some protection against scrolling triggering the quantity up/down. See: https://stackoverflow.com/a/51076231
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
min: 0,
|
||||
placeholder: "0",
|
||||
"ofn-disable-scroll" => true,
|
||||
"ng-debounce" => "500",
|
||||
onwheel: "this.blur()",
|
||||
"ng-model" => "variant.line_item.quantity",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.on_hand }}",
|
||||
"ng-disabled" => "!variant.on_demand && variant.on_hand == 0",
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
"ng-model" => "variant.line_item.quantity",
|
||||
placeholder: "{{::'shop_variant_quantity_min' | t}}",
|
||||
"ofn-disable-scroll" => true,
|
||||
"ng-debounce" => "500",
|
||||
onwheel: "this.blur()",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.on_hand }}",
|
||||
name: "variants[{{::variant.id}}]", id: "variants_{{::variant.id}}"}
|
||||
%span.bulk-input
|
||||
@@ -19,6 +21,8 @@
|
||||
"ng-model" => "variant.line_item.max_quantity",
|
||||
placeholder: "{{::'shop_variant_quantity_max' | t}}",
|
||||
"ofn-disable-scroll" => true,
|
||||
"ng-debounce" => "500",
|
||||
onwheel: "this.blur()",
|
||||
min: "{{variant.line_item.quantity}}",
|
||||
name: "variant_attributes[{{::variant.id}}][max_quantity]",
|
||||
id: "variants_{{::variant.id}}_max"}
|
||||
|
||||
@@ -246,24 +246,25 @@ feature "As a consumer I want to shop with a distributor", js: true do
|
||||
before do
|
||||
add_variant_to_order_cycle(exchange, variant)
|
||||
set_order_cycle(order, oc1)
|
||||
set_order(order)
|
||||
visit shop_path
|
||||
end
|
||||
|
||||
it "should save group buy data to the cart and display it on shopfront reload" do
|
||||
# -- Quantity
|
||||
fill_in "variants[#{variant.id}]", with: 6
|
||||
wait_for_debounce
|
||||
expect(page).to have_in_cart product.name
|
||||
wait_until { !cart_dirty }
|
||||
|
||||
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
|
||||
expect(li.quantity).to eq(6)
|
||||
expect(order.reload.line_items.first.quantity).to eq(6)
|
||||
|
||||
# -- Max quantity
|
||||
fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7
|
||||
wait_for_debounce
|
||||
wait_until { !cart_dirty }
|
||||
|
||||
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
|
||||
expect(li.max_quantity).to eq(7)
|
||||
expect(order.reload.line_items.first.max_quantity).to eq(7)
|
||||
|
||||
# -- Reload
|
||||
visit shop_path
|
||||
@@ -536,4 +537,10 @@ feature "As a consumer I want to shop with a distributor", js: true do
|
||||
expect(page).to have_no_content "This shop is for customers only."
|
||||
expect(page).to have_content product.name
|
||||
end
|
||||
|
||||
def wait_for_debounce
|
||||
# The auto-submit on these specific form elements (add to cart) now has a small built-in
|
||||
# waiting period before submitting the data...
|
||||
sleep 0.6
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user