Move PageHeader into their own components and fix some tests

This commit is contained in:
Henriette Darge
2024-12-05 14:00:12 +01:00
parent f5930b5d08
commit a4904fb491
12 changed files with 229 additions and 132 deletions
@@ -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 !@topic.locked? && 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
%>
@@ -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
end
-1
View File
@@ -35,7 +35,6 @@ class ForumsController < ApplicationController
accept_key_auth :show
include SortHelper
include WatchersHelper
include PaginationHelper
def index
+1 -58
View File
@@ -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 !@topic.locked? && 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 %>
+3 -1
View File
@@ -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)
@@ -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
%>
@@ -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
end
@@ -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>
@@ -40,14 +40,12 @@ module Pages
end
def click_copy
within ".toolbar-items" do
click_link "Copy"
end
page.find_test_selector("budget-copy-button").click
end
def click_delete
within ".toolbar-items" do
click_link "Delete"
accept_confirm do
page.find_test_selector("budget-delete-button").click
end
end
@@ -68,9 +68,7 @@ RSpec.describe "Upload attachment to forum message", :js do
expect(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").click
retry_block do
find(".op-uc-figure").click
@@ -115,9 +113,7 @@ RSpec.describe "Upload attachment to forum message", :js do
wait_for_network_idle
attachments_list.expect_attached("image.png")
within ".toolbar-items" do
click_on "Edit"
end
page.find_test_selector("message-edit-button").click
wait_for_network_idle
retry_block do
+4 -8
View File
@@ -47,10 +47,8 @@ RSpec.describe "version delete", :js, :with_cuprite do
# from the version show page
visit version_path(version)
within ".toolbar" do
accept_confirm do
click_link "Delete"
end
accept_confirm do
page.find_test_selector("version-delete-button").click
end
expect_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 page
visit version_path(version)
within ".toolbar" do
accept_confirm do
click_link "Delete"
end
accept_confirm do
page.find_test_selector("version-delete-button").click
end
expect_flash(type: :error, message: "There are also work packages in archived projects.")
+1 -3
View File
@@ -44,9 +44,7 @@ RSpec.describe "version edit" do
# from the version show page
visit version_path(version)
within ".toolbar" do
click_link "Edit"
end
page.find_test_selector("version-edit-button").click
fill_in "Name", with: new_version_name