diff --git a/app/views/polls/_results_subnavigation.html.erb b/app/views/polls/_results_subnavigation.html.erb index 43aa95b40..9c2a7e8b0 100644 --- a/app/views/polls/_results_subnavigation.html.erb +++ b/app/views/polls/_results_subnavigation.html.erb @@ -4,14 +4,14 @@
  • <%= link_to "#tab-stats" do %>

    - <%= "Estadísticas" %> + <%= t("polls.show.stats_menu") %>

    <% end %>
  • <%= link_to "#tab-information" do %>

    - <%= "Información" %> + <%= t("polls.show.info_menu") %>

    <% end %>
  • diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index e39d1aa07..6867a1aa1 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -497,6 +497,8 @@ en: read_more: "Read more about %{answer}" read_less: "Read less about %{answer}" participate_in_other_polls: Participate in other polls + info_menu: "Information" + stats_menu: "Participation statistics" stats: title: "Participation data" total_participation: "Total participation" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 8ba167a05..38f4077c7 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -497,6 +497,8 @@ es: read_more: "Leer más sobre %{answer}" read_less: "Leer menos sobre %{answer}" participate_in_other_polls: Participar en otras votaciones + info_menu: "Información" + stats_menu: "Estadísticas de participación" stats: title: "Datos de participación" total_participation: "Participación total" diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 90deca711..223aa9e9d 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -357,4 +357,17 @@ feature 'Polls' do end end + + context "Results and stats" do + scenario "See polls statistics", :js do + user = create(:user) + poll = create(:poll, summary: "Summary", description: "Description") + login_as user + visit poll_path(poll) + + click_link "Participation statistics" + + expect(page).to have_content("Total participation") + end + end end diff --git a/spec/models/poll/stats_spec.rb b/spec/models/poll/stats_spec.rb new file mode 100644 index 000000000..ee431fa97 --- /dev/null +++ b/spec/models/poll/stats_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +describe Poll::Stats do + + describe "Calculate stats" do + it "Generate the correct stats" do + poll = create(:poll) + booth = create(:poll_booth) + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_voter, poll: poll, origin: 'web') + 3.times {create(:poll_voter, poll: poll, origin: 'booth')} + create(:poll_voter, poll: poll) + create(:poll_recount, origin: 'booth', white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id) + stats = Poll::Stats.new(poll).generate + + expect(stats[:total_participants]).to eq(5) + expect(stats[:total_participants_web]).to eq(2) + expect(stats[:total_participants_booth]).to eq(3) + expect(stats[:total_valid_votes]).to eq(4) + expect(stats[:total_white_votes]).to eq(1) + expect(stats[:total_null_votes]).to eq(0) + + expect(stats[:total_web_valid]).to eq(2) + expect(stats[:total_web_white]).to eq(0) + expect(stats[:total_web_null]).to eq(0) + + expect(stats[:total_booth_valid]).to eq(2) + expect(stats[:total_booth_white]).to eq(1) + expect(stats[:total_booth_null]).to eq(0) + + expect(stats[:total_participants_web_percentage]).to eq(40) + expect(stats[:total_participants_booth_percentage]).to eq(60) + expect(stats[:valid_percentage_web]).to eq(50) + expect(stats[:white_percentage_web]).to eq(0) + expect(stats[:null_percentage_web]).to eq(0) + expect(stats[:valid_percentage_booth]).to eq(50) + expect(stats[:white_percentage_booth]).to eq(100) + expect(stats[:null_percentage_booth]).to eq(0) + expect(stats[:total_valid_percentage]).to eq(80) + expect(stats[:total_white_percentage]).to eq(20) + expect(stats[:total_null_percentage]).to eq(0) + end + end + +end \ No newline at end of file