From 202fe2953b2f1f52878ebd1169c569866eb1aceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 13 Oct 2020 17:59:40 +0200 Subject: [PATCH] Fix matchers checking elements are obscured These tests were supposed to check the link to vote is hidden when users don't have permission to vote. However, they aren't testing that, since the `visible: false` option also matches visible elements. The links are actually considered visible since they're displayed by the browser; there's just another element on top of them. Using `obscured: true` instead of `visible: false` solves the issue. However, while the `obscured` option is true when the element is hidden by another element, it's also true when the element is not currently visible in the browser window, so in some cases we need to scroll so the condition is effective. --- spec/support/common_actions/budgets.rb | 7 ++- spec/support/common_actions/votes.rb | 6 +-- spec/system/budget_polls/voter_spec.rb | 2 +- spec/system/budgets/ballots_spec.rb | 63 ++++++++++++++++---------- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/spec/support/common_actions/budgets.rb b/spec/support/common_actions/budgets.rb index 9477c6e3d..baf7b058c 100644 --- a/spec/support/common_actions/budgets.rb +++ b/spec/support/common_actions/budgets.rb @@ -1,7 +1,12 @@ module Budgets def expect_message_organizations_cannot_vote expect(page).to have_content "Organization" - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) + end + + def hover_over_ballot + scroll_to find("div.ballot"), align: :bottom + find("div.ballot").hover end def add_to_ballot(investment_title) diff --git a/spec/support/common_actions/votes.rb b/spec/support/common_actions/votes.rb index 1fd37e631..2f917a154 100644 --- a/spec/support/common_actions/votes.rb +++ b/spec/support/common_actions/votes.rb @@ -1,7 +1,7 @@ module Votes def expect_message_you_need_to_sign_in expect(page).to have_content "You must sign in or sign up to continue" - expect(page).to have_selector(".in-favor", visible: false) + expect(page).to have_selector(".in-favor", obscured: true) end def expect_message_you_need_to_sign_in_to_vote_comments @@ -12,11 +12,11 @@ module Votes def expect_message_to_many_anonymous_votes expect(page).to have_content "Too many anonymous votes to admit vote" - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end def expect_message_only_verified_can_vote_proposals expect(page).to have_content "Only verified users can vote on proposals" - expect(page).to have_selector(".in-favor", visible: false) + expect(page).to have_selector(".in-favor", obscured: true) end end diff --git a/spec/system/budget_polls/voter_spec.rb b/spec/system/budget_polls/voter_spec.rb index 32c2ddd6c..b6c71c031 100644 --- a/spec/system/budget_polls/voter_spec.rb +++ b/spec/system/budget_polls/voter_spec.rb @@ -83,7 +83,7 @@ describe "BudgetPolls", :with_frozen_time do within("#budget_investment_#{investment.id}") do expect(page).to have_content "You have already participated offline" - expect(page).to have_css(".add a", visible: false) + expect(page).to have_css(".add a", obscured: true) end end end diff --git a/spec/system/budgets/ballots_spec.rb b/spec/system/budgets/ballots_spec.rb index 5667bf0d4..6e8648cb5 100644 --- a/spec/system/budgets/ballots_spec.rb +++ b/spec/system/budgets/ballots_spec.rb @@ -502,9 +502,10 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: new_york.id) within("#budget_investment_#{investment.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content "You must sign in or sign up to continue." - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end end @@ -516,9 +517,10 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: new_york.id) within("#budget_investment_#{investment.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content "Only verified users can vote on investments" - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end end @@ -530,7 +532,8 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: new_york.id) within("#budget_investment_#{investment.id}") do - find("div.ballot").hover + hover_over_ballot + expect_message_organizations_cannot_vote end end @@ -569,9 +572,10 @@ describe "Ballots" do visit budget_investments_path(budget, heading: new_york) within("#budget_investment_#{bi2.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content("already voted a different heading") - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end end @@ -584,9 +588,10 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: california.id) within("#budget_investment_#{bi2.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end end @@ -598,17 +603,19 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: california.id) within(".budget-investment", text: "Build replicants") do - find("div.ballot").hover + hover_over_ballot + expect(page).not_to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: true) + expect(page).to have_selector(".in-favor a", obscured: false) end add_to_ballot("Build replicants") within(".budget-investment", text: "Build terminators") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end end @@ -621,9 +628,10 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: california.id) within("#budget_investment_#{bi2.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end within("#budget_investment_#{bi1.id}") do @@ -632,9 +640,10 @@ describe "Ballots" do end within("#budget_investment_#{bi2.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).not_to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: true) + expect(page).to have_selector(".in-favor a", obscured: false) end end @@ -647,9 +656,10 @@ describe "Ballots" do visit budget_investments_path(budget, heading_id: california.id) within("#budget_investment_#{bi2.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end within("#budget_investment_#{bi1.id}_sidebar") do @@ -659,9 +669,10 @@ describe "Ballots" do expect(page).not_to have_css "#budget_investment_#{bi1.id}_sidebar" within("#budget_investment_#{bi2.id}") do - find("div.ballot").hover + hover_over_ballot + expect(page).not_to have_content("You have already assigned the available budget") - expect(page).to have_selector(".in-favor a", visible: true) + expect(page).to have_selector(".in-favor a", obscured: false) end end @@ -676,13 +687,15 @@ describe "Ballots" do new_york.update!(price: 10) within("#budget_investment_#{investment1.id}") do - expect(page).to have_selector(".in-favor a", visible: true) - find(".add a").click + find(".in-favor a").click + expect(page).not_to have_content "Remove" expect(page).to have_selector(".participation-not-allowed", visible: false) - find("div.ballot").hover + + hover_over_ballot + expect(page).to have_selector(".participation-not-allowed", visible: true) - expect(page).to have_selector(".in-favor a", visible: false) + expect(page).to have_selector(".in-favor a", obscured: true) end end