diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 86223c53d0c..c43cd6e7a22 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -1198,13 +1198,9 @@ def expect_other_columns_visible expect(input_content).not_to match /COPY OF Apples/ end - within row_containing_name("Apples") do - page.find(".vertical-ellipsis-menu").click - click_link('Clone') - end + click_product_clone "Apples" expect(page).to have_content "Successfully cloned the product" - within "table.products" do # Gather input values, because page.content doesn't include them. input_content = page.find_all('input[type=text]').map(&:value).join @@ -1213,6 +1209,21 @@ def expect_other_columns_visible expect(input_content).to match /COPY OF Apples/ end end + + it "fails to clone the product on page when clicked on the cloned option" do + # Mock the +save+ method to return fail. That's the only expected fail case + allow_any_instance_of(Spree::Product).to receive(:save).and_return(false) + + click_product_clone "Apples" + + expect(page).to have_content "Unable to clone the product" + within "table.products" do + # Gather input values, because page.content doesn't include them. + input_content = page.find_all('input[type=text]').map(&:value).join + # Products does not include the cloned product. + expect(input_content).not_to match /COPY OF Apples/ + end + end end end @@ -1587,4 +1598,11 @@ def random_tax_category def all_input_values page.find_all('input[type=text]').map(&:value).join end + + def click_product_clone(product_name) + within row_containing_name(product_name) do + page.find(".vertical-ellipsis-menu").click + click_link('Clone') + end + end end