diff --git a/Gemfile b/Gemfile index 90c096f93e7..6cd14670fb8 100644 --- a/Gemfile +++ b/Gemfile @@ -295,7 +295,7 @@ group :test do gem "rails-controller-testing", "~> 1.0.2" gem "capybara", "~> 3.40.0" - gem "capybara_accessible_selectors", git: "https://github.com/citizensadvice/capybara_accessible_selectors", tag: "v0.15.0" + gem "capybara_accessible_selectors", git: "https://github.com/citizensadvice/capybara_accessible_selectors", tag: "v0.16.0" gem "capybara-screenshot", "~> 1.0.17" gem "cuprite", "~> 0.17.0" gem "rspec-wait" diff --git a/Gemfile.lock b/Gemfile.lock index 4a9df999d10..b3a20bfd480 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/citizensadvice/capybara_accessible_selectors - revision: 5b9ce7840d04270e99f4f0cb03989e05437326a6 - tag: v0.15.0 + revision: 568699fc71b6648e7186a4ac77bba072447c131e + tag: v0.16.0 specs: capybara_accessible_selectors (0.15.0) capybara (~> 3.36) diff --git a/app/components/table_component.html.erb b/app/components/table_component.html.erb index 17e2a3410b9..27c53b728d6 100644 --- a/app/components/table_component.html.erb +++ b/app/components/table_component.html.erb @@ -42,7 +42,7 @@ See COPYRIGHT and LICENSE files for more details. <% if sortable_column?(name) %> <%= helpers.sort_header_tag(name, **options) %> <% else %> - +
diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb index 3fd55d4e29a..982b0524c57 100644 --- a/app/helpers/sort_helper.rb +++ b/app/helpers/sort_helper.rb @@ -338,7 +338,7 @@ module SortHelper # Extracts the given `options` and provides them to a block. # See #sort_header_tag and #sort_header_with_action_menu for usage examples. - def with_sort_header_options(column, allowed_params: nil, with_title: false, **options) + def with_sort_header_options(column, allowed_params: nil, with_title: false, **options) # rubocop:disable Metrics/AbcSize caption = get_caption(column, options) default_order = options.delete(:default_order) || "asc" @@ -349,6 +349,12 @@ module SortHelper options[:title] = sort_header_title(column, caption, options) if with_title options[:icon_only_header] = column == :favorited + # Give the header cell an explicit accessible name equal to the plain caption. + # Without it, the column header's accessible name is derived from its contents, + # which can include the action menu trigger text and is uppercased by the + # `text-transform` styling, neither of which should be part of the name. + options[:"aria-label"] = caption if caption.present? + within_sort_header_tag_hierarchy(options, sort_class(column)) do yield(column, caption, default_order, allowed_params:, param:, lang:, title: options[:title], sortable: options.fetch(:sortable, false), data:) diff --git a/app/views/workflows/summaries/show.html.erb b/app/views/workflows/summaries/show.html.erb index f5ed8bcff9e..3add4663a34 100644 --- a/app/views/workflows/summaries/show.html.erb +++ b/app/views/workflows/summaries/show.html.erb @@ -45,7 +45,7 @@ See COPYRIGHT and LICENSE files for more details.
<% @roles.each do |role| %> - +
<%= content_tag(role.builtin? ? "em" : "span", h(role.name)) %> diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html index ddd77c1e302..f2e3fa4ac1f 100644 --- a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html +++ b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html @@ -49,6 +49,7 @@ } @for (column of columns; track column.href) { +
@@ -165,7 +165,7 @@ RSpec.describe SortHelper do it "adds the sort class" do expect(output).to be_html_eql(<<-HTML) - +
@@ -187,7 +187,7 @@ RSpec.describe SortHelper do it "adds the sort class" do expect(output).to be_html_eql(<<-HTML) - +
@@ -219,7 +219,7 @@ RSpec.describe SortHelper do context "when not given allowed parameters" do it "copies default ones to the link" do expect(output).to be_html_eql(<<-HTML) - +
@@ -240,7 +240,7 @@ RSpec.describe SortHelper do it "copies them to the link" do expect(output).to be_html_eql(<<-HTML) - +
@@ -262,7 +262,7 @@ RSpec.describe SortHelper do it "includes the passed data param in the link" do expect(output).to be_html_eql(<<~HTML) - +
diff --git a/spec/support/capybara/additional_accessible_selectors.rb b/spec/support/capybara/additional_accessible_selectors.rb index 1a7d338377c..a16c57d0818 100644 --- a/spec/support/capybara/additional_accessible_selectors.rb +++ b/spec/support/capybara/additional_accessible_selectors.rb @@ -28,49 +28,20 @@ # See COPYRIGHT and LICENSE files for more details. #++ -# Workaround to support role filters in component specs. This should be fixed upstream. -Capybara::Node::Simple.class_eval do - def role - self[:role] - end +CapybaraAccessibleSelectors.add_role_selector(:list, within: true) do + filter_set(:capybara_accessible_selectors, %i[aria described_by]) end -Capybara.add_selector(:list) do - xpath do |*| - XPath.descendant[[ - XPath.self(:ul), - XPath.self(:ol) - ].reduce(:|)] - end - - locator_filter skip_if: nil do |node, locator, exact:, **| - method = exact ? :eql? : :include? - if node[:"aria-labelledby"] - CapybaraAccessibleSelectors::Helpers.element_labelledby(node).public_send(method, locator) - elsif node[:"aria-label"] - node[:"aria-label"].public_send(method, locator.to_s) - end - end - - filter_set(:capybara_accessible_selectors, %i[aria role described_by]) -end - -Capybara.add_selector(:list_item) do - label "list item" - - xpath do |*| - XPath.descendant[XPath.self(:li)] - end - - expression_filter(:position) do |xpath, position| - position ? "#{xpath}[#{position}]" : xpath +CapybaraAccessibleSelectors.add_role_selector(:list_item, role: :listitem, within: true, content_fallback: true) do + expression_filter(:position, skip_if: nil) do |xpath, position| + xpath[position] end describe_expression_filters do |position: nil, **| position ? " at position #{position}" : "" end - filter_set(:capybara_accessible_selectors, %i[aria role described_by]) + filter_set(:capybara_accessible_selectors, %i[aria described_by]) end module Capybara