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

Improve coverage for "Share" button rendering behavior

Aaron Contrerasa4ffe2b46594
diff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rb
index 0f55996571b..63cf4b8e8ba 100644
--- a/spec/features/work_packages/share_spec.rb
+++ b/spec/features/work_packages/share_spec.rb
@@ -268,53 +268,72 @@ RSpec.describe 'Work package sharing',
end
end
- context 'when lacking share permission' do
- context 'with :view_shared_work_packages permission' do
- let(:sharer_role) do
- create(:project_role,
- permissions: %i(view_work_packages
- view_shared_work_packages))
- end
- it 'allows seeing shares but not editing' do
- work_package_page.visit!
+ context 'when lacking share permission but having the viewing permission' do
+ let(:sharer_role) do
+ create(:project_role,
+ permissions: %i(view_work_packages
+ view_shared_work_packages))
+ end
- # Clicking on the share button opens a modal which lists all of the users a work package
- # is explicitly shared with.
- # Project members are not listed unless the work package is also shared with them explicitly.
- click_button 'Share'
+ it 'allows seeing shares but not editing' do
+ work_package_page.visit!
- share_modal.expect_open
- share_modal.expect_shared_with(view_user, editable: false)
- share_modal.expect_shared_with(comment_user, editable: false)
- share_modal.expect_shared_with(dinesh, editable: false)
- share_modal.expect_shared_with(edit_user, editable: false)
- share_modal.expect_shared_with(shared_project_user, editable: false)
- share_modal.expect_shared_with(current_user, editable: false)
+ # Clicking on the share button opens a modal which lists all of the users a work package
+ # is explicitly shared with.
+ # Project members are not listed unless the work package is also shared with them explicitly.
+ work_package_page.click_share_button
- share_modal.expect_not_shared_with(non_shared_project_user)
- share_modal.expect_not_shared_with(not_shared_yet_with_user)
+ share_modal.expect_open
+ share_modal.expect_shared_with(view_user, editable: false)
+ share_modal.expect_shared_with(comment_user, editable: false)
+ share_modal.expect_shared_with(dinesh, editable: false)
+ share_modal.expect_shared_with(edit_user, editable: false)
+ share_modal.expect_shared_with(shared_project_user, editable: false)
+ share_modal.expect_shared_with(current_user, editable: false)
- share_modal.expect_shared_count_of(6)
+ share_modal.expect_not_shared_with(non_shared_project_user)
+ share_modal.expect_not_shared_with(not_shared_yet_with_user)
- share_modal.expect_no_invite_option
- end
+ share_modal.expect_shared_count_of(6)
+
+ share_modal.expect_no_invite_option
end
+ end
+
+ shared_examples_for "'Share' button is not rendered" do
+ it "doesn't render the 'Share' button" do
+ work_package_page.visit!
- context 'without the :view_shared_work_packages permission' do
- let(:sharer_role) do
- create(:project_role,
- permissions: %i(view_work_packages))
+ within work_package_page.toolbar do
+ # The button's rendering is conditional to the
+ # response of the capabilities request for +shares/index+.
+ # Hence, not waiting for the network to be idle could lead to
+ # false positives on the button not being rendered because
+ # its request is still pending.
+ wait_for_network_idle(timeout: 10)
+ expect(page).not_to have_button("Share")
end
+ end
+ end
- it 'does not render the "Share" button to open the modal' do
- work_package_page.visit!
+ context 'without the feature flag enabled', with_flag: { work_package_sharing: false } do
+ let(:sharer_role) do
+ create(:project_role,
+ permissions: %i(view_work_packages
+ view_shared_work_packages))
+ end
- within work_package_page.toolbar do
- expect(page).not_to have_button('Share', wait: 0)
- end
- end
+ it_behaves_like "'Share' button is not rendered"
+ end
+
+ context "without the viewing permission" do
+ let(:sharer_role) do
+ create(:project_role,
+ permissions: %i(view_work_packages))
end
+
+ it_behaves_like "'Share' button is not rendered"
end
context 'when having global invite permission' do