mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Factorize expects and include testing html inside modal and in description
This commit is contained in:
@@ -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('<p><b>Formatted</b> product description.</p> Link to an <a href="http://google.fr" target="_blank">external site</a>')
|
||||
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("<p>Safe</p>")
|
||||
expect(html).not_to include("<script>alert('Dangerous!');</script>")
|
||||
end
|
||||
expect_product_description_html_to_be_displayed(product, "<p>Safe</p>", "<script>alert('Dangerous!');</script>")
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user