diff --git a/app/assets/javascripts/templates/product_modal.html.haml b/app/assets/javascripts/templates/product_modal.html.haml index ec9cb00625e5..374f1bda4ed5 100644 --- a/app/assets/javascripts/templates/product_modal.html.haml +++ b/app/assets/javascripts/templates/product_modal.html.haml @@ -11,7 +11,7 @@ %filter-selector{ 'selector-set' => "productPropertySelectors", objects: "[product] | propertiesWithValuesOf" } .product-description{"ng-if" => "product.description_html"} - %p.text-small{"ng-bind-html" => "::product.description_html", "data-controller" => "richtext"} + %p.text-small{"ng-bind-html" => "::product.description_html", "data-controller" => "add-blank-to-link"} .columns.small-12.medium-6.large-6.product-img %img{"ng-src" => "{{::product.largeImage}}", "ng-if" => "::product.largeImage"} diff --git a/app/webpacker/controllers/richtext_controller.js b/app/webpacker/controllers/add_blank_to_link_controller.js similarity index 100% rename from app/webpacker/controllers/richtext_controller.js rename to app/webpacker/controllers/add_blank_to_link_controller.js diff --git a/spec/javascripts/stimulus/add_blank_to_link_controller_test.js b/spec/javascripts/stimulus/add_blank_to_link_controller_test.js new file mode 100644 index 000000000000..97fdc884e0a0 --- /dev/null +++ b/spec/javascripts/stimulus/add_blank_to_link_controller_test.js @@ -0,0 +1,24 @@ +/** + * @jest-environment jsdom + */ + +import { Application } from "stimulus"; +import add_blank_to_link_controller from "../../../app/webpacker/controllers/add_blank_to_link_controller"; + +describe("AddBlankToLink", () => { + beforeAll(() => { + const application = Application.start(); + application.register("add-blank-to-link", add_blank_to_link_controller); + }); + + describe("#add-blank-to-link", () => { + beforeEach(() => { + document.body.innerHTML = `
www.ofn.com
`; + }); + + it("adds target='_blank' to anchor tags", () => { + const anchorTag = document.querySelector('a') + expect(anchorTag.getAttribute('target')).toBe("_blank"); + }); + }); +}); diff --git a/spec/system/consumer/shopping/products_spec.rb b/spec/system/consumer/shopping/products_spec.rb index d568095ec562..ee2d81fc5856 100644 --- a/spec/system/consumer/shopping/products_spec.rb +++ b/spec/system/consumer/shopping/products_spec.rb @@ -84,7 +84,7 @@ visit shop_path expect(page).to have_content product.name expect_product_description_html_to_be_displayed(product, product.description, nil, - truncate: true) + truncate: true, href: true) end it "does not show unsecure HTML" do @@ -144,7 +144,7 @@ end def expect_product_description_html_to_be_displayed(product, html, not_include = nil, - truncate: false) + truncate: false, href: false) # check inside list of products within "#product-#{product.id} .product-description" do expect(html).to include(html) @@ -157,6 +157,7 @@ def expect_product_description_html_to_be_displayed(product, html, not_include = expect(page).to have_selector '.reveal-modal' modal_should_be_open_for product within(".reveal-modal") do + expect(html.match?('_blank')).to be(true) if href expect(html).to include(html) expect(html).not_to include(not_include) if not_include end