Merge pull request #3650 from consul/fix_votation_spec

Fix flaky votation type specs
This commit is contained in:
Javier Martín
2019-09-10 16:40:51 +02:00
committed by GitHub

View File

@@ -34,8 +34,9 @@ describe "Poll Votation Type" do
within("#poll_question_#{unique.id}_answers") do
click_link answer1.title
expect(page).to have_css("a", text: answer2.title)
expect(page).not_to have_css("a", text: answer1.title)
expect(page).to have_link answer2.title
expect(page).not_to have_link answer1.title
end
end
@@ -44,11 +45,14 @@ describe "Poll Votation Type" do
within("#poll_question_#{unique.id}_answers") do
click_link answer1.title
expect(page).to have_css("a", text: answer2.title)
expect(page).not_to have_css("a", text: answer1.title)
expect(page).to have_link answer2.title
expect(page).not_to have_link answer1.title
click_link answer2.title
expect(page).to have_css("a", text: answer1.title)
expect(page).not_to have_css("a", text: answer2.title)
expect(page).to have_link answer1.title
expect(page).not_to have_link answer2.title
end
end
end
@@ -84,7 +88,8 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
expect(page).to have_css(".answered", text: answer.title)
expect(page).to have_link answer.title, class: "answered"
end
end
end
@@ -95,6 +100,8 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
expect(page).to have_link text: answer.title, class: "answered"
end
end
@@ -104,7 +111,8 @@ describe "Poll Votation Type" do
within("#poll_question_#{question.id}_answers") do
click_link answer6.title
expect(page).not_to have_css(".answered", text: answer6.title)
expect(page).not_to have_link text: answer6.title, class: "answered"
end
end
@@ -121,6 +129,8 @@ describe "Poll Votation Type" do
within("#poll_question_#{question.id}_answers") do
click_link answer1.title
expect(page).not_to have_link text: answer1.title, class: "answered"
end
answer6 = create(:poll_question_answer, question: question, title: "answer_6")
@@ -128,11 +138,11 @@ describe "Poll Votation Type" do
visit poll_path(poll_current)
within("#poll_question_#{question.id}_answers") do
expect(page).to have_css("a", text: answer6.title)
expect(page).to have_link answer6.title
click_link answer6.title
expect(page).to have_css(".answered", text: answer6.title)
expect(page).to have_link answer6.title, class: "answered"
end
end
end
@@ -173,7 +183,7 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
expect(page).to have_css("a", text: answer.title)
expect(page).to have_link answer.title
end
end
@@ -185,6 +195,8 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
expect(page).to have_link text: answer.title, class: "answered"
end
end
@@ -194,7 +206,8 @@ describe "Poll Votation Type" do
within("#poll_question_#{question.id}_answers") do
click_link answer6.title
expect(page).not_to have_css(".answered", text: answer6.title)
expect(page).not_to have_link answer6.title, class: "answered"
end
end
end
@@ -230,7 +243,8 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
expect(page).to have_css(".answered", text: answer.title)
expect(page).to have_link answer.title, class: "answered"
end
end
end
@@ -241,6 +255,8 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
expect(page).to have_link text: answer.title, class: "answered"
end
end
@@ -250,7 +266,8 @@ describe "Poll Votation Type" do
within("#poll_question_#{question.id}_answers") do
click_link answer6.title
expect(page).not_to have_css(".answered", text: answer6.title)
expect(page).not_to have_link answer6.title, class: "answered"
end
end
@@ -260,6 +277,8 @@ describe "Poll Votation Type" do
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
expect(page).to have_link text: answer.title, class: "answered"
end
end
@@ -267,6 +286,8 @@ describe "Poll Votation Type" do
within("#poll_question_#{question.id}_answers") do
click_link answer1.title
expect(page).not_to have_link text: answer1.title, class: "answered"
end
answer6 = create(:poll_question_answer, question: question, title: "answer_6")
@@ -275,117 +296,25 @@ describe "Poll Votation Type" do
within("#poll_question_#{question.id}_answers") do
click_link answer6.title
expect(page).to have_css(".answered", text: answer6.title)
expect(page).to have_link answer6.title, class: "answered"
end
end
scenario "add answer", :js do
visit poll_path(poll_current)
fill_in "answer", with: "added_answer"
fill_in "answer", with: "Added answer"
click_button "Add answer"
visit poll_path(poll_current)
within("#poll_question_#{question.id}_answers") do
expect(page).to have_css("a", text: "added_answer")
click_link "added_answer"
expect(page).to have_css(".answered", text: "added_answer")
end
end
end
xcontext "Positive and negative open" do
let(:user) { create(:user, :verified) }
let(:poll_current) { create(:poll, :current) }
let(:question) { create(:poll_question_positive_negative_open, poll: poll_current) }
let!(:answer1) { create(:poll_question_answer, question: question, title: "answer_1") }
let!(:answer2) { create(:poll_question_answer, question: question, title: "answer_2") }
let!(:answer3) { create(:poll_question_answer, question: question, title: "answer_3") }
let!(:answer4) { create(:poll_question_answer, question: question, title: "answer_4") }
let!(:answer5) { create(:poll_question_answer, question: question, title: "answer_5") }
before do
login_as(user)
end
scenario "response question" do
visit poll_path(poll_current)
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
expect(page).to have_content(answer.title)
end
end
end
scenario "response question vote", :js do
visit poll_path(poll_current)
question.question_answers.each do |answer|
title = "vote #{answer.title}"
page.find("poll_question_#{question.id}_answers .in-favor a[title=#{title}]").click
page.find("poll_question_#{question.id}_answers .in-favor a[title=#{title}]").has_css?(".answered")
end
end
scenario "response question no more vote than allowed", :js do
visit poll_path(poll_current)
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
end
end
answer6 = create(:poll_question_answer, question: question, title: "answer_6")
expect(page).to have_link "Added answer"
visit poll_path(poll_current)
within("#poll_question_#{question.id}_answers") do
click_link answer6.title
expect(page.find_link(answer6.title)).not_to have_css(".answered")
end
end
click_link "Added answer"
scenario "response question remove vote and vote again", :js do
visit poll_path(poll_current)
question.question_answers.each do |answer|
within("#poll_question_#{question.id}_answers") do
click_link answer.title
end
end
visit poll_path(poll_current)
within("#poll_question_#{question.id}_answers") do
click_link answer1.title
end
answer6 = create(:poll_question_answer, question: question, title: "answer_6")
visit poll_path(poll_current)
within("#poll_question_#{question.id}_answers") do
click_link answer6.title
page.find_link(answer6.title).has_css?(".answered")
end
end
scenario "add answer", :js do
visit poll_path(poll_current)
fill_in "answer", with: "added_answer"
click_button "Add answer"
visit poll_path(poll_current)
within("#poll_question_#{question.id}_answers") do
expect(page).to have_css("a", text: "added_answer")
click_link "added_answer"
expect(page).to have_css(".answered", text: "added_answer")
expect(page).to have_link "Added answer", class: "answered"
end
end
end