Add investment name to vote links aria-label

Note we're using the `budgets.investments.investment.add_label` and
`budgets.ballots.show.remove_label` internationalization keys so they're
consistent with the `budgets.investments.investment.add` and
`budgets.ballots.show.remove` keys which were already present. We aren't
unifying these keys in order to keep existing translations.
This commit is contained in:
Javi Martín
2021-09-30 21:57:01 +02:00
parent 4fd99e2d30
commit 704687dc54
5 changed files with 63 additions and 2 deletions

View File

@@ -14,7 +14,8 @@
investments_ids: investment_ids), investments_ids: investment_ids),
class: "button button-remove-support expanded", class: "button button-remove-support expanded",
method: :delete, method: :delete,
remote: true %> remote: true,
"aria-label": remove_vote_aria_label %>
<% end %> <% end %>
</div> </div>
<% else %> <% else %>
@@ -30,7 +31,8 @@
class: "button button-support expanded", class: "button button-support expanded",
title: t("budgets.investments.investment.support_title"), title: t("budgets.investments.investment.support_title"),
method: :post, method: :post,
remote: true %> remote: true,
"aria-label": vote_aria_label %>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>

View File

@@ -24,6 +24,14 @@ class Budgets::Investments::BallotComponent < ApplicationComponent
@reason ||= investment.reason_for_not_being_ballotable_by(current_user, ballot) @reason ||= investment.reason_for_not_being_ballotable_by(current_user, ballot)
end end
def vote_aria_label
t("budgets.investments.investment.add_label", investment: investment.title)
end
def remove_vote_aria_label
t("budgets.ballots.show.remove_label", investment: investment.title)
end
def link_to_my_heading def link_to_my_heading
link_to(investment.heading.name, link_to(investment.heading.name,
budget_investments_path(budget_id: investment.budget_id, budget_investments_path(budget_id: investment.budget_id,

View File

@@ -23,6 +23,7 @@ en:
other: "You can vote up to <span>%{count}</span> projects" other: "You can vote up to <span>%{count}</span> projects"
no_balloted_group_yet: "You have not voted on this group yet, go vote!" no_balloted_group_yet: "You have not voted on this group yet, go vote!"
remove: Remove vote remove: Remove vote
remove_label: "Remove your vote for %{investment}"
voted: voted:
one: "You have voted <span>one</span> investment." one: "You have voted <span>one</span> investment."
other: "You have voted <span>%{count}</span> investments." other: "You have voted <span>%{count}</span> investments."
@@ -151,6 +152,7 @@ en:
wrong_price_format: Only integer numbers wrong_price_format: Only integer numbers
investment: investment:
add: Vote add: Vote
add_label: "Vote %{investment}"
already_added: You have already added this investment project already_added: You have already added this investment project
support_title: Support this project support_title: Support this project
supports: supports:

View File

@@ -23,6 +23,7 @@ es:
other: "Puedes votar hasta <span>%{count}</span> proyectos" other: "Puedes votar hasta <span>%{count}</span> proyectos"
no_balloted_group_yet: "Todavía no has votado proyectos de este grupo, ¡vota!" no_balloted_group_yet: "Todavía no has votado proyectos de este grupo, ¡vota!"
remove: Quitar voto remove: Quitar voto
remove_label: "Quitar tu voto a %{investment}"
voted: voted:
one: "Has votado <span>un</span> proyecto." one: "Has votado <span>un</span> proyecto."
other: "Has votado <span>%{count}</span> proyectos." other: "Has votado <span>%{count}</span> proyectos."
@@ -151,6 +152,7 @@ es:
wrong_price_format: Solo puede incluir caracteres numéricos wrong_price_format: Solo puede incluir caracteres numéricos
investment: investment:
add: Votar add: Votar
add_label: "Votar %{investment}"
already_added: Ya has añadido este proyecto de gasto already_added: Ya has añadido este proyecto de gasto
support_title: Apoyar este proyecto support_title: Apoyar este proyecto
supports: supports:

View File

@@ -0,0 +1,47 @@
require "rails_helper"
describe Budgets::Investments::BallotComponent do
describe "vote investment link" do
let(:budget) { create(:budget, :balloting) }
let(:investment) { create(:budget_investment, :selected, title: "New Sports Center", budget: budget) }
let(:component) do
Budgets::Investments::BallotComponent.new(
investment: investment,
investment_ids: [],
ballot: Budget::Ballot.where(budget: budget, user: controller.current_user).first_or_create!,
assigned_heading: nil
)
end
it "is shown alongside a 'not allowed' message to unverified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_link "Vote"
expect(page).to have_content "Only verified users can vote on investments; verify your account."
end
it "is shown to verified users" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).to have_link count: 1
expect(page).to have_link "Vote", title: "Support this project"
expect(page).to have_link "Vote New Sports Center"
expect(page).not_to have_link "Remove vote"
end
it "is replaced with a link to remove the vote when the user has already voted" do
sign_in(create(:user, :level_two, ballot_lines: [investment]))
render_inline component
expect(page).to have_link count: 1
expect(page).to have_link "Remove vote"
expect(page).to have_link "Remove your vote for New Sports Center"
expect(page).not_to have_link "Vote"
end
end
end