Use a <main> tag on every page
Many pages had this tag, but many other didn't, which made navigation inconsistent for people using screen readers. Note that there are slight changes in two pages: * The homepage now includes the banner and the content of the `shared/header` element inside the <main> tag * The budgets index now includes the banner inside the <main> tag I see both potential advantages and disadvantages of this approach, since banners aren't necessarily related to the main content of a page but on the other hand they aren't the same across pages and people using screen readers might accidentally skip them if they jump to the <main> tag. So I'm choosing the option that is easier to implement. Note we're adding a `public-content` class to the <main> element in the application layout. This might be redundat because the element could already be accessed through the `.public main` selector, but this is consistent with the `admin-content` class used in the admin section, and without it the <main> element would sometimes have an empty class attribute and we'd have to use `if content_for?(:main_class)` or `tag.main` which IMHO makes the code less consistent. The Capybara::DSL monkey-patch is only done on the `visit` method because it's the only reliable one. Other methods like `click_link` generate AJAX requests, so `expect(page).to have_css "main", count: 1` might be executed before the AJAX request is finished, meaning it wouldn't properly test anything.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<main class="admin-budgets-show">
|
||||
<% provide :main_class, "admin-budgets-show" %>
|
||||
|
||||
<%= back_link_to admin_budgets_path %>
|
||||
|
||||
<%= header %>
|
||||
@@ -21,4 +22,3 @@
|
||||
<h3 id="actions_header"><%= t("admin.budgets.edit.actions") %></h3>
|
||||
<%= render Admin::Budgets::ActionsComponent.new(budget) %>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="admin-budgets-wizard-headings-index">
|
||||
<% provide :main_class, "admin-budgets-wizard-headings-index" %>
|
||||
|
||||
<%= back_link_to admin_budgets_wizard_budget_groups_path(budget, url_params), back_link_text %>
|
||||
|
||||
<%= header %>
|
||||
@@ -11,4 +12,3 @@
|
||||
<%= render Admin::BudgetHeadings::HeadingsComponent.new(headings) %>
|
||||
<% end %>
|
||||
<%= render Admin::BudgetsWizard::Headings::CreationStepComponent.new(new_heading) %>
|
||||
</main>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<% provide :main_class, "budget-groups-index" %>
|
||||
|
||||
<% content_for :canonical do %>
|
||||
<%= render "shared/canonical", href: budget_groups_url %>
|
||||
<% end %>
|
||||
|
||||
<main class="budget-groups-index">
|
||||
<%= header(before: back_link_to(budget_path(budget))) %>
|
||||
<%= render Budgets::GroupsAndHeadingsComponent.new(budget) %>
|
||||
</main>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<main class="budget-investment-new">
|
||||
<% provide :main_class, "budget-investment-new" %>
|
||||
|
||||
<%= back_link_to budgets_path %>
|
||||
|
||||
<%= header %>
|
||||
|
||||
<%= render "/budgets/investments/form", form_url: budget_investments_path(budget) %>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="debate-new">
|
||||
<% provide :main_class, "debate-new" %>
|
||||
|
||||
<%= back_link_to debates_path, t("debates.index.section_header.title") %>
|
||||
|
||||
<%= header do %>
|
||||
@@ -17,4 +18,3 @@
|
||||
</aside>
|
||||
|
||||
<%= render Debates::FormComponent.new(debate) %>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="moderation-users-index">
|
||||
<% provide :main_class, "moderation-users-index" %>
|
||||
|
||||
<h2><%= t("moderation.users.index.title") %></h2>
|
||||
|
||||
<%= render Admin::SearchComponent.new(label: t("moderation.users.index.search_placeholder")) %>
|
||||
@@ -44,4 +45,3 @@
|
||||
|
||||
<%= paginate users %>
|
||||
<% end %>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="proposal-new">
|
||||
<% provide :main_class, "proposal-new" %>
|
||||
|
||||
<%= back_link_to proposals_path, t("proposals.index.section_header.title") %>
|
||||
|
||||
<%= header do %>
|
||||
@@ -16,4 +17,3 @@
|
||||
</aside>
|
||||
|
||||
<%= render Proposals::FormComponent.new(proposal, url: proposals_path) %>
|
||||
</main>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% provide(:title) { title } %>
|
||||
<% provide :main_class, "sdg-goals-index" %>
|
||||
|
||||
<main class="sdg-goals-index">
|
||||
<% if header.present? %>
|
||||
<%= render "shared/header", header: header %>
|
||||
<% else %>
|
||||
@@ -22,4 +22,3 @@
|
||||
<%= render "shared/cards", cards: phase.cards.sort_by_order %>
|
||||
</section>
|
||||
<% end %>
|
||||
</main>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% provide(:title) { goal.title } %>
|
||||
<% provide :main_class, "sdg-goal-show" %>
|
||||
|
||||
<main class="sdg-goal-show">
|
||||
<%= back_link_to sdg_goals_path %>
|
||||
|
||||
<article class="sdg-goal sdg-goal-<%= code %>">
|
||||
@@ -36,4 +36,3 @@
|
||||
<% end %>
|
||||
|
||||
<%= render SDG::Goals::TargetsComponent.new(goal) %>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="subscriptions-edit">
|
||||
<% provide :main_class, "subscriptions-edit" %>
|
||||
|
||||
<%= form_for user, url: subscriptions_path(token: user.subscriptions_token) do |f| %>
|
||||
<h2><%= t("account.show.notifications") %></h2>
|
||||
|
||||
@@ -10,4 +11,3 @@
|
||||
|
||||
<%= f.submit t("account.show.save_changes_submit"), class: "button margin-top" %>
|
||||
<% end %>
|
||||
</main>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<main id="ballot" class="budget-ballot-show">
|
||||
<% provide :main_class, "budget-ballot-show" %>
|
||||
|
||||
<div id="ballot">
|
||||
<%= render "budgets/ballot/ballot" %>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="budget-group-show">
|
||||
<% provide :main_class, "budget-group-show" %>
|
||||
|
||||
<header>
|
||||
<%= back_link_to budget_path(@budget) %>
|
||||
<h1><%= t("budgets.groups.show.title") %></h1>
|
||||
@@ -25,4 +26,3 @@
|
||||
<%= image_tag(image_path_for("map.jpg")) %>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<%= render Shared::BannerComponent.new("budgets") %>
|
||||
|
||||
<% provide :title do %><%= t("budgets.index.title") %><% end %>
|
||||
<% provide :main_class, "budgets-index" %>
|
||||
|
||||
<% content_for :canonical do %>
|
||||
<%= render "shared/canonical", href: budgets_url %>
|
||||
<% end %>
|
||||
|
||||
<main class="budgets-index">
|
||||
<% if @budget.present? %>
|
||||
<%= render Budgets::BudgetComponent.new(@budget) %>
|
||||
|
||||
@@ -28,4 +28,3 @@
|
||||
<% end %>
|
||||
|
||||
<%= render Budgets::FooterComponent.new %>
|
||||
</main>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<main id="budget-investments-main">
|
||||
<% if @search_terms || @advanced_search_terms %>
|
||||
<%= render Shared::SearchResultsSummaryComponent.new(
|
||||
results: @investments,
|
||||
@@ -87,4 +86,3 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<%= render "shared/canonical", href: debates_url %>
|
||||
<% end %>
|
||||
|
||||
<main>
|
||||
<% if @search_terms || @advanced_search_terms %>
|
||||
<%= render Shared::SearchResultsSummaryComponent.new(
|
||||
results: @debates,
|
||||
@@ -82,6 +81,4 @@
|
||||
<%= render "shared/tag_cloud", taggable: "Debate" %>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<% end %>
|
||||
</nav>
|
||||
|
||||
<div class="admin-content <%= yield(:main_class) %>">
|
||||
<main class="admin-content <%= yield(:main_class) %>">
|
||||
<%= label_tag :show_menu, t("admin.menu.admin"),
|
||||
"aria-hidden": true, class: "button hollow expanded" %>
|
||||
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
|
||||
<div class="wrapper <%= yield(:wrapper_class) %>">
|
||||
<%= render "layouts/header", with_subnavigation: true %>
|
||||
<%= render "layouts/flash" %>
|
||||
|
||||
<main class="public-content <%= yield(:main_class) %>">
|
||||
<%= render "layouts/flash" %>
|
||||
<%= yield %>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<%= render "dashboard/menu" %>
|
||||
</nav>
|
||||
|
||||
<div class="admin-content">
|
||||
<main class="admin-content <%= yield(:main_class) %>">
|
||||
<%= label_tag :show_menu, t("admin.menu.admin"),
|
||||
"aria-hidden": true, class: "button hollow expanded" %>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<%= render "layouts/dashboard/proposal_totals" %>
|
||||
<%= render "layouts/dashboard/proposal_header" %>
|
||||
<%= yield %>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
<div class="small-12 medium-9 column">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 large-7 small-centered column">
|
||||
<div class="auth-form margin">
|
||||
<main class="auth-form margin <%= yield(:main_class) %>">
|
||||
<%= render "layouts/flash" %>
|
||||
|
||||
<%= yield %>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<%= render "shared/canonical", href: proposals_url %>
|
||||
<% end %>
|
||||
|
||||
<main>
|
||||
<% if [
|
||||
@search_terms,
|
||||
@advanced_search_terms,
|
||||
@@ -125,6 +124,4 @@
|
||||
<%= render "proposals_lists" %>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<main>
|
||||
<div class="row proposals-summary">
|
||||
<div id="proposals" class="proposals-list small-12 medium-9 column">
|
||||
<%= back_link_to %>
|
||||
@@ -50,4 +49,3 @@
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<main class="topic-edit">
|
||||
<% provide :main_class, "topic-edit" %>
|
||||
|
||||
<%= back_link_to community_path(@community) %>
|
||||
|
||||
<h1><%= t("community.topic.edit") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<main class="topic-new">
|
||||
<% provide :main_class, "topic-new" %>
|
||||
|
||||
<%= back_link_to community_path(@community) %>
|
||||
|
||||
<h1><%= t("community.topic.create") %></h1>
|
||||
@@ -14,4 +15,3 @@
|
||||
</aside>
|
||||
|
||||
<%= render "form" %>
|
||||
</main>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<main>
|
||||
<div class="activity row margin-top">
|
||||
<div class="small-12 column">
|
||||
|
||||
@@ -25,4 +24,3 @@
|
||||
<%= render Users::PublicActivityComponent.new(@user) %>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
<%= render "shared/header", header: @header %>
|
||||
|
||||
<main>
|
||||
<%= render "feeds" %>
|
||||
|
||||
<div class="row">
|
||||
@@ -37,4 +36,3 @@
|
||||
recommended_debates: @recommended_debates,
|
||||
recommended_proposals: @recommended_proposals %>
|
||||
<% end %>
|
||||
</main>
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="error">
|
||||
<main class="error">
|
||||
<h1>403</h1>
|
||||
<h2>Access to this page has been disabled by the administrators.</h2>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="error">
|
||||
<main class="error">
|
||||
<h1>404</h1>
|
||||
<h2>Not found.</h2>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="error">
|
||||
<main class="error">
|
||||
<h1>422</h1>
|
||||
<h2>The change you wanted was rejected.</h2>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="error">
|
||||
<main class="error">
|
||||
<h1>500</h1>
|
||||
<h2>Internal server error.</h2>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -53,6 +53,20 @@ end
|
||||
|
||||
FactoryBot.use_parent_strategy = false
|
||||
|
||||
module Capybara
|
||||
module DSL
|
||||
alias_method :original_visit, :visit
|
||||
|
||||
def visit(url, ...)
|
||||
original_visit(url, ...)
|
||||
|
||||
unless url.match?("robots.txt") || url.match?("active_storage/representations")
|
||||
expect(page).to have_css "main", count: 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.register_driver :headless_chrome do |app|
|
||||
options = Selenium::WebDriver::Chrome::Options.new.tap do |opts|
|
||||
opts.add_argument "--headless"
|
||||
|
||||
Reference in New Issue
Block a user