Skip to content

Commit

Permalink
Merge branch 'dev' into 88_evaluators_evaluation_progress_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
emmabjj authored Jan 10, 2025
2 parents 6621d4e + 7348242 commit 1abb4eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
</head>

<body>
<a class="usa-skipnav" href="#main-content">Skip to main content</a>

<%= render "layouts/header" %>
<% if logged_in? %>
<%= render "layouts/utility_menu" %>
<% end %>
<%= render "shared/flash" %>

<main class="grid-container">
<main id="main-content" class="grid-container" tabindex="-1">
<%= yield %>
</main>

Expand Down
49 changes: 49 additions & 0 deletions spec/system/skip_to_main_content_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Skip to main content navigation', :js, type: :system do
let(:user) { create_user(role: "challenge_manager") }

before do
system_login_user(user)
end

context "when on dashboard index page" do
before { visit dashboard_path }

it 'is hidden by default but present in the DOM' do
expect(page).to have_css('.usa-skipnav', visible: false)
end

it 'becomes visible when focused via keyboard tab' do
find('body').send_keys(:tab)
expect(page).to have_css('.usa-skipnav', visible: true)
end

it 'moves focus to main content when using keyboard' do
find('body').send_keys(:tab)
find('.usa-skipnav', visible: true).send_keys(:return)
expect(page.evaluate_script('document.activeElement.id')).to eq('main-content')
end
end

context "when on phases index page" do
before { visit phases_path }

it 'is hidden by default but present in the DOM' do
expect(page).to have_css('.usa-skipnav', visible: false)
end

it 'becomes visible when focused via keyboard tab' do
find('body').send_keys(:tab)
expect(page).to have_css('.usa-skipnav', visible: true)
end

it 'moves focus to main content when using keyboard' do
find('body').send_keys(:tab)
find('.usa-skipnav', visible: true).send_keys(:return)
expect(page.evaluate_script('document.activeElement.id')).to eq('main-content')
end
end
end

0 comments on commit 1abb4eb

Please sign in to comment.