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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Move PageHeader into their own components and fix some tests
Henriette Dargea4904fb49182
diff --git a/app/components/messages/show_page_header_component.html.erb b/app/components/messages/show_page_header_component.html.erbnew file mode 100644index 00000000000..e10de5f9c91--- /dev/null+++ b/app/components/messages/show_page_header_component.html.erb@@ -0,0 +1,60 @@+<%=+ render Primer::OpenProject::PageHeader.new do |header|+ header.with_title { @topic.subject }+ header.with_breadcrumbs(breadcrumb_items)++ watcher_button_args = watcher_button_arguments(@topic, User.current)+ header.with_action_button(**watcher_button_args) do |button|+ button.with_leading_visual_icon(icon: watcher_button_args[:mobile_icon])+ watcher_button_args[:mobile_label]+ end++ if [email protected]? && authorize_for('messages', 'reply')+ header.with_action_button(tag: :a,+ scheme: :default,+ mobile_icon: :quote,+ mobile_label: t(:button_quote),+ size: :medium,+ href: url_for({ action: 'quote', id: @topic }),+ aria: { label: I18n.t(:button_delete) },+ data: { 'action': 'forum-messages#quote' },+ title: t(:button_quote)) do |button|+ button.with_leading_visual_icon(icon: :quote)+ t(:button_quote)+ end+ end++ if @message.editable_by?(User.current)+ header.with_action_button(tag: :a,+ scheme: :default,+ mobile_icon: :pencil,+ mobile_label: t(:button_edit),+ size: :medium,+ href: edit_topic_path(@topic),+ aria: { label: t(:button_edit) },+ data: { test_selector: "message-edit-button" },+ title: t(:button_edit)) do |button|+ button.with_leading_visual_icon(icon: :pencil)+ t(:button_edit)+ end+ end++ if @message.destroyable_by?(User.current)+ header.with_action_button(tag: :a,+ scheme: :danger,+ mobile_icon: :trash,+ mobile_label: t(:button_delete),+ size: :medium,+ href: topic_path(@topic),+ aria: { label: I18n.t(:button_delete) },+ data: {+ confirm: I18n.t(:text_are_you_sure),+ method: :delete+ },+ title: I18n.t(:button_delete)) do |button|+ button.with_leading_visual_icon(icon: :trash)+ t(:button_delete)+ end+ end+ end+%>diff --git a/app/components/messages/show_page_header_component.rb b/app/components/messages/show_page_header_component.rbnew file mode 100644index 00000000000..23a60603459--- /dev/null+++ b/app/components/messages/show_page_header_component.rb@@ -0,0 +1,54 @@+# 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 Messages+ class ShowPageHeaderComponent < ApplicationComponent+ include OpPrimer::ComponentHelpers+ include ApplicationHelper+ include WatchersHelper++ def initialize(topic:, message:, forum:, project:)+ super+ @topic = topic+ @message = message+ @forum = forum+ @project = project+ end++ def breadcrumb_items+ [+ { href: project_overview_path(@project.id), text: @project.name },+ { href: project_forums_path(@project), text: t(:label_forum_plural) },+ { href: project_forum_path(@project, @forum), text: @forum.name },+ @topic.subject+ ]+ end+ end+enddiff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rbindex 434b7686ffd..414248f8161 100644--- a/app/controllers/forums_controller.rb+++ b/app/controllers/forums_controller.rb@@ -35,7 +35,6 @@ class ForumsController < ApplicationControlleraccept_key_auth :showinclude SortHelper- include WatchersHelperinclude PaginationHelperdef indexdiff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erbindex ceb18b4bee7..5ec9cbdda7d 100644--- a/app/views/messages/show.html.erb+++ b/app/views/messages/show.html.erb@@ -27,64 +27,7 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%=- render Primer::OpenProject::PageHeader.new do |header|- header.with_title { @topic.subject }- header.with_breadcrumbs( [{ href: project_overview_path(@project.id), text: @project.name },- { href: project_forums_path(@project), text: t(:label_forum_plural) },- { href: project_forum_path(@project, @forum), text: @forum.name },- @topic.subject- ])- watcher_button_args = watcher_button_arguments(@topic, User.current)- header.with_action_button(**watcher_button_args) do |button|- button.with_leading_visual_icon(icon: watcher_button_args[:mobile_icon])- watcher_button_args[:mobile_label]- end- if [email protected]? && authorize_for('messages', 'reply')- header.with_action_button(tag: :a,- scheme: :default,- mobile_icon: :quote,- mobile_label: t(:button_quote),- size: :medium,- href: url_for({ action: 'quote', id: @topic }),- aria: { label: I18n.t(:button_delete) },- data: { 'action': 'forum-messages#quote' },- title: t(:button_quote)) do |button|- button.with_leading_visual_icon(icon: :quote)- t(:button_quote)- end- end- if @message.editable_by?(User.current)- header.with_action_button(tag: :a,- scheme: :default,- mobile_icon: :pencil,- mobile_label: t(:button_edit),- size: :medium,- href: edit_topic_path(@topic),- aria: { label: t(:button_edit) },- title: t(:button_edit)) do |button|- button.with_leading_visual_icon(icon: :pencil)- t(:button_edit)- end- end- if @message.destroyable_by?(User.current)- header.with_action_button(tag: :a,- scheme: :danger,- mobile_icon: :trash,- mobile_label: t(:button_delete),- size: :medium,- href: topic_path(@topic),- aria: { label: I18n.t(:button_delete) },- data: {- confirm: I18n.t(:text_are_you_sure),- method: :delete- },- title: I18n.t(:button_delete)) do |button|- button.with_leading_visual_icon(icon: :trash)- t(:button_delete)- end- end- end %>+<%= render Messages::ShowPageHeaderComponent.new(topic: @topic, message: @message, forum: @forum, project:@project) %><% content_controller 'forum-messages',dynamic: true %>diff --git a/app/views/versions/show.html.erb b/app/views/versions/show.html.erbindex ba1a3aab1d8..91278a36d54 100644--- a/app/views/versions/show.html.erb+++ b/app/views/versions/show.html.erb@@ -41,6 +41,7 @@ See COPYRIGHT and LICENSE files for more details.size: :medium,href: edit_version_path(@version),aria: { label: I18n.t(:button_edit) },+ data: { test_selector: "version-edit-button" },title: I18n.t(:button_edit)) do |button|button.with_leading_visual_icon(icon: :pencil)t(:button_edit)@@ -56,7 +57,8 @@ See COPYRIGHT and LICENSE files for more details.aria: { label: I18n.t(:button_delete) },data: {confirm: I18n.t(:text_are_you_sure),- method: :delete+ method: :delete,+ test_selector: "version-delete-button"},title: I18n.t(:button_delete)) do |button|button.with_leading_visual_icon(icon: :trash)diff --git a/modules/budgets/app/components/budgets/show_page_header_component.html.erb b/modules/budgets/app/components/budgets/show_page_header_component.html.erbnew file mode 100644index 00000000000..bca91081ef5--- /dev/null+++ b/modules/budgets/app/components/budgets/show_page_header_component.html.erb@@ -0,0 +1,51 @@+<%=+ render(Primer::OpenProject::PageHeader.new) do |header|+ header.with_title { t(:label_budget_id, id: @budget.id) }+ header.with_breadcrumbs(breadcrumb_items)++ if authorize_for(:budgets, :edit)+ header.with_action_button(tag: :a,+ mobile_icon: :pencil,+ mobile_label: t(:button_edit),+ size: :medium,+ href: url_for({ controller: 'budgets', action: 'edit', id: @budget }),+ aria: { label: t(:button_update) },+ data: {test_selector: "budget-edit-button" },+ title: t(:button_update)) do |button|+ button.with_leading_visual_icon(icon: :pencil)+ t(:button_update)+ end+ end+ if authorize_for(:budgets, :copy)+ header.with_action_button(tag: :a,+ mobile_icon: :copy,+ mobile_label: t(:button_copy),+ size: :medium,+ href: url_for({ controller: 'budgets', action: 'copy', id: @budget }),+ aria: { label: I18n.t(:button_copy) },+ data: {test_selector: "budget-copy-button" },+ title: I18n.t(:button_copy)) do |button|+ button.with_leading_visual_icon(icon: :copy)+ t(:button_copy)+ end+ end+ if authorize_for(:budgets, :destroy)+ header.with_action_button(tag: :a,+ scheme: :danger,+ mobile_icon: :trash,+ mobile_label: t(:button_delete),+ size: :medium,+ href: url_for({ controller: 'budgets', action: 'destroy', id: @budget }),+ aria: { label: I18n.t(:button_delete) },+ data: {+ confirm: I18n.t(:text_are_you_sure),+ method: :delete,+ test_selector: "budget-delete-button",+ },+ title: I18n.t(:button_delete)) do |button|+ button.with_leading_visual_icon(icon: :trash)+ t(:button_delete)+ end+ end+ end+%>diff --git a/modules/budgets/app/components/budgets/show_page_header_component.rb b/modules/budgets/app/components/budgets/show_page_header_component.rbnew file mode 100644index 00000000000..198df535ee1--- /dev/null+++ b/modules/budgets/app/components/budgets/show_page_header_component.rb@@ -0,0 +1,49 @@+# 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 Budgets+ class ShowPageHeaderComponent < ApplicationComponent+ include OpPrimer::ComponentHelpers+ include ApplicationHelper++ def initialize(budget:, project:)+ super++ @budget = budget+ @project = project+ end++ def breadcrumb_items+ [{ href: project_overview_path(@project.id), text: @project.name },+ { href: projects_budgets_path(@project.id), text: t(:label_budget_plural) },+ t(:label_budget_id, id: @budget.id)]+ end+ end+enddiff --git a/modules/budgets/app/views/budgets/show.html.erb b/modules/budgets/app/views/budgets/show.html.erbindex 53dae027c22..331837a5d54 100644--- a/modules/budgets/app/views/budgets/show.html.erb+++ b/modules/budgets/app/views/budgets/show.html.erb@@ -28,56 +28,7 @@ See COPYRIGHT and LICENSE files for more details.++#%><% html_title "#{t(:label_budget_id, id: @budget.id)}: #{@budget.subject}" %>-<%=- render(Primer::OpenProject::PageHeader.new) do |header|- header.with_title { t(:label_budget_id, id: @budget.id) }- header.with_breadcrumbs([{ href: project_overview_path(@project.id), text: @project.name },- { href: projects_budgets_path(@project.id), text: t(:label_budget_plural) },- t(:label_budget_id, id: @budget.id)])-- if authorize_for(:budgets, :edit)- header.with_action_button(tag: :a,- mobile_icon: :pencil,- mobile_label: t(:button_edit),- size: :medium,- href: url_for({ controller: 'budgets', action: 'edit', id: @budget }),- aria: { label: t(:button_update) },- title: t(:button_update)) do |button|- button.with_leading_visual_icon(icon: :pencil)- t(:button_update)- end- end- if authorize_for(:budgets, :copy)- header.with_action_button(tag: :a,- mobile_icon: :copy,- mobile_label: t(:button_copy),- size: :medium,- href: url_for({ controller: 'budgets', action: 'copy', id: @budget }),- aria: { label: I18n.t(:button_copy) },- title: I18n.t(:button_copy)) do |button|- button.with_leading_visual_icon(icon: :copy)- t(:button_copy)- end- end- if authorize_for(:budgets, :destroy)- header.with_action_button(tag: :a,- scheme: :danger,- mobile_icon: :trash,- mobile_label: t(:button_delete),- size: :medium,- href: url_for({ controller: 'budgets', action: 'destroy', id: @budget }),- aria: { label: I18n.t(:button_delete) },- data: {- confirm: I18n.t(:text_are_you_sure),- method: :delete- },- title: I18n.t(:button_delete)) do |button|- button.with_leading_visual_icon(icon: :trash)- t(:button_delete)- end- end- end-%>+<%= render Budgets::ShowPageHeaderComponent.new(budget: @budget, project: @project) %><div class="<%= @budget.css_classes %> details"><h3><%=h @budget.subject %></h3>diff --git a/modules/budgets/spec/support/pages/edit_budget.rb b/modules/budgets/spec/support/pages/edit_budget.rbindex 5e78629cf73..cabf1c75583 100644--- a/modules/budgets/spec/support/pages/edit_budget.rb+++ b/modules/budgets/spec/support/pages/edit_budget.rb@@ -40,14 +40,12 @@ module Pagesenddef click_copy- within ".toolbar-items" do- click_link "Copy"- end+ page.find_test_selector("budget-copy-button").clickenddef click_delete- within ".toolbar-items" do- click_link "Delete"+ accept_confirm do+ page.find_test_selector("budget-delete-button").clickendenddiff --git a/spec/features/forums/attachment_upload_spec.rb b/spec/features/forums/attachment_upload_spec.rbindex 0fb0fe9b947..dfb2a7bd0bd 100644--- a/spec/features/forums/attachment_upload_spec.rb+++ b/spec/features/forums/attachment_upload_spec.rb@@ -68,9 +68,7 @@ RSpec.describe "Upload attachment to forum message", :js doexpect(page).to have_content("Image uploaded on creation")attachments_list.expect_attached("image.png")- within ".toolbar-items" do- click_on "Edit"- end+ page.find_test_selector("message-edit-button").clickretry_block dofind(".op-uc-figure").click@@ -115,9 +113,7 @@ RSpec.describe "Upload attachment to forum message", :js dowait_for_network_idleattachments_list.expect_attached("image.png")- within ".toolbar-items" do- click_on "Edit"- end+ page.find_test_selector("message-edit-button").clickwait_for_network_idleretry_block dodiff --git a/spec/features/versions/delete_spec.rb b/spec/features/versions/delete_spec.rbindex 6f6cdffd3be..1085227bac4 100644--- a/spec/features/versions/delete_spec.rb+++ b/spec/features/versions/delete_spec.rb@@ -47,10 +47,8 @@ RSpec.describe "version delete", :js, :with_cuprite do# from the version show pagevisit version_path(version)- within ".toolbar" do- accept_confirm do- click_link "Delete"- end+ accept_confirm do+ page.find_test_selector("version-delete-button").clickendexpect_flash(type: :error, message: I18n.t(:error_can_not_delete_in_use_archived_undisclosed))@@ -61,10 +59,8 @@ RSpec.describe "version delete", :js, :with_cuprite do# from the version show pagevisit version_path(version)- within ".toolbar" do- accept_confirm do- click_link "Delete"- end+ accept_confirm do+ page.find_test_selector("version-delete-button").clickendexpect_flash(type: :error, message: "There are also work packages in archived projects.")diff --git a/spec/features/versions/edit_spec.rb b/spec/features/versions/edit_spec.rbindex 28bbcde862b..f853e07f6f5 100644--- a/spec/features/versions/edit_spec.rb+++ b/spec/features/versions/edit_spec.rb@@ -44,9 +44,7 @@ RSpec.describe "version edit" do# from the version show pagevisit version_path(version)- within ".toolbar" do- click_link "Edit"- end+ page.find_test_selector("version-edit-button").clickfill_in "Name", with: new_version_name