diff --git a/spec/features/products_form_spec.rb b/spec/features/products_form_spec.rb index 4eddddfb48..f34a5e5aec 100644 --- a/spec/features/products_form_spec.rb +++ b/spec/features/products_form_spec.rb @@ -3,7 +3,7 @@ describe "product form has_one relationship" do include ActiveSupport::Testing::TimeHelpers - it "saves product and meta tag data correctly" do + it "saves product and meta tag data correctly", js: true do visit new_admin_product_path fill_in "Name", with: "Example" @@ -12,11 +12,19 @@ fill_in "Image url", with: "http://imageurlthatdoesnotexist" fill_in "Meta title", with: "Example meta title" fill_in "Meta description", with: "Example meta description" + fill_in_rich_text_area "Banner", with: <<~HTML +
A banner with a link.
+ HTML expect(page).to have_css("legend", text: "Product Meta Tag") click_on "Create Product" + within(".trix-content") do + within("div", text: "A banner with a link") do + expect(page).to have_link("link", href: "https://example.com") + end + end expect(page).to have_link("Example meta title") expect(page).to have_flash( t("administrate.controller.create.success", resource: "Product") @@ -53,13 +61,29 @@ ProductDashboard::ATTRIBUTE_TYPES[:release_year] = old_release_year end - it "edits product and meta tag data correctly" do - product = create(:product) + it "edits product and meta tag data correctly", js: true do + product = create(:product, banner: <<~HTML) +
A banner with a link.
+ HTML visit edit_admin_product_path(product) + within(:rich_text_area, "Banner") do + within("div", text: "A banner with a link") do + expect(page).to have_link("link", href: "https://example.com") + end + end + + fill_in_rich_text_area "Banner", with: <<~HTML +
A changed banner without a link.
+ HTML click_on "Update Product" + within(".trix-content") do + within("div", text: "A changed banner without a link.") do + expect(page).to have_no_link(href: "https://example.com") + end + end expect(page).to have_link(product.product_meta_tag.meta_title.to_s) expect(page).to have_flash( t("administrate.controller.update.success", resource: "Product") diff --git a/spec/support/features/action_text.rb b/spec/support/features/action_text.rb new file mode 100644 index 0000000000..7261238805 --- /dev/null +++ b/spec/support/features/action_text.rb @@ -0,0 +1,13 @@ +module Features + if RAILS_VERSION > "6.0" + require "action_text/system_test_helper" + + include ActionText::SystemTestHelper + else + def fill_in_rich_text_area(locator, with:) + trix_editor = find(:element, "trix-editor", "aria-label": locator) + + trix_editor.execute_script("this.editor.loadHTML(arguments[0])", with.to_s) + end + end +end