fix: complete CHRNX responsive edge states

This commit is contained in:
chrnx committed 2026-08-12 09:02:34 -05:00
1 parent 5073178492
commit 1e9386ac13
15 files changed
+384 -35

No files matched your search

+148 -3
View File
@@ -1,5 +1,18 @@
import { expect, test } from '@playwright/test';
import { injectAxe } from 'axe-playwright';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const projectRoot = fileURLToPath( new URL( '../..', import.meta.url ) );
const seedScenario = ( scenario ) =>
execFileSync( './scripts/seed-test-content.sh', [ scenario ], {
cwd: projectRoot,
env: {
...process.env,
PATH: `/opt/homebrew/opt/docker/bin:${ process.env.PATH ?? '' }`,
},
stdio: 'pipe',
} );
const viewports = [
{ width: 375, height: 812 },
@@ -77,7 +90,10 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page
await page.goto( '/conversacion-pendiente-de-datos-editoriales/' );
await expect(
page.getByRole( 'heading', { level: 1, name: 'Conversación pendiente de datos editoriales' } ),
page.getByRole( 'heading', {
level: 1,
name: 'Conversación pendiente de datos editoriales',
} ),
).toBeVisible();
await expect( page.locator( '.chrnx-podcast-meta' ) ).toHaveCount( 0 );
@@ -85,15 +101,144 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page
await expect( page.locator( 'pre code' ) ).toContainText( 'const state' );
await expectNoHorizontalOverflow( page );
for ( const [ path, title ] of [
[
'/long-title-night-writing-fixture/',
'Escribir cuando la casa por fin se queda en silencio',
],
[
'/una-cuerda-rota-tambien-puede-decidir-el-arreglo/',
'Una cuerda rota también puede decidir el arreglo',
],
[ '/nota-local-sin-extracto/', 'Nota local sin extracto' ],
[ '/note-without-topic/', 'Note without a topic' ],
[ '/nota-sin-idioma-asignado/', 'Nota sin idioma asignado' ],
] ) {
await page.goto( path );
await expect( page.getByRole( 'heading', { level: 1 } ) ).toContainText( title );
await expectNoHorizontalOverflow( page );
}
await expect( page.locator( '.chrnx-entry__meta a', { hasText: 'English' } ) ).toHaveCount( 0 );
await page.goto( '/unbroken-token-overflow-test/' );
await expect( page.locator( 'pre code' ) ).toContainText(
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
);
await expectNoHorizontalOverflow( page );
await page.goto( '/journal/?chrnx_topic=..%2F..%2Fcode&chrnx_language%5B%5D=en&s%5B%5D=x' );
await expect( page.locator( 'select[name="chrnx_topic"]' ) ).toHaveValue( '' );
await expect( page.locator( 'select[name="chrnx_language"]' ) ).toHaveValue( '' );
await expect( page.locator( '.chrnx-journal-stream__filters input[name="s"]' ) ).toHaveValue(
'',
);
await expectNoHorizontalOverflow( page );
await page.goto( '/this-route-does-not-exist/' );
await expect( page ).toHaveTitle( /Page not found/i );
await expect( page.getByRole( 'heading', { level: 1, name: 'Page not found' } ) ).toBeVisible();
} );
test( 'cards without featured media use CSS-only topic treatments', async ( { page } ) => {
await page.goto( '/' );
const fallbacks = page.locator(
'.chrnx-featured-story__fallback, .chrnx-journal-card__fallback, .chrnx-podcast-card__fallback',
);
await expect( fallbacks.first() ).toBeVisible();
expect( await fallbacks.locator( 'img' ).count() ).toBe( 0 );
for ( const fallback of await fallbacks.all() ) {
const background = await fallback.evaluate(
( element ) => window.getComputedStyle( element ).backgroundImage,
);
expect( background ).not.toMatch( /alter-ego-|the-no-names-musician-cutout/ );
}
} );
test( 'local featured and subscribe scenarios restore the default dataset', async ( {
page,
}, testInfo ) => {
test.skip( testInfo.project.name !== 'chromium', 'Database scenarios run once in Chromium.' );
try {
for ( const count of [ 1, 2 ] ) {
seedScenario( `featured-${ count }` );
await page.goto( `/?fixtureScenario=featured-${ count }` );
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( count );
const hrefs = await page
.locator( '.chrnx-featured-stories article a' )
.evaluateAll( ( links ) => links.map( ( link ) => link.href ) );
expect( new Set( hrefs ).size ).toBe( hrefs.length );
}
for ( const scenario of [ 'subscribe-unpublished', 'subscribe-unavailable' ] ) {
seedScenario( scenario );
await page.goto( `/?fixtureScenario=${ scenario }` );
await expect( page.locator( '.chrnx-subscribe-cta' ) ).toHaveCount( 0 );
}
} finally {
seedScenario( 'default' );
}
await page.goto( '/' );
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( 3 );
await expect(
page.getByRole( 'link', { name: 'Subscribe', exact: true } ).first(),
).toBeVisible();
} );
test( 'podcast canonical metadata is safe and missing metadata never invents a player or link', async ( {
page,
} ) => {
await page.goto( '/silicon-ranch-conversaciones-sin-diapositivas/' );
await expect( page.getByRole( 'link', { name: 'Open canonical episode page' } ) ).toHaveAttribute(
'href',
'https://example.test/local-podcast-episode',
);
await expect( page.locator( 'iframe, audio' ) ).toHaveCount( 0 );
await page.goto( '/conversacion-pendiente-de-datos-editoriales/' );
await expect( page.locator( '.chrnx-podcast-meta, iframe, audio' ) ).toHaveCount( 0 );
await expect( page.getByRole( 'link', { name: 'Open canonical episode page' } ) ).toHaveCount(
0,
);
} );
test( 'site routes preserve heading order, named landmarks, and skip-link keyboard flow', async ( {
page,
}, testInfo ) => {
for ( const path of [ '/', '/music/', '/podcasts/', '/about/', '/topic/code/', '/journal/' ] ) {
await page.goto( path );
const headings = await page
.locator( 'h1, h2, h3, h4, h5, h6' )
.evaluateAll( ( nodes ) => nodes.map( ( node ) => Number( node.tagName.slice( 1 ) ) ) );
expect( headings.filter( ( level ) => level === 1 ) ).toHaveLength( 1 );
for ( let index = 1; index < headings.length; index += 1 ) {
expect(
headings[ index ] - headings[ index - 1 ],
`${ path } heading sequence`,
).toBeLessThanOrEqual( 1 );
}
await expect( page.getByRole( 'banner' ) ).toHaveCount( 1 );
await expect( page.getByRole( 'main' ) ).toHaveCount( 1 );
await expect( page.getByRole( 'contentinfo' ) ).toHaveCount( 1 );
const landmarkNames = await page
.locator( 'nav' )
.evaluateAll( ( nodes ) => nodes.map( ( node ) => node.getAttribute( 'aria-label' ) ) );
expect( landmarkNames.every( Boolean ) ).toBeTruthy();
expect( new Set( landmarkNames ).size ).toBe( landmarkNames.length );
if ( testInfo.project.name === 'chromium' ) {
await page.keyboard.press( 'Tab' );
const skip = page.getByRole( 'link', { name: 'Skip to content' } );
await expect( skip ).toBeFocused();
await skip.press( 'Enter' );
await expect( page.locator( 'main#chrnx-main' ) ).toBeFocused();
}
}
} );
test( 'reduced motion removes card transitions while theme preference remains user-controlled', async ( {
page,
} ) => {
await page.emulateMedia( { reducedMotion: 'reduce', colorScheme: 'light' } );
await page.emulateMedia( {
reducedMotion: 'reduce',
colorScheme: 'light',
} );
await page.goto( '/' );
const card = page.locator( '.chrnx-featured-story' ).first();
const duration = await card.evaluate( ( element ) =>
@@ -111,7 +256,7 @@ test( 'key public surfaces pass automated WCAG 2.2 AA checks', async ( { page },
'One engine is sufficient for deterministic axe rules.',
);
const tags = [ 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa' ];
for ( const viewport of [ viewports[ 0 ], viewports[ 2 ] ] ) {
for ( const viewport of viewports ) {
await page.setViewportSize( viewport );
for ( const path of [
'/',
+41 -1
View File
@@ -28,6 +28,7 @@
},
{
"fixtureKey": "post-literature-long",
"slug": "long-title-night-writing-fixture",
"title": "Escribir cuando la casa por fin se queda en silencio y cada pequeño ruido parece tener una opinión larguísima sobre el borrador abierto",
"excerpt": "Notas sobre escribir de noche, editar sin piedad y conservar la parte que todavía respira.",
"content": "<!-- wp:paragraph --><p>La noche no vuelve más inteligente al texto, pero sí deja escuchar dónde está fingiendo.</p><!-- /wp:paragraph -->",
@@ -37,6 +38,7 @@
},
{
"fixtureKey": "post-music-studio",
"slug": "una-cuerda-rota-tambien-puede-decidir-el-arreglo",
"title": "Una cuerda rota también puede decidir el arreglo",
"excerpt": "Diario de producción de The No Names: estudio crudo, cero live.",
"content": "<!-- wp:paragraph --><p>La toma no quedó limpia. Quedó viva, que para este disco importa bastante más.</p><!-- /wp:paragraph -->",
@@ -53,7 +55,8 @@
"language": "es",
"show": "silicon-ranch",
"episodeNumber": 2,
"episodeDuration": "58:24"
"episodeDuration": "58:24",
"canonicalEpisodeUrl": "https://example.test/local-podcast-episode"
},
{
"fixtureKey": "post-podcast-missing-meta",
@@ -103,5 +106,42 @@
"content": "<!-- wp:quote --><blockquote class=\"wp-block-quote\"><p>La tinta sabía algo que el narrador todavía no.</p></blockquote><!-- /wp:quote -->",
"topic": "literature",
"language": "es"
},
{
"fixtureKey": "post-missing-excerpt",
"slug": "nota-local-sin-extracto",
"title": "Nota local sin extracto",
"content": "<!-- wp:paragraph --><p>Fixture local para comprobar el resumen ausente.</p><!-- /wp:paragraph -->",
"topic": "life",
"language": "es",
"fixtureState": "missing-excerpt"
},
{
"fixtureKey": "post-missing-topic",
"slug": "note-without-topic",
"title": "Note without a topic",
"excerpt": "A local fixture with no editorial topic.",
"content": "<!-- wp:paragraph --><p>The theme must not infer a private identity or category.</p><!-- /wp:paragraph -->",
"language": "en",
"fixtureState": "missing-topic"
},
{
"fixtureKey": "post-missing-language",
"slug": "nota-sin-idioma-asignado",
"title": "Nota sin idioma asignado",
"excerpt": "Fixture local sin taxonomía de idioma.",
"content": "<!-- wp:paragraph --><p>El contenido permanece legible sin inventar metadatos.</p><!-- /wp:paragraph -->",
"topic": "research",
"fixtureState": "missing-language"
},
{
"fixtureKey": "post-unbroken-code",
"slug": "unbroken-token-overflow-test",
"title": "Unbroken token overflow test",
"excerpt": "A deliberately hostile local layout fixture.",
"content": "<!-- wp:code --><pre class=\"wp-block-code\"><code>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</code></pre><!-- /wp:code -->",
"topic": "code",
"language": "en",
"fixtureState": "unbroken-code"
}
]
+14 -1
View File
@@ -460,7 +460,8 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringContainsString( 'alt=""', $output );
$this->assertStringContainsString( 'width="1122"', $output );
$this->assertStringContainsString( 'height="1402"', $output );
$this->assertStringContainsString( 'loading="lazy"', $output );
$this->assertStringContainsString( 'loading="eager"', $output );
$this->assertStringContainsString( 'fetchpriority="high"', $output );
$this->assertStringContainsString( 'decoding="async"', $output );
$unsafe = render_block(
@@ -635,6 +636,18 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringNotContainsString( '<img', $output );
}
/** Topic heroes are the section surface and prioritize their approved portrait. */
public function test_topic_hero_portrait_is_eager_and_high_priority() {
$output = render_block(
array(
'blockName' => 'chrnx/topic-hero',
'attrs' => array( 'topic' => 'code' ),
)
);
$this->assertStringContainsString( 'loading="eager"', $output );
$this->assertStringContainsString( 'fetchpriority="high"', $output );
}
/** Journal pagination preserves only validated filters in actual rendered links. */
public function test_journal_pagination_links_preserve_only_valid_bounded_filters() {
$raw_search = 'needle' . str_repeat( 'x', 150 ) . '<b>unsafe</b>';
+9
View File
@@ -27,4 +27,13 @@ class ResponsiveMediaTest extends WP_UnitTestCase {
public function test_unknown_topic_portrait_returns_empty_markup() {
$this->assertSame( '', chrnx_get_topic_portrait_markup( '../../private', '', '' ) );
}
/** Above-fold art opts into eager high-priority loading while defaults remain lazy. */
public function test_topic_portrait_loading_is_explicitly_allowlisted() {
$eager = chrnx_get_topic_portrait_markup( 'code', '', '', 'eager' );
$this->assertStringContainsString( 'loading="eager"', $eager );
$this->assertStringContainsString( 'fetchpriority="high"', $eager );
$this->assertStringContainsString( 'loading="lazy"', chrnx_get_topic_portrait_markup( 'code' ) );
$this->assertStringNotContainsString( 'fetchpriority="high"', chrnx_get_topic_portrait_markup( 'code', '', '', 'invalid' ) );
}
}
+13
View File
@@ -87,6 +87,19 @@ class SettingsTest extends WP_UnitTestCase {
$this->assertSame( '', chrnx_get_subscribe_url() );
}
/** An unavailable setting cannot fall through to the current global page. */
public function test_subscribe_url_rejects_zero_even_with_a_global_page() {
$page = self::factory()->post->create_and_get(
array(
'post_type' => 'page',
'post_status' => 'publish',
)
);
$GLOBALS['post'] = $page;
update_option( 'chrnx_subscribe_page_id', 0 );
$this->assertSame( '', chrnx_get_subscribe_url() );
}
/** Field callback uses the core page dropdown and escaped description. */
public function test_subscribe_field_renders_a_core_page_dropdown() {
self::factory()->post->create(
+50 -7
View File
@@ -1,5 +1,8 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
const read = ( path ) => readFileSync( new URL( `../../${ path }`, import.meta.url ), 'utf8' );
@@ -18,6 +21,13 @@ test( 'local visual fixtures define stable pages and representative editorial st
assert.ok( posts.some( ( post ) => post.content.includes( 'wp:code' ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-media' ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-excerpt' && !( 'excerpt' in post ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-topic' && !( 'topic' in post ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-language' && !( 'language' in post ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'unbroken-code' && /[A-Z0-9]{256}/.test( post.content ) ) );
assert.ok( posts.some( ( post ) => /^https:\/\//.test( post.canonicalEpisodeUrl ?? '' ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' && !( 'canonicalEpisodeUrl' in post ) ) );
assert.equal( new Set( posts.map( ( post ) => post.fixtureKey ) ).size, posts.length );
for ( const topic of [ 'code', 'research', 'gaming', 'literature', 'music', 'podcasts', 'life' ] ) {
assert.ok( posts.some( ( post ) => post.topic === topic ), `missing ${ topic } fixture` );
}
@@ -29,7 +39,10 @@ test( 'the seed entrypoint is explicitly local-only and uses a stable fixture ke
assert.match( shell, /localhost|127\.0\.0\.1/ );
assert.match( shell, /wp eval-file/ );
assert.match( shell, /featured-1/ );
assert.match( shell, /subscribe-unavailable/ );
assert.match( php, /_chrnx_fixture_key/ );
assert.match( php, /canonical_episode_url/ );
assert.match( php, /show_on_front/ );
assert.match( php, /page_on_front/ );
assert.match( php, /page_for_posts/ );
@@ -46,15 +59,45 @@ test( 'the visual layer is separately enqueued and covers responsive accessible
assert.match( components, /html\[data-theme="light"\]/ );
} );
test( 'all approved portraits expose reproducible WebP and AVIF derivatives', () => {
for ( const topic of [ 'code', 'gaming', 'life', 'literature', 'podcasts', 'research' ] ) {
const manifest = JSON.parse( read( `assets/images/generated/alter-ego-${ topic }.json` ) );
assert.equal( manifest.source, `alter-ego-${ topic }.png` );
assert.deepEqual( manifest.formats, [ 'avif', 'webp' ] );
assert.deepEqual( manifest.widths, [ 384, 768 ] );
test( 'all approved portraits rebuild byte-identically within payload bounds', () => {
const output = mkdtempSync( join( tmpdir(), 'chrnx-image-test-' ) );
const unsafeOutput = join( output, 'unsafe-output' );
try {
assert.throws( () => execFileSync( './scripts/build-responsive-images.sh', [ unsafeOutput ], { cwd: new URL( '../..', import.meta.url ) } ) );
execFileSync( './scripts/build-responsive-images.sh', [ output ], { cwd: new URL( '../..', import.meta.url ) } );
const names = readdirSync( output ).sort();
assert.equal( names.length, 35 );
let total = 0;
for ( const name of names ) {
const generated = readFileSync( join( output, name ) );
const committed = readFileSync( new URL( `../../assets/images/generated/${ name }`, import.meta.url ) );
assert.deepEqual( generated, committed, `${ name } must rebuild byte-identically` );
if ( /\.(?:avif|webp)$/.test( name ) ) {
assert.ok( statSync( join( output, name ) ).size <= 160 * 1024, `${ name } exceeds 160 KiB` );
const expectedWidth = Number( name.match( /-(384|768)\.(?:avif|webp)$/ )[ 1 ] );
const dimensions = execFileSync( 'sips', [ '-g', 'pixelWidth', '-g', 'pixelHeight', join( output, name ) ], { encoding: 'utf8' } );
assert.match( dimensions, new RegExp( `pixelWidth: ${ expectedWidth }` ) );
assert.match( dimensions, /pixelHeight: [1-9][0-9]*/ );
if ( name.endsWith( '.webp' ) ) {
assert.equal( generated.subarray( 0, 4 ).toString(), 'RIFF' );
assert.equal( generated.subarray( 8, 12 ).toString(), 'WEBP' );
} else {
assert.equal( generated.subarray( 4, 12 ).toString(), 'ftypavif' );
}
total += generated.length;
}
}
assert.ok( total <= 1.7 * 1024 * 1024, `derivatives exceed 1.7 MiB: ${ total }` );
} finally {
rmSync( output, { recursive: true, force: true } );
}
} );
test( 'post-card CSS fallbacks never reuse approved section portraits', () => {
const components = read( 'assets/css/components.css' );
assert.doesNotMatch( components, /url\([^)]*(?:alter-ego-|the-no-names-musician-cutout)/ );
} );
test( 'front page and section pages connect the real editorial patterns', () => {
const front = read( 'templates/front-page.html' );
assert.match( front, /chrnx\/home-intro/ );