fix: harden CHRNX shell accessibility
This commit is contained in:
14 files changed
+520
-54
No files matched your search
@@ -45,7 +45,15 @@ test.describe( 'site navigation shell', () => {
|
||||
const link = nav.getByRole( 'link', { name, exact: true } );
|
||||
await expect( link ).toHaveAttribute( 'href', path );
|
||||
}
|
||||
await expect( header.getByRole( 'button', { name: /menu/i } ) ).toBeHidden();
|
||||
await expect( header.locator( '[data-chrnx-menu-toggle]' ) ).toBeHidden();
|
||||
const compactSearch = header.locator( '.wp-block-search__button' );
|
||||
await expect( compactSearch ).toBeVisible();
|
||||
await expect( compactSearch ).toHaveAccessibleName( 'Expand search field' );
|
||||
await expect( header.getByRole( 'searchbox' ) ).toBeHidden();
|
||||
await expectTargetSize( compactSearch );
|
||||
await compactSearch.click();
|
||||
await expect( header.getByRole( 'searchbox' ) ).toBeVisible();
|
||||
await expect( compactSearch ).toHaveAccessibleName( 'Submit Search' );
|
||||
const before = await header.boundingBox();
|
||||
await page.evaluate( () => window.scrollTo( 0, document.body.scrollHeight ) );
|
||||
const after = await header.boundingBox();
|
||||
@@ -54,6 +62,11 @@ test.describe( 'site navigation shell', () => {
|
||||
|
||||
const footer = page.getByRole( 'contentinfo' );
|
||||
await expect( footer ).toBeVisible();
|
||||
expect(
|
||||
await footer
|
||||
.locator( '.chrnx-site-footer__inner' )
|
||||
.evaluate( ( element ) => window.getComputedStyle( element ).display ),
|
||||
).toBe( 'flex' );
|
||||
await expect( footer.getByRole( 'navigation', { name: 'Footer navigation' } ) ).toBeVisible();
|
||||
await expect( footer.getByText( 'Made in Sinaloa, shared from home.' ) ).toBeVisible();
|
||||
await expect(
|
||||
@@ -72,19 +85,23 @@ test.describe( 'site navigation shell', () => {
|
||||
await journal.evaluate( ( element ) => window.getComputedStyle( element ).outlineStyle ),
|
||||
).not.toBe( 'none' );
|
||||
await expectTargetSize( journal );
|
||||
await expectTargetSize( page.getByRole( 'searchbox' ) );
|
||||
await expectTargetSize(
|
||||
page.getByRole( 'banner' ).getByRole( 'button', { name: 'Expand search field' } ),
|
||||
);
|
||||
} );
|
||||
|
||||
test( 'mobile core navigation opens, closes with Escape, and restores focus without trapping Tab', async ( {
|
||||
test( 'mobile navigation follows normal Tab order and Escape restores the trigger', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
}, testInfo ) => {
|
||||
await page.setViewportSize( { width: 390, height: 844 } );
|
||||
await page.goto( '/' );
|
||||
const header = page.getByRole( 'banner' );
|
||||
const open = header.getByRole( 'button', { name: /open menu/i } );
|
||||
const open = header.locator( '[data-chrnx-menu-toggle]' );
|
||||
await expect( open ).toBeVisible();
|
||||
await expect( open ).toHaveAccessibleName( 'Open primary navigation' );
|
||||
await expectTargetSize( open );
|
||||
await open.click();
|
||||
await expect( open ).toHaveAccessibleName( 'Close primary navigation' );
|
||||
const nav = header.getByRole( 'navigation', { name: 'Primary navigation' } );
|
||||
await expect( nav ).toBeVisible();
|
||||
for ( const [ name, path ] of destinations ) {
|
||||
@@ -93,17 +110,29 @@ test.describe( 'site navigation shell', () => {
|
||||
path,
|
||||
);
|
||||
}
|
||||
await open.focus();
|
||||
const focusKey = testInfo.project.name === 'webkit' ? 'Alt+Tab' : 'Tab';
|
||||
for ( const [ name ] of destinations ) {
|
||||
await page.keyboard.press( focusKey );
|
||||
await expect( nav.getByRole( 'link', { name, exact: true } ) ).toBeFocused();
|
||||
}
|
||||
await page.keyboard.press( focusKey );
|
||||
await expect( header.getByRole( 'button', { name: 'Expand search field' } ) ).toBeFocused();
|
||||
await page.keyboard.press( focusKey );
|
||||
await expect( header.getByRole( 'radio', { name: 'System', exact: true } ) ).toBeFocused();
|
||||
await nav.getByRole( 'link', { name: 'Music', exact: true } ).focus();
|
||||
await page.keyboard.press( 'Escape' );
|
||||
await expect( open ).toBeFocused();
|
||||
await expect( nav.getByRole( 'link', { name: 'Journal', exact: true } ) ).toBeHidden();
|
||||
|
||||
await open.click();
|
||||
const close = header.getByRole( 'button', { name: /close menu/i } );
|
||||
await expectTargetSize( close );
|
||||
await close.focus();
|
||||
await page.keyboard.press( 'Tab' );
|
||||
await expect( close ).not.toBeFocused();
|
||||
await close.click();
|
||||
await expect( open ).toBeFocused();
|
||||
await expect( open ).toHaveAccessibleName( 'Open primary navigation' );
|
||||
await expect( nav ).toBeHidden();
|
||||
const compactSearch = header.locator( '.wp-block-search__button' );
|
||||
await expect( compactSearch ).toHaveAccessibleName( 'Expand search field' );
|
||||
await expectTargetSize( compactSearch );
|
||||
await compactSearch.click();
|
||||
await expect( header.getByRole( 'searchbox' ) ).toBeVisible();
|
||||
await page.setViewportSize( { width: 1280, height: 800 } );
|
||||
await expect( open ).toBeHidden();
|
||||
await expect( nav ).toBeVisible();
|
||||
await expect( open ).toHaveAttribute( 'aria-expanded', 'false' );
|
||||
} );
|
||||
} );
|
||||
@@ -136,6 +136,7 @@ test.describe( 'real theme preference shell', () => {
|
||||
const page = await context.newPage();
|
||||
await page.goto( '/' );
|
||||
await expect( page.locator( '[data-chrnx-theme-toggle]' ) ).toBeHidden();
|
||||
await expect( page.locator( '[data-chrnx-menu-toggle]' ) ).toBeHidden();
|
||||
await expect( page.locator( '.chrnx-theme-noscript' ) ).toHaveText(
|
||||
'Enable JavaScript to choose a color theme.',
|
||||
);
|
||||
@@ -144,4 +145,32 @@ test.describe( 'real theme preference shell', () => {
|
||||
).toBeVisible();
|
||||
await context.close();
|
||||
} );
|
||||
|
||||
for ( const [ scheme, background, colorScheme ] of [
|
||||
[ 'light', 'rgb(246, 242, 233)', 'light' ],
|
||||
[ 'dark', 'rgb(13, 17, 23)', 'dark' ],
|
||||
] ) {
|
||||
test( `without JavaScript follows ${ scheme } system colors`, async ( {
|
||||
browser,
|
||||
baseURL,
|
||||
} ) => {
|
||||
const context = await browser.newContext( {
|
||||
baseURL,
|
||||
colorScheme: scheme,
|
||||
javaScriptEnabled: false,
|
||||
} );
|
||||
const page = await context.newPage();
|
||||
await page.goto( '/' );
|
||||
await expect( page.locator( 'html' ) ).not.toHaveAttribute( 'data-theme' );
|
||||
const actual = await page.evaluate( () => ( {
|
||||
background: window.getComputedStyle( document.body ).backgroundColor,
|
||||
colorScheme: window.getComputedStyle( document.documentElement ).colorScheme,
|
||||
} ) );
|
||||
expect( actual ).toEqual( { background, colorScheme } );
|
||||
await expect(
|
||||
page.getByRole( 'banner' ).getByRole( 'link', { name: 'Journal', exact: true } ),
|
||||
).toBeVisible();
|
||||
await context.close();
|
||||
} );
|
||||
}
|
||||
} );
|
||||
Reference in new issue
Block a user