fix: make CHRNX header fully progressive

This commit is contained in:
chrnx committed 2026-08-11 17:26:48 -05:00
1 parent e1579657d6
commit f983cec4f9
13 files changed
+414 -36

No files matched your search

+62 -9
View File
@@ -14,6 +14,10 @@ async function expectTargetSize( locator ) {
expect( box.height ).toBeGreaterThanOrEqual( 44 );
}
async function getHomeURL( page ) {
return page.getByRole( 'banner' ).getByRole( 'link', { name: 'CHRNX' } ).getAttribute( 'href' );
}
test.describe( 'site navigation shell', () => {
test( 'desktop has a stable accessible header, approved local brand, and compact footer', async ( {
page,
@@ -41,19 +45,29 @@ test.describe( 'site navigation shell', () => {
/\/wp-content\/themes\/chrnx\/assets\/icons\/chrnx-wordmark\.svg$/,
);
expect( await header.getByRole( 'navigation' ).count() ).toBe( 1 );
const homeURL = await getHomeURL( page );
for ( const [ name, path ] of destinations ) {
const link = nav.getByRole( 'link', { name, exact: true } );
await expect( link ).toHaveAttribute( 'href', path );
await expect( link ).toHaveAttribute( 'href', new URL( path.slice( 1 ), homeURL ).href );
}
await expect( header.locator( '[data-chrnx-menu-toggle]' ) ).toBeHidden();
const compactSearch = header.locator( '.wp-block-search__button' );
const compactSearch = header.locator( '[data-chrnx-search-button]' );
await expect( compactSearch ).toBeVisible();
await expect( compactSearch ).toHaveAccessibleName( 'Expand search field' );
await expect( compactSearch ).toHaveAccessibleName( 'Open search' );
await expect( header.getByRole( 'searchbox' ) ).toBeHidden();
await expectTargetSize( compactSearch );
await compactSearch.click();
await expect( header.getByRole( 'searchbox' ) ).toBeVisible();
await expect( compactSearch ).toHaveAccessibleName( 'Submit Search' );
await expect( header.getByRole( 'searchbox' ) ).toBeFocused();
await expect( compactSearch ).toHaveAccessibleName( 'Search' );
await page.keyboard.press( 'Escape' );
await expect( compactSearch ).toBeFocused();
await expect( header.getByRole( 'searchbox' ) ).toBeHidden();
await compactSearch.click();
await header.getByRole( 'searchbox' ).fill( 'portable cats' );
await compactSearch.click();
await expect( page ).toHaveURL( new RegExp( `[?&]s=portable(?:\\+|%20)cats(?:&|$)` ) );
const before = await header.boundingBox();
await page.evaluate( () => window.scrollTo( 0, document.body.scrollHeight ) );
const after = await header.boundingBox();
@@ -86,7 +100,7 @@ test.describe( 'site navigation shell', () => {
).not.toBe( 'none' );
await expectTargetSize( journal );
await expectTargetSize(
page.getByRole( 'banner' ).getByRole( 'button', { name: 'Expand search field' } ),
page.getByRole( 'banner' ).getByRole( 'button', { name: 'Open search' } ),
);
} );
@@ -104,10 +118,11 @@ test.describe( 'site navigation shell', () => {
await expect( open ).toHaveAccessibleName( 'Close primary navigation' );
const nav = header.getByRole( 'navigation', { name: 'Primary navigation' } );
await expect( nav ).toBeVisible();
const homeURL = await getHomeURL( page );
for ( const [ name, path ] of destinations ) {
await expect( nav.getByRole( 'link', { name, exact: true } ) ).toHaveAttribute(
'href',
path,
new URL( path.slice( 1 ), homeURL ).href,
);
}
await open.focus();
@@ -117,7 +132,7 @@ test.describe( 'site navigation shell', () => {
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 expect( header.getByRole( 'button', { name: 'Open search' } ) ).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();
@@ -125,8 +140,8 @@ test.describe( 'site navigation shell', () => {
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' );
const compactSearch = header.locator( '[data-chrnx-search-button]' );
await expect( compactSearch ).toHaveAccessibleName( 'Open search' );
await expectTargetSize( compactSearch );
await compactSearch.click();
await expect( header.getByRole( 'searchbox' ) ).toBeVisible();
@@ -135,4 +150,42 @@ test.describe( 'site navigation shell', () => {
await expect( nav ).toBeVisible();
await expect( open ).toHaveAttribute( 'aria-expanded', 'false' );
} );
test( 'resize never leaves focus inside hidden navigation', async ( { page } ) => {
await page.setViewportSize( { width: 1280, height: 800 } );
await page.goto( '/' );
const header = page.getByRole( 'banner' );
const nav = header.getByRole( 'navigation', { name: 'Primary navigation' } );
const journal = nav.getByRole( 'link', { name: 'Journal', exact: true } );
const toggle = header.locator( '[data-chrnx-menu-toggle]' );
await journal.focus();
await page.setViewportSize( { width: 390, height: 844 } );
await expect( nav ).toBeHidden();
await expect( toggle ).toBeFocused();
await toggle.click();
await journal.focus();
await page.setViewportSize( { width: 1280, height: 800 } );
await expect( nav ).toBeVisible();
await expect( journal ).toBeFocused();
} );
test.describe( 'without JavaScript', () => {
test.use( { javaScriptEnabled: false } );
test( 'navigation and named search remain fully usable', async ( { page } ) => {
await page.setViewportSize( { width: 390, height: 844 } );
await page.goto( '/' );
const header = page.getByRole( 'banner' );
await expect(
header.getByRole( 'navigation', { name: 'Primary navigation' } ),
).toBeVisible();
const search = header.getByRole( 'searchbox', { name: 'Search' } );
const submit = header.getByRole( 'button', { name: 'Search', exact: true } );
await expect( search ).toBeVisible();
await expect( submit ).toBeVisible();
await search.fill( 'no js cats' );
await submit.click();
await expect( page ).toHaveURL( new RegExp( `[?&]s=no(?:\\+|%20)js(?:\\+|%20)cats(?:&|$)` ) );
} );
} );
} );