style: integrate CHRNX navigation and footer

This commit is contained in:
chrnx committed 2026-08-12 15:08:07 -05:00
1 parent 5a49cc5137
commit c7de54995f
8 files changed
+437 -26

No files matched your search

+142 -4
View File
@@ -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 );
}
} );
}
+178
View File
@@ -175,6 +175,171 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringNotContainsString( '<form', $output );
}
/** Exact destination pages map to their canonical local navigation URLs. */
public function test_current_navigation_destination_maps_exact_destination_pages() {
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
return;
}
foreach ( array( 'journal', 'projects', 'music', 'podcasts', 'about' ) as $slug ) {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => $slug,
'post_title' => ucfirst( $slug ),
)
);
$this->go_to( get_permalink( $page_id ) );
$this->assertSame( home_url( '/' . $slug . '/' ), chrnx_get_current_navigation_destination(), $slug );
}
}
/** Editorial requests all map to Journal, including every public editorial taxonomy. */
public function test_current_navigation_destination_maps_all_journal_contexts() {
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
return;
}
$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_name' => 'journal-entry',
)
);
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'post single' );
$this->go_to( home_url( '/?s=editorial' ) );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'search' );
foreach (
array(
'chrnx_topic' => 'code',
'chrnx_language' => 'en',
'chrnx_show' => 'silicon-ranch',
) as $taxonomy => $slug
) {
$term = get_term_by( 'slug', $slug, $taxonomy );
$this->assertInstanceOf( WP_Term::class, $term );
$this->go_to( get_term_link( $term ) );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), $taxonomy );
}
$previous_show_on_front = get_option( 'show_on_front' );
$previous_page_for_posts = get_option( 'page_for_posts' );
try {
update_option( 'show_on_front', 'posts' );
update_option( 'page_for_posts', 0 );
$this->go_to( home_url( '/' ) );
$this->assertTrue( is_home() );
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'Journal listing' );
} finally {
update_option( 'show_on_front', $previous_show_on_front );
update_option( 'page_for_posts', $previous_page_for_posts );
}
}
/** Front, unrelated, boundary-lookalike, and missing requests select no destination. */
public function test_current_navigation_destination_rejects_false_positives() {
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
return;
}
$previous_show_on_front = get_option( 'show_on_front' );
$previous_page_on_front = get_option( 'page_on_front' );
$front_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'home',
)
);
try {
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $front_id );
$this->go_to( home_url( '/' ) );
$this->assertTrue( is_front_page() );
$this->assertSame( '', chrnx_get_current_navigation_destination(), 'front page' );
} finally {
update_option( 'show_on_front', $previous_show_on_front );
update_option( 'page_on_front', $previous_page_on_front );
}
foreach ( array( 'contact', 'music-notes' ) as $slug ) {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => $slug,
)
);
$this->go_to( get_permalink( $page_id ) );
$this->assertSame( '', chrnx_get_current_navigation_destination(), '/' . $slug . '/' );
}
$parent_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'collection',
)
);
$nested_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'music',
'post_parent' => $parent_id,
)
);
$this->go_to( get_permalink( $nested_id ) );
$this->assertSame( '', chrnx_get_current_navigation_destination(), '/collection/music/' );
$this->go_to( home_url( '/definitely-missing-chrnx-route/' ) );
$GLOBALS['wp_query']->is_404 = true;
$this->assertTrue( is_404() );
$this->assertSame( '', chrnx_get_current_navigation_destination(), '404' );
}
/** Header and footer each expose exactly one matching aria-current link. */
public function test_navigation_blocks_render_one_current_page_for_the_active_destination() {
$music_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => 'music',
'post_title' => 'Music',
)
);
$this->go_to( get_permalink( $music_id ) );
foreach ( array( 'chrnx/header-tools', 'chrnx/footer-content' ) as $block_name ) {
$output = $this->render_navigation_block( $block_name );
$this->assertSame( 1, substr_count( $output, 'aria-current="page"' ), $block_name );
$this->assertMatchesRegularExpression( '/<a[^>]+href="' . preg_quote( esc_url( home_url( '/music/' ) ), '/' ) . '"[^>]+aria-current="page"[^>]*>Music<\/a>/', $output );
}
}
/** Journal semantics apply to post singles without marking lookalike destinations. */
public function test_navigation_blocks_mark_only_journal_for_post_singles() {
$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_name' => 'music-notes',
)
);
$this->go_to( get_permalink( $post_id ) );
foreach ( array( 'chrnx/header-tools', 'chrnx/footer-content' ) as $block_name ) {
$output = $this->render_navigation_block( $block_name );
$this->assertSame( 1, substr_count( $output, 'aria-current="page"' ), $block_name );
$this->assertMatchesRegularExpression( '/<a[^>]+href="' . preg_quote( esc_url( home_url( '/journal/' ) ), '/' ) . '"[^>]+aria-current="page"[^>]*>Journal<\/a>/', $output );
$this->assertDoesNotMatchRegularExpression( '/href="[^"]*music[^"]*"[^>]+aria-current="page"/', $output );
}
}
/** The approved local wordmark links to the portable site home URL. */
public function test_site_brand_renders_escaped_local_home_and_wordmark_urls() {
$output = render_block(
@@ -906,6 +1071,19 @@ class BlockRenderingTest extends WP_UnitTestCase {
);
}
/** Render one navigation block for the current main query. */
private function render_navigation_block( $block_name ) {
return render_block(
array(
'blockName' => $block_name,
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
)
);
}
/** Render one dynamic post-context block for a specific post. */
private function render_for_post( $block_name, $post_id ) {
global $post;