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

Add test cases for filtering the shareWP modal

Henriette Dargedc5d8e6c92cd
diff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erb
index bb5065b7c67..2ac033b81f5 100644
--- a/app/components/work_packages/share/modal_body_component.html.erb
+++ b/app/components/work_packages/share/modal_body_component.html.erb
@@ -37,7 +37,8 @@
flex_layout do |header_actions|
header_actions.with_column(mr: 2) do
render(Primer::Alpha::ActionMenu.new(anchor_align: :end,
- color: :subtle)) do |menu|
+ color: :subtle,
+ data: { 'test-selector': 'op-share-wp-filter-type' })) do |menu|
menu.with_show_button(scheme: :invisible, color: :subtle) do |button|
button.with_trailing_action_icon(icon: "triangle-down")
I18n.t('work_package.sharing.filter.type')
@@ -51,7 +52,8 @@
header_actions.with_column do
render(Primer::Alpha::ActionMenu.new(anchor_align: :end,
- color: :subtle)) do |menu|
+ color: :subtle,
+ data: { 'test-selector': 'op-share-wp-filter-role' })) do |menu|
menu.with_show_button(scheme: :invisible, color: :subtle) do |button|
button.with_trailing_action_icon(icon: "triangle-down")
I18n.t('work_package.sharing.filter.role')
diff --git a/spec/features/work_packages/share/filter_spec.rb b/spec/features/work_packages/share/filter_spec.rb
new file mode 100644
index 00000000000..cb75fd1d379
--- /dev/null
+++ b/spec/features/work_packages/share/filter_spec.rb
@@ -0,0 +1,180 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 'Work package sharing',
+ :js,
+ :with_cuprite,
+ with_flag: { work_package_sharing: true } do
+ shared_let(:view_work_package_role) { create(:view_work_package_role) }
+ shared_let(:comment_work_package_role) { create(:comment_work_package_role) }
+ shared_let(:edit_work_package_role) { create(:edit_work_package_role) }
+
+ shared_let(:project_user) { create(:user, firstname: 'Anton') }
+ shared_let(:project_user2) { create(:user, firstname: 'Bertha') }
+ shared_let(:non_project_user) { create(:user, firstname: 'Caesar') }
+ shared_let(:non_project_user2) { create(:user, firstname: 'Dora') }
+
+ shared_let(:shared_project_group) { create(:group, members: [project_user, non_project_user]) }
+ shared_let(:shared_non_project_group) { create(:group, members: [project_user2, non_project_user2]) }
+
+ let(:project) do
+ create(:project,
+ members: { current_user => [sharer_role],
+ project_user => [sharer_role],
+ project_user2 => [sharer_role],
+ shared_project_group => [sharer_role] })
+ end
+
+ let(:sharer_role) do
+ create(:project_role,
+ permissions: %i(view_work_packages
+ view_shared_work_packages
+ share_work_packages))
+ end
+ let(:work_package) do
+ create(:work_package, project:) do |wp|
+ create(:work_package_member, entity: wp, user: project_user, roles: [view_work_package_role])
+ create(:work_package_member, entity: wp, user: project_user2, roles: [comment_work_package_role])
+ create(:work_package_member, entity: wp, user: non_project_user, roles: [edit_work_package_role])
+ create(:work_package_member, entity: wp, user: non_project_user2, roles: [edit_work_package_role])
+ create(:work_package_member, entity: wp, user: shared_project_group, roles: [view_work_package_role])
+ create(:work_package_member, entity: wp, user: shared_non_project_group, roles: [view_work_package_role])
+ end
+ end
+
+ let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
+ let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+
+ current_user { create(:user, firstname: 'Signed in', lastname: 'User') }
+
+ def shared_principals
+ Principal.where(id: Member.of_work_package(work_package).select(:user_id))
+ end
+
+ def inherited_member_roles(group:)
+ MemberRole.where(inherited_from: MemberRole.where(member_id: group.memberships))
+ end
+
+ context 'when having share permission' do
+ before do
+ work_package_page.visit!
+ click_button 'Share'
+ end
+
+ it 'allows to filter for the type' do
+ share_modal.expect_open
+ share_modal.expect_shared_count_of(6)
+
+ # Filter for: project members (users only)
+ share_modal.filter('type', I18n.t('work_package.sharing.filter.project_member'))
+ share_modal.expect_shared_count_of(2)
+
+ share_modal.expect_shared_with(project_user, 'View')
+ share_modal.expect_shared_with(project_user2, 'Comment')
+ share_modal.expect_not_shared_with(non_project_user)
+ share_modal.expect_not_shared_with(non_project_user2)
+ share_modal.expect_not_shared_with(shared_project_group)
+ share_modal.expect_not_shared_with(shared_non_project_group)
+
+ # Filter for: non-project members (users only)
+ share_modal.filter('type', I18n.t('work_package.sharing.filter.not_project_member'))
+ share_modal.expect_shared_count_of(2)
+
+ share_modal.expect_shared_with(non_project_user, 'Edit')
+ share_modal.expect_shared_with(non_project_user2, 'Edit')
+ share_modal.expect_not_shared_with(project_user)
+ share_modal.expect_not_shared_with(project_user2)
+ share_modal.expect_not_shared_with(shared_project_group)
+ share_modal.expect_not_shared_with(shared_non_project_group)
+
+ # Filter for: project members (groups only)
+ share_modal.filter('type', I18n.t('work_package.sharing.filter.project_group'))
+ share_modal.expect_shared_count_of(1)
+
+ share_modal.expect_shared_with(shared_project_group, 'View')
+ share_modal.expect_not_shared_with(project_user)
+ share_modal.expect_not_shared_with(project_user2)
+ share_modal.expect_not_shared_with(non_project_user)
+ share_modal.expect_not_shared_with(non_project_user2)
+ share_modal.expect_not_shared_with(shared_non_project_group)
+
+ # Filter for: non-project members (groups only)
+ share_modal.filter('type', I18n.t('work_package.sharing.filter.not_project_group'))
+ share_modal.expect_shared_count_of(1)
+
+ share_modal.expect_shared_with(shared_non_project_group, 'View')
+ share_modal.expect_not_shared_with(project_user)
+ share_modal.expect_not_shared_with(project_user2)
+ share_modal.expect_not_shared_with(non_project_user)
+ share_modal.expect_not_shared_with(non_project_user2)
+ share_modal.expect_not_shared_with(shared_project_group)
+ end
+
+ it 'allow to filter for the role' do
+ share_modal.expect_open
+ share_modal.expect_shared_count_of(6)
+
+ # Filter for: all principals with Edit permission
+ share_modal.filter('role', I18n.t('work_package.sharing.permissions.edit'))
+ share_modal.expect_shared_count_of(2)
+
+ share_modal.expect_shared_with(non_project_user, 'Edit')
+ share_modal.expect_shared_with(non_project_user2, 'Edit')
+ share_modal.expect_not_shared_with(project_user)
+ share_modal.expect_not_shared_with(project_user2)
+ share_modal.expect_not_shared_with(shared_project_group)
+ share_modal.expect_not_shared_with(shared_non_project_group)
+
+ # Filter for: all principals with View permission
+ share_modal.filter('role', I18n.t('work_package.sharing.permissions.view'))
+ share_modal.expect_shared_count_of(3)
+
+ share_modal.expect_shared_with(project_user, 'View')
+ share_modal.expect_shared_with(shared_project_group, 'View')
+ share_modal.expect_shared_with(shared_non_project_group, 'View')
+ share_modal.expect_not_shared_with(project_user2)
+ share_modal.expect_not_shared_with(non_project_user)
+ share_modal.expect_not_shared_with(non_project_user2)
+
+ # Filter for: all principals with Comment permission
+ share_modal.filter('role', I18n.t('work_package.sharing.permissions.view'))
+ share_modal.expect_shared_count_of(1)
+
+ share_modal.expect_shared_with(project_user2, 'Comment')
+ share_modal.expect_not_shared_with(project_user)
+ share_modal.expect_not_shared_with(non_project_user)
+ share_modal.expect_not_shared_with(non_project_user2)
+ share_modal.expect_not_shared_with(shared_project_group)
+ share_modal.expect_not_shared_with(shared_non_project_group)
+ end
+ end
+end
diff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rb
index 3b7a086d48a..d8ef2741e02 100644
--- a/spec/support/components/work_packages/share_modal.rb
+++ b/spec/support/components/work_packages/share_modal.rb
@@ -238,6 +238,15 @@ module Components
end
end
+ def filter(filter_name, value)
+ within modal_element.find("[data-test-selector='op-share-wp-filter-#{filter_name}']") do
+ # Open the ActionMenu
+ click_button filter_name.capitalize
+
+ find('.ActionListContent', text: value).click
+ end
+ end
+
def close
within modal_element do
click_button 'Close'