From 702898210396b8be38e3420f2049e6e8143b4178 Mon Sep 17 00:00:00 2001 From: German Galia Date: Thu, 6 Jun 2019 10:37:16 +0200 Subject: [PATCH] Add set tests and change votation type tests --- spec/features/polls/votation_type_spec.rb | 106 +++++++++++++++++----- 1 file changed, 85 insertions(+), 21 deletions(-) diff --git a/spec/features/polls/votation_type_spec.rb b/spec/features/polls/votation_type_spec.rb index 48fac5693..255a52e5c 100644 --- a/spec/features/polls/votation_type_spec.rb +++ b/spec/features/polls/votation_type_spec.rb @@ -34,8 +34,8 @@ feature "Poll Votation Type" do within("#poll_question_#{unique.id}_answers") do click_link answer1.title - expect(page).to have_link(answer2.title) - expect(page).not_to have_link(answer1.title) + expect(page).to have_css("a", text: answer2.title) + expect(page).not_to have_css("a", text: answer1.title) end end @@ -44,11 +44,11 @@ feature "Poll Votation Type" do within("#poll_question_#{unique.id}_answers") do click_link answer1.title - expect(page).to have_link(answer2.title) - expect(page).not_to have_link(answer1.title) + expect(page).to have_css("a", text: answer2.title) + expect(page).not_to have_css("a", text: answer1.title) click_link answer2.title - expect(page).to have_link(answer1.title) - expect(page).not_to have_link(answer2.title) + expect(page).to have_css("a", text: answer1.title) + expect(page).not_to have_css("a", text: answer2.title) end end end @@ -84,7 +84,7 @@ feature "Poll Votation Type" do question.question_answers.each do |answer| within("#poll_question_#{question.id}_answers") do click_link answer.title - page.find_link(answer.title).has_css?(".answered") + expect(page).to have_css(".answered", text: answer.title) end end end @@ -104,7 +104,7 @@ feature "Poll Votation Type" do within("#poll_question_#{question.id}_answers") do click_link answer6.title - expect(page.find_link(answer6.title)).not_to have_css(".answered") + expect(page).not_to have_css(".answered", text: answer6.title) end end @@ -117,6 +117,8 @@ feature "Poll Votation Type" do end end + visit poll_path(poll_current) + within("#poll_question_#{question.id}_answers") do click_link answer1.title end @@ -126,8 +128,11 @@ feature "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) + click_link answer6.title - page.find_link(answer6.title).has_css?(".answered") + + expect(page).to have_css(".answered", text: answer6.title) end end end @@ -163,10 +168,15 @@ feature "Poll Votation Type" do question.question_answers.each do |answer| within("#poll_question_#{question.id}_answers") do click_link answer.title - page.find_link(answer.title).has_css?(".answered") - page.find("span", text: answer.title).has_css?(".answered") end end + + question.question_answers.each do |answer| + within("#poll_question_#{question.id}_answers") do + expect(page).to have_css("a", text: answer.title) + end + end + end scenario "response question no more vote than allowed", :js do @@ -184,7 +194,7 @@ feature "Poll Votation Type" do within("#poll_question_#{question.id}_answers") do click_link answer6.title - expect(page.find_link(answer6.title)).not_to have_css(".answered") + expect(page).not_to have_css(".answered", text: answer6.title) end end end @@ -220,7 +230,7 @@ feature "Poll Votation Type" do question.question_answers.each do |answer| within("#poll_question_#{question.id}_answers") do click_link answer.title - page.find_link(answer.title).has_css?(".answered") + expect(page).to have_css(".answered", text: answer.title) end end end @@ -240,7 +250,7 @@ feature "Poll Votation Type" do within("#poll_question_#{question.id}_answers") do click_link answer6.title - expect(page.find_link(answer6.title)).not_to have_css(".answered") + expect(page).not_to have_css(".answered", text: answer6.title) end end @@ -253,6 +263,8 @@ feature "Poll Votation Type" do end end + visit poll_path(poll_current) + within("#poll_question_#{question.id}_answers") do click_link answer1.title end @@ -263,7 +275,7 @@ feature "Poll Votation Type" do within("#poll_question_#{question.id}_answers") do click_link answer6.title - page.find_link(answer6.title).has_css?(".answered") + expect(page).to have_css(".answered", text: answer6.title) end end @@ -273,10 +285,12 @@ feature "Poll Votation Type" do 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_link("added_answer") + expect(page).to have_css("a", text: "added_answer") click_link "added_answer" - page.find_link("added_answer").has_css?(".answered") + expect(page).to have_css(".answered", text: "added_answer") end end end @@ -299,8 +313,6 @@ feature "Poll Votation Type" do scenario "response question" do visit poll_path(poll_current) - save_page - question.question_answers.each do |answer| within("#poll_question_#{question.id}_answers") do expect(page).to have_content(answer.title) @@ -346,6 +358,8 @@ feature "Poll Votation Type" do end end + visit poll_path(poll_current) + within("#poll_question_#{question.id}_answers") do click_link answer1.title end @@ -366,10 +380,60 @@ feature "Poll Votation Type" do 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_link("added_answer") + expect(page).to have_css("a", text: "added_answer") click_link "added_answer" - page.find_link("added_answer").has_css?(".answered") + expect(page).to have_css(".answered", text: "added_answer") + end + end + end + + context "Answers set" do + + let(:user) { create(:user, :verified) } + let(:poll_current) { create(:poll, :current) } + let(:question) { create(:poll_question_answer_set_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) + + expect(page.find("#poll_question_#{question.id}_answers")).to have_css("a", count: question.max_groups_answers) + end + + scenario "response question vote", :js do + visit poll_path(poll_current) + + question.votation_type.votation_set_answers.by_author(user).each do |answer| + within("#poll_question_#{question.id}_answers") do + click_link answer.answer + end + end + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_css(".answered", count: question.max_votes) + end + + end + + scenario "add answer", :js do + visit poll_path(poll_current) + + fill_in "answer", with: "added_answer" + click_button "Add answer" + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_content("Answer added succesfully") end end end