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
Add specs for Bulk Selection Behavior
Aaron Contreras4d1efd97bcc2
diff --git a/spec/features/work_packages/share/bulk_sharing_spec.rb b/spec/features/work_packages/share/bulk_sharing_spec.rbnew file mode 100644index 00000000000..12cba0535c5--- /dev/null+++ b/spec/features/work_packages/share/bulk_sharing_spec.rb@@ -0,0 +1,153 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 Packages', 'Bulk 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(:sharer_role) do+ create(:project_role, permissions: %i[view_work_packages+ view_shared_work_packages+ share_work_packages])+ end++ shared_let(:sharer) { create(:user, firstname: 'Sharer', lastname: 'User') }+ shared_let(:project) { create(:project, members: { sharer => [sharer_role] }) }++ shared_let(:dinesh) { create(:user, firstname: 'Dinesh', lastname: 'Chugtai') }+ shared_let(:gilfoyle) { create(:user, firstname: 'Bertram', lastname: 'Gilfoyle') }+ shared_let(:richard) { create(:user, firstname: 'Richard', lastname: 'Hendricks') }++ shared_let(:work_package) do+ create(:work_package, project:) do |wp|+ create(:work_package_member, principal: richard, entity: wp, roles: [view_work_package_role])+ create(:work_package_member, principal: dinesh, entity: wp, roles: [edit_work_package_role])+ create(:work_package_member, principal: gilfoyle, entity: wp, roles: [comment_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 { sharer }++ context 'when having share permission' do+ it 'allows administrating shares in bulk' do+ work_package_page.visit!++ click_button 'Share'+ share_modal.expect_open+ share_modal.expect_shared_count_of(3)++ aggregate_failures "Selection behavior" do+ # Selecting one individually+ share_modal.select_shares(richard)+ share_modal.expect_selected(richard)+ share_modal.expect_selected_count_of(1)+ share_modal.expect_select_all_untoggled++ # Toggling all selects all+ share_modal.toggle_select_all+ share_modal.expect_selected(richard, dinesh, gilfoyle)+ share_modal.expect_selected_count_of(3)+ share_modal.expect_select_all_toggled++ # Deselecting one individually+ share_modal.deselect_shares(richard)+ share_modal.expect_selected(dinesh, gilfoyle)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_select_all_untoggled++ # Re-selecting the missing share+ share_modal.select_shares(richard)+ share_modal.expect_selected(richard, dinesh, gilfoyle)+ share_modal.expect_selected_count_of(3)+ share_modal.expect_select_all_toggled++ # De-selecting all+ share_modal.toggle_select_all+ share_modal.expect_deselected(richard, dinesh, gilfoyle)+ share_modal.expect_shared_count_of(3)+ share_modal.expect_select_all_untoggled++ # Re-selecting all+ share_modal.toggle_select_all+ share_modal.expect_selected(richard, dinesh, gilfoyle)+ share_modal.expect_selected_count_of(3)+ share_modal.expect_select_all_toggled++ # De-selecting all individually+ share_modal.deselect_shares(richard, dinesh, gilfoyle)+ share_modal.expect_shared_count_of(3)+ share_modal.expect_select_all_untoggled+ end++ aggregate_failures "Preserving selected states when performing individual updates" do+ share_modal.select_shares(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_select_all_untoggled++ share_modal.remove_user(gilfoyle)+ share_modal.expect_not_shared_with(gilfoyle)++ share_modal.expect_selected(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_select_all_toggled++ share_modal.invite_user(gilfoyle, 'Comment')+ share_modal.expect_shared_with(gilfoyle)+ share_modal.expect_selected(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_select_all_untoggled+ end++ aggregate_failures "Bulk deletion" do+ # Richard and Dinesh already selected from above+ share_modal.bulk_remove++ share_modal.expect_not_shared_with(richard, dinesh)+ share_modal.expect_shared_with(gilfoyle)+ share_modal.expect_shared_count_of(1)++ share_modal.select_shares(gilfoyle)+ share_modal.expect_selected_count_of(1)+ share_modal.expect_select_all_toggled+ share_modal.bulk_remove++ share_modal.expect_blankslate+ end+ end+ end+enddiff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rbindex 6b7de23d113..c7de3e05ba3 100644--- a/spec/features/work_packages/share_spec.rb+++ b/spec/features/work_packages/share_spec.rb@@ -192,6 +192,8 @@ RSpec.describe 'Work package sharing',# Updating a group's share role also propagates to the inherited member roles of# its usersshare_modal.change_role(not_shared_yet_with_group, 'Comment')+ wait_for_network_idle+share_modal.expect_shared_with(not_shared_yet_with_group, 'Comment')share_modal.expect_shared_count_of(8)expect(inherited_member_roles(group: not_shared_yet_with_group))@@ -206,12 +208,13 @@ RSpec.describe 'Work package sharing',# When removing a group's share, its users also get their inherited member roles removed# while keeping member roles that were granted independently of the groupshare_modal.remove_user(not_shared_yet_with_group)+ wait_for_network_idle+share_modal.expect_not_shared_with(not_shared_yet_with_group)share_modal.expect_not_shared_with(richard)share_modal.expect_shared_with(dinesh, 'Edit')share_modal.expect_shared_with(gilfoyle, 'Comment')share_modal.expect_shared_count_of(7)-expect(inherited_member_roles(group: not_shared_yet_with_group)).to be_emptydiff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rbindex 216dba6d78e..697a38482d8 100644--- a/spec/support/components/work_packages/share_modal.rb+++ b/spec/support/components/work_packages/share_modal.rb@@ -45,6 +45,77 @@ module Components@work_package = work_packageend+ def select_shares(*principals)+ within shares_list do+ principals.each do |principal|+ check principal.name+ end+ end+ end++ def deselect_shares(*principals)+ within shares_list do+ principals.each do |principal|+ uncheck principal.name+ end+ end+ end++ def toggle_select_all+ within shares_header do+ if page.find_field('toggle_all').checked?+ uncheck 'toggle_all'+ else+ check 'toggle_all'+ end+ end+ end++ def expect_selected(*principals)+ within shares_list do+ principals.each do |principal|+ expect(page).to have_checked_field(principal.name)+ end+ end+ end++ def expect_deselected(*principals)+ within shares_list do+ principals.each do |principal|+ expect(page).to have_unchecked_field(principal.name)+ end+ end+ end++ def expect_selected_count_of(count)+ expect(shares_header)+ .to have_text("#{count} selected")+ end++ def expect_select_all_toggled+ within shares_header do+ expect(page).to have_checked_field('toggle_all')+ end+ end++ def expect_select_all_untoggled+ within shares_header do+ expect(page).to have_unchecked_field('toggle_all')+ end+ end++ def bulk_remove+ within shares_header do+ click_button 'Remove'+ end+ end++ def expect_blankslate+ within_modal do+ expect(page).to have_text(I18n.t('work_package.sharing.text_empty_state_description'))+ end+ end+def invite_user(user, role_name)# Adding a user to the list of shared usersselect_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),@@ -115,16 +186,18 @@ module Componentsendend- def expect_not_shared_with(user)+ def expect_not_shared_with(*principals)within shares_list do- expect(page)- .not_to have_text(user.name)+ principals.each do |principal|+ expect(page)+ .not_to have_text(principal.name)+ endendenddef expect_shared_count_of(count)- expect(active_list)- .to have_css('[data-test-selector="op-share-wp-active-count"]', text: "#{count} users")+ expect(shares_header)+ .to have_text(I18n.t('work_package.sharing.count', count:))enddef expect_no_invite_option@@ -135,7 +208,7 @@ module Componentsenddef user_row(user)- modal_element+ shares_list.find("[data-test-selector=\"op-share-wp-active-user-#{user.id}\"]")end@@ -144,6 +217,14 @@ module Components.find('[data-test-selector="op-share-wp-active-list"]')end+ def shares_header+ active_list.find('[data-test-selector="op-share-wp-header"]')+ end++ def shares_counter+ shares_header.find('[data-test-selector="op-share-wp-active-count"]')+ end+def shares_listactive_list.find_by_id('op-share-wp-active-shares')end