Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specs cleanup #44

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _includes/toggle-color-scheme.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<button type="button"
class="btn js-unset-color-scheme btn-outline px-2"
style="margin-left: -3px; border-top-left-radius: 0; border-bottom-left-radius: 0;"
aria-label="Reset color scheme"
></button>
aria-label="Automatically switch theme"
><i class="fa-solid fa-rotate" title="Automatically switch theme"></i></button>
</span>

<script>
Expand Down
6 changes: 3 additions & 3 deletions home.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
layout: page
title: Just the Class
title: Welcome!
nav_exclude: true
permalink: /:path/
permalink: /
seo:
type: Course
name: Just the Class
name: Berkeley Class Site
---

# UC Berkeley Class Site Template
Expand Down
42 changes: 29 additions & 13 deletions spec/accessibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,40 @@
puts "Running tests on #{ALL_PAGES.count} pages."
puts " - #{ALL_PAGES.join("\n - ")}\n\n"

RSpec.shared_examples 'a11y tests' do
it 'meets WCAG 2.1' do
expect(page).to be_axe_clean
.according_to(*required_a11y_standards)
.skipping(*skipped_rules)
.excluding(*excluded_elements)
end

it 'meets WCAG 2.2' do
expect(page).to be_axe_clean
.according_to(*complete_a11y_standards)
.skipping(*skipped_rules)
.excluding(*excluded_elements)
end
end

ALL_PAGES.each do |path|
describe "#{path} is accessible", :js, type: :feature do
before do
visit(path)
end
context 'when light mode' do
before do
visit(path)
page.execute_script('jtd.setTheme("light")')
end

it 'meets WCAG 2.1' do
expect(page).to be_axe_clean
.according_to(*required_a11y_standards)
.skipping(*skipped_rules)
.excluding(*excluded_elements)
include_context 'a11y tests'
end

it 'meets WCAG 2.2' do
expect(page).to be_axe_clean
.according_to(*complete_a11y_standards)
.skipping(*skipped_rules)
.excluding(*excluded_elements)
context 'when dark mode' do
before do
visit(path)
page.execute_script('jtd.setTheme("dark")')
end

include_context 'a11y tests'
end
end
end
12 changes: 9 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@
end

Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
page = example.example_group.top_level_description.gsub(%r{^/}, '').gsub('/', '-').gsub(' is accessible', '')
standards = example.description.split.last
"tmp/capybara/screenshot_#{page}_#{standards}"
# Highly specific to a11y specs: path-mode-wcag-version
# TODO: Find a nice way to name "index" pages, or consider using Capybara.page.title
page = example.example_group.top_level_description.gsub(' is accessible', '')
mode = example.example_group.description # i.e. light mode / dark mode
standard = example.description.split.last # i.e "meets WCAG 2.1"
test_case = "#{page}_#{mode}_#{standard}"
test_case = test_case.gsub(%r{^/}, '').gsub(%r{[/\s+]}, '-')

"tmp/capybara/screenshot_#{test_case}"
end

Capybara::Screenshot.autosave_on_failure = true
Expand Down
Loading