Files
grecia/spec/components/proposals/votes_component_spec.rb
Javi Martín abec716308 Show "not allowed" message on click
Defining a behavior on hover means making it different for people using
a keyboard or a touchscreen (most of the population, nowadays).

In this case, we had an accessibility issue where the message wouldn't
disappear once it appeared. That meant that, after tabbing through all
the links and buttons in, for instance, the debates index, the page
would be filled with "participation not allowed" messages, and in order
to see the information about how many people have voted, reloading the
page was required.

For touchscreen users the behavior was similar to what we get on hover,
although we've found some inconsistencies when trying to support several
elements on the same page.

We think in proposals it makes sense to hide the "support" button when
users click on it, and the same applies to the buttonsto support and
vote investment projects. However, we aren't hiding the buttons to
agree/disagree with a debate in order to keep the information about the
current number of people agreeing and disagreeing visible.

Note we're removing some support spec methods because after these
changes the duplication isn't as obvious as it was in the past.
2022-02-23 16:43:37 +01:00

78 lines
2.5 KiB
Ruby

require "rails_helper"
describe Proposals::VotesComponent do
let(:proposal) { create(:proposal, title: "Create a monthly transport ticket") }
let(:component) { Proposals::VotesComponent.new(proposal) }
describe "support proposal button" do
it "is shown to unverified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_button "Support"
end
it "is shown to verified users" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).to have_button count: 1
expect(page).to have_button "Support", title: "Support this proposal"
expect(page).to have_button "Support Create a monthly transport ticket"
expect(page).not_to have_content "You have already supported this proposal. Share it!"
end
it "is replaced with a success message when the proposal is already supported" do
sign_in(create(:user, :level_two, votables: [proposal]))
render_inline component
expect(page).to have_content "You have already supported this proposal. Share it!"
expect(page).not_to have_button "Support", disabled: :all
end
end
describe "participation not allowed" do
it "asks anonymous users to sign in or sign up" do
render_inline component
expect(page).to have_link "sign in"
expect(page).to have_link "sign up"
end
it "says voting is not allowed to organizations" do
sign_in(create(:organization, user: create(:user, :level_two)).user)
render_inline component
expect(page).to have_content "Organizations are not permitted to vote"
expect(page).not_to have_link "sign in", visible: :all
expect(page).not_to have_link "sign up", visible: :all
end
it "says only verified users can vote to unverified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_content "Only verified users can vote on proposals"
expect(page).to have_link "verify your account"
expect(page).not_to have_link "sign in", visible: :all
expect(page).not_to have_link "sign up", visible: :all
end
it "is not rendered for verified users" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).not_to have_css ".participation-not-allowed"
expect(page).not_to have_link "verify your account", visible: :all
expect(page).not_to have_link "sign in", visible: :all
expect(page).not_to have_link "sign up", visible: :all
end
end
end