diff --git a/spec/system/admin/order_cycles/simple_spec.rb b/spec/system/admin/order_cycles/simple_spec.rb index 29dfba4af8..0d2be4f125 100644 --- a/spec/system/admin/order_cycles/simple_spec.rb +++ b/spec/system/admin/order_cycles/simple_spec.rb @@ -395,17 +395,41 @@ describe ' ex_out.save! # hide via inventory settings variant v1 - supplier_managed.update preferred_product_selection_from_inventory_only: true + distributor_managed.update preferred_product_selection_from_inventory_only: true oc.update prefers_product_selection_from_coordinator_inventory_only: false end - it "shows a warning when going to 'outgoing products' tab" do - visit edit_admin_order_cycle_path(oc) - click_link "Outgoing Products" - within "tr.distributor-#{distributor_managed.id}" do - page.find("td.products").click + shared_examples "inventory warning" do + |inventory_visible, inventory_only, it_description, expect_message| + before do + # hides/displays variant within coordinator's inventory + inventory_item_v1.update!(visible: inventory_visible) + # changes coordinator's inventory preferences + supplier_managed.update preferred_product_selection_from_inventory_only: inventory_only end - expect(page).to have_content "(Some variants might be hidden via inventory settings)" + + it "#{it_description} a warning when going to 'outgoing products' tab" do + visit edit_admin_order_cycle_path(oc) + click_link "Outgoing Products" + within "tr.distributor-#{distributor_managed.id}" do + page.find("td.products").click + end + + # we need this assertion here to assure there is enough time to + # toggle the variant box and evaluate the following assertion + expect(page).to have_content product.name.upcase + + # iterates between true / false, depending on the test case + expectation = expect_message ? :to : :not_to + expect(page).public_send(expectation, + have_content(%(No variant available for this product + (hidden via inventory settings)).squish)) + end + end + + it_behaves_like "inventory warning", false, true, "shows", true + it_behaves_like "inventory warning", false, false, "does not show", false do + before { pending("#11851") } end end