test: harden CHRNX mobile header behavior
This commit is contained in:
2 files changed
+262
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { injectAxe } from 'axe-playwright';
|
||||
|
||||
const destinations = [
|
||||
[ 'Journal', '/journal/' ],
|
||||
@@ -8,6 +9,13 @@ const destinations = [
|
||||
[ 'About', '/about/' ],
|
||||
];
|
||||
|
||||
const reviewViewports = [
|
||||
{ width: 375, height: 812 },
|
||||
{ width: 768, height: 1024 },
|
||||
{ width: 1440, height: 900 },
|
||||
{ width: 2560, height: 1440 },
|
||||
];
|
||||
|
||||
async function expectTargetSize( locator ) {
|
||||
const box = await locator.boundingBox();
|
||||
expect( box.width ).toBeGreaterThanOrEqual( 44 );
|
||||
@@ -476,6 +484,192 @@ test.describe( 'site navigation shell', () => {
|
||||
await expect( journal ).toBeFocused();
|
||||
} );
|
||||
|
||||
test( 'mobile panels exclude each other while retained search submits on its active click', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
const header = page.getByRole( 'banner' );
|
||||
const searchButton = header.locator( '[data-chrnx-search-button]' );
|
||||
const searchInput = header.getByRole( 'searchbox' );
|
||||
const searchPanel = header.locator( '[data-chrnx-search-panel]' );
|
||||
const themeButton = header.locator( '[data-chrnx-theme-button]' );
|
||||
const themePanel = header.locator( '[data-chrnx-theme-panel]' );
|
||||
const menuButton = header.locator( '[data-chrnx-menu-toggle]' );
|
||||
const nav = header.getByRole( 'navigation', { name: 'Primary navigation' } );
|
||||
|
||||
await searchButton.click();
|
||||
await searchInput.fill( 'retained cats' );
|
||||
await themeButton.click();
|
||||
await expect( searchPanel ).toBeHidden();
|
||||
await expect( themePanel ).toBeVisible();
|
||||
await expect( nav ).toBeHidden();
|
||||
await menuButton.click();
|
||||
await expect( searchPanel ).toBeHidden();
|
||||
await expect( themePanel ).toBeHidden();
|
||||
await expect( nav ).toBeVisible();
|
||||
|
||||
await searchButton.click();
|
||||
await expect( searchPanel ).toBeVisible();
|
||||
await expect( searchInput ).toHaveValue( 'retained cats' );
|
||||
await expect( searchInput ).toBeFocused();
|
||||
await expect( themePanel ).toBeHidden();
|
||||
await expect( nav ).toBeHidden();
|
||||
await searchButton.click();
|
||||
await expect( page ).toHaveURL( new RegExp( `[?&]s=retained(?:\\+|%20)cats(?:&|$)` ) );
|
||||
} );
|
||||
|
||||
test( 'real Tab order crosses all mobile controls without a focus trap', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
const header = page.getByRole( 'banner' );
|
||||
const searchButton = header.locator( '[data-chrnx-search-button]' );
|
||||
const themeButton = header.locator( '[data-chrnx-theme-button]' );
|
||||
const menuButton = header.locator( '[data-chrnx-menu-toggle]' );
|
||||
const journal = header.getByRole( 'link', { name: 'Journal', exact: true } );
|
||||
const focusKey = testInfo.project.name === 'webkit' ? 'Alt+Tab' : 'Tab';
|
||||
|
||||
await searchButton.focus();
|
||||
await page.keyboard.press( focusKey );
|
||||
await expect( themeButton ).toBeFocused();
|
||||
await page.keyboard.press( focusKey );
|
||||
await expect( menuButton ).toBeFocused();
|
||||
await menuButton.press( 'Enter' );
|
||||
await page.keyboard.press( focusKey );
|
||||
await expect( journal ).toBeFocused();
|
||||
} );
|
||||
|
||||
test( 'resize sends focus only from controls that become hidden', async ( { page } ) => {
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
let header = page.getByRole( 'banner' );
|
||||
const searchButton = header.locator( '[data-chrnx-search-button]' );
|
||||
const searchInput = header.getByRole( 'searchbox' );
|
||||
|
||||
await searchButton.click();
|
||||
await expect( searchInput ).toBeFocused();
|
||||
await page.setViewportSize( { width: 600, height: 844 } );
|
||||
await expect( searchButton ).toBeFocused();
|
||||
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
header = page.getByRole( 'banner' );
|
||||
let themeButton = header.locator( '[data-chrnx-theme-button]' );
|
||||
let checkedTheme = header.locator( '[data-chrnx-theme-panel] input:checked' );
|
||||
await expect( themeButton ).toBeVisible();
|
||||
await themeButton.focus();
|
||||
await page.setViewportSize( { width: 600, height: 844 } );
|
||||
await expect( checkedTheme ).toBeFocused();
|
||||
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
header = page.getByRole( 'banner' );
|
||||
let menuButton = header.locator( '[data-chrnx-menu-toggle]' );
|
||||
let journal = header.getByRole( 'link', { name: 'Journal', exact: true } );
|
||||
await expect( menuButton ).toBeVisible();
|
||||
await menuButton.focus();
|
||||
await page.setViewportSize( { width: 600, height: 844 } );
|
||||
await expect( journal ).toBeFocused();
|
||||
|
||||
await page.goto( '/' );
|
||||
header = page.getByRole( 'banner' );
|
||||
journal = header.getByRole( 'link', { name: 'Journal', exact: true } );
|
||||
menuButton = header.locator( '[data-chrnx-menu-toggle]' );
|
||||
await journal.focus();
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await expect( menuButton ).toBeFocused();
|
||||
|
||||
await page.setViewportSize( { width: 600, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
header = page.getByRole( 'banner' );
|
||||
checkedTheme = header.locator( '[data-chrnx-theme-panel] input:checked' );
|
||||
themeButton = header.locator( '[data-chrnx-theme-button]' );
|
||||
await checkedTheme.focus();
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await expect( themeButton ).toBeFocused();
|
||||
} );
|
||||
|
||||
test( 'visible navigation and theme controls retain focus across resize', async ( { page } ) => {
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
const header = page.getByRole( 'banner' );
|
||||
const menuButton = header.locator( '[data-chrnx-menu-toggle]' );
|
||||
const themeButton = header.locator( '[data-chrnx-theme-button]' );
|
||||
const journal = header.getByRole( 'link', { name: 'Journal', exact: true } );
|
||||
const checkedTheme = header.locator( '[data-chrnx-theme-panel] input:checked' );
|
||||
|
||||
await menuButton.click();
|
||||
await journal.focus();
|
||||
await page.setViewportSize( { width: 600, height: 844 } );
|
||||
await expect( journal ).toBeFocused();
|
||||
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
await themeButton.click();
|
||||
await checkedTheme.focus();
|
||||
await page.setViewportSize( { width: 600, height: 844 } );
|
||||
await expect( checkedTheme ).toBeFocused();
|
||||
} );
|
||||
|
||||
test( 'mobile header states pass automated WCAG checks', async ( { page }, testInfo ) => {
|
||||
test.skip(
|
||||
testInfo.project.name !== 'chromium',
|
||||
'One engine is sufficient for deterministic axe rules.',
|
||||
);
|
||||
await page.setViewportSize( reviewViewports[ 0 ] );
|
||||
await page.goto( '/' );
|
||||
const header = page.getByRole( 'banner' );
|
||||
const triggers = [
|
||||
null,
|
||||
header.locator( '[data-chrnx-search-button]' ),
|
||||
header.locator( '[data-chrnx-theme-button]' ),
|
||||
header.locator( '[data-chrnx-menu-toggle]' ),
|
||||
];
|
||||
const tags = [ 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa' ];
|
||||
|
||||
for ( const trigger of triggers ) {
|
||||
if ( trigger ) {
|
||||
await trigger.click();
|
||||
}
|
||||
await injectAxe( page );
|
||||
const violations = await page.evaluate( async ( runOnly ) => {
|
||||
const result = await globalThis.axe.run( document, {
|
||||
runOnly: { type: 'tag', values: runOnly },
|
||||
} );
|
||||
return result.violations.map( ( violation ) => ( {
|
||||
id: violation.id,
|
||||
impact: violation.impact,
|
||||
nodes: violation.nodes.map( ( node ) => node.target ),
|
||||
} ) );
|
||||
}, tags );
|
||||
expect( violations ).toEqual( [] );
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'approved review viewports have no horizontal overflow and preserve the breakpoint', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
for ( const viewport of reviewViewports ) {
|
||||
await page.setViewportSize( viewport );
|
||||
await page.goto( '/' );
|
||||
const header = page.getByRole( 'banner' );
|
||||
await expectNoHorizontalOverflow( page, header );
|
||||
if ( viewport.width <= 599 ) {
|
||||
await expect( header.locator( '[data-chrnx-menu-toggle]' ) ).toBeVisible();
|
||||
await expect( header.locator( '[data-chrnx-theme-button]' ) ).toBeVisible();
|
||||
} else {
|
||||
await expect( header.locator( '[data-chrnx-menu-toggle]' ) ).toBeHidden();
|
||||
await expect( header.locator( '[data-chrnx-theme-button]' ) ).toBeHidden();
|
||||
await expect(
|
||||
header.getByRole( 'navigation', { name: 'Primary navigation' } ),
|
||||
).toBeVisible();
|
||||
await expect( header.locator( '[data-chrnx-theme-panel]' ) ).toBeVisible();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
test.describe( 'without JavaScript', () => {
|
||||
test.use( { javaScriptEnabled: false } );
|
||||
|
||||
@@ -492,6 +686,7 @@ test.describe( 'site navigation shell', () => {
|
||||
await expect( submit ).toBeVisible();
|
||||
await expect( header.getByRole( 'img', { name: 'CHRNX' } ) ).toBeVisible();
|
||||
await expect( header.locator( '.chrnx-theme-noscript' ) ).toBeVisible();
|
||||
await expect( submit ).toHaveAttribute( 'aria-expanded', 'true' );
|
||||
await expectNoHorizontalOverflow( page, header );
|
||||
await search.fill( 'no js cats' );
|
||||
await submit.click();
|
||||
|
||||
Reference in new issue
Block a user