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 test cases for handling multiple principals at once in the share WP Modal
Henriette Darge4b3640d1def7
diff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rbindex 2e368207514..3a5c4ebe2b0 100644--- a/spec/features/work_packages/share_spec.rb+++ b/spec/features/work_packages/share_spec.rb@@ -44,11 +44,13 @@ RSpec.describe 'Work package sharing',shared_let(:non_shared_project_user) { create(:user, firstname: 'Non Shared Project', lastname: 'User') }shared_let(:shared_project_user) { create(:user, firstname: 'Shared Project', lastname: 'User') }shared_let(:not_shared_yet_with_user) { create(:user, firstname: 'Not shared Yet', lastname: 'User') }+ shared_let(:another_not_shared_yet_with_user) { create(:user, firstname: 'Not shared Yet', lastname: 'User') }shared_let(:richard) { create(:user, firstname: 'Richard', lastname: 'Hendricks') }shared_let(:dinesh) { create(:user, firstname: 'Dinesh', lastname: 'Chugtai') }shared_let(:gilfoyle) { create(:user, firstname: 'Bertram', lastname: 'Gilfoyle') }shared_let(:not_shared_yet_with_group) { create(:group, members: [richard, dinesh, gilfoyle]) }+ shared_let(:empty_group) { create(:group, members: []) }let(:project) docreate(:project,@@ -108,6 +110,7 @@ RSpec.describe 'Work package sharing',share_modal.expect_not_shared_with(non_shared_project_user)share_modal.expect_not_shared_with(not_shared_yet_with_user)+ share_modal.expect_not_shared_with(another_not_shared_yet_with_user)share_modal.expect_shared_count_of(6)end@@ -224,6 +227,50 @@ RSpec.describe 'Work package sharing',.not_to include(not_shared_yet_with_group, richard)end+ aggregate_failures "Inviting multiple users or groups at once" do+ # Inviting multiple users at once+ share_modal.invite_user([richard, another_not_shared_yet_with_user], 'Edit')++ share_modal.expect_shared_count_of(9)++ share_modal.expect_shared_with(another_not_shared_yet_with_user, 'Edit', position: 1)+ share_modal.expect_shared_with(richard, 'Edit', position: 2)++ # They can be removed again+ share_modal.remove_user(richard)+ share_modal.remove_user(another_not_shared_yet_with_user)++ share_modal.expect_shared_count_of(7)++ # Groups can be added simultaneously as well+ share_modal.invite_user([not_shared_yet_with_group, empty_group], 'Comment')++ share_modal.expect_shared_count_of(9)++ share_modal.expect_shared_with(not_shared_yet_with_group, 'Comment', position: 1)+ share_modal.expect_shared_with(empty_group, 'Comment', position: 2)++ # They can be removed again+ share_modal.remove_user(not_shared_yet_with_group)+ share_modal.remove_user(empty_group)++ share_modal.expect_shared_count_of(7)++ # We can also mix+ share_modal.invite_user([richard, empty_group], 'View')++ share_modal.expect_shared_count_of(9)++ share_modal.expect_shared_with(empty_group, 'View', position: 1)+ share_modal.expect_shared_with(richard, 'View', position: 2)++ # They can be removed again+ share_modal.remove_user(richard)+ share_modal.remove_user(empty_group)++ share_modal.expect_shared_count_of(7)+ end+share_modal.closeclick_button 'Share'@@ -290,10 +337,12 @@ RSpec.describe 'Work package sharing',let(:global_manager_user) { create(:user, global_permissions: %i[manage_user create_user]) }let(:current_user) { global_manager_user }- it 'allows inviting and directly sharing with a user who is not part of the instance yet' do+ before dowork_package_page.visit!click_button 'Share'+ end+ it 'allows inviting and directly sharing with a user who is not part of the instance yet' doshare_modal.expect_openshare_modal.expect_shared_count_of(6)@@ -326,6 +375,66 @@ RSpec.describe 'Work package sharing',share_modal.expect_not_shared_with(new_user)share_modal.expect_shared_count_of(6)end++ it 'allows creating multiple users at once' do+ share_modal.expect_open+ share_modal.expect_shared_count_of(6)++ # Invite two users that does not exist yet+ share_modal.create_and_invite_user(['[email protected]', '[email protected]'], 'Comment')++ # New user is shown in the list of shares+ share_modal.expect_shared_count_of(8)++ # New user is created+ new_users = User.last(2)++ share_modal.expect_shared_with(new_users[0], 'Comment', position: 1)+ share_modal.expect_shared_with(new_users[1], 'Comment', position: 2)++ # The new users can be interacted with+ share_modal.change_role(new_users[0], 'View')+ share_modal.expect_shared_with(new_user, 'View', position: 1)+ share_modal.change_role(new_users[1], 'View')+ share_modal.expect_shared_with(new_user, 'View', position: 2)+ share_modal.expect_shared_count_of(8)++ # The new users can be updated simultaneously+ share_modal.invite_user(new_users, 'Edit')+ share_modal.expect_shared_with(new_users[0], 'Edit', position: 1)+ share_modal.expect_shared_with(new_users[1], 'Edit', position: 2)+ share_modal.expect_shared_count_of(8)++ # The new users can be deleted+ share_modal.remove_user(new_user[0])+ share_modal.expect_not_shared_with(new_user[0])+ share_modal.remove_user(new_user[1])+ share_modal.expect_not_shared_with(new_user[1])+ share_modal.expect_shared_count_of(6)+ end++ it 'allows sharing with an existing user and creating a new one at the same time' do+ share_modal.expect_open+ share_modal.expect_shared_count_of(6)++ # Add an existing and a non-existing user to the automcompleter+ share_modal.select_existing_user not_shared_yet_with_user+ share_modal.select_not_existing_user_option "[email protected]"++ share_modal.select_invite_role('View')+ within share_modal.modal_element do+ click_button 'Share'+ end++ # Two users are added+ share_modal.expect_shared_count_of(8)++ # New user is created+ new_user = User.last++ share_modal.expect_shared_with(new_user, 'View', position: 1)+ share_modal.expect_shared_with(not_shared_yet_with_user, 'View', position: 2)+ endendcontext 'when lacking global invite permission' dodiff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rbindex 27ee6aa4330..34d4dae5765 100644--- a/spec/support/components/work_packages/share_modal.rb+++ b/spec/support/components/work_packages/share_modal.rb@@ -189,12 +189,11 @@ module Componentsendend- def invite_user(user, role_name)+ def invite_user(users, role_name)# Adding a user to the list of shared users- select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),- query: user.firstname,- select_text: user.name,- results_selector: 'body'+ Array(users).each do |user|+ select_existing_user user+ endselect_invite_role(role_name)@@ -205,12 +204,11 @@ module Componentsalias_method :invite_group, :invite_user- def create_and_invite_user(email, role_name)+ def create_and_invite_user(emails, role_name)# Adding a user to the list of shared users- select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),- query: email,- select_text: "Send invite to\"#{email}\"",- results_selector: 'body'+ Array(emails).each do |email|+ select_not_existing_user_option email+ endselect_invite_role(role_name)@@ -325,6 +323,20 @@ module Componentsdef shares_listactive_list.find_by_id('op-share-wp-active-shares')end++ def select_existing_user(user)+ select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),+ query: user.firstname,+ select_text: user.name,+ results_selector: 'body'+ end++ def select_not_existing_user_option(email)+ select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),+ query: email,+ select_text: "Send invite to\"#{email}\"",+ results_selector: 'body'+ endendendend