From 0a28abbf2d66f5fdcc71f71ec72b3a917d0e0e99 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 4 May 2020 19:59:48 +0200 Subject: [PATCH] Add additional feature specs for soft-deleted variants in cart --- .../consumer/shopping/shopping_spec.rb | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 432f750f17..429f4ba3d3 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -429,6 +429,34 @@ feature "As a consumer I want to shop with a distributor", js: true do end end end + + context "when a variant is soft-deleted" do + describe "adding the soft-deleted variant to the cart" do + it "handles it as if the variant has gone out of stock" do + variant.delete + + fill_in "variants[#{variant.id}]", with: '1' + + expect_out_of_stock_behavior + end + end + + context "when the soft-deleted variant has an associated override" do + describe "adding the soft-deleted variant to the cart" do + let!(:variant_override) { + create(:variant_override, variant: variant, hub: distributor, count_on_hand: 100) + } + + it "handles it as if the variant has gone out of stock" do + variant.delete + + fill_in "variants[#{variant.id}]", with: '1' + + expect_out_of_stock_behavior + end + end + end + end end context "when no order cycles are available" do @@ -543,4 +571,24 @@ feature "As a consumer I want to shop with a distributor", js: true do # waiting period before submitting the data... sleep 0.6 end + + def expect_out_of_stock_behavior + wait_for_debounce + wait_until { !cart_dirty } + + # Shows an "out of stock" modal, with helpful user feedback + within(".out-of-stock-modal") do + expect(page).to have_content I18n.t('js.out_of_stock.out_of_stock_text') + end + + # Removes the item from the client-side cart and marks the variant as unavailable + expect(page).to have_field "variants[#{variant.id}]", with: '0', disabled: true + expect(page).to have_selector "#variant-#{variant.id}.out-of-stock" + expect(page).to have_selector "#variants_#{variant.id}[ofn-on-hand='0']" + expect(page).to have_selector "#variants_#{variant.id}[disabled='disabled']" + + # We need to wait again for the cart to finish updating in Angular or the test can fail + # as the session cannot be reset properly (after the test) while it's still loading + wait_until { !cart_dirty } + end end