From e54fad9bfda60d8bfb51dddf0e76be4ad8e01abd Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 19 May 2020 10:21:06 +0200 Subject: [PATCH 1/2] Add spec for maximum quantities with multiple items in cart This currently fails --- spec/features/consumer/shopping/cart_spec.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index 6a02206e1d..d28764475e 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -159,6 +159,7 @@ feature "full-page cart", js: true do describe "updating quantities" do let(:li) { order.line_items(true).last } let(:variant) { product_with_tax.variants.first } + let(:variant2) { product_with_fee.variants.first } before do add_product_to_cart order, product_with_tax @@ -175,15 +176,26 @@ feature "full-page cart", js: true do end 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 + xit "prevents user from entering invalid values" do + add_product_to_cart order, product_with_fee + variant.update_attributes!(on_hand: 2, on_demand: false) + variant2.update_attributes!(on_hand: 3, on_demand: false) visit main_app.cart_path accept_alert 'Insufficient stock available, only 2 remaining' do - fill_in "order_line_items_attributes_0_quantity", with: '4' + within "tr.variant-#{variant.id}" do + fill_in "order_line_items_attributes_0_quantity", with: '4' + end end expect(page).to have_field "order_line_items_attributes_0_quantity", with: '2' + + accept_alert 'Insufficient stock available, only 3 remaining' do + within "tr.variant-#{variant2.id}" do + fill_in "order_line_items_attributes_1_quantity", with: '4' + end + end + expect(page).to have_field "order_line_items_attributes_1_quantity", with: '3' end it "shows the quantities saved, not those submitted" do From 05e6f5792df24af4cb335a2e0c9de74dc9744fb1 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 19 May 2020 09:25:00 +0200 Subject: [PATCH 2/2] Fix cart fields sharing same scope All cart page quantity fields were displaying a single max quantity instead of a different value for each one. --- app/assets/javascripts/darkswarm/directives/on_hand.js.coffee | 1 + spec/features/consumer/shopping/cart_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee b/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee index 1086363676..8ad5a8748a 100644 --- a/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee @@ -1,6 +1,7 @@ Darkswarm.directive "ofnOnHand", -> restrict: 'A' require: "ngModel" + scope: true link: (scope, elem, attr, ngModel) -> # In cases where this field gets its value from the HTML element rather than the model, diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index d28764475e..95a51ce1ec 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -176,7 +176,7 @@ feature "full-page cart", js: true do end describe "with insufficient stock available" do - xit "prevents user from entering invalid values" do + it "prevents user from entering invalid values" do add_product_to_cart order, product_with_fee variant.update_attributes!(on_hand: 2, on_demand: false)