-
-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open external links in product description in a new page #11761
Changes from 1 commit
e78fe66
f52c7e8
249c002
d0c07df
b626ec1
58d2e9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,8 +83,14 @@ | |
|
||
visit shop_path | ||
expect(page).to have_content product.name | ||
|
||
# It truncates a long product description. | ||
within_product_description(product) do | ||
expect(html).to include product.description | ||
expect(page).to have_content "..." | ||
end | ||
expect_product_description_html_to_be_displayed(product, product.description, nil, | ||
truncate: true, href: true) | ||
href: true) | ||
end | ||
|
||
it "does not show unsecure HTML" do | ||
|
@@ -94,8 +100,12 @@ | |
visit shop_path | ||
expect(page).to have_content product.name | ||
|
||
within_product_description(product) 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>", truncate: false | ||
product, "<p>Safe</p>", "<script>alert('Dangerous!');</script>" | ||
) | ||
end | ||
end | ||
|
@@ -144,13 +154,7 @@ | |
end | ||
|
||
def expect_product_description_html_to_be_displayed(product, html, not_include = nil, | ||
truncate: false, href: false) | ||
# check inside list of products | ||
within "#product-#{product.id} .product-description" do | ||
expect(html).not_to include(not_include) if not_include | ||
expect(page).to have_content "..." if truncate # it truncates a long product description | ||
end | ||
|
||
href: false) | ||
# check in product description modal | ||
click_link product.name | ||
modal_should_be_open_for product | ||
|
@@ -160,4 +164,8 @@ def expect_product_description_html_to_be_displayed(product, html, not_include = | |
expect(html).not_to include(not_include) if not_include | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not split this up? There are two distinct chunks of tests here. One is about the product list and the other about the modal. Boolean flags are often a code smell as well. There are some strange things in this method. This line is self-fulfilling: expect(html).to include(html) This line also seems unnecessary: expect(page).to have_selector '.reveal-modal' The next line should test the same thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have removed those redundant assertions. I tried to make the other assertions better but have not found a clear way to do so. I think the intention is to check whether in the rendered HTML the html passed into the method exists but I couldn't come up with a solution that can make the assertion.
says that unsecure html should not be displayed but is calling the same method at the end, I don't know what the actual behaviour should be but what's currently happening is that the unsecure HTML does show up (as text) in the page. |
||
end | ||
|
||
def within_product_description(product, &) | ||
within("#product-#{product.id} .product-description", &) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I brought this line back but it's actually wrong because we want to see only part of the description with
...
at the end. It'll be fixed in a later commit.