From 5e39b11c2f2d81274f3f6fff956d3e84dfae0fc3 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 8 Apr 2016 11:44:28 +1000 Subject: [PATCH] Spec out of stock handling for group buy --- .../shop_variant_with_group_buy.html.haml | 3 +- .../consumer/shopping/shopping_spec.rb | 37 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/templates/partials/shop_variant_with_group_buy.html.haml b/app/assets/javascripts/templates/partials/shop_variant_with_group_buy.html.haml index 51f7599af7..c44a71948b 100644 --- a/app/assets/javascripts/templates/partials/shop_variant_with_group_buy.html.haml +++ b/app/assets/javascripts/templates/partials/shop_variant_with_group_buy.html.haml @@ -19,4 +19,5 @@ placeholder: "{{'shop_variant_quantity_max' | t}}", "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", - name: "variant_attributes[{{variant.id}}][max_quantity]"} + name: "variant_attributes[{{variant.id}}][max_quantity]", + id: "variants_{{variant.id}}_max"} diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index ab94c678d7..c252a3f041 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -239,11 +239,9 @@ feature "As a consumer I want to shop with a distributor", js: true do end describe "when a product goes out of stock just before it's added to the cart" do - before do - variant.update_attributes! on_hand: 0 - end - it "stops the attempt, shows an error message and refreshes the products asynchronously" do + variant.update_attributes! on_hand: 0 + # -- Messaging alert_message = accept_alert do fill_in "variants[#{variant.id}]", with: '1' @@ -266,7 +264,36 @@ feature "As a consumer I want to shop with a distributor", js: true do page.should have_selector "#variants_#{variant.id}[disabled='disabled']" end - it "does the same for group buy products" + context "group buy products" do + let(:product) { create(:simple_product, group_buy: true) } + + it "does the same" do + # -- Place in cart so we can set max_quantity, then make out of stock + fill_in "variants[#{variant.id}]", with: '1' + wait_until { !cart_dirty } + variant.update_attributes! on_hand: 0 + + # -- Messaging + alert_message = accept_alert do + fill_in "variant_attributes[#{variant.id}][max_quantity]", with: '1' + wait_until { !cart_dirty } + end + + # TODO: This will be a modal + expect(alert_message).to be + puts alert_message + + # -- Page updates + # Update amount in cart + page.should have_field "variant_attributes[#{variant.id}][max_quantity]", with: '0', disabled: true + + # Update amount available in product list + # If amount falls to zero, variant should be greyed out and input disabled + page.should have_selector "#variant-#{variant.id}.out-of-stock" + page.should have_selector "#variants_#{variant.id}_max[max='0']" + page.should have_selector "#variants_#{variant.id}_max[disabled='disabled']" + end + end end end