From 4ddc869441a63c8c68fad0044a9c13d2cd5ce6de Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Fri, 2 Feb 2018 09:44:07 -0400 Subject: [PATCH 1/2] Mitigate recurrent flaky specs for voting comments --- spec/features/comments/budget_investments_spec.rb | 5 +++++ spec/features/comments/debates_spec.rb | 5 +++++ spec/features/comments/legislation_annotations_spec.rb | 5 +++++ spec/features/comments/polls_spec.rb | 5 +++++ spec/features/comments/topics_spec.rb | 10 ++++++++++ 5 files changed, 30 insertions(+) diff --git a/spec/features/comments/budget_investments_spec.rb b/spec/features/comments/budget_investments_spec.rb index c22ab56cb..bf30bace6 100644 --- a/spec/features/comments/budget_investments_spec.rb +++ b/spec/features/comments/budget_investments_spec.rb @@ -471,6 +471,11 @@ feature 'Commenting Budget::Investments' do within("#comment_#{@comment.id}_votes") do find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + find('.against a').click within('.in_favor') do diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index 66b35e671..a6015620b 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -476,6 +476,11 @@ feature 'Commenting debates' do within("#comment_#{@comment.id}_votes") do find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + find('.against a').click within('.in_favor') do diff --git a/spec/features/comments/legislation_annotations_spec.rb b/spec/features/comments/legislation_annotations_spec.rb index 1b54bf33a..cb86b203f 100644 --- a/spec/features/comments/legislation_annotations_spec.rb +++ b/spec/features/comments/legislation_annotations_spec.rb @@ -553,6 +553,11 @@ feature 'Commenting legislation questions' do within("#comment_#{@comment.id}_votes") do find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + find('.against a').click within('.in_favor') do diff --git a/spec/features/comments/polls_spec.rb b/spec/features/comments/polls_spec.rb index b706a198a..5e4bb51ef 100644 --- a/spec/features/comments/polls_spec.rb +++ b/spec/features/comments/polls_spec.rb @@ -485,6 +485,11 @@ feature 'Commenting polls' do within("#comment_#{@comment.id}_votes") do find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + find('.against a').click within('.in_favor') do diff --git a/spec/features/comments/topics_spec.rb b/spec/features/comments/topics_spec.rb index f8c9f3fc5..d66afc756 100644 --- a/spec/features/comments/topics_spec.rb +++ b/spec/features/comments/topics_spec.rb @@ -515,6 +515,11 @@ feature 'Commenting topics from proposals' do within("#comment_#{@comment.id}_votes") do find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + find('.against a').click within('.in_favor') do @@ -1065,6 +1070,11 @@ feature 'Commenting topics from budget investments' do within("#comment_#{@comment.id}_votes") do find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + find('.against a').click within('.in_favor') do From 32504b884041245ec130cc12931a2d6700168e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mart=C3=ADn?= Date: Fri, 13 Jul 2018 22:51:17 +0200 Subject: [PATCH 2/2] Make Capybara check the page between votes. As pointed out in PR #2734: "After clicking the first link, there's an AJAX request which replaces the existing `.in-favor a` and `.against a` links with new elements. So if Capybara tries to click the existing `.against a` link at the same moment it's being replaced, clicking the link won't generate a new request". Making Capybara check the page for new content before clicking the second link solves the problem, in the same way 4ddc869 solved the same problem in the comments section. --- spec/features/votes_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index c837deebf..1ebdcfc91 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -83,6 +83,12 @@ feature 'Votes' do visit debate_path(create(:debate)) find('.in-favor a').click + + within('.in-favor') do + expect(page).to have_content "100%" + expect(page).to have_css("a.voted") + end + find('.against a').click within('.in-favor') do