style: integrate CHRNX navigation and footer
This commit is contained in:
8 files changed
+437
-26
No files matched your search
@@ -89,6 +89,22 @@ function contrastRatio( first, second ) {
|
||||
return ( lighter + 0.05 ) / ( darker + 0.05 );
|
||||
}
|
||||
|
||||
function firstComputedColor( value ) {
|
||||
return value.match( /(?:rgba?\([^)]*\)|color\(srgb[^)]*\))/ )?.[ 0 ] ?? '';
|
||||
}
|
||||
|
||||
function colorAlpha( value ) {
|
||||
if ( value === 'transparent' ) {
|
||||
return 0;
|
||||
}
|
||||
const slashAlpha = value.match( /\/\s*([\d.]+)\s*\)$/ );
|
||||
if ( slashAlpha ) {
|
||||
return Number.parseFloat( slashAlpha[ 1 ] );
|
||||
}
|
||||
const channels = value.match( /[\d.]+/g )?.map( Number ) ?? [];
|
||||
return value.startsWith( 'rgba(' ) && channels.length >= 4 ? channels[ 3 ] : 1;
|
||||
}
|
||||
|
||||
async function expectContainedTarget( locator, viewportWidth ) {
|
||||
const box = await getBox( locator );
|
||||
expect( box.x ).toBeGreaterThanOrEqual( 0 );
|
||||
@@ -98,6 +114,123 @@ async function expectContainedTarget( locator, viewportWidth ) {
|
||||
}
|
||||
|
||||
test.describe( 'site navigation shell', () => {
|
||||
for ( const theme of [ 'light', 'dark' ] ) {
|
||||
test( `${ theme } navigation and footer expose the integrated editorial treatment`, async ( {
|
||||
page,
|
||||
} ) => {
|
||||
await page.setViewportSize( { width: 1280, height: 800 } );
|
||||
await page.goto( '/' );
|
||||
await page.evaluate( ( value ) => localStorage.setItem( 'chrnx-theme', value ), theme );
|
||||
await page.goto( '/music/' );
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme );
|
||||
|
||||
const header = page.getByRole( 'banner' );
|
||||
const footer = page.getByRole( 'contentinfo' );
|
||||
const headerNav = header.getByRole( 'navigation', { name: 'Primary navigation' } );
|
||||
const footerNav = footer.getByRole( 'navigation', { name: 'Footer navigation' } );
|
||||
for ( const nav of [ headerNav, footerNav ] ) {
|
||||
const current = nav.getByRole( 'link', { name: 'Music', exact: true } );
|
||||
await expect( nav.locator( '[aria-current="page"]' ) ).toHaveCount( 1 );
|
||||
await expect( current ).toHaveAttribute( 'aria-current', 'page' );
|
||||
const currentStyle = await current.evaluate( ( element ) => {
|
||||
const style = window.getComputedStyle( element );
|
||||
const marker = window.getComputedStyle( element, '::after' );
|
||||
const surface = window.getComputedStyle( element.closest( 'header, footer' ) );
|
||||
return {
|
||||
color: style.color,
|
||||
decoration: style.textDecorationLine,
|
||||
fontFamily: style.fontFamily,
|
||||
fontWeight: Number.parseInt( style.fontWeight, 10 ),
|
||||
fontSize: Number.parseFloat( style.fontSize ),
|
||||
letterSpacing: Number.parseFloat( style.letterSpacing ),
|
||||
markerContent: marker.content,
|
||||
markerWidth: Number.parseFloat( marker.width ),
|
||||
markerHeight: Number.parseFloat( marker.height ),
|
||||
markerOpacity: Number.parseFloat( marker.opacity ),
|
||||
surface: surface.backgroundColor,
|
||||
};
|
||||
} );
|
||||
expect( currentStyle.decoration ).toBe( 'none' );
|
||||
expect( currentStyle.fontFamily ).toContain( 'Zen Maru Gothic' );
|
||||
expect( currentStyle.fontWeight ).toBe( 500 );
|
||||
expect( currentStyle.fontSize ).toBeLessThanOrEqual( 16 );
|
||||
expect( currentStyle.letterSpacing ).toBeGreaterThan( 0 );
|
||||
expect( contrastRatio( currentStyle.color, currentStyle.surface ) ).toBeGreaterThanOrEqual(
|
||||
4.5,
|
||||
);
|
||||
expect( currentStyle.markerContent ).not.toBe( 'none' );
|
||||
expect( currentStyle.markerWidth ).toBeGreaterThan( 0 );
|
||||
expect( currentStyle.markerHeight ).toBeGreaterThanOrEqual( 2 );
|
||||
expect( currentStyle.markerOpacity ).toBe( 1 );
|
||||
|
||||
const hover = nav.getByRole( 'link', { name: 'Projects', exact: true } );
|
||||
await hover.hover();
|
||||
const hoverStyle = await hover.evaluate( ( element ) => {
|
||||
const style = window.getComputedStyle( element );
|
||||
const marker = window.getComputedStyle( element, '::after' );
|
||||
const surface = window.getComputedStyle( element.closest( 'header, footer' ) );
|
||||
return {
|
||||
color: style.color,
|
||||
decoration: style.textDecorationLine,
|
||||
markerOpacity: Number.parseFloat( marker.opacity ),
|
||||
surface: surface.backgroundColor,
|
||||
};
|
||||
} );
|
||||
expect( hoverStyle.decoration ).toBe( 'none' );
|
||||
expect( hoverStyle.markerOpacity ).toBe( 1 );
|
||||
expect( contrastRatio( hoverStyle.color, hoverStyle.surface ) ).toBeGreaterThanOrEqual(
|
||||
4.5,
|
||||
);
|
||||
}
|
||||
|
||||
await page.goto( '/' );
|
||||
await expect( page.locator( 'header [aria-current], footer [aria-current]' ) ).toHaveCount(
|
||||
0,
|
||||
);
|
||||
await page.goto( '/music/' );
|
||||
const footerStyle = await footer.evaluate( ( element ) => {
|
||||
const style = window.getComputedStyle( element );
|
||||
const innerStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__inner' ),
|
||||
);
|
||||
const siteStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__site' ),
|
||||
);
|
||||
const creditStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__credit' ),
|
||||
);
|
||||
const lineStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__line' ),
|
||||
);
|
||||
return {
|
||||
background: style.backgroundColor,
|
||||
borderStyle: style.borderTopStyle,
|
||||
borderWidth: Number.parseFloat( style.borderTopWidth ),
|
||||
borderColor: style.borderTopColor,
|
||||
paddingTop: Number.parseFloat( innerStyle.paddingTop ),
|
||||
paddingBottom: Number.parseFloat( innerStyle.paddingBottom ),
|
||||
siteFamily: siteStyle.fontFamily,
|
||||
siteWeight: Number.parseInt( siteStyle.fontWeight, 10 ),
|
||||
siteSize: Number.parseFloat( siteStyle.fontSize ),
|
||||
creditFamily: creditStyle.fontFamily,
|
||||
creditSize: Number.parseFloat( creditStyle.fontSize ),
|
||||
lineFamily: lineStyle.fontFamily,
|
||||
};
|
||||
} );
|
||||
expect( colorAlpha( footerStyle.background ) ).toBe( 1 );
|
||||
expect( footerStyle.borderStyle ).not.toBe( 'none' );
|
||||
expect( footerStyle.borderWidth ).toBeGreaterThanOrEqual( 1 );
|
||||
expect( colorAlpha( footerStyle.borderColor ) ).toBeGreaterThan( 0 );
|
||||
expect( footerStyle.paddingTop ).toBeGreaterThanOrEqual( 24 );
|
||||
expect( footerStyle.paddingBottom ).toBeGreaterThanOrEqual( 24 );
|
||||
expect( footerStyle.siteFamily ).toContain( 'Zen Maru Gothic' );
|
||||
expect( footerStyle.siteWeight ).toBeGreaterThanOrEqual( 700 );
|
||||
expect( footerStyle.siteSize ).toBeGreaterThan( footerStyle.creditSize );
|
||||
expect( footerStyle.creditFamily ).toMatch( /monospace|Menlo|Monaco|Consolas/ );
|
||||
expect( footerStyle.lineFamily ).toBe( footerStyle.creditFamily );
|
||||
} );
|
||||
}
|
||||
|
||||
test( 'desktop has a stable accessible header, approved local brand, and compact footer', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
@@ -405,7 +538,7 @@ test.describe( 'site navigation shell', () => {
|
||||
}
|
||||
|
||||
for ( const colorScheme of [ 'light', 'dark' ] ) {
|
||||
test( `compact mobile header has contrasting ${ colorScheme } focus outlines`, async ( {
|
||||
test( `compact mobile header has contrasting rounded ${ colorScheme } focus halos`, async ( {
|
||||
page,
|
||||
} ) => {
|
||||
await page.emulateMedia( { colorScheme } );
|
||||
@@ -427,15 +560,20 @@ test.describe( 'site navigation shell', () => {
|
||||
const controlStyle = window.getComputedStyle( element );
|
||||
const headerStyle = window.getComputedStyle( element.closest( 'header' ) );
|
||||
return {
|
||||
boxShadow: controlStyle.boxShadow,
|
||||
borderRadius: Number.parseFloat( controlStyle.borderRadius ),
|
||||
outline: controlStyle.outlineColor,
|
||||
outlineStyle: controlStyle.outlineStyle,
|
||||
outlineWidth: Number.parseFloat( controlStyle.outlineWidth ),
|
||||
background: headerStyle.backgroundColor,
|
||||
};
|
||||
} );
|
||||
const halo = firstComputedColor( colors.boxShadow );
|
||||
expect( colors.boxShadow ).not.toBe( 'none' );
|
||||
expect( halo ).not.toBe( '' );
|
||||
expect( colors.borderRadius ).toBeGreaterThan( 0 );
|
||||
expect( colors.outlineStyle ).not.toBe( 'none' );
|
||||
expect( colors.outlineWidth ).toBeGreaterThanOrEqual( 3 );
|
||||
expect( contrastRatio( colors.outline, colors.background ) ).toBeGreaterThanOrEqual( 3 );
|
||||
expect( colorAlpha( colors.outline ) ).toBe( 0 );
|
||||
expect( contrastRatio( halo, colors.background ) ).toBeGreaterThanOrEqual( 3 );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user