From 8f519eaf216851e5239522fd92f549a2dcf4aec1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 26 Jan 2023 18:12:25 +0100 Subject: [PATCH] Factorize expects and include testing html inside modal and in description --- .../system/consumer/shopping/products_spec.rb | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/spec/system/consumer/shopping/products_spec.rb b/spec/system/consumer/shopping/products_spec.rb index 7ee9e3c799..21ff3e8dd8 100644 --- a/spec/system/consumer/shopping/products_spec.rb +++ b/spec/system/consumer/shopping/products_spec.rb @@ -47,16 +47,8 @@ describe "As a consumer I want to view products", js: true do visit shop_path expect(page).to have_content product.name - click_link product.name - - expect(page).to have_selector '.reveal-modal' - modal_should_be_open_for product - - within(".reveal-modal") do - expect(html).to include('

Formatted product description.

Link to an external site') - end - + expect_product_description_html_to_be_displayed(product, product.description) end it "does not show unsecure HTML" do @@ -65,15 +57,8 @@ describe "As a consumer I want to view products", js: true do visit shop_path expect(page).to have_content product.name - click_link product.name - expect(page).to have_selector '.reveal-modal' - modal_should_be_open_for product - - within(".reveal-modal") do - expect(html).to include("

Safe

") - expect(html).not_to include("") - end + expect_product_description_html_to_be_displayed(product, "

Safe

", "") end end @@ -119,4 +104,21 @@ describe "As a consumer I want to view products", js: true do end end end + + def expect_product_description_html_to_be_displayed(product, html, not_include = nil) + # check inside list of products + within "#product-#{product.id} .product-description" do + expect(html).to include(html) + expect(html).not_to include(not_include) if not_include + end + + # check in product description modal + click_link product.name + expect(page).to have_selector '.reveal-modal' + modal_should_be_open_for product + within(".reveal-modal") do + expect(html).to include(html) + expect(html).not_to include(not_include) if not_include + end + end end