Adds scenarios (some missing) for poll voting
This commit is contained in:
28
app/views/polls/_warnings.html.erb
Normal file
28
app/views/polls/_warnings.html.erb
Normal file
@@ -0,0 +1,28 @@
|
||||
<% if current_user.nil? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout primary">
|
||||
<%= t("polls.show.cant_answer_not_logged_in",
|
||||
signin: link_to(t("polls.show.signin"), new_user_session_path, class: "probe-message"),
|
||||
signup: link_to(t("polls.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif current_user.unverified? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout warning">
|
||||
<%= t('polls.show.cant_answer_verify_html',
|
||||
verify_link: link_to(t('polls.show.verify_link'), verification_path)) %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif @poll.incoming? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout primary">
|
||||
<%= t('polls.show.cant_answer_incoming') %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif @poll.expired? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout alert">
|
||||
<%= t('polls.show.cant_answer_expired') %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,10 +1,23 @@
|
||||
<%= @poll.name %>
|
||||
|
||||
<%= render 'warnings' %>
|
||||
|
||||
<% @questions.each do |question| %>
|
||||
<div id="<%= dom_id(question) %>">
|
||||
<%= question.title %>
|
||||
|
||||
<%= question.valid_answers.each do |valid_answer| %>
|
||||
<%= link_to valid_answer %>
|
||||
<% if can? :answer, @poll %>
|
||||
<%= link_to valid_answer %>
|
||||
<% else %>
|
||||
<span><%= valid_answer %></span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if false #wrong geozone %>
|
||||
<div class="callout warning">
|
||||
<%= t('polls.show.cant_answer_wrong_geozone') %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -375,6 +375,16 @@ en:
|
||||
update:
|
||||
form:
|
||||
submit_button: Save changes
|
||||
polls:
|
||||
show:
|
||||
cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate."
|
||||
signin: Sign in
|
||||
signup: Sign up
|
||||
cant_answer_verify_html: "You must %{verify_link} in order to answer."
|
||||
verify_link: "verify your account"
|
||||
cant_answer_incoming: "This poll has not yet started."
|
||||
cant_answer_expired: "This poll has finished."
|
||||
cant_answer_wrong_geozone: "This enquiry is not available on your geozone."
|
||||
proposal_ballots:
|
||||
title: "Votings"
|
||||
description_html: "The following citizen proposals that have reached the <strong>required supports</strong> and will be voted."
|
||||
|
||||
@@ -3,31 +3,173 @@ require 'rails_helper'
|
||||
|
||||
feature 'Polls' do
|
||||
|
||||
scenario 'Polls can be listed' do
|
||||
polls = create_list(:poll, 3)
|
||||
context '#index' do
|
||||
|
||||
visit polls_path
|
||||
scenario 'Polls can be listed' do
|
||||
polls = create_list(:poll, 3)
|
||||
|
||||
polls.each do |poll|
|
||||
expect(page).to have_link(poll.name)
|
||||
end
|
||||
end
|
||||
visit polls_path
|
||||
|
||||
scenario 'Polls can be seen' do
|
||||
poll = create(:poll)
|
||||
questions = create_list(:poll_question, 5, poll: poll)
|
||||
|
||||
visit poll_path(poll)
|
||||
expect(page).to have_content(poll.name)
|
||||
|
||||
questions.each do |question|
|
||||
within("#poll_question_#{question.id}") do
|
||||
expect(page).to have_content(question.title)
|
||||
question.valid_answers.each do |answer|
|
||||
expect(page).to have_link(answer)
|
||||
end
|
||||
polls.each do |poll|
|
||||
expect(page).to have_link(poll.name)
|
||||
end
|
||||
end
|
||||
|
||||
xscenario 'Filtering enquiries' do
|
||||
create(:poll_question, poll: poll, title: "Open question")
|
||||
create(:poll_question, :incoming, poll: poll, title: "Incoming question")
|
||||
create(:poll_question, :expired, poll: poll, title: "Expired question")
|
||||
|
||||
visit enquiries_path
|
||||
expect(page).to have_content('Open question')
|
||||
expect(page).to_not have_content('Incoming question')
|
||||
expect(page).to_not have_content('Expired question')
|
||||
|
||||
visit enquiries_path(filter: 'incoming')
|
||||
expect(page).to_not have_content('Open question')
|
||||
expect(page).to have_content('Incoming question')
|
||||
expect(page).to_not have_content('Expired question')
|
||||
|
||||
visit enquiries_path(filter: 'expired')
|
||||
expect(page).to_not have_content('Open question')
|
||||
expect(page).to_not have_content('Incoming question')
|
||||
expect(page).to have_content('Expired question')
|
||||
end
|
||||
|
||||
xscenario "Current filter is properly highlighted" do
|
||||
visit enquiries_path
|
||||
expect(page).to_not have_link('Open')
|
||||
expect(page).to have_link('Incoming')
|
||||
expect(page).to have_link('Expired')
|
||||
|
||||
visit enquiries_path(filter: 'incoming')
|
||||
expect(page).to have_link('Open')
|
||||
expect(page).to_not have_link('Incoming')
|
||||
expect(page).to have_link('Expired')
|
||||
|
||||
visit enquiries_path(filter: 'expired')
|
||||
expect(page).to have_link('Open')
|
||||
expect(page).to have_link('Incoming')
|
||||
expect(page).to_not have_link('Expired')
|
||||
end
|
||||
end
|
||||
|
||||
context 'Show' do
|
||||
let(:geozone) { create(:geozone) }
|
||||
let(:poll) { create(:poll) }
|
||||
|
||||
scenario 'Lists questions from proposals as well as regular ones' do
|
||||
normal_question = create(:poll_question, poll: poll)
|
||||
proposal_question = create(:poll_question, poll: poll, proposal: create(:proposal))
|
||||
|
||||
visit poll_path(poll)
|
||||
expect(page).to have_content(poll.name)
|
||||
|
||||
expect(page).to have_content(normal_question.title)
|
||||
expect(page).to have_content(proposal_question.title)
|
||||
end
|
||||
|
||||
scenario 'Non-logged in users' do
|
||||
create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content('Han Solo')
|
||||
expect(page).to have_content('Chewbacca')
|
||||
expect(page).to have_content('You must Sign in or Sign up to participate')
|
||||
|
||||
expect(page).to_not have_link('Han Solo')
|
||||
expect(page).to_not have_link('Chewbacca')
|
||||
end
|
||||
|
||||
scenario 'Level 1 users' do
|
||||
create(:poll_question, poll: poll, geozone_ids: [geozone.id], valid_answers: 'Han Solo, Chewbacca')
|
||||
login_as(create(:user, geozone: geozone))
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content('Han Solo')
|
||||
expect(page).to have_content('Chewbacca')
|
||||
expect(page).to have_content('You must verify your account in order to answer')
|
||||
|
||||
expect(page).to_not have_link('Han Solo')
|
||||
expect(page).to_not have_link('Chewbacca')
|
||||
end
|
||||
|
||||
scenario 'Level 2 users in an incoming question' do
|
||||
incoming_poll = create(:poll, :incoming)
|
||||
create(:poll_question, poll: incoming_poll, geozone_ids: [geozone.id], valid_answers: 'Rey, Finn')
|
||||
login_as(create(:user, :level_two, geozone: geozone))
|
||||
|
||||
visit poll_path(incoming_poll)
|
||||
|
||||
expect(page).to have_content('Rey')
|
||||
expect(page).to have_content('Finn')
|
||||
expect(page).to_not have_link('Rey')
|
||||
expect(page).to_not have_link('Finn')
|
||||
|
||||
expect(page).to have_content('This poll has not yet started')
|
||||
end
|
||||
|
||||
scenario 'Level 2 users in an expired question' do
|
||||
expired_poll = create(:poll, :expired)
|
||||
create(:poll_question, poll: expired_poll, geozone_ids: [geozone.id], valid_answers: 'Luke, Leia')
|
||||
login_as(create(:user, :level_two, geozone: geozone))
|
||||
|
||||
visit poll_path(expired_poll)
|
||||
|
||||
expect(page).to have_content('Luke')
|
||||
expect(page).to have_content('Leia')
|
||||
expect(page).to_not have_link('Luke')
|
||||
expect(page).to_not have_link('Leia')
|
||||
|
||||
expect(page).to have_content('This poll has finished')
|
||||
end
|
||||
|
||||
xscenario 'Level 2 users in an question for a geozone which is not theirs' do
|
||||
create(:poll_question, poll: poll, geozone_ids: [], valid_answers: 'Vader, Palpatine')
|
||||
login_as(create(:user, :level_two))
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content('Vader')
|
||||
expect(page).to have_content('Palpatine')
|
||||
expect(page).to_not have_link('Vader')
|
||||
expect(page).to_not have_link('Palpatine')
|
||||
end
|
||||
|
||||
xscenario 'Level 2 users who can answer' do
|
||||
create(:poll_question, poll: poll, geozone_ids: [geozone.id], valid_answers: 'Han Solo, Chewbacca')
|
||||
login_as(create(:user, :level_two, geozone: geozone))
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_link('Han Solo')
|
||||
expect(page).to have_link('Chewbacca')
|
||||
end
|
||||
|
||||
xscenario 'Level 2 users who have already answered' do
|
||||
question = create(:poll_question, poll: poll, geozone_ids:[geozone.id], valid_answers: 'Han Solo, Chewbacca')
|
||||
user = create(:user, :level_two, geozone: geozone)
|
||||
create(:question_answer, question: question, author: user, answer: 'Chewbacca')
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_link('Han Solo')
|
||||
expect(page).to_not have_link('Chewbacca')
|
||||
expect(page).to have_content('Chewbacca')
|
||||
end
|
||||
|
||||
xscenario 'Level 2 users answering', :js do
|
||||
create(:poll_question, poll: poll, geozone_ids: [geozone.id], valid_answers: 'Han Solo, Chewbacca')
|
||||
user = create(:user, :level_two, geozone: geozone)
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
click_link 'Han Solo'
|
||||
|
||||
expect(page).to_not have_link('Han Solo')
|
||||
expect(page).to have_link('Chewbacca')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user