-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: Add Accessibility test for the Similar School Page #84
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
Open
vipinsamreddy
wants to merge
2
commits into
main
Choose a base branch
from
feature/Accessibility-test-similar-school
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
Tests/SAPSec.UI.Tests/AccessibilityTests/SimilarSchoolsAccessibilityTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| using Deque.AxeCore.Playwright; | ||
| using FluentAssertions; | ||
| using Microsoft.Playwright; | ||
| using SAPSec.UI.Tests.Infrastructure; | ||
| using Xunit; | ||
|
|
||
| namespace SAPSec.UI.Tests.AccessibilityTests; | ||
|
|
||
| [Collection("UITestsCollection")] | ||
| public class SimilarSchoolsAccessibilityTests(WebApplicationSetupFixture fixture) : BasePageTest(fixture) | ||
| { | ||
| private const string SimilarSchoolsPath = "/school/108088/view-similar-schools"; | ||
|
|
||
| private async Task NavigateToPageAsync() | ||
| { | ||
| await Page.GotoAsync(SimilarSchoolsPath); | ||
| await Page.WaitForLoadStateAsync(LoadState.DOMContentLoaded); | ||
| await Page.WaitForSelectorAsync("main"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SimilarSchools_PassesAxeAccessibilityChecks() | ||
| { | ||
| await NavigateToPageAsync(); | ||
|
|
||
| var results = await Page.RunAxe(); | ||
| var criticalViolations = results.Violations | ||
| .Where(v => v.Impact == "critical" || v.Impact == "serious") | ||
| .ToList(); | ||
|
|
||
| criticalViolations.Should().BeEmpty( | ||
| $"Found violations: {string.Join(", ", criticalViolations.Select(v => v.Description))}"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SimilarSchools_HasExpectedLandmarksAndHeadingStructure() | ||
| { | ||
| await NavigateToPageAsync(); | ||
|
|
||
| (await Page.Locator("main#main-content").CountAsync()).Should().Be(1); | ||
| (await Page.Locator("header").CountAsync()).Should().BeGreaterThan(0); | ||
| (await Page.Locator("footer").CountAsync()).Should().Be(1); | ||
| (await Page.Locator("h1").CountAsync()).Should().Be(1); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SimilarSchools_FilterFormControls_HaveLabels() | ||
| { | ||
| await NavigateToPageAsync(); | ||
|
|
||
| var unlabeledControls = await Page.EvaluateAsync<int>(@" | ||
| () => { | ||
| const form = document.querySelector('#similar-schools-filter-form'); | ||
| if (!form) return -1; | ||
|
|
||
| const controls = form.querySelectorAll('input, select, textarea'); | ||
| const isHidden = (el) => | ||
| el.type === 'hidden' || el.closest('[hidden], [aria-hidden=""true""]'); | ||
|
|
||
| let unlabeled = 0; | ||
| controls.forEach(control => { | ||
| if (isHidden(control)) return; | ||
| const id = control.getAttribute('id'); | ||
| const hasLabel = (id && document.querySelector(`label[for=""${id}""]`)) || | ||
| control.hasAttribute('aria-label') || | ||
| control.hasAttribute('aria-labelledby'); | ||
| if (!hasLabel) unlabeled++; | ||
| }); | ||
|
|
||
| return unlabeled; | ||
| } | ||
| "); | ||
|
|
||
| unlabeledControls.Should().Be(0, "All visible form controls should have accessible labels"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SimilarSchools_MapRegion_HasAccessibleName() | ||
| { | ||
| await NavigateToPageAsync(); | ||
|
|
||
| var map = Page.Locator("#map"); | ||
| (await map.CountAsync()).Should().Be(1); | ||
| (await map.GetAttributeAsync("role")).Should().Be("region"); | ||
| (await map.GetAttributeAsync("aria-label")).Should().NotBeNullOrWhiteSpace(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SimilarSchools_FilterSections_ExposeExpandCollapseState() | ||
| { | ||
| await NavigateToPageAsync(); | ||
|
|
||
| var toggles = Page.Locator(".app-filter-section__toggle"); | ||
| var count = await toggles.CountAsync(); | ||
| count.Should().BeGreaterThan(0); | ||
|
|
||
| for (var i = 0; i < Math.Min(count, 5); i++) | ||
| { | ||
| var toggle = toggles.Nth(i); | ||
| var controls = await toggle.GetAttributeAsync("aria-controls"); | ||
| var expanded = await toggle.GetAttributeAsync("aria-expanded"); | ||
|
|
||
| controls.Should().NotBeNullOrWhiteSpace(); | ||
| (expanded == "true" || expanded == "false").Should().BeTrue(); | ||
|
|
||
|
vipinsamreddy marked this conversation as resolved.
|
||
| var controlledCount = await Page.Locator($"#{controls}").CountAsync(); | ||
| controlledCount.Should().Be(1, $"Filter toggle {i + 1} should reference a valid panel"); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SimilarSchools_Pagination_CurrentPageUsesAriaCurrent() | ||
| { | ||
| await NavigateToPageAsync(); | ||
|
|
||
| var pagination = Page.Locator("nav.govuk-pagination"); | ||
| var paginationCount = await pagination.CountAsync(); | ||
|
|
||
| if (paginationCount == 0) | ||
| { | ||
| return; | ||
| } | ||
|
vipinsamreddy marked this conversation as resolved.
|
||
|
|
||
| (await pagination.GetAttributeAsync("aria-label")).Should().NotBeNullOrWhiteSpace(); | ||
|
|
||
| var currentPageLink = pagination.Locator("a[aria-current='page']"); | ||
| (await currentPageLink.CountAsync()).Should().Be(1); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.