Merge pull request #3341 from consul/improvement_for_options_display_results_polls

Improvements about displaying results for voted polls
This commit is contained in:
Julian Nicolas Herrero
2019-03-18 10:51:03 +01:00
committed by GitHub
3 changed files with 72 additions and 45 deletions

View File

@@ -11,13 +11,13 @@
</div>
<% end %>
<% if !@partial_results.empty? %>
<% if @partial_results.present? %>
<%= render "recount", resource: @poll %>
<%= render "result" %>
<%= render "results_by_booth" %>
<% end %>
<% if !@poll.voters.empty? %>
<% if @poll.voters.any? %>
<%= render "show_results", resource: @poll %>
<% end %>
</div>

View File

@@ -92,6 +92,12 @@ FactoryBot.define do
trait :from_booth do
association :booth_assignment, factory: :poll_booth_assignment
origin "booth"
before :create do |voter|
voter.officer_assignment = create(:poll_officer_assignment,
officer: voter.officer,
booth_assignment: voter.booth_assignment)
end
end
trait :valid_document do

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
require "rails_helper"
feature 'Admin polls' do
feature "Admin polls" do
background do
admin = create(:administrator)
@@ -44,7 +44,7 @@ feature 'Admin polls' do
expect(page).not_to have_content "There are no polls"
end
scenario 'Show' do
scenario "Show" do
poll = create(:poll)
visit admin_polls_path
@@ -61,10 +61,10 @@ feature 'Admin polls' do
end_date = 2.weeks.from_now
fill_in "Name", with: "Upcoming poll"
fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y")
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in 'Summary', with: "Upcoming poll's summary. This poll..."
fill_in 'Description', with: "Upcomming poll's description. This poll..."
fill_in "poll_starts_at", with: start_date.strftime("%d/%m/%Y")
fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y")
fill_in "Summary", with: "Upcoming poll's summary. This poll..."
fill_in "Description", with: "Upcomming poll's description. This poll..."
expect(page).not_to have_css("#poll_results_enabled")
expect(page).not_to have_css("#poll_stats_enabled")
@@ -89,7 +89,7 @@ feature 'Admin polls' do
expect(page).to have_css("img[alt='#{poll.image.title}']")
fill_in "Name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y")
click_button "Update poll"
@@ -98,7 +98,7 @@ feature 'Admin polls' do
expect(page).to have_content I18n.l(end_date.to_date)
end
scenario 'Edit from index' do
scenario "Edit from index" do
poll = create(:poll)
visit admin_polls_path
@@ -247,18 +247,18 @@ feature 'Admin polls' do
within("#poll_booth_assignment_#{booth_assignment.id}_recounts") do
expect(page).to have_content(booth_assignment.booth.name)
expect(page).to have_content('63')
expect(page).to have_content("63")
end
within("#poll_booth_assignment_#{booth_assignment_recounted.id}_recounts") do
expect(page).to have_content(booth_assignment_recounted.booth.name)
expect(page).to have_content('-')
expect(page).to have_content("-")
end
within("#poll_booth_assignment_#{booth_assignment_final_recounted.id}_recounts") do
expect(page).to have_content(booth_assignment_final_recounted.booth.name)
expect(page).to have_content('55555')
expect(page).to have_content('2')
expect(page).to have_content("55555")
expect(page).to have_content("2")
end
end
end
@@ -274,7 +274,7 @@ feature 'Admin polls' do
expect(page).to have_content "There are no results"
end
scenario 'Show partial results' do
scenario "Show partial results" do
poll = create(:poll)
booth_assignment_1 = create(:poll_booth_assignment, poll: poll)
@@ -282,24 +282,24 @@ feature 'Admin polls' do
booth_assignment_3 = create(:poll_booth_assignment, poll: poll)
question_1 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: 'Oui', question: question_1)
create(:poll_question_answer, title: 'Non', question: question_1)
create(:poll_question_answer, title: "Oui", question: question_1)
create(:poll_question_answer, title: "Non", question: question_1)
question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Aujourd'hui", question: question_2)
create(:poll_question_answer, title: 'Demain', question: question_2)
create(:poll_question_answer, title: "Demain", question: question_2)
[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
booth_assignment: ba,
question: question_1,
answer: 'Oui',
answer: "Oui",
amount: 11)
create(:poll_partial_result,
booth_assignment: ba,
question: question_2,
answer: 'Demain',
answer: "Demain",
amount: 5)
end
@@ -311,24 +311,45 @@ feature 'Admin polls' do
visit admin_poll_results_path(poll)
expect(page).to have_content 'Results by booth'
expect(page).to have_content "Results by booth"
end
scenario "Enable stats and results" do
poll = create(:poll)
scenario "Enable stats and results for booth polls" do
unvoted_poll = create(:poll)
visit admin_poll_results_path(poll)
voted_poll = create(:poll)
booth_assignment = create(:poll_booth_assignment, poll: voted_poll)
create(:poll_voter, :from_booth, :valid_document,
booth_assignment: booth_assignment,
poll: voted_poll)
expect(page).to have_content 'There are no results'
expect(page).not_to have_content 'Show results and stats'
visit admin_poll_results_path(unvoted_poll)
poll_voter = create(:poll_voter)
expect(page).to have_content "There are no results"
expect(page).not_to have_content "Show results and stats"
visit admin_poll_results_path(poll_voter.poll)
visit admin_poll_results_path(voted_poll)
expect(page).to have_content 'Show results and stats'
expect(page).not_to have_content 'There are no results'
expect(page).not_to have_content 'Results by booth'
expect(page).to have_content "Show results and stats"
expect(page).not_to have_content "There are no results"
end
scenario "Enable stats and results for online polls" do
unvoted_poll = create(:poll)
voted_poll = create(:poll)
create(:poll_voter, poll: voted_poll)
visit admin_poll_results_path(unvoted_poll)
expect(page).to have_content "There are no results"
expect(page).not_to have_content "Show results and stats"
visit admin_poll_results_path(voted_poll)
expect(page).to have_content "Show results and stats"
expect(page).not_to have_content "There are no results"
expect(page).not_to have_content "Results by booth"
end
scenario "Results by answer", :js do
@@ -338,23 +359,23 @@ feature 'Admin polls' do
booth_assignment_3 = create(:poll_booth_assignment, poll: poll)
question_1 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: 'Yes', question: question_1)
create(:poll_question_answer, title: 'No', question: question_1)
create(:poll_question_answer, title: "Yes", question: question_1)
create(:poll_question_answer, title: "No", question: question_1)
question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: 'Today', question: question_2)
create(:poll_question_answer, title: 'Tomorrow', question: question_2)
create(:poll_question_answer, title: "Today", question: question_2)
create(:poll_question_answer, title: "Tomorrow", question: question_2)
[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
booth_assignment: ba,
question: question_1,
answer: 'Yes',
answer: "Yes",
amount: 11)
create(:poll_partial_result,
booth_assignment: ba,
question: question_2,
answer: 'Tomorrow',
answer: "Tomorrow",
amount: 5)
end
create(:poll_recount,
@@ -383,9 +404,9 @@ feature 'Admin polls' do
end
end
within('#white_results') { expect(page).to have_content('21') }
within('#null_results') { expect(page).to have_content('44') }
within('#total_results') { expect(page).to have_content('66') }
within("#white_results") { expect(page).to have_content("21") }
within("#null_results") { expect(page).to have_content("44") }
within("#total_results") { expect(page).to have_content("66") }
end
scenario "Link to results by booth" do
@@ -394,19 +415,19 @@ feature 'Admin polls' do
booth_assignment2 = create(:poll_booth_assignment, poll: poll)
question = create(:poll_question, poll: poll)
create(:poll_question_answer, title: 'Yes', question: question)
create(:poll_question_answer, title: 'No', question: question)
create(:poll_question_answer, title: "Yes", question: question)
create(:poll_question_answer, title: "No", question: question)
create(:poll_partial_result,
booth_assignment: booth_assignment1,
question: question,
answer: 'Yes',
answer: "Yes",
amount: 5)
create(:poll_partial_result,
booth_assignment: booth_assignment2,
question: question,
answer: 'Yes',
answer: "Yes",
amount: 6)
visit admin_poll_path(poll)