Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

support rich text input

Jonas Jabari3de8c221149e
diff --git a/app/forms/custom_fields/inputs/text.rb b/app/forms/custom_fields/inputs/text.rb
index 792c948138f..d0645a41956 100644
--- a/app/forms/custom_fields/inputs/text.rb
+++ b/app/forms/custom_fields/inputs/text.rb
@@ -33,6 +33,6 @@ class CustomFields::Inputs::Text < CustomFields::Inputs::Base::Input
# --> rich_text_area is not using the configured id, which is not scoped to model via base_config
# --> ids with '[' ']' are not valid selectors
# using simple text area for now
- custom_value_form.text_area(**input_attributes)
+ custom_value_form.rich_text_area(**input_attributes)
end
end
diff --git a/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb b/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb
index 1e54e7685ae..68dc72be600 100644
--- a/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb
+++ b/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb
@@ -245,6 +245,37 @@ RSpec.describe 'Edit project custom fields on project overview page', :js do
end
end
+ shared_examples 'a rich text custom field input' do
+ it 'shows the correct value if given' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ field.expect_value(expected_initial_value)
+ end
+ end
+
+ it 'shows a blank input if no value or default value is given' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ field.expect_value(expected_blank_value)
+ end
+ end
+
+ it 'shows the default value if no value is given' do
+ custom_field.custom_values.destroy_all
+ custom_field.update!(default_value:)
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ field.expect_value(default_value)
+ end
+ end
+ end
+
describe 'with boolean CF' do
let(:custom_field) { boolean_project_custom_field }
let(:default_value) { false }
@@ -292,11 +323,12 @@ RSpec.describe 'Edit project custom fields on project overview page', :js do
describe 'with text CF' do
let(:custom_field) { text_project_custom_field }
+ let(:field) { FormFields::Primerized::EditorFormField.new(custom_field) }
let(:default_value) { 'Default value' }
let(:expected_blank_value) { '' }
- let(:expected_initial_value) { "Lorem\nipsum" }
+ let(:expected_initial_value) { "Lorem\nipsum" } # TBD: why is the second newline missing?
- it_behaves_like 'a custom field input'
+ it_behaves_like 'a rich text custom field input'
end
end
diff --git a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb b/spec/features/projects/project_custom_fields/overview_page/shared_context.rb
index 5af4fb30494..3c50c90a452 100644
--- a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb
+++ b/spec/features/projects/project_custom_fields/overview_page/shared_context.rb
@@ -131,7 +131,7 @@ RSpec.shared_context 'with seeded projects, members and project custom fields' d
field = create(:text_project_custom_field, projects: [project], name: 'Text field',
project_custom_field_section: section_for_input_fields)
- create(:custom_value, customized: project, custom_field: field, value: "Lorem\nipsum")
+ create(:custom_value, customized: project, custom_field: field, value: "Lorem\n\nipsum")
field
end
diff --git a/spec/support/form_fields/primerized/editor_form_field.rb b/spec/support/form_fields/primerized/editor_form_field.rb
new file mode 100644
index 00000000000..9bbb23e2cb6
--- /dev/null
+++ b/spec/support/form_fields/primerized/editor_form_field.rb
@@ -0,0 +1,32 @@
+require_relative 'form_field'
+
+module FormFields
+ module Primerized
+ class EditorFormField < FormField
+ attr_reader :editor
+
+ delegate :expect_value, to: :editor
+
+ def initialize(property, selector: nil)
+ super
+
+ @editor = ::Components::WysiwygEditor.new(selector)
+ end
+
+ def expect_visible
+ !!editor.container
+ end
+
+ ##
+ # Set or select the given value.
+ # For fields of type select, will check for an option with that value.
+ def set_value(content)
+ editor.set_markdown(content)
+ end
+
+ def input_element
+ editor.editor_element
+ end
+ end
+ end
+end