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

adapt feature spec to also cover adding shares

ulferts129ba341dbe7
diff --git a/app/components/work_packages/share/modal_component.html.erb b/app/components/work_packages/share/modal_component.html.erb
index 303250b489e..d958cb83461 100644
--- a/app/components/work_packages/share/modal_component.html.erb
+++ b/app/components/work_packages/share/modal_component.html.erb
@@ -16,9 +16,9 @@
if shared_users.empty?
# Todo: show empty state?
else
- modal_content.with_row(mt: 3) do
+ modal_content.with_row(mt: 3, data: { 'test-selector': 'op-share-wp-active-list'}) do
render(Primer::Beta::BorderBox.new) do |invited_user_list|
- invited_user_list.with_header(color: :subtle) do
+ invited_user_list.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-active-count'}) do
I18n.t('work_package.sharing.count', count: shared_users.count)
end
diff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rb
index 70bd1d5923f..848e0890a73 100644
--- a/spec/features/work_packages/share_spec.rb
+++ b/spec/features/work_packages/share_spec.rb
@@ -27,14 +27,16 @@
# ++
require 'spec_helper'
-require_relative '../../support/pages/work_packages/full_work_package'
-require_relative '../../support/components/common/modal'
+require 'support/pages/work_packages/full_work_package'
+require 'support/components/work_packages/share_modal'
RSpec.describe 'Work package sharing', :js do
let(:sharer_role) do
+ # TODO: Remove necessity to have manage_members permission
create(:role,
permissions: %i(view_work_packages
- share_work_packages))
+ share_work_packages
+ manage_members))
end
let(:view_work_package_role) { create(:view_work_package_role) }
let(:comment_work_package_role) { create(:comment_work_package_role) }
@@ -57,16 +59,21 @@ RSpec.describe 'Work package sharing', :js do
end
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::Common::Modal.new }
+ let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
- let!(:view_user) { create(:user) }
- let!(:comment_user) { create(:user) }
- let!(:edit_user) { create(:user) }
- let!(:non_shared_project_user) { create(:user) }
- let!(:shared_project_user) { create(:user) }
+ let!(:view_user) { create(:user, firstname: 'View', lastname: 'User') }
+ let!(:comment_user) { create(:user, firstname: 'Comment', lastname: 'User') }
+ let!(:edit_user) { create(:user, firstname: 'Edit', lastname: 'User') }
+ let!(:non_shared_project_user) { create(:user, firstname: 'Non Shared Project', lastname: 'User') }
+ let!(:shared_project_user) { create(:user, firstname: 'Shared Project', lastname: 'User') }
+ let!(:not_shared_yet_with_user) { create(:user, firstname: 'Not shared Yet', lastname: 'User') }
current_user { create(:user) }
+ # TODO:
+ # - Check title
+ # - Check roles
+ # - Delete case
it 'allows seeing and administrating sharing' do
work_package_page.visit!
@@ -76,14 +83,21 @@ RSpec.describe 'Work package sharing', :js do
click_button 'Share'
share_modal.expect_open
- share_modal.expect_title('Share work package')
- # TODO: Move into specific share modal support class
- share_modal.expect_text(view_user.name)
- share_modal.expect_text(comment_user.name)
- share_modal.expect_text(edit_user.name)
- within share_modal.modal_element do
- expect(page).not_to have_text(non_shared_project_user.name)
- end
- share_modal.expect_text(shared_project_user.name)
+ share_modal.expect_shared_with(view_user)
+ share_modal.expect_shared_with(comment_user)
+ share_modal.expect_shared_with(edit_user)
+ share_modal.expect_shared_with(shared_project_user)
+
+ share_modal.expect_not_shared_with(non_shared_project_user)
+ share_modal.expect_not_shared_with(not_shared_yet_with_user)
+
+ share_modal.expect_shared_count_of(4)
+
+ # Inviting a user will lead to that user being listed together with the rest of the shared with users.
+ share_modal.invite_user(not_shared_yet_with_user)
+
+ share_modal.expect_shared_with(not_shared_yet_with_user)
+
+ share_modal.expect_shared_count_of(5)
end
end
diff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rb
new file mode 100644
index 00000000000..9b4a00cf7a6
--- /dev/null
+++ b/spec/support/components/work_packages/share_modal.rb
@@ -0,0 +1,86 @@
+# -- 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 'support/components/common/modal'
+require 'support/components/autocompleter/ng_select_autocomplete_helpers'
+
+module Components
+ module WorkPackages
+ class ShareModal < Components::Common::Modal
+ include Capybara::DSL
+ include Capybara::RSpecMatchers
+ include RSpec::Matchers
+ include Components::Autocompleter::NgSelectAutocompleteHelpers
+
+ attr_reader :work_package
+
+ def initialize(work_package)
+ super()
+
+ @work_package = work_package
+ end
+
+ # TODO: add role selection
+ def invite_user(user)
+ # Adding a user to the list of shared users
+ select_autocomplete page.find('[data-test-selector="op-share-wp-user-autocomplete"]'),
+ query: user.firstname,
+ select_text: user.name,
+ results_selector: 'body'
+
+ within modal_element do
+ click_button 'Invite'
+ end
+ end
+
+ def expect_shared_with(user)
+ within active_list do
+ expect(page)
+ .to have_text(user.name)
+ end
+ end
+
+ def expect_not_shared_with(user)
+ within active_list do
+ expect(page)
+ .not_to have_text(user.name)
+ end
+ end
+
+ def expect_shared_count_of(count)
+ expect(active_list)
+ .to have_selector('[data-test-selector="op-share-wp-active-count"]', text: "#{count} members")
+ end
+
+ def active_list
+ modal_element
+ .find('[data-test-selector="op-share-wp-active-list"]')
+ end
+ end
+ end
+end