diff --git a/app/components/users/budget_investment_table_actions_component.rb b/app/components/users/budget_investment_table_actions_component.rb index 8a12a4e33..e3dfb12db 100644 --- a/app/components/users/budget_investment_table_actions_component.rb +++ b/app/components/users/budget_investment_table_actions_component.rb @@ -11,6 +11,7 @@ class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent def edit_link link_to t("shared.edit"), edit_budget_investment_path(investment.budget, investment), + "aria-label": action_label(t("shared.edit")), class: "button hollow" end @@ -18,7 +19,12 @@ class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent button_to t("shared.delete"), budget_investment_path(investment.budget, investment), method: :delete, + "aria-label": action_label(t("shared.delete")), class: "button hollow alert", data: { confirm: t("users.show.delete_alert") } end + + def action_label(action_text) + t("shared.actions.label", action: action_text, name: investment.title) + end end diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 5168cbd9d..95a9db662 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -644,6 +644,8 @@ en: show: back: "Go back to my content" shared: + actions: + label: "%{action} %{name}" edit: "Edit" filter: "Filter" save: "Save" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index e8bf22da2..05071f11f 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -644,6 +644,8 @@ es: show: back: "Volver a mi contenido" shared: + actions: + label: "%{action} %{name}" edit: "Editar" filter: "Filtrar" save: "Guardar" diff --git a/spec/components/users/budget_investment_table_actions_component_spec.rb b/spec/components/users/budget_investment_table_actions_component_spec.rb new file mode 100644 index 000000000..400721f8a --- /dev/null +++ b/spec/components/users/budget_investment_table_actions_component_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +describe Users::BudgetInvestmentTableActionsComponent do + let(:user) { create(:user, :level_two) } + let(:budget) { create(:budget, :accepting) } + let(:investment) { create(:budget_investment, budget: budget, author: user, title: "User investment") } + + describe "#edit_link" do + it "generates an aria-label attribute" do + sign_in(user) + + render_inline Users::BudgetInvestmentTableActionsComponent.new(investment) + + expect(page).to have_link count: 1 + expect(page).to have_link "Edit" + expect(page).to have_css "a[aria-label='Edit User investment']" + end + end + + describe "#destroy_button" do + it "generates an aria-label attribute" do + sign_in(user) + + render_inline Users::BudgetInvestmentTableActionsComponent.new(investment) + + expect(page).to have_button count: 1 + expect(page).to have_button "Delete" + expect(page).to have_css "button[aria-label='Delete User investment']" + end + end +end