From b89fdaf1405d635f3a193da8ba94eed6d256134f Mon Sep 17 00:00:00 2001 From: Inga Mai Date: Tue, 16 Oct 2018 11:33:38 +0200 Subject: [PATCH] Basic tests for watchers counter added --- .../details/relations/hierarchy_spec.rb | 12 ++++++----- .../details/relations/relations_spec.rb | 8 +++++--- .../work_packages/new/create_child_spec.rb | 5 +++-- .../work_packages/tabs/watcher_tab_spec.rb | 8 ++++++++ .../components/work_packages/tabs_counter.rb | 20 ++++++------------- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/spec/features/work_packages/details/relations/hierarchy_spec.rb b/spec/features/work_packages/details/relations/hierarchy_spec.rb index a19d9b302c..a82257f1a6 100644 --- a/spec/features/work_packages/details/relations/hierarchy_spec.rb +++ b/spec/features/work_packages/details/relations/hierarchy_spec.rb @@ -12,6 +12,8 @@ describe 'Work package relations tab', js: true, selenium: true do 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 } before do @@ -58,7 +60,7 @@ describe 'Work package relations tab', js: true, selenium: true do relations.add_existing_child(child2) # Count parent and child relations in split view - tabs.expect_counter(3, 3) + tabs.expect_counter(relations_tab, 3) end describe 'inline create' do @@ -78,7 +80,7 @@ describe 'Work package relations tab', js: true, selenium: true do expect(work_package.children.count).to eq(1) # If new child is inline created, counter should increase - tabs.expect_counter(3, 1) + tabs.expect_counter(relations_tab, 1) end end end @@ -149,7 +151,7 @@ describe 'Work package relations tab', js: true, selenium: true do expect(page).to have_selector('.wp-relations-hierarchy-subject', text: parent.subject) # And it should count parent and the two relations - tabs.expect_counter(3, 3) + tabs.expect_counter(relations_tab, 3) end end @@ -179,7 +181,7 @@ describe 'Work package relations tab', js: true, selenium: true do relations.expect_child(child) # Expect counter to add up new parent and child to the existing relations - tabs.expect_counter(3, 4) + tabs.expect_counter(relations_tab, 4) # Remove parent relations.remove_parent(parent) @@ -192,7 +194,7 @@ describe 'Work package relations tab', js: true, selenium: true do relations.expect_not_child(child) # Expect counter to only count the two existing relations - tabs.expect_counter(3, 2) + tabs.expect_counter(relations_tab, 2) end end end diff --git a/spec/features/work_packages/details/relations/relations_spec.rb b/spec/features/work_packages/details/relations/relations_spec.rb index e1a0d0ad21..51a4341bc9 100644 --- a/spec/features/work_packages/details/relations/relations_spec.rb +++ b/spec/features/work_packages/details/relations/relations_spec.rb @@ -12,6 +12,8 @@ describe 'Work package relations tab', js: true, selenium: true do 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 } before do @@ -149,13 +151,13 @@ describe 'Work package relations tab', js: true, selenium: true do relations.add_relation(type: 'follows', to: relatable) # Relations counter badge should increase number of relations - tabs.expect_counter(3, 1) + 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() + tabs.expect_no_counter(relations_tab) work_package.reload expect(work_package.relations.direct).to be_empty @@ -164,7 +166,7 @@ describe 'Work package relations tab', js: true, selenium: true do 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(3, 1) + tabs.expect_counter(relations_tab, 1) # Switch to full view find('.work-packages--details-fullscreen-icon').click diff --git a/spec/features/work_packages/new/create_child_spec.rb b/spec/features/work_packages/new/create_child_spec.rb index 818c7db93c..d223c12419 100644 --- a/spec/features/work_packages/new/create_child_spec.rb +++ b/spec/features/work_packages/new/create_child_spec.rb @@ -30,6 +30,7 @@ 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, @@ -120,7 +121,7 @@ RSpec.feature 'Work package create children', js: true, selenium: true do text: I18n.t('js.notice_successful_create')) # Relations counter in full view (with index 2) should equal 1 - tabs.expect_counter(2, 1) + tabs.expect_counter(relations_tab, 1) child_work_package = WorkPackage.order(created_at: 'desc').first @@ -154,7 +155,7 @@ RSpec.feature 'Work package create children', js: true, selenium: true do text: I18n.t('js.notice_successful_create')) # # Relations counter in split view (with index 3) should equal 1 - tabs.expect_counter(3, 1) + tabs.expect_counter(relations_tab, 1) child_work_package = WorkPackage.order(created_at: 'desc').first diff --git a/spec/features/work_packages/tabs/watcher_tab_spec.rb b/spec/features/work_packages/tabs/watcher_tab_spec.rb index cdc7421d32..5e54398904 100644 --- a/spec/features/work_packages/tabs/watcher_tab_spec.rb +++ b/spec/features/work_packages/tabs/watcher_tab_spec.rb @@ -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') @@ -69,10 +71,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 diff --git a/spec/support/components/work_packages/tabs_counter.rb b/spec/support/components/work_packages/tabs_counter.rb index 5067c8ed68..8cee286c82 100644 --- a/spec/support/components/work_packages/tabs_counter.rb +++ b/spec/support/components/work_packages/tabs_counter.rb @@ -13,22 +13,14 @@ module Components @work_package = work_package end - # Counter elements - # 2: Relation tab in split view - # 3: Relation tab in full view and watchers tab in split view - # 4: Watchers tab in full view - def counter_for(tabindex) - find('ul.tabrow > li:nth-child(' + tabindex.to_s + ') .wp-tabs-count') + # Check value of counter for the given tab + def expect_counter(tab, content) + expect(tab).to have_selector('.wp-tabs-count', text: "#{content}") end - # Check number of relations or watchers for tab with given index - def expect_counter(tabindex, content) - expect(counter_for(tabindex)).to have_content(content.to_s) - end - - # There are no relations or watchers - def expect_no_counter() - expect(page).to have_no_selector('.wp-tabs-count') + # 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