Allow HTML via trix editor for custom tab content

+ update spec as well
This commit is contained in:
Jean-Baptiste Bellet
2023-05-24 17:44:20 +02:00
parent 4dede3b361
commit bb211bfc84
5 changed files with 16 additions and 8 deletions

View File

@@ -56,4 +56,5 @@
.three.columns.alpha
= custom_tab_form.label :content, t('.custom_tab_content')
.eight.columns
= custom_tab_form.text_area :content, rows: 5
= custom_tab_form.hidden_field :content, id: "custom_tab_content"
%trix-editor{ input: "custom_tab_content" }

View File

@@ -1,3 +1,3 @@
.content
.row
= @distributor.custom_tab.content
= @distributor.custom_tab.content.html_safe if @distributor.custom_tab&.content.present?

View File

@@ -182,5 +182,6 @@ RSpec.configure do |config|
config.include Devise::Test::IntegrationHelpers, type: :request
config.include Features::DatepickerHelper, type: :system
config.include Features::TrixEditorHelper, type: :system
config.include DownloadsHelper, type: :system
end

View File

@@ -0,0 +1,9 @@
# frozen_string_literal: true
module Features
module TrixEditorHelper
def fill_in_trix_editor(id, with:)
find(:xpath, "//trix-editor[@input='#{id}']").click.set(with)
end
end
end

View File

@@ -737,19 +737,17 @@ describe '
it "display a form with the custom tab fields: title and content" do
expect(page).to have_content "TITLE FOR CUSTOM TAB"
expect(page).to have_field "enterprise_custom_tab_attributes_title"
expect(page).to have_content "CONTENT FOR CUSTOM TAB"
expect(page).to have_field "enterprise_custom_tab_attributes_content"
end
it "can save custom tab fields" do
fill_in "enterprise_custom_tab_attributes_title", with: "Custom tab title"
fill_in "enterprise_custom_tab_attributes_content", with: "Custom tab content"
fill_in_trix_editor "custom_tab_content", with: "Custom tab content"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.custom_tab.title).to eq("Custom tab title")
expect(distributor1.reload.custom_tab.content).to eq("Custom tab content")
expect(distributor1.reload.custom_tab.content).to eq("<div>Custom tab content</div>")
end
context "when custom tab is already created" do
@@ -767,8 +765,7 @@ describe '
expect(page).to have_checked_field "Create custom tab in shopfront"
expect(page).
to have_field "enterprise_custom_tab_attributes_title", with: custom_tab.title
expect(page).
to have_field "enterprise_custom_tab_attributes_content", with: custom_tab.content
expect(page).to have_content(custom_tab.content)
end
it "can delete custom tab if uncheck the checkbox" do