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

tests[Op#54456]: feature tests for the project mappings page

Kabiru Mwenja9c71f30dadcf
diff --git a/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb b/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb
index fc359803426..7c5052cffc0 100644
--- a/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb
+++ b/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb
@@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= render(Settings::ProjectCustomFields::EditFormHeaderComponent.new(custom_field: @custom_field)) %>
<%=
- render(Primer::Alpha::TabNav.new(label: "label")) do |component|
+ render(Primer::Alpha::TabNav.new(label: nil, test_selector: :project_attribute_detail_header)) do |component|
component.with_tab(
selected: project_custom_field_edit_selected?,
href: edit_admin_settings_project_custom_field_path(@custom_field)
diff --git a/spec/features/admin/project_custom_fields/edit_spec.rb b/spec/features/admin/project_custom_fields/edit_spec.rb
index 2d2c4fa9fe7..a366a69abdf 100644
--- a/spec/features/admin/project_custom_fields/edit_spec.rb
+++ b/spec/features/admin/project_custom_fields/edit_spec.rb
@@ -56,6 +56,13 @@ RSpec.describe "Edit project custom fields", :js do
end
end
+ it "shows tab navigation" do
+ within_test_selector("project_attribute_detail_header") do
+ expect(page).to have_link("Details")
+ expect(page).to have_link("Projects")
+ end
+ end
+
it "allows to change basic attributes and the section of the project custom field" do
# TODO: reuse specs for classic custom field form in order to test for other attribute manipulations
expect(page).to have_css(".PageHeader-title", text: boolean_project_custom_field.name)
diff --git a/spec/features/admin/project_custom_fields/project_mappings_spec.rb b/spec/features/admin/project_custom_fields/project_mappings_spec.rb
new file mode 100644
index 00000000000..0d9f88287fc
--- /dev/null
+++ b/spec/features/admin/project_custom_fields/project_mappings_spec.rb
@@ -0,0 +1,89 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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 "spec_helper"
+
+RSpec.describe "Project Custom Field Mappings", :js do
+ shared_let(:admin) { create(:admin) }
+ shared_let(:non_admin) { create(:user) }
+ shared_let(:project) { create(:project) }
+ shared_let(:project_custom_field) { create(:project_custom_field) }
+ shared_let(:project_custom_field_mapping) { create(:project_custom_field_project_mapping, project_custom_field:, project:) }
+
+ let(:project_custom_field_mappings_page) { Pages::Admin::Settings::ProjectCustomFields::ProjectCustomFieldMappingsIndex.new }
+
+ context "with insufficient permissions" do
+ it "is not accessible" do
+ login_as(non_admin)
+ visit project_mappings_admin_settings_project_custom_field_path(project_custom_field)
+
+ expect(page).to have_text("You are not authorized to access this page.")
+ end
+ end
+
+ context "with sufficient permissions" do
+ before do
+ login_as(admin)
+ visit project_mappings_admin_settings_project_custom_field_path(project_custom_field)
+ end
+
+ it "shows a correct breadcrumb menu" do
+ within ".PageHeader-breadcrumbs" do
+ expect(page).to have_link("Administration")
+ expect(page).to have_link("Projects")
+ expect(page).to have_link("Project attributes")
+ expect(page).to have_text(project_custom_field.name)
+ end
+ end
+
+ it "shows tab navigation" do
+ within_test_selector("project_attribute_detail_header") do
+ expect(page).to have_link("Details")
+ expect(page).to have_link("Projects")
+ end
+ end
+
+ it "shows the correct project mappings" do
+ within "#project-table" do
+ expect(page).to have_text(project.name)
+ end
+ end
+
+ it "renders more menu list item" do
+ project_custom_field_mappings_page.activate_menu_of(project) do |menu|
+ expect(menu).to have_link("Delete")
+ end
+ end
+
+ it "allows to unlink a project" do
+ project_custom_field_mappings_page.click_menu_item_of("Delete", project)
+
+ expect(page).to have_no_text(project.name)
+ end
+ end
+end
diff --git a/spec/support/pages/admin/settings/project_custom_fields/project_custom_field_mappings_index.rb b/spec/support/pages/admin/settings/project_custom_fields/project_custom_field_mappings_index.rb
new file mode 100644
index 00000000000..cb33a5c6906
--- /dev/null
+++ b/spec/support/pages/admin/settings/project_custom_fields/project_custom_field_mappings_index.rb
@@ -0,0 +1,51 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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 "support/pages/projects/index"
+
+module Pages
+ module Admin
+ module Settings
+ module ProjectCustomFields
+ class ProjectCustomFieldMappingsIndex < ::Pages::Projects::Index
+ def path
+ "/admin/settings/project_custom_fields/#{project_custom_field.id}/project_mappings"
+ end
+
+ def within_row(project)
+ row = page.find("#settings-project-custom-fields-project-custom-field-mapping-row-component-project-#{project.id}")
+ row.hover
+ within row do
+ yield row
+ end
+ end
+ end
+ end
+ end
+ end
+end