OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/modules/boards/spec/features/action_boards/subproject_board_spec.rb

251 lines
8.7 KiB

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
require_relative './../support//board_index_page'
require_relative './../support/board_page'
4 years ago
describe 'Subproject action board', type: :feature, js: true do
let(:user) do
FactoryBot.create(:user,
member_in_project: project,
member_through_role: role)
end
let(:type) { FactoryBot.create(:type_standard) }
let(:project) do
FactoryBot.create(:project, name: 'Parent', types: [type], enabled_module_names: %i[work_package_tracking board_view])
end
let(:subproject1) do
FactoryBot.create(:project, parent: project, name: 'Child 1', types: [type], enabled_module_names: %i[work_package_tracking])
end
let(:subproject2) do
FactoryBot.create(:project, parent: project, name: 'Child 2', types: [type], enabled_module_names: %i[work_package_tracking])
end
let(:role) { FactoryBot.create(:role, permissions: permissions) }
let(:board_index) { Pages::BoardIndex.new(project) }
let(:permissions) do
%i[show_board_views manage_board_views add_work_packages
4 years ago
edit_work_packages view_work_packages manage_public_queries move_work_packages]
end
let!(:priority) { FactoryBot.create :default_priority }
let!(:open_status) { FactoryBot.create :default_status, name: 'Open' }
4 years ago
let!(:work_package) { FactoryBot.create :work_package, project: subproject1, subject: 'Foo', status: open_status }
before do
with_enterprise_token :board_view
4 years ago
subproject1
subproject2
project.reload
login_as(user)
end
4 years ago
context 'without the move_work_packages permission' do
let(:permissions) do
4 years ago
%i[show_board_views manage_board_views add_work_packages
edit_work_packages view_work_packages manage_public_queries]
end
4 years ago
let(:user) do
FactoryBot.create(:user,
member_in_projects: [project, subproject1, subproject2],
member_through_role: role)
end
it 'does not allow to move work packages' do
board_index.visit!
# Create new board
4 years ago
board_page = board_index.create_board action: :Subproject, expect_empty: true
# Expect we can add a child 1
board_page.add_list option: 'Child 1'
board_page.expect_list 'Child 1'
4 years ago
# Expect one work package there
board_page.expect_card 'Child 1', 'Foo'
board_page.expect_movable 'Child 1', 'Foo', movable: false
end
end
4 years ago
context 'with permissions in all subprojects' do
let(:user) do
FactoryBot.create(:user,
member_in_projects: [project, subproject1, subproject2],
member_through_role: role)
end
4 years ago
let(:only_parent_user) do
FactoryBot.create(:user,
member_in_project: project,
member_through_role: role)
end
it 'allows management of subproject work packages' do
board_index.visit!
4 years ago
# Create new board
board_page = board_index.create_board action: :Subproject, expect_empty: true
4 years ago
# Expect we can add a child 1
board_page.add_list option: 'Child 1'
board_page.expect_list 'Child 1'
4 years ago
# Expect one work package there
board_page.expect_card 'Child 1', 'Foo'
4 years ago
# Expect move permission to be granted
board_page.expect_movable 'Child 1', 'Foo', movable: true
board_page.board(reload: true) do |board|
expect(board.name).to eq 'Action board (subproject)'
4 years ago
queries = board.contained_queries
expect(queries.count).to eq(1)
query = queries.first
expect(query.name).to eq 'Child 1'
expect(query.filters.first.name).to eq :only_subproject_id
expect(query.filters.first.values).to eq [subproject1.id.to_s]
end
# Create new list
4 years ago
board_page.add_list option: 'Child 2'
board_page.expect_list 'Child 2'
board_page.expect_cards_in_order 'Child 2'
# Add item
4 years ago
board_page.add_card 'Child 1', 'Task 1'
sleep 2
# Expect added to query
queries = board_page.board(reload: true).contained_queries
4 years ago
expect(queries.count).to eq 2
first = queries.find_by(name: 'Child 1')
second = queries.find_by(name: 'Child 2')
expect(first.ordered_work_packages.count).to eq(1)
expect(second.ordered_work_packages).to be_empty
# Expect work package to be saved in query first
4 years ago
subjects = WorkPackage.where(id: first.ordered_work_packages.pluck(:work_package_id)).pluck(:subject, :project_id)
expect(subjects).to match_array [['Task 1', subproject1.id]]
# Move item to Child 2 list
board_page.move_card(0, from: 'Child 1', to: 'Child 2')
4 years ago
board_page.expect_card('Child 1', 'Task 1', present: false)
board_page.expect_card('Child 2', 'Task 1', present: true)
# Expect work package to be saved in query second
retry_block do
4 years ago
raise "first should be empty" if first.reload.ordered_work_packages.any?
raise "second should have one item" if second.reload.ordered_work_packages.count != 1
end
4 years ago
subjects = WorkPackage.where(id: second.ordered_work_packages.pluck(:work_package_id)).pluck(:subject, :project_id)
expect(subjects).to match_array [['Task 1', subproject2.id]]
end
end
context 'with permissions in only one subproject' do
let(:user) do
FactoryBot.create(:user,
# The membership in subproject2 gets removed later on
member_in_projects: [project, subproject1, subproject2],
member_through_role: role)
end
let!(:board) do
FactoryBot.create(:subproject_board,
project: project,
projects_columns: [subproject1, subproject2])
end
let(:board_page) { Pages::Board.new(board) }
let!(:invisible_work_package) do
FactoryBot.create :work_package, project: subproject2, status: open_status
end
before do
# The membership needs to first be present in order to create the board
# which is created as the current_user, in this case :user.
# After setup, we do not want to have the user to have the permissions within the project any more
# as this is the goal of the test.
Member.where(project: subproject2, principal: user).destroy_all
end
it 'displays only the columns for the projects in which the current user has permission' do
board_page.visit!
board_page.expect_card subproject1.name, work_package.subject
# No error is to be displayed as erroneous columns are filtered out
expect(page).not_to have_selector('.notification-box.-error')
board_page.expect_no_list(subproject2.name)
expect(page)
.to have_no_content invisible_work_package.subject
end
end
context 'with an archived subproject' do
let(:user) do
FactoryBot.create(:user,
member_in_projects: [project, subproject1, subproject2],
member_through_role: role)
end
let!(:board) do
FactoryBot.create(:subproject_board,
project: project,
projects_columns: [subproject1])
end
let(:board_page) { Pages::Board.new(board) }
before do
# Archive the second project
subproject2.update! active: false
end
it 'displays only the columns for the projects in which the current user has permission' do
board_page.visit!
board_page.expect_list subproject1.name
board_page.expect_no_list(subproject2.name)
board_page.open_and_fill_add_list_modal subproject2.name
expect(page).to have_no_selector('.ng-option', text: subproject2.name)
end
end
end