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/spec/features/work_packages/details/relations/relations_spec.rb

282 lines
10 KiB

Add relations tables to Types via form configuration (#6773) * WIP: PrecedesFilter and FollowsFilter for WorkPackages * Create Type Form Groups per Query Type * generalize filters on relations avoiding alias * fix flickering spec * Rename dependency represeners for Follower and Predecessor Filters * Allow configuring templated queries within query configuring modal * Use `{id}` as templated value, instead of a now deprecated `templated` string * Rewrite ParentFilter to follow same structure as other relation filters. * Set Follower and Predecessor filters as hidden in Frontend * Default query shall show closed WPs, too * Remove relation filter type selection from form configuration view as we extend query configuration modal instead. * Allow ExternalQueryConfiguration to be more specific and prepend relation filters in its modal. * Quick unrelated fix on the way: the instruction text should start below the columns input and not to the right of it * - Add all missing relation filters. - Use verbs for naming instead of nouns to stay consistent with UI. * fix typo * Add relation filters to hidden filters and fix a rebase bug * Typo in docs * Fix broken rebase conflict resolution * Add part of and includes filter * adding specs for relation filters * rename RelatesFilter to RelatesToFilter * Rename shared example as direction does not matter anymore. * Fix spec for IncludesFilter * Fix name conflict for `includes` by calling typed_dag's `direct` later. * Fix shared filter examples as the parent filter does not get added per default anymore. * Fix spec after renaming PredecessorFilter to PrecedesFilter * Fix integration spec for type configuration form * Add filter dependency specs * Differentiate between WorkPackageFormChildrenQueryGroup and WorkPackageRelationQueryGroup types * Create inline-create for relation tables * Rewrite filters to use actual relation_type as key * Reload relations on change, change symbols * Fix relation filter i18n strings * Test presence of all relation filters frontend. * Extend integration test for form configuration to not only cover hierarchy, but also undirectional and directional relation types. * Consistent naming of filter dependency representer files * Satisfy codeclimate * Add missing copyright notes * Fixing PartofFilter and its specs * Reverse relation direction when created inline * WIP integration test for Relation Query Component and Children Query Component. * Correctly reload children tables when refreshed * Fix FilterOnUndirectedMixin * Fix removing of relation from embedded table after reload * Adding intergration tests for removing and adding relation or children, initiated form either embedded table or relations tab. * Fix specs * Fix implementation of duplicates and duplicated They are reversed in typed_dag and causes confusion [ci skip]
6 years ago
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
Add relations tables to Types via form configuration (#6773) * WIP: PrecedesFilter and FollowsFilter for WorkPackages * Create Type Form Groups per Query Type * generalize filters on relations avoiding alias * fix flickering spec * Rename dependency represeners for Follower and Predecessor Filters * Allow configuring templated queries within query configuring modal * Use `{id}` as templated value, instead of a now deprecated `templated` string * Rewrite ParentFilter to follow same structure as other relation filters. * Set Follower and Predecessor filters as hidden in Frontend * Default query shall show closed WPs, too * Remove relation filter type selection from form configuration view as we extend query configuration modal instead. * Allow ExternalQueryConfiguration to be more specific and prepend relation filters in its modal. * Quick unrelated fix on the way: the instruction text should start below the columns input and not to the right of it * - Add all missing relation filters. - Use verbs for naming instead of nouns to stay consistent with UI. * fix typo * Add relation filters to hidden filters and fix a rebase bug * Typo in docs * Fix broken rebase conflict resolution * Add part of and includes filter * adding specs for relation filters * rename RelatesFilter to RelatesToFilter * Rename shared example as direction does not matter anymore. * Fix spec for IncludesFilter * Fix name conflict for `includes` by calling typed_dag's `direct` later. * Fix shared filter examples as the parent filter does not get added per default anymore. * Fix spec after renaming PredecessorFilter to PrecedesFilter * Fix integration spec for type configuration form * Add filter dependency specs * Differentiate between WorkPackageFormChildrenQueryGroup and WorkPackageRelationQueryGroup types * Create inline-create for relation tables * Rewrite filters to use actual relation_type as key * Reload relations on change, change symbols * Fix relation filter i18n strings * Test presence of all relation filters frontend. * Extend integration test for form configuration to not only cover hierarchy, but also undirectional and directional relation types. * Consistent naming of filter dependency representer files * Satisfy codeclimate * Add missing copyright notes * Fixing PartofFilter and its specs * Reverse relation direction when created inline * WIP integration test for Relation Query Component and Children Query Component. * Correctly reload children tables when refreshed * Fix FilterOnUndirectedMixin * Fix removing of relation from embedded table after reload * Adding intergration tests for removing and adding relation or children, initiated form either embedded table or relations tab. * Fix specs * Fix implementation of duplicates and duplicated They are reversed in typed_dag and causes confusion [ci skip]
6 years ago
#
# 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-2017 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'
describe 'Work package relations tab', js: true, selenium: true do
include_context 'ng-select-autocomplete helpers'
let(:user) { FactoryBot.create :admin }
8 years ago
let(:project) { FactoryBot.create :project }
let(:work_package) { FactoryBot.create(:work_package, project: project) }
let(:work_packages_page) { ::Pages::SplitWorkPackage.new(work_package) }
let(:full_wp) { ::Pages::FullWorkPackage.new(work_package) }
let(:relations) { ::Components::WorkPackages::Relations.new(work_package) }
let(:tabs) { ::Components::WorkPackages::Tabs.new(work_package) }
let(:relations_tab) { find('.tabrow li.selected', text: 'RELATIONS') }
8 years ago
let(:visit) { true }
before do
login_as user
8 years ago
if visit
visit_relations
end
end
def visit_relations
work_packages_page.visit_tab!('relations')
expect_angular_frontend_initialized
work_packages_page.expect_subject
loading_indicator_saveguard
end
8 years ago
describe 'relation group-by toggler' do
let(:project) { FactoryBot.create :project, types: [type_1, type_2] }
let(:type_1) { FactoryBot.create :type }
let(:type_2) { FactoryBot.create :type }
8 years ago
let(:to_1) { FactoryBot.create(:work_package, type: type_1, project: project) }
let(:to_2) { FactoryBot.create(:work_package, type: type_2, project: project) }
8 years ago
let!(:relation_1) do
FactoryBot.create :relation,
8 years ago
from: work_package,
to: to_1,
relation_type: Relation::TYPE_FOLLOWS
8 years ago
end
let!(:relation_2) do
FactoryBot.create :relation,
8 years ago
from: work_package,
to: to_2,
relation_type: Relation::TYPE_RELATES
8 years ago
end
let(:toggle_btn_selector) { '#wp-relation-group-by-toggle' }
let(:visit) { false }
before do
8 years ago
visit_relations
work_packages_page.visit_tab!('relations')
8 years ago
work_packages_page.expect_subject
loading_indicator_saveguard
scroll_to_element find('.detail-panel--relations')
end
8 years ago
it 'allows to toggle how relations are grouped' do
# Expect to be grouped by relation type by default
8 years ago
expect(page).to have_selector(toggle_btn_selector,
text: 'Group by work package type', wait: 20)
8 years ago
expect(page).to have_selector('.relation-group--header', text: 'FOLLOWS')
expect(page).to have_selector('.relation-group--header', text: 'RELATED TO')
expect(page).to have_selector('.relation-row--type', text: type_1.name)
expect(page).to have_selector('.relation-row--type', text: type_2.name)
find(toggle_btn_selector).click
expect(page).to have_selector(toggle_btn_selector, text: 'Group by relation type', wait: 10)
expect(page).to have_selector('.relation-group--header', text: type_1.name.upcase)
expect(page).to have_selector('.relation-group--header', text: type_2.name.upcase)
expect(page).to have_selector('.relation-row--type', text: 'Follows')
expect(page).to have_selector('.relation-row--type', text: 'Related To')
8 years ago
end
it 'allows to edit relation types when toggled' do
find(toggle_btn_selector).click
expect(page).to have_selector(toggle_btn_selector, text: 'Group by relation type', wait: 20)
# Expect current to be follows and other one related
expect(page).to have_selector('.relation-row--type', text: 'Follows')
expect(page).to have_selector('.relation-row--type', text: 'Related To')
# edit to blocks
relations.edit_relation_type(to_1, to_type: 'Blocks')
# the other one should not be altered
expect(page).to have_selector('.relation-row--type', text: 'Blocks')
expect(page).to have_selector('.relation-row--type', text: 'Related To')
updated_relation = Relation.find(relation_1.id)
expect(updated_relation.relation_type).to eq('blocks')
expect(updated_relation.from_id).to eq(work_package.id)
expect(updated_relation.to_id).to eq(to_1.id)
relations.edit_relation_type(to_1, to_type: 'Blocked by')
expect(page).to have_selector('.relation-row--type', text: 'Blocked by')
expect(page).to have_selector('.relation-row--type', text: 'Related To')
updated_relation = Relation.find(relation_1.id)
expect(updated_relation.relation_type).to eq('blocks')
expect(updated_relation.from_id).to eq(to_1.id)
expect(updated_relation.to_id).to eq(work_package.id)
end
8 years ago
end
describe 'with limited permissions' do
let(:permissions) { %i(view_work_packages) }
let(:user_role) do
FactoryBot.create :role, permissions: permissions
end
let(:user) do
FactoryBot.create :user,
member_in_project: project,
member_through_role: user_role
end
context 'as view-only user, with parent set' do
let(:work_package) { FactoryBot.create(:work_package, project: project) }
it 'shows no links to create relations' do
# No create buttons should exist
expect(page).to have_no_selector('.wp-relations-create-button')
# Test for add relation
expect(page).to have_no_selector('#relation--add-relation')
end
end
context 'with relations permissions' do
let(:permissions) do
%i(view_work_packages add_work_packages manage_subtasks manage_work_package_relations)
end
let!(:relatable) { FactoryBot.create(:work_package, project: project) }
it 'should allow to manage relations' do
relations.add_relation(type: 'follows', to: relatable)
# Relations counter badge should increase number of relations
tabs.expect_counter(relations_tab, 1)
relations.remove_relation(relatable)
expect(page).to have_no_selector('.relation-group--header', text: 'FOLLOWS')
# If there are no relations, the counter badge should not be displayed
tabs.expect_no_counter(relations_tab)
8 years ago
work_package.reload
expect(work_package.relations.direct).to be_empty
8 years ago
end
it 'should allow to move between split and full view (Regression #24194)' do
relations.add_relation(type: 'follows', to: relatable)
# Relations counter should increase
tabs.expect_counter(relations_tab, 1)
# Switch to full view
8 years ago
find('.work-packages--details-fullscreen-icon').click
# Expect to have row
relations.hover_action(relatable, :delete)
expect(page).to have_no_selector('.relation-group--header', text: 'FOLLOWS')
expect(page).to have_no_selector('.wp-relations--subject-field', text: relatable.subject)
# Back to split view
page.execute_script('window.history.back()')
work_packages_page.expect_subject
expect(page).to have_no_selector('.relation-group--header', text: 'FOLLOWS')
expect(page).to have_no_selector('.wp-relations--subject-field', text: relatable.subject)
end
it 'should follow the relation links (Regression #26794)' do
relations.add_relation(type: 'follows', to: relatable)
relations.click_relation(relatable)
subject = full_wp.edit_field(:subject)
subject.expect_state_text relatable.subject
relations.click_relation(work_package)
subject = full_wp.edit_field(:subject)
subject.expect_state_text work_package.subject
end
8 years ago
it 'should allow to change relation descriptions' do
relations.add_relation(type: 'follows', to: relatable)
8 years ago
## Toggle description
relations.hover_action(relatable, :info)
8 years ago
# Open textarea
created_row = relations.find_row(relatable)
8 years ago
created_row.find('.wp-relation--description-read-value.-placeholder',
text: I18n.t('js.placeholders.relation_description')).click
8 years ago
expect(page).to have_focus_on('.wp-relation--description-textarea')
textarea = created_row.find('.wp-relation--description-textarea')
textarea.set 'my description!'
8 years ago
# Save description
created_row.find('.inplace-edit--control--save a').click
loading_indicator_saveguard
# Wait for the relations table to be present
sleep 2
expect(page).to have_selector('.wp-relations--subject-field')
scroll_to_element find('.detail-panel--relations')
## Toggle description again
retry_block do
relations.hover_action(relatable, :info)
created_row = relations.find_row(relatable)
find'.wp-relation--description-read-value'
end
8 years ago
created_row.find('.wp-relation--description-read-value',
text: 'my description!').click
8 years ago
# Cancel edition
created_row.find('.inplace-edit--control--cancel a').click
created_row.find('.wp-relation--description-read-value',
text: 'my description!').click
relation = work_package.relations.direct.first
8 years ago
relation.reload
expect(relation.description).to eq('my description!')
8 years ago
# Toggle to close
relations.hover_action(relatable, :info)
8 years ago
expect(created_row).to have_no_selector('.wp-relation--description-read-value')
end
end
end
end