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

[#63738] Primerize attribute help texts

Alexander Brandon Coles2b0e95244d34
diff --git a/app/components/_index.sass b/app/components/_index.sass
index b85bb451e78..c0c27dc3275 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -4,6 +4,8 @@
@import "op_primer/border_box_table_component"
@import "op_primer/form_helpers"
@import "open_project/common/attribute_component"
+@import "open_project/common/attribute_help_text_component"
+@import "open_project/common/attribute_label_component"
@import "open_project/common/submenu_component"
@import "projects/row_component"
@import "projects/phases/hover_card_component"
diff --git a/app/components/application_component.rb b/app/components/application_component.rb
index 53dc6caf507..077111d26f2 100644
--- a/app/components/application_component.rb
+++ b/app/components/application_component.rb
@@ -42,6 +42,21 @@ class ApplicationComponent < ViewComponent::Base
end
class << self
+ ##
+ # Generates a unique identifier suitable for use as an HTML `id` attribute
+ # value. If passed a non-nil model instance, it will use the model's id to
+ # generate the identifier (see {ActiveModel::Conversion#to_param}).
+ # Otherwise, it will generate an identifier with random numbers.
+ #
+ # @see ActiveModel::Conversion#to_param
+ #
+ # @param [ActiveModel::Model] model an optional model instance.
+ # @param [String] base_name a prefix for the unique identifier.
+ # @return [String] a unique identifier.
+ def generate_id(model = nil, base_name: name.demodulize.underscore.dasherize)
+ "#{base_name}-#{model&.to_param || SecureRandom.uuid}"
+ end
+
##
# Defines options for this cell which can be used within the cell's template.
# Options are passed to the cell during the render call.
diff --git a/app/components/attribute_help_texts/show_dialog_component.html.erb b/app/components/attribute_help_texts/show_dialog_component.html.erb
new file mode 100644
index 00000000000..f5ad22ce1c1
--- /dev/null
+++ b/app/components/attribute_help_texts/show_dialog_component.html.erb
@@ -0,0 +1,33 @@
+<%=
+ render(Primer::Alpha::Dialog.new(id: dialog_id, title:, size: :large)) do |dialog|
+ dialog.with_header(variant: :large)
+
+ dialog.with_body do
+ concat(
+ render(Primer::Box.new(mt: 1, classes: "op-uc-container op-uc-container__no-permalinks")) do
+ helpers.format_text(@attribute_help_text, :help_text)
+ end
+ )
+
+ if has_attachments?
+ concat render(Primer::Beta::Heading.new(tag: :h4)) { I18n.t(:label_attachment_plural) }
+ concat helpers.list_attachments(resource_representer, inputs: { allowUploading: false })
+ end
+ end
+
+ dialog.with_footer(show_divider: true) do
+ if allowed_to_edit?
+ concat(
+ render(Primer::Beta::Button.new(tag: :a, href: edit_button_href)) do |button|
+ button.with_leading_visual_icon(icon: :pencil)
+ I18n.t(:button_edit)
+ end
+ )
+ end
+
+ concat(
+ render(Primer::Beta::Button.new(data: { close_dialog_id: dialog_id })) { I18n.t(:button_close) }
+ )
+ end
+ end
+%>
diff --git a/app/components/attribute_help_texts/show_dialog_component.rb b/app/components/attribute_help_texts/show_dialog_component.rb
new file mode 100644
index 00000000000..93ac44f425f
--- /dev/null
+++ b/app/components/attribute_help_texts/show_dialog_component.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+class AttributeHelpTexts::ShowDialogComponent < ApplicationComponent
+ include OpTurbo::Streamable
+
+ DIALOG_ID = "attribute-help-text-show-modal"
+
+ def initialize(attribute_help_text:, current_user: User.current)
+ super
+ @attribute_help_text = attribute_help_text
+ @current_user = current_user
+ end
+
+ private
+
+ def dialog_id = DIALOG_ID
+
+ def title = @attribute_help_text.attribute_caption
+
+ def has_attachments? = @attribute_help_text.attachments.any?
+
+ def allowed_to_edit? = @current_user.allowed_globally?(:edit_attribute_help_texts)
+
+ def edit_button_href = url_helpers.edit_attribute_help_text_path(@attribute_help_text)
+
+ def resource_representer
+ ::API::V3::HelpTexts::HelpTextRepresenter.new(@attribute_help_text, current_user: @current_user, embed_links: false)
+ end
+end
diff --git a/app/components/open_project/common/attribute_help_text_component.html.erb b/app/components/open_project/common/attribute_help_text_component.html.erb
new file mode 100644
index 00000000000..f8d11778925
--- /dev/null
+++ b/app/components/open_project/common/attribute_help_text_component.html.erb
@@ -0,0 +1,6 @@
+<%=
+ render Primer::Beta::Link.new(**@system_arguments) do
+ render Primer::Beta::Octicon.new(:question, size: :xsmall)
+ end
+%>
+<%= render @tooltip %>
diff --git a/app/components/open_project/common/attribute_help_text_component.rb b/app/components/open_project/common/attribute_help_text_component.rb
new file mode 100644
index 00000000000..85e191c7444
--- /dev/null
+++ b/app/components/open_project/common/attribute_help_text_component.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module OpenProject
+ module Common
+ class AttributeHelpTextComponent < ApplicationComponent
+ def initialize(help_text:, **system_arguments) # rubocop:disable Metrics/AbcSize
+ super()
+
+ @help_text = help_text
+
+ @system_arguments = system_arguments
+ @system_arguments[:id] ||= self.class.generate_id(help_text)
+ @system_arguments[:muted] = true
+ @system_arguments[:classes] = class_names(
+ @system_arguments[:classes],
+ "op-attribute-help-text"
+ )
+ @system_arguments[:data] ||= {}
+ @system_arguments[:data][:controller] = "async-dialog"
+
+ @tooltip = Primer::Alpha::Tooltip.new(
+ for_id: @system_arguments[:id],
+ type: :label,
+ text: I18n.t("js.help_texts.show_modal"),
+ direction: :e
+ )
+ @system_arguments[:aria] ||= {}
+ @system_arguments[:aria][:labelledby] = @tooltip.id
+ end
+
+ private
+
+ def render?
+ @help_text.present?
+ end
+
+ def before_render
+ return unless @help_text
+
+ @system_arguments[:href] = show_dialog_attribute_help_text_path(@help_text)
+ end
+ end
+ end
+end
diff --git a/app/components/open_project/common/attribute_help_text_component.sass b/app/components/open_project/common/attribute_help_text_component.sass
new file mode 100644
index 00000000000..bc659993cb4
--- /dev/null
+++ b/app/components/open_project/common/attribute_help_text_component.sass
@@ -0,0 +1,30 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+.op-attribute-help-text
+ line-height: 1rem
diff --git a/app/components/open_project/common/attribute_label_component.html.erb b/app/components/open_project/common/attribute_label_component.html.erb
new file mode 100644
index 00000000000..c4d4bf4fd6a
--- /dev/null
+++ b/app/components/open_project/common/attribute_label_component.html.erb
@@ -0,0 +1,4 @@
+<%= render Primer::ConditionalWrapper.new(condition: [email protected]?, trim: true, **@system_arguments) do %>
+ <%= content %>
+ <%= render OpenProject::Common::AttributeHelpTextComponent.new(help_text: @help_text) if @help_text.present? %>
+<% end %>
diff --git a/app/components/open_project/common/attribute_label_component.rb b/app/components/open_project/common/attribute_label_component.rb
new file mode 100644
index 00000000000..dbc84503cc0
--- /dev/null
+++ b/app/components/open_project/common/attribute_label_component.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module OpenProject
+ module Common
+ class AttributeLabelComponent < ApplicationComponent
+ def initialize(
+ attribute:,
+ model:,
+ tag: :span,
+ current_user: User.current,
+ **system_arguments
+ )
+ super()
+
+ @tag = tag
+ @system_arguments = system_arguments
+ @system_arguments[:tag] = @tag
+ @system_arguments[:classes] = class_names(
+ @system_arguments[:classes],
+ "op-attribute-label"
+ )
+
+ @help_text = ::AttributeHelpText.for(model)
+ &.cached(current_user)
+ &.[](attribute.to_s)
+ end
+ end
+ end
+end
diff --git a/app/components/open_project/common/attribute_label_component.sass b/app/components/open_project/common/attribute_label_component.sass
new file mode 100644
index 00000000000..06b81126d13
--- /dev/null
+++ b/app/components/open_project/common/attribute_label_component.sass
@@ -0,0 +1,34 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+.op-attribute-label
+ display: inline-flex
+
+ > .op-attribute-help-text
+ align-self: baseline
+ margin-left: var(--base-size-6)
diff --git a/app/controllers/attribute_help_texts_controller.rb b/app/controllers/attribute_help_texts_controller.rb
index cf5fb015493..d9f970788f3 100644
--- a/app/controllers/attribute_help_texts_controller.rb
+++ b/app/controllers/attribute_help_texts_controller.rb
@@ -27,17 +27,29 @@
#++
class AttributeHelpTextsController < ApplicationController
+ include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
+
layout "admin"
menu_item :attribute_help_texts
- before_action :authorize_global
+ before_action :authorize_global, except: :show_dialog
before_action :find_entry, only: %i(edit update destroy)
before_action :find_type_scope
+ authorization_checked! :show_dialog
+
def index
@texts_by_type = AttributeHelpText.all_by_scope
end
+ def show_dialog
+ @attribute_help_text = AttributeHelpText.visible(current_user).find(params[:id])
+ respond_with_dialog(
+ AttributeHelpTexts::ShowDialogComponent.new(attribute_help_text: @attribute_help_text)
+ )
+ end
+
def new
@attribute_help_text = AttributeHelpText.new type: @attribute_scope
end
diff --git a/app/models/attribute_help_text.rb b/app/models/attribute_help_text.rb
index 558991547ad..a138103f83e 100644
--- a/app/models/attribute_help_text.rb
+++ b/app/models/attribute_help_text.rb
@@ -29,6 +29,14 @@
class AttributeHelpText < ApplicationRecord
acts_as_attachable viewable_by_all_users: true
+ def self.cached(user)
+ OpenProject::Cache.fetch([name, user]) { visible(user).select(:id, :attribute_name).index_by(&:attribute_name) }
+ end
+
+ def self.for(model)
+ subclasses.find { |child| child.name.demodulize == model.model_name }
+ end
+
def self.available_types
subclasses.map { |child| child.name.demodulize }
end
diff --git a/config/routes.rb b/config/routes.rb
index d5f23c73e73..4698a4846de 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -116,6 +116,12 @@ Rails.application.routes.draw do
post "/account/confirm_consent", action: "confirm_consent", as: "account_confirm_consent"
end
+ resources :attribute_help_texts, only: [] do
+ member do
+ get :show_dialog
+ end
+ end
+
# Because of https://github.com/intridea/grape/pull/853/files this has to be
# placed behind handling the deprecated v1 because otherwise, a 405 is
# returned for all routes for which the v3 has also resources. Grape does
diff --git a/spec/components/attribute_help_texts/show_dialog_component_spec.rb b/spec/components/attribute_help_texts/show_dialog_component_spec.rb
new file mode 100644
index 00000000000..fe62f4dc726
--- /dev/null
+++ b/spec/components/attribute_help_texts/show_dialog_component_spec.rb
@@ -0,0 +1,117 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe AttributeHelpTexts::ShowDialogComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ let(:attribute_help_text) { build_stubbed(:project_help_text, help_text:) }
+ let(:help_text) do
+ <<~MARKDOWN
+ ## The lowdown on filling in this form field!
+ ### Getting started
+
+ Take a deep breath! _It ain't hard!_ Relax and have your Kaffee und Kuchen. Or a cup of tea if you're British.
+ MARKDOWN
+ end
+
+ let(:current_user) { build_stubbed(:user) }
+
+ subject do
+ render_inline(described_class.new(attribute_help_text:, current_user:))
+ page
+ end
+
+ describe "dialog heading" do
+ it "renders the heading" do
+ expect(subject).to have_heading attribute_help_text.attribute_caption
+ end
+ end
+
+ describe "dialog body" do
+ it "applies correct classes to user-generated content" do
+ expect(subject).to have_css ".op-uc-container.op-uc-container__no-permalinks"
+ end
+
+ it "renders the user-generated content", :aggregate_failures do
+ expect(subject).to have_css "h2", text: "The lowdown on filling in this form field!"
+ expect(subject).to have_css "h3", text: "Getting started"
+ expect(subject).to have_text "Relax and have your Kaffee und Kuchen"
+ end
+
+ context "without attachments" do
+ it "does not render the Attachments heading" do
+ expect(subject).to have_no_heading "Attachments"
+ end
+
+ it "does not render the opce-attachments component" do
+ expect(subject).to have_no_element "opce-attachments"
+ end
+ end
+
+ context "with attachments" do
+ let!(:attachments) { create_list(:attachment, 2, container: attribute_help_text) }
+
+ it "renders the Attachments heading" do
+ expect(subject).to have_heading "Attachments"
+ end
+
+ it "renders the opce-attachments component" do
+ expect(subject).to have_element "opce-attachments" do |element|
+ expect(element["data-allow-uploading"]).to be_json_eql("false")
+ expect(element["data-destroy-immediately"]).to be_json_eql("true")
+ expect(element["data-resource"]).to have_json_path("_links/attachments/href")
+ end
+ end
+ end
+ end
+
+ describe "dialog footer" do
+ it "renders a Close button" do
+ expect(subject).to have_button "Close"
+ end
+
+ context "when the user does not have edit permissions" do
+ it "does not render an Edit button" do
+ expect(subject).to have_no_link "Edit"
+ end
+ end
+
+ context "when the user has edit permissions" do
+ let(:current_user) { build_stubbed(:admin) }
+
+ it "renders an Edit button with icon" do
+ expect(subject).to have_link "Edit", href: edit_attribute_help_text_path(attribute_help_text)
+ expect(subject).to have_octicon :pencil
+ end
+ end
+ end
+end
diff --git a/spec/components/open_project/common/attribute_help_text_component_spec.rb b/spec/components/open_project/common/attribute_help_text_component_spec.rb
new file mode 100644
index 00000000000..cdf3bd5cf72
--- /dev/null
+++ b/spec/components/open_project/common/attribute_help_text_component_spec.rb
@@ -0,0 +1,99 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe OpenProject::Common::AttributeHelpTextComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ subject do
+ render_inline(described_class.new(help_text:))
+ page
+ end
+
+ shared_examples "component renders" do
+ it "renders a muted link" do
+ expect(subject).to have_link href: show_dialog_attribute_help_text_path(help_text),
+ class: "Link Link--muted"
+ end
+
+ it "renders a tooltip" do
+ expect(subject).to have_element "tool-tip", text: "Show attribute help text entry",
+ for: /attribute-help-text-component-\d+/,
+ popover: "manual",
+ "data-direction": "e",
+ "data-type": "label"
+ end
+
+ it "renders an icon" do
+ expect(subject).to have_octicon :question, size: :xsmall
+ end
+
+ it "connects an 'async-dialog' controller" do
+ expect(subject).to have_element :a, "data-controller": "async-dialog"
+ end
+
+ it "applies .op-attribute-help-text class" do
+ expect(subject).to have_element :a, class: "op-attribute-help-text"
+ end
+
+ it "applies an ID" do
+ expect(subject).to have_element :a, id: /attribute-help-text-component-\d+/
+ end
+ end
+
+ shared_examples "component does not render" do
+ it "renders nothing" do
+ expect(subject).to have_no_element
+ end
+
+ it "does not raise an error" do
+ expect { subject }.not_to raise_error
+ end
+ end
+
+ context "with a project help text" do
+ let(:help_text) { build_stubbed(:project_help_text) }
+
+ it_behaves_like "component renders"
+ end
+
+ context "with a work package help text" do
+ let(:help_text) { build_stubbed(:work_package_help_text) }
+
+ it_behaves_like "component renders"
+ end
+
+ context "with nil help text" do
+ let(:help_text) { nil }
+
+ it_behaves_like "component does not render"
+ end
+end
diff --git a/spec/components/open_project/common/attribute_label_component_spec.rb b/spec/components/open_project/common/attribute_label_component_spec.rb
new file mode 100644
index 00000000000..a42c0b3e1b1
--- /dev/null
+++ b/spec/components/open_project/common/attribute_label_component_spec.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe OpenProject::Common::AttributeLabelComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ let(:attribute) { "name" }
+ let(:model) { create(:project) }
+ let(:tag) { :span }
+ let(:current_user) { create(:user) }
+ let(:content) { "Name" }
+
+ subject do
+ render_inline(described_class.new(attribute:, model:, tag:, current_user:)) do
+ content
+ end
+
+ page
+ end
+
+ shared_examples "component renders" do
+ context "without a wrapper" do
+ let(:tag) { nil }
+
+ it "renders no wrapper" do
+ expect(subject).to have_no_element class: "op-attribute-label"
+ end
+ end
+
+ context "with a wrapper" do
+ let(:tag) { :div }
+
+ it "applies .op-attribute-label class" do
+ expect(subject).to have_element :div, class: "op-attribute-label"
+ end
+ end
+
+ it "renders content" do
+ expect(subject).to have_text "Name"
+ end
+ end
+
+ context "without help text" do
+ it_behaves_like "component renders"
+
+ it "does not render help text" do
+ expect(subject).to have_no_element class: "op-attribute-help-text"
+ end
+ end
+
+ context "with help text" do
+ let!(:help_text) { create(:project_help_text, attribute_name: attribute) }
+
+ it_behaves_like "component renders"
+
+ it "renders help text" do
+ expect(subject).to have_element class: "op-attribute-help-text"
+ end
+ end
+end
diff --git a/spec/controllers/attribute_help_texts_controller_spec.rb b/spec/controllers/attribute_help_texts_controller_spec.rb
index 5d029ad1dd5..e74f182ca55 100644
--- a/spec/controllers/attribute_help_texts_controller_spec.rb
+++ b/spec/controllers/attribute_help_texts_controller_spec.rb
@@ -4,7 +4,7 @@ require "spec_helper"
RSpec.describe AttributeHelpTextsController do
let(:user) { build_stubbed(:user) }
- let(:model) { build(:work_package_help_text) }
+ let(:model) { build_stubbed(:work_package_help_text) }
let(:find_expectation) do
allow(AttributeHelpText)
@@ -34,6 +34,50 @@ RSpec.describe AttributeHelpTextsController do
end
end
+ describe "#show_dialog" do
+ let(:visible_scope) { instance_double(ActiveRecord::Relation) }
+
+ before do
+ allow(AttributeHelpText)
+ .to receive(:visible)
+ .with(user)
+ .and_return(visible_scope)
+
+ find_expectation
+
+ get :show_dialog, params: { id: 1234 }, format: :turbo_stream
+ end
+
+ context "when found" do
+ let(:find_expectation) do
+ allow(visible_scope)
+ .to receive(:find)
+ .with("1234")
+ .and_return(model)
+ end
+
+ it "renders turbo stream dialog action", :aggregate_failures do
+ expect(response).to be_successful
+ expect(assigns(:attribute_help_text)).to eq model
+ expect(response).to have_turbo_stream action: "dialog", target: "attribute-help-texts-show-dialog-component"
+ end
+ end
+
+ context "when not found" do
+ let(:find_expectation) do
+ allow(visible_scope)
+ .to receive(:find)
+ .with("1234")
+ .and_raise(ActiveRecord::RecordNotFound)
+ end
+
+ it "responds with 404 Not Found status", :aggregate_failures do
+ expect(response).not_to be_successful
+ expect(response).to have_http_status :not_found
+ end
+ end
+ end
+
describe "#edit" do
before do
find_expectation
diff --git a/spec/routing/attribute_help_text_spec.rb b/spec/routing/attribute_help_text_spec.rb
index 42d8b6ab664..827add51370 100644
--- a/spec/routing/attribute_help_text_spec.rb
+++ b/spec/routing/attribute_help_text_spec.rb
@@ -31,6 +31,11 @@
require "spec_helper"
RSpec.describe AttributeHelpTextsController do
+ it "routes to show_dialog" do
+ expect(get("/attribute_help_texts/1/show_dialog"))
+ .to route_to(controller: "attribute_help_texts", action: "show_dialog", id: "1")
+ end
+
it "routes CRUD to the controller" do
expect(get("/admin/attribute_help_texts"))
.to route_to(controller: "attribute_help_texts", action: "index")