Merge pull request #6750 from opf/realtions-and-watcher-count-spec

Add feature specs for relations count and watchers count

[ci skip]
pull/6777/head
Oliver Günther 6 years ago committed by GitHub
commit 176788599b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      spec/features/work_packages/details/relations/hierarchy_spec.rb
  2. 12
      spec/features/work_packages/details/relations/relations_spec.rb
  3. 13
      spec/features/work_packages/new/create_child_spec.rb
  4. 9
      spec/features/work_packages/tabs/watcher_tab_spec.rb
  5. 2
      spec/support/components/work_packages/relations.rb
  6. 27
      spec/support/components/work_packages/tabs_counter.rb

@ -1,15 +1,16 @@
require 'spec_helper'
describe 'Work package relations tab', js: true, selenium: true do
shared_examples 'work package relations tab', js: true, selenium: true do
include_context 'ui-autocomplete helpers'
let(:user) { FactoryBot.create :admin }
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') }
let(:visit) { true }
@ -22,8 +23,9 @@ describe 'Work package relations tab', js: true, selenium: true do
end
def visit_relations
work_packages_page.visit_tab!('relations')
work_packages_page.expect_subject
wp_page.visit_tab!('relations')
expect_angular_frontend_initialized
wp_page.expect_subject
loading_indicator_saveguard
end
@ -35,7 +37,7 @@ describe 'Work package relations tab', js: true, selenium: true do
it 'allows to manage hierarchy' do
# Shows link parent link
expect(page).to have_selector('#hierarchy--add-parent')
find('.work-packages--details .wp-inline-create--add-link',
find('.wp-inline-create--add-link',
text: I18n.t('js.relation_buttons.add_parent')).click
# Add parent
@ -44,17 +46,20 @@ describe 'Work package relations tab', js: true, selenium: true do
##
# Add child #1
find('.work-packages--details .wp-inline-create--add-link',
find('.wp-inline-create--add-link',
text: I18n.t('js.relation_buttons.add_existing_child')).click
relations.add_existing_child(child)
##
# Add child #2
find('.work-packages--details .wp-inline-create--add-link',
find('.wp-inline-create--add-link',
text: I18n.t('js.relation_buttons.add_existing_child')).click
relations.add_existing_child(child2)
# Count parent and child relations in split view
tabs.expect_counter(relations_tab, 3)
end
describe 'inline create' do
@ -72,6 +77,9 @@ describe 'Work package relations tab', js: true, selenium: true do
table.expect_work_package_subject 'my new child'
work_package.reload
expect(work_package.children.count).to eq(1)
# If new child is inline created, counter should increase
tabs.expect_counter(relations_tab, 1)
end
end
end
@ -103,8 +111,8 @@ describe 'Work package relations tab', js: true, selenium: true do
before do
visit_relations
work_packages_page.visit_tab!('relations')
work_packages_page.expect_subject
wp_page.visit_tab!('relations')
wp_page.expect_subject
loading_indicator_saveguard
end
@ -140,6 +148,9 @@ describe 'Work package relations tab', js: true, selenium: true do
# But it should show the linked parent
expect(page).to have_selector('.wp-relations-hierarchy-subject', text: parent.subject)
# And it should count parent and the two relations
tabs.expect_counter(relations_tab, 3)
end
end
@ -151,34 +162,50 @@ describe 'Work package relations tab', js: true, selenium: true do
it 'should be able to link parent and children' do
# Shows link parent link
expect(page).to have_selector('#hierarchy--add-parent')
find('.work-packages--details .wp-inline-create--add-link',
find('.wp-inline-create--add-link',
text: I18n.t('js.relation_buttons.add_parent')).click
# Add parent
relations.add_parent(parent.id, parent)
work_packages_page.expect_and_dismiss_notification(message: 'Successful update.')
wp_page.expect_and_dismiss_notification(message: 'Successful update.')
relations.expect_parent(parent)
##
# Add child
find('.work-packages--details .wp-inline-create--add-link',
find('.wp-inline-create--add-link',
text: I18n.t('js.relation_buttons.add_existing_child')).click
relations.add_existing_child(child)
work_packages_page.expect_and_dismiss_notification(message: 'Successful update.')
wp_page.expect_and_dismiss_notification(message: 'Successful update.')
relations.expect_child(child)
# Expect counter to add up new parent and child to the existing relations
tabs.expect_counter(relations_tab, 4)
# Remove parent
relations.remove_parent(parent)
work_packages_page.expect_and_dismiss_notification(message: 'Successful update.')
wp_page.expect_and_dismiss_notification(message: 'Successful update.')
relations.expect_not_parent(parent)
# Remove child
relations.remove_child(child)
# Should also check for successful update but no message is shown, yet.
relations.expect_not_child(child)
# Expect counter to only count the two existing relations
tabs.expect_counter(relations_tab, 2)
end
end
end
end
end
context 'Split screen' do
let(:wp_page) { Pages::SplitWorkPackage.new(work_package) }
it_behaves_like 'work package relations tab'
end
context 'Full screen' do
let(:wp_page) { Pages::FullWorkPackage.new(work_package) }
it_behaves_like 'work package relations tab'
end

@ -10,6 +10,9 @@ describe 'Work package relations tab', js: true, selenium: true do
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') }
let(:visit) { true }
@ -23,6 +26,7 @@ describe 'Work package relations tab', js: true, selenium: true do
def visit_relations
work_packages_page.visit_tab!('relations')
expect_angular_frontend_initialized
work_packages_page.expect_subject
loading_indicator_saveguard
end
@ -147,15 +151,23 @@ describe 'Work package relations tab', js: true, selenium: true do
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)
work_package.reload
expect(work_package.relations.direct).to be_empty
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
find('.work-packages--details-fullscreen-icon').click

@ -29,6 +29,8 @@
require 'spec_helper'
RSpec.feature 'Work package create children', js: true, selenium: true do
let(:tabs) { ::Components::WorkPackages::Tabs.new(original_work_package) }
let(:relations_tab) { find('.tabrow li', text: 'RELATIONS') }
let(:user) do
FactoryBot.create(:user,
member_in_project: project,
@ -41,7 +43,6 @@ RSpec.feature 'Work package create children', js: true, selenium: true do
old_status: original_work_package.status,
new_status: FactoryBot.create(:status))
end
let(:create_role) do
FactoryBot.create(:role,
permissions: [:view_work_packages,
@ -104,6 +105,8 @@ RSpec.feature 'Work package create children', js: true, selenium: true do
original_work_package_page = Pages::FullWorkPackage.new(original_work_package)
child_work_package_page = original_work_package_page.add_child
expect_angular_frontend_initialized
type_field = child_work_package_page.edit_field :type
type_field.expect_active!
@ -119,6 +122,9 @@ RSpec.feature 'Work package create children', js: true, selenium: true do
expect(page).to have_selector('.notification-box--content',
text: I18n.t('js.notice_successful_create'))
# Relations counter in full view should equal 1
tabs.expect_counter(relations_tab, 1)
child_work_package = WorkPackage.order(created_at: 'desc').first
expect(child_work_package).to_not eql original_work_package
@ -136,6 +142,8 @@ RSpec.feature 'Work package create children', js: true, selenium: true do
original_work_package_page = Pages::SplitWorkPackage.new(original_work_package, project)
child_work_package_page = original_work_package_page.add_child
expect_angular_frontend_initialized
type_field = child_work_package_page.edit_field :type
expect(type_field.input_element).to have_selector('option[selected]', text: 'Please select')
@ -150,6 +158,9 @@ RSpec.feature 'Work package create children', js: true, selenium: true do
expect(page).to have_selector('.notification-box--content',
text: I18n.t('js.notice_successful_create'))
# # Relations counter in split view should equal 1
tabs.expect_counter(relations_tab, 1)
child_work_package = WorkPackage.order(created_at: 'desc').first
expect(child_work_package).to_not eql original_work_package

@ -6,6 +6,7 @@ require 'support/work_packages/work_package_field'
describe 'Watcher tab', js: true, selenium: true do
let(:project) { FactoryBot.create(:project) }
let(:work_package) { FactoryBot.create(:work_package, project: project) }
let(:tabs) { ::Components::WorkPackages::Tabs.new(work_package) }
let(:user) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
let(:role) { FactoryBot.create(:role, permissions: permissions) }
@ -17,6 +18,7 @@ describe 'Watcher tab', js: true, selenium: true do
}
let(:watch_button) { find '#watch-button' }
let(:watchers_tab) { find('.tabrow li.selected', text: 'WATCHERS') }
def expect_button_is_watching
title = I18n.t('js.label_unwatch_work_package')
@ -54,6 +56,7 @@ describe 'Watcher tab', js: true, selenium: true do
before do
login_as(user)
wp_page.visit_tab! :watchers
expect_angular_frontend_initialized
expect(page).to have_selector('.tabrow li.selected', text: 'WATCHERS')
end
@ -69,10 +72,16 @@ describe 'Watcher tab', js: true, selenium: true do
expect(page).to have_selector('.work-package--watcher-name', count: 1, text: user.name)
expect_button_is_watching
# Expect watchers counter to increase
tabs.expect_counter(watchers_tab, 1)
# Remove watcher from list
page.find('wp-watcher-entry', text: user.name).hover
page.find('.form--selected-value--remover').click
# Watchers counter should not be displayed
tabs.expect_no_counter(watchers_tab)
# Expect the removal of the user to toggle WP watch button
expect(page).to have_no_selector('.work-package--watcher-name')
expect_button_is_not_watching

@ -131,7 +131,7 @@ module Components
autocomplete = container.find(".wp-relations--autocomplete")
select_autocomplete autocomplete,
query: query,
results_selector: '.wp-relations-autocomplete--results',
results_selector: '.detail-panel--relations .wp-relations-autocomplete--results',
select_text: work_package.id
container.find('.wp-create-relation--save').click

@ -0,0 +1,27 @@
require 'features/support/components/ui_autocomplete'
module Components
module WorkPackages
class Tabs
include Capybara::DSL
include RSpec::Matchers
include ::Components::UIAutocompleteHelpers
attr_reader :work_package
def initialize(work_package)
@work_package = work_package
end
# Check value of counter for the given tab
def expect_counter(tab, content)
expect(tab).to have_selector('.wp-tabs-count', text: "#{content}")
end
# Counter should not be displayed, if there are no relations or watchers
def expect_no_counter(tab)
expect(tab).to have_no_selector('.wp-tabs-count')
end
end
end
end
Loading…
Cancel
Save