mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix editing cart when variant on_demand but on_hand is zero or negative
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
%td.text-right.cart-item-price{"data-hook" => "cart_item_price"}
|
||||
= line_item.single_display_amount_with_adjustments.to_html
|
||||
%td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"}
|
||||
= item_form.number_field :quantity, :min => 0, "ofn-on-hand" => variant.on_hand, "ng-model" => "line_item_#{line_item.id}", :class => "line_item_quantity", :size => 5
|
||||
= item_form.number_field :quantity, :min => 0, "ofn-on-hand" => "#{variant.on_demand && 9999 || variant.on_hand}", "ng-model" => "line_item_#{line_item.id}", :class => "line_item_quantity", :size => 5
|
||||
%td.cart-item-total.text-right{"data-hook" => "cart_item_total"}
|
||||
= line_item.display_amount_with_adjustments.to_html unless line_item.quantity.nil?
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ feature "full-page cart", js: true do
|
||||
end
|
||||
end
|
||||
|
||||
describe "updating quantities with insufficient stock available" do
|
||||
describe "updating quantities" do
|
||||
let(:li) { order.line_items(true).last }
|
||||
let(:variant) { product_with_tax.variants.first }
|
||||
|
||||
@@ -134,31 +134,43 @@ feature "full-page cart", js: true do
|
||||
add_product_to_cart order, product_with_tax
|
||||
end
|
||||
|
||||
it "prevents me from entering an invalid value" do
|
||||
# Given we have 2 on hand, and we've loaded the page after that fact
|
||||
variant.update_attributes!(on_hand: 2, on_demand: false)
|
||||
visit main_app.cart_path
|
||||
describe "when on_hand is zero but variant is on demand" do
|
||||
it "allows updating the quantity" do
|
||||
variant.update_attributes!(on_hand: 0, on_demand: true)
|
||||
visit main_app.cart_path
|
||||
|
||||
accept_alert 'Insufficient stock available, only 2 remaining' do
|
||||
fill_in "order_line_items_attributes_0_quantity", with: '4'
|
||||
fill_in "order_line_items_attributes_0_quantity", with: '5'
|
||||
expect(page).to have_field "order_line_items_attributes_0_quantity", with: '5'
|
||||
end
|
||||
expect(page).to have_field "order_line_items_attributes_0_quantity", with: '2'
|
||||
end
|
||||
|
||||
it "shows the quantities saved, not those submitted" do
|
||||
# Given we load the page with 3 on hand, then the number available drops to 2
|
||||
variant.update_attributes! on_demand: false
|
||||
variant.update_attributes! on_hand: 3
|
||||
visit main_app.cart_path
|
||||
variant.update_attributes! on_hand: 2
|
||||
describe "with insufficient stock available" do
|
||||
it "prevents user from entering an invalid value" do
|
||||
# Given we have 2 on hand, and we've loaded the page after that fact
|
||||
variant.update_attributes!(on_hand: 2, on_demand: false)
|
||||
visit main_app.cart_path
|
||||
|
||||
accept_alert do
|
||||
fill_in "order_line_items_attributes_0_quantity", with: '4'
|
||||
accept_alert 'Insufficient stock available, only 2 remaining' do
|
||||
fill_in "order_line_items_attributes_0_quantity", with: '4'
|
||||
end
|
||||
expect(page).to have_field "order_line_items_attributes_0_quantity", with: '2'
|
||||
end
|
||||
click_button 'Update'
|
||||
|
||||
expect(page).to have_content "Insufficient stock available, only 2 remaining"
|
||||
expect(page).to have_field "order_line_items_attributes_0_quantity", with: '1'
|
||||
it "shows the quantities saved, not those submitted" do
|
||||
# Given we load the page with 3 on hand, then the number available drops to 2
|
||||
variant.update_attributes! on_demand: false
|
||||
variant.update_attributes! on_hand: 3
|
||||
visit main_app.cart_path
|
||||
variant.update_attributes! on_hand: 2
|
||||
|
||||
accept_alert do
|
||||
fill_in "order_line_items_attributes_0_quantity", with: '4'
|
||||
end
|
||||
click_button 'Update'
|
||||
|
||||
expect(page).to have_content "Insufficient stock available, only 2 remaining"
|
||||
expect(page).to have_field "order_line_items_attributes_0_quantity", with: '1'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user