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#53117]: add gitlab tab feature spec

Kabiru Mwenjabee5a122f8ee
diff --git a/modules/gitlab_integration/spec/factories/gitlab_pipelines.rb b/modules/gitlab_integration/spec/factories/gitlab_pipelines.rb
index 89a53928f3a..523c03721f5 100644
--- a/modules/gitlab_integration/spec/factories/gitlab_pipelines.rb
+++ b/modules/gitlab_integration/spec/factories/gitlab_pipelines.rb
@@ -41,6 +41,7 @@ FactoryBot.define do
status { 'pending' }
started_at { 1.hour.ago }
completed_at { nil }
+ project_id { 1 }
ci_details do
build_list(:gitlab_pipeline_ci_detail, 3)
diff --git a/modules/gitlab_integration/spec/features/work_package_gitlab_tab_spec.rb b/modules/gitlab_integration/spec/features/work_package_gitlab_tab_spec.rb
new file mode 100644
index 00000000000..ce8505b944a
--- /dev/null
+++ b/modules/gitlab_integration/spec/features/work_package_gitlab_tab_spec.rb
@@ -0,0 +1,159 @@
+#-- 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'
+require_module_spec_helper
+require_relative '../support/pages/work_package_gitlab_tab'
+
+RSpec.describe 'Open the Gitlab tab', :js do
+ let(:user) { create(:user, member_with_roles: { project => role }) }
+
+ let(:role) do
+ create(:project_role,
+ permissions: %i(view_work_packages
+ add_work_package_notes
+ show_gitlab_content))
+ end
+
+ let(:project) do
+ create(:project,
+ enabled_module_names: %i[work_package_tracking gitlab])
+ end
+
+ let(:work_package) { create(:work_package, project:, subject: 'A test work_package') }
+
+ let(:tabs) { Components::WorkPackages::Tabs.new(work_package) }
+ let(:gitlab_tab_element) { find('.op-tab-row--link_selected', text: 'GITLAB') }
+ let(:gitlab_tab) { Pages::GitlabTab.new(work_package.id) }
+
+ let(:issue) { create(:gitlab_issue, :open, work_packages: [work_package], title: 'A Test Issue title') }
+ let(:merge_request) { create(:gitlab_merge_request, :open, work_packages: [work_package], title: 'A Test MR title') }
+
+ let(:pipeline) do
+ create(:gitlab_pipeline, gitlab_merge_request: merge_request, name: 'a pipeline name')
+ end
+
+ shared_examples_for "a gitlab tab" do
+ before do
+ issue
+ pipeline
+ login_as(user)
+ end
+
+ # compares the clipboard content by drafting a new comment, pressing ctrl+v and
+ # comparing the pasted content against the provided text
+ def expect_clipboard_content(text)
+ work_package_page.switch_to_tab(tab: 'activity')
+
+ work_package_page.trigger_edit_comment
+ work_package_page.update_comment(' ') # ensure the comment editor is fully loaded
+ gitlab_tab.paste_clipboard_content
+ expect(work_package_page.add_comment_container).to have_content(text)
+
+ work_package_page.switch_to_tab(tab: 'gitlab')
+ end
+
+ it 'shows the gitlab tab when the user is allowed to see it' do
+ work_package_page.visit!
+ work_package_page.switch_to_tab(tab: 'gitlab')
+
+ tabs.expect_counter(gitlab_tab_element, 2)
+
+ gitlab_tab.git_actions_menu_button.click
+ gitlab_tab.git_actions_copy_branch_name_button.click
+ expect(page).to have_text('Copied!')
+ expect_clipboard_content("#{work_package.type.name.downcase}/#{work_package.id}-a-test-work_package")
+
+ within('.op-issue') do
+ expect(page).to have_text('A Test Issue title')
+ expect(page).to have_text('Open')
+ end
+
+ within('.op-merge-request') do
+ expect(page).to have_text('A Test MR title')
+ expect(page).to have_text('Pending')
+ end
+ end
+
+ context 'when there are no merge requests or issues' do
+ let(:pipeline) { nil }
+ let(:merge_request) { nil }
+ let(:issue) { nil }
+
+ it 'shows the gitlab tab with an empty message' do
+ work_package_page.visit!
+ work_package_page.switch_to_tab(tab: 'gitlab')
+ tabs.expect_no_counter(gitlab_tab_element)
+
+ expect(page).to have_content('There are no issues linked yet.')
+ expect(page).to have_content("Link an existing issue by using the code OP##{work_package.id} " \
+ "(or PP##{work_package.id} for private links) in the issue title/description " \
+ "or create a new issue")
+
+ expect(page).to have_content('There are no merge requests')
+ expect(page).to have_content("Link an existing MR by using the code OP##{work_package.id}")
+ end
+ end
+
+ context 'when the user does not have the permissions to see the gitlab tab' do
+ let(:role) do
+ create(:project_role,
+ permissions: %i(view_work_packages
+ add_work_package_notes))
+ end
+
+ it 'does not show the gitlab tab' do
+ work_package_page.visit!
+
+ gitlab_tab.expect_tab_not_present
+ end
+ end
+
+ context 'when the gitlab integration is not enabled for the project' do
+ let(:project) { create(:project, disable_modules: 'gitlab') }
+
+ it 'does not show the gitlab tab' do
+ work_package_page.visit!
+
+ gitlab_tab.expect_tab_not_present
+ end
+ end
+ end
+
+ describe 'work package full view' do
+ let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
+
+ it_behaves_like 'a gitlab tab'
+ end
+
+ describe 'work package split view' do
+ let(:work_package_page) { Pages::SplitWorkPackage.new(work_package) }
+
+ it_behaves_like 'a gitlab tab'
+ end
+end
diff --git a/modules/gitlab_integration/spec/support/pages/work_package_gitlab_tab.rb b/modules/gitlab_integration/spec/support/pages/work_package_gitlab_tab.rb
new file mode 100644
index 00000000000..4792431eeef
--- /dev/null
+++ b/modules/gitlab_integration/spec/support/pages/work_package_gitlab_tab.rb
@@ -0,0 +1,68 @@
+#-- 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 'rbconfig'
+require 'support/pages/page'
+
+module Pages
+ class GitlabTab < Page
+ attr_reader :work_package_id
+
+ def initialize(work_package_id)
+ super()
+ @work_package_id = work_package_id
+ end
+
+ def path
+ "/work_packages/#{work_package_id}/tabs/gitlab"
+ end
+
+ def git_actions_menu_button
+ find('.gitlab-git-copy:not([disabled])', text: 'Git')
+ end
+
+ def git_actions_copy_branch_name_button
+ find('.git-actions-menu .copy-button:not([disabled])', match: :first)
+ end
+
+ def paste_clipboard_content
+ meta_key = osx? ? :command : :control
+ page.send_keys(meta_key, 'v')
+ end
+
+ def expect_tab_not_present
+ expect(page).to have_no_css('.op-tab-row--link', text: 'GITLAB')
+ end
+
+ private
+
+ def osx?
+ RbConfig::CONFIG['host_os'].include?('darwin')
+ end
+ end
+end