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 tests for showing a warning when the user limit is reached for the members page and the share modal
Henriette Darge972f6aa95d18
diff --git a/app/components/work_packages/share/invite_user_form_component.html.erb b/app/components/work_packages/share/invite_user_form_component.html.erbindex 980b2c64edf..89d370ada54 100644--- a/app/components/work_packages/share/invite_user_form_component.html.erb+++ b/app/components/work_packages/share/invite_user_form_component.html.erb@@ -26,8 +26,11 @@if OpenProject::Enterprise.user_limit.present?invite_form.with_area('userLimit',- data: { 'user-limit-target': 'limitWarning' },- display: OpenProject::Enterprise.user_limit_reached? ? :block : :none) do+ data: {+ 'user-limit-target': 'limitWarning',+ 'test-selector': 'op-share-wp-user-limit'+ },+ display: :none) doflex_layout do |user_limit_row|user_limit_row.with_column(mr: 2) dorender(Primer::Beta::Octicon.new(icon: :'alert-fill', color: :danger))diff --git a/frontend/src/stimulus/controllers/dynamic/user-limit.controller.ts b/frontend/src/stimulus/controllers/dynamic/user-limit.controller.tsindex f4bbf8658be..d5548ddbcf4 100644--- a/frontend/src/stimulus/controllers/dynamic/user-limit.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/user-limit.controller.ts@@ -41,6 +41,7 @@ export default class UserLimitController extends Controller {static values = {openSeats: Number,+ // Special case, that the autocompleter is a members-autocompleter, instead of the normal user-autocompletermemberAutocompleter: Boolean,};diff --git a/spec/features/members/invitation_spec.rb b/spec/features/members/invitation_spec.rbindex 92cbea34f43..04664fc927b 100644--- a/spec/features/members/invitation_spec.rb+++ b/spec/features/members/invitation_spec.rb@@ -70,6 +70,35 @@ RSpec.describe 'invite user via email', js: true domembers_page.visit!expect(members_page).to have_user 'finkelstein @openproject.com'end++ context 'with an instance with a user limit (regression)' do+ before do+ allow(OpenProject::Enterprise).to receive_messages(+ user_limit: 10,+ user_limit_reached?: false,+ open_seats_count: 1+ )+ end++ it 'shows a warning when the limit is reached' do+ members_page.visit!+ click_button 'Add member'++ members_page.search_and_select_principal! '[email protected]',+ 'Send invite to [email protected]'++ expect(members_page).not_to have_text sanitize_string(I18n.t(:warning_user_limit_reached,+ upgrade_url: OpenProject::Enterprise.upgrade_path)),+ normalize_ws: true++ members_page.search_and_select_principal! '[email protected]',+ 'Send invite to [email protected]'++ expect(members_page).to have_text sanitize_string(I18n.t(:warning_user_limit_reached,+ upgrade_url: OpenProject::Enterprise.upgrade_path)),+ normalize_ws: true+ end+ endendcontext 'with a registered user' dodiff --git a/spec/features/work_packages/share/multi_invite_spec.rb b/spec/features/work_packages/share/multi_invite_spec.rbindex 7aaca0d74ec..c4dda2f66bb 100644--- a/spec/features/work_packages/share/multi_invite_spec.rb+++ b/spec/features/work_packages/share/multi_invite_spec.rb@@ -255,5 +255,28 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(not_shared_yet_with_user, 'View', position: 1)share_modal.expect_shared_with(new_user, 'View', position: 2)end++ context 'and an instance user limit' do+ before do+ allow(OpenProject::Enterprise).to receive_messages(+ user_limit: 10,+ user_limit_reached?: false,+ open_seats_count: 1+ )+ end++ it 'shows a warning as soon as you reach the user limit' do+ share_modal.expect_open+ share_modal.expect_shared_count_of(1)++ # Add a non-existing user to the autocompleter+ share_modal.select_not_existing_user_option "[email protected]"+ share_modal.expect_no_user_limit_warning++ # Add another non-existing user that would exceed the user limit+ share_modal.select_not_existing_user_option "[email protected]"+ share_modal.expect_user_limit_warning(open_seats: 1)+ end+ endendenddiff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rbindex 3bda399e64b..c9a65ea6303 100644--- a/spec/support/components/work_packages/share_modal.rb+++ b/spec/support/components/work_packages/share_modal.rb@@ -347,6 +347,19 @@ module Components.to have_text(I18n.t(:label_enterprise_addon))endend++ def expect_no_user_limit_warning+ within modal_element do+ expect(page).not_to have_css('[data-test-selector="op-share-wp-user-limit"]')+ end+ end++ def expect_user_limit_warning(open_seats:)+ within modal_element do+ expect(page)+ .to have_text(I18n.t('work_package.sharing.text_user_limit_reached', count: open_seats))+ end+ endendendend