refactor: compose CHRNX music and podcast stages

This commit is contained in:
chrnx committed 2026-08-13 01:45:03 -05:00
1 parent 06d2c88b81
commit 9b94eb17c5
8 files changed
+543 -19

No files matched your search

+220
View File
@@ -0,0 +1,220 @@
import { expect, test } from '@playwright/test';
const patterns = [
{
label: 'Music',
pageSlug: 'music',
patternSlug: 'chrnx/music-landing',
atmosphereAsset: 'the-no-names-collage.jpeg',
artAsset: 'the-no-names-musician-cutout.png',
contentCopy: 'The No Names es una banda activa',
supportingCopy: 'El proceso usa generative AI',
},
{
label: 'Podcasts',
pageSlug: 'podcasts',
patternSlug: 'chrnx/podcast-landing',
atmosphereAsset: 'podcast-frequency-grunge.png',
artAsset: 'alter-ego-podcasts.png',
contentCopy: 'Conversations about the work behind software, research, music, and games.',
supportingCopy: '<!-- wp:chrnx/latest-podcast /-->',
},
];
async function logIn( page ) {
await page.goto( '/wp-login.php' );
await page.locator( '#user_login' ).fill( 'admin' );
await page.locator( '#user_pass' ).fill( 'password' );
await page.getByRole( 'button', { name: /log in/i } ).click();
if ( ! new URL( page.url() ).pathname.startsWith( '/wp-admin/' ) ) {
await page.locator( '#user_login' ).fill( 'admin' );
await page.locator( '#user_pass' ).fill( 'password' );
await page.getByRole( 'button', { name: /log in/i } ).click();
}
await page.waitForURL( ( url ) => url.pathname.startsWith( '/wp-admin/' ) );
}
async function closeWelcomeGuide( page ) {
const welcomeDialog = page.getByRole( 'dialog', {
name: /^Welcome to the (?:site )?editor$/,
} );
const visible = await welcomeDialog
.waitFor( { state: 'visible', timeout: 3000 } )
.then( () => true )
.catch( () => false );
if ( visible ) {
const close = welcomeDialog.getByRole( 'button', { name: 'Close' } );
if ( await close.isVisible() ) {
await close.click();
} else {
await welcomeDialog.getByRole( 'button', { name: 'Get started' } ).click();
}
}
}
async function waitForEditor( page ) {
await expect
.poll( () =>
page.evaluate( () => {
const editor = window.wp?.data?.select( 'core/block-editor' );
return typeof editor?.getBlocks === 'function' && editor.getBlocks().length > 0;
} ),
)
.toBe( true );
}
async function editorSnapshot( page, rootClientIds = [], resolvePatternReferences = false ) {
return page.evaluate(
async ( { insertedRootIds, shouldResolvePatterns } ) => {
const store = window.wp.data.select( 'core/block-editor' );
let roots = insertedRootIds.length
? insertedRootIds.map( ( clientId ) => store.getBlock( clientId ) ).filter( Boolean )
: store.getBlocks();
if ( shouldResolvePatterns ) {
const registered = await window.wp.apiFetch( { path: '/wp/v2/block-patterns/patterns' } );
roots = roots.flatMap( ( block ) => {
if ( block.name !== 'core/pattern' ) {
return [ block ];
}
const pattern = registered.find(
( candidate ) => candidate.name === block.attributes.slug,
);
if ( ! pattern ) {
throw new Error( `Registered pattern not found: ${ block.attributes.slug }` );
}
return window.wp.blocks.parse( pattern.content );
} );
}
const flatten = ( blocks ) =>
blocks.flatMap( ( block ) => [ block, ...flatten( block.innerBlocks || [] ) ] );
const all = flatten( roots );
const stage = all.find(
( block ) =>
block.name === 'core/group' &&
block.attributes?.className?.split( /\s+/ ).includes( 'chrnx-character-stage' ),
);
const serialized = window.wp.blocks.serialize( roots );
const layerName = ( block ) => {
const source = window.wp.blocks.serialize( block );
return [ 'atmosphere', 'content', 'art' ].find( ( layer ) =>
source.includes( `chrnx-character-stage__${ layer }` ),
);
};
return {
invalid: all.filter( ( block ) => block.isValid === false ).map( ( block ) => block.name ),
layerOrder: stage ? stage.innerBlocks.map( layerName ) : [],
layerMarkup: stage
? Object.fromEntries(
stage.innerBlocks.map( ( block ) => [
layerName( block ),
window.wp.blocks.serialize( block ),
] ),
)
: {},
serialized,
};
},
{ insertedRootIds: rootClientIds, shouldResolvePatterns: resolvePatternReferences },
);
}
async function expectNoRecoveryUi( page ) {
await expect( page.getByText( /unexpected or invalid content/i ) ).toHaveCount( 0 );
await expect( page.getByRole( 'button', { name: /attempt (?:block )?recovery/i } ) ).toHaveCount(
0,
);
const canvas = page.locator( 'iframe' ).contentFrame();
await expect( canvas.getByText( /unexpected or invalid content/i ) ).toHaveCount( 0 );
await expect(
canvas.getByRole( 'button', { name: /attempt (?:block )?recovery/i } ),
).toHaveCount( 0 );
}
function expectPatternContract( snapshot, pattern ) {
expect( snapshot.invalid ).toEqual( [] );
expect( snapshot.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( snapshot.layerMarkup.atmosphere ).toContain( pattern.atmosphereAsset );
expect( snapshot.layerMarkup.content ).toContain( pattern.contentCopy );
expect( snapshot.layerMarkup.content ).not.toContain( pattern.atmosphereAsset );
expect( snapshot.layerMarkup.art ).toContain( pattern.artAsset );
expect( snapshot.serialized ).toContain( pattern.supportingCopy );
}
async function getTemplateRowCount( page ) {
return page.evaluate( async () => {
const templates = await window.wp.apiFetch( {
path: '/wp/v2/templates?context=edit&per_page=100&_fields=wp_id',
} );
return templates.filter( ( template ) => Number( template.wp_id ) > 0 ).length;
} );
}
for ( const pattern of patterns ) {
test( `${ pattern.label } Post Editor keeps the seeded pattern valid without saving`, async ( {
page,
} ) => {
await logIn( page );
const pagesResponse = await page.request.get(
`/wp-json/wp/v2/pages?slug=${ pattern.pageSlug }&_fields=id`,
);
expect( pagesResponse.ok() ).toBeTruthy();
const [ seededPage ] = await pagesResponse.json();
expect( seededPage?.id ).toBeTruthy();
const persistenceRequests = [];
page.on( 'request', ( request ) => {
if (
! [ 'GET', 'HEAD', 'OPTIONS' ].includes( request.method() ) &&
/\/wp-json\/wp\/v2\/(?:pages|templates)|\/wp-admin\/post\.php/.test( request.url() )
) {
persistenceRequests.push( `${ request.method() } ${ request.url() }` );
}
} );
await page.goto( `/wp-admin/post.php?post=${ seededPage.id }&action=edit` );
await closeWelcomeGuide( page );
await waitForEditor( page );
expectPatternContract( await editorSnapshot( page, [], true ), pattern );
await expectNoRecoveryUi( page );
expect( persistenceRequests ).toEqual( [] );
} );
test( `${ pattern.label } Site Editor inserts the registered pattern validly without saving`, async ( {
page,
} ) => {
await logIn( page );
const persistenceRequests = [];
page.on( 'request', ( request ) => {
if (
! [ 'GET', 'HEAD', 'OPTIONS' ].includes( request.method() ) &&
/\/wp-json\/wp\/v2\/(?:pages|templates)|\/wp-admin\/post\.php/.test( request.url() )
) {
persistenceRequests.push( `${ request.method() } ${ request.url() }` );
}
} );
await page.goto(
'/wp-admin/site-editor.php?postType=wp_template&postId=chrnx%2F%2Fpage&canvas=edit',
);
await closeWelcomeGuide( page );
await waitForEditor( page );
const templatesBefore = await getTemplateRowCount( page );
const insertedRootIds = await page.evaluate( async ( slug ) => {
const registered = await window.wp.apiFetch( { path: '/wp/v2/block-patterns/patterns' } );
const selected = registered.find( ( candidate ) => candidate.name === slug );
if ( ! selected ) {
throw new Error( `Registered pattern not found: ${ slug }` );
}
const blocks = window.wp.blocks.parse( selected.content );
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( [] );
window.wp.data.dispatch( 'core/block-editor' ).insertBlocks( blocks );
return blocks.map( ( block ) => block.clientId );
}, pattern.patternSlug );
expectPatternContract( await editorSnapshot( page, insertedRootIds ), pattern );
await expectNoRecoveryUi( page );
expect( await getTemplateRowCount( page ) ).toBe( templatesBefore );
expect( persistenceRequests ).toEqual( [] );
} );
}
+176 -1
View File
@@ -931,7 +931,7 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt
}
if ( surface.name === 'music' ) {
const collage = stage.locator(
'.chrnx-character-stage__content > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage)',
'.chrnx-character-stage__atmosphere > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage)',
);
const collageContract = await collage.evaluate(
( picture, stageElement ) => {
@@ -1201,3 +1201,178 @@ test( 'character stage below-fold derivatives wait for approach and then load re
.toMatch( /-384\.avif$/ );
}
} );
const musicPodcastLandingCases = [
{
name: 'Music',
path: '/music/',
root: '.chrnx-music-landing',
copy: 'The No Names es una banda activa',
atmosphere: 'img[src*="the-no-names-collage.jpeg"]',
art: 'img[src*="the-no-names-musician-cutout.png"]',
supporting: 'text=El proceso usa generative AI',
},
{
name: 'Podcast',
path: '/podcasts/',
root: '.chrnx-podcast-landing',
copy: 'Conversations about the work behind software, research, music, and games.',
atmosphere: 'img[src*="podcast-frequency-grunge.png"]',
art: 'img[src*="alter-ego-podcasts.png"]',
supporting: '.chrnx-latest-podcast',
},
];
async function readMusicPodcastLandingState( page, landing ) {
return page.locator( landing.root ).evaluate( ( root ) => {
const stage = root.querySelector( '.chrnx-character-stage' );
const layers = [ ...stage.children ];
const layerOrder = layers.map( ( layer ) =>
[ 'atmosphere', 'content', 'art' ].find( ( name ) =>
layer.classList.contains( `chrnx-character-stage__${ name }` ),
),
);
const rect = ( element ) => {
const bounds = element.getBoundingClientRect();
return {
x: bounds.x,
y: bounds.y,
width: bounds.width,
height: bounds.height,
};
};
const visible = ( element ) => {
if ( ! element ) {
return false;
}
const bounds = element.getBoundingClientRect();
const style = window.getComputedStyle( element );
return (
bounds.width > 0 &&
bounds.height > 0 &&
style.display !== 'none' &&
style.visibility !== 'hidden' &&
Number.parseFloat( style.opacity ) > 0
);
};
const animated = [ stage, ...stage.querySelectorAll( '*' ) ].some( ( element ) => {
const style = window.getComputedStyle( element );
const durations = `${ style.animationDuration },${ style.transitionDuration }`
.split( ',' )
.map( ( duration ) => Number.parseFloat( duration ) || 0 );
return durations.some( ( duration ) => duration > 0.001 );
} );
return {
layerOrder,
stage: rect( stage ),
layers: layers.map( rect ),
copyVisible: visible( stage.querySelector( '.chrnx-character-stage__content' ) ),
atmosphereVisible: visible(
stage.querySelector( '.chrnx-character-stage__atmosphere picture img' ),
),
artVisible: visible( stage.querySelector( '.chrnx-character-stage__art picture img' ) ),
animated,
overflow: Math.max(
document.documentElement.scrollWidth - window.innerWidth,
document.body.scrollWidth - window.innerWidth,
),
};
} );
}
test( 'Music and Podcast without JavaScript preserve the complete landing composition', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 120_000 );
for ( const colorScheme of [ 'dark', 'light' ] ) {
for ( const width of [ 375, 1440 ] ) {
const context = await browser.newContext( {
baseURL: testInfo.project.use.baseURL,
colorScheme,
javaScriptEnabled: false,
viewport: { width, height: width === 375 ? 812 : 900 },
} );
const page = await context.newPage();
try {
for ( const landing of musicPodcastLandingCases ) {
await page.goto( landing.path );
const root = page.locator( landing.root );
await expect( root.getByText( landing.copy, { exact: false } ) ).toBeVisible();
await expect( root.locator( landing.atmosphere ) ).toBeVisible();
await expect( root.locator( landing.art ) ).toBeVisible();
await expect( root.locator( landing.supporting ) ).toBeVisible();
const state = await readMusicPodcastLandingState( page, landing );
expect( state.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( state.copyVisible ).toBeTruthy();
expect( state.atmosphereVisible ).toBeTruthy();
expect( state.artVisible ).toBeTruthy();
expect( state.overflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page );
}
} finally {
await context.close();
}
}
}
} );
test( 'Music and Podcast reduced motion match settled layout without displacement', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 120_000 );
for ( const colorScheme of [ 'dark', 'light' ] ) {
for ( const width of [ 375, 1440 ] ) {
const context = await browser.newContext( {
baseURL: testInfo.project.use.baseURL,
colorScheme,
reducedMotion: 'no-preference',
viewport: { width, height: width === 375 ? 812 : 900 },
} );
const page = await context.newPage();
try {
for ( const landing of musicPodcastLandingCases ) {
await page.goto( landing.path );
await page
.locator( `${ landing.root } .chrnx-character-stage__art img` )
.evaluate( ( image ) => image.decode() );
const settled = await readMusicPodcastLandingState( page, landing );
await page.emulateMedia( { colorScheme, reducedMotion: 'reduce' } );
await page.reload();
await page
.locator( `${ landing.root } .chrnx-character-stage__art img` )
.evaluate( ( image ) => image.decode() );
const reduced = await readMusicPodcastLandingState( page, landing );
expect( reduced.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( reduced.copyVisible ).toBeTruthy();
expect( reduced.atmosphereVisible ).toBeTruthy();
expect( reduced.artVisible ).toBeTruthy();
expect( reduced.animated ).toBeFalsy();
expect( reduced.overflow ).toBeLessThanOrEqual( 1 );
for ( const key of [ 'x', 'y', 'width', 'height' ] ) {
expect( Math.abs( reduced.stage[ key ] - settled.stage[ key ] ) ).toBeLessThanOrEqual(
1,
);
}
reduced.layers.forEach( ( layer, index ) => {
for ( const key of [ 'x', 'y', 'width', 'height' ] ) {
expect(
Math.abs( layer[ key ] - settled.layers[ index ][ key ] ),
).toBeLessThanOrEqual( 1 );
}
} );
await expect(
page.locator( landing.root ).getByText( landing.copy, { exact: false } ),
).toBeVisible();
await expect( page.locator( landing.root ).locator( landing.supporting ) ).toBeVisible();
await expectNoHorizontalOverflow( page );
}
} finally {
await context.close();
}
}
}
} );
+1 -1
View File
@@ -32,7 +32,7 @@
"slug": "podcasts",
"title": "Podcasts",
"status": "publish",
"content": "<!-- wp:pattern {\"slug\":\"chrnx/podcast-landing\"} /--><!-- wp:chrnx/latest-podcast /-->"
"content": "<!-- wp:pattern {\"slug\":\"chrnx/podcast-landing\"} /-->"
},
{
"fixtureKey": "page-about",
+18
View File
@@ -604,6 +604,24 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringNotContainsString( '<iframe', $output );
}
/** Podcast landing owns one dynamic latest block and renders one supporting card. */
public function test_podcast_landing_renders_exactly_one_latest_podcast_card() {
$post_id = self::factory()->post->create( array( 'post_title' => 'One landing conversation' ) );
wp_set_object_terms( $post_id, 'podcasts', 'chrnx_topic' );
wp_set_object_terms( $post_id, 'silicon-ranch', 'chrnx_show' );
ob_start();
include get_theme_file_path( 'patterns/podcast-landing.php' );
$content = (string) ob_get_clean();
$output = do_blocks( $content );
$this->assertSame( 1, substr_count( $content, '<!-- wp:chrnx/latest-podcast /-->' ) );
$this->assertSame( 1, preg_match_all( '/<section\b[^>]*class="[^"]*\bchrnx-latest-podcast\b[^"]*"/', $output ) );
$this->assertSame( 1, substr_count( $output, 'One landing conversation' ) );
$this->assertStringNotContainsString( '<audio', $output );
$this->assertStringNotContainsString( '<iframe', $output );
}
/** Topic hero uses approved decorative art for mapped topics and rejects arbitrary paths. */
public function test_topic_hero_rejects_paths_and_uses_approved_decorative_art() {
$output = render_block(
+77 -11
View File
@@ -215,16 +215,20 @@ class PatternsTest extends WP_UnitTestCase {
'atmosphere' => 'chrnx-character-stage__collage',
),
'music-landing' => array(
'heading' => 'The No Names',
'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'The No Names es una banda activa', 'El proceso usa generative AI' ),
'art' => 'the-no-names-musician-cutout.png',
'art_alt' => 'The No Names musician portrait',
'heading' => 'The No Names',
'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'The No Names es una banda activa' ),
'art' => 'the-no-names-musician-cutout.png',
'art_alt' => 'The No Names musician portrait',
'atmosphere' => 'chrnx-character-stage__collage',
'atmos_alt' => 'The No Names collage',
'atmosphere_hidden' => false,
),
'podcast-landing' => array(
'heading' => 'Podcasts',
'order' => array( 'Podcasts' ),
'art' => 'alter-ego-podcasts.png',
'art_alt' => '',
'heading' => 'Podcasts',
'order' => array( 'Podcasts', 'Conversations about the work behind software, research, music, and games.' ),
'art' => 'alter-ego-podcasts.png',
'art_alt' => '',
'atmosphere' => 'chrnx-character-stage__frequency',
),
'about' => array(
'heading' => 'About',
@@ -251,7 +255,11 @@ class PatternsTest extends WP_UnitTestCase {
}
$this->assertCount( 3, $children, $name );
$this->assert_element_has_class( $children[0], 'chrnx-character-stage__atmosphere', $name );
$this->assertSame( 'true', $children[0]->getAttribute( 'aria-hidden' ), $name );
if ( false === ( $contract['atmosphere_hidden'] ?? true ) ) {
$this->assertFalse( $children[0]->hasAttribute( 'aria-hidden' ), $name );
} else {
$this->assertSame( 'true', $children[0]->getAttribute( 'aria-hidden' ), $name );
}
$this->assert_element_has_class( $children[1], 'chrnx-character-stage__content', $name );
$this->assert_element_has_class( $children[2], 'chrnx-character-stage__art', $name );
$this->assertCount( 1, $xpath->query( './/picture', $children[2] ), $name );
@@ -321,11 +329,60 @@ class PatternsTest extends WP_UnitTestCase {
$this->assertInstanceOf( DOMElement::class, $collage );
$this->assertCount( 3, $xpath->query( './*', $stage ) );
$this->assertCount( 0, $xpath->query( 'ancestor::*[@aria-hidden="true"]', $collage ) );
$this->assertCount( 1, $xpath->query( 'ancestor::*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__content ")]', $collage ) );
$this->assertCount( 0, $xpath->query( './*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__atmosphere ")]//picture', $stage ) );
$this->assertCount( 0, $xpath->query( 'ancestor::*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__content ")]', $collage ) );
$this->assertCount( 1, $xpath->query( './*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__atmosphere ")]//picture', $stage ) );
$this->assertCount( 1, $xpath->query( './*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage__art ")]//picture', $stage ) );
}
/** Music and Podcast compose their complete landing structures around one exact stage. */
public function test_music_and_podcast_landing_compositions_are_structurally_complete() {
$music = $this->render_pattern( get_theme_file_path( 'patterns/music-landing.php' ) );
$music_dom = $this->load_html_fragment( $music );
$music_xpath = new DOMXPath( $music_dom );
$music_stage = $music_xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 );
$music_root = $music_xpath->query( '//*[@id="chrnx-test-root"]/*[1]' )->item( 0 );
$this->assertInstanceOf( DOMElement::class, $music_stage );
$this->assertSame( 1, substr_count( $music, 'the-no-names-collage.jpeg' ) );
$this->assertSame( 1, substr_count( $music, 'the-no-names-musician-cutout.png' ) );
$this->assertSame( 1, $music_xpath->query( './*[1]//img[@alt="The No Names collage"]', $music_stage )->length );
$this->assertSame( 0, $music_xpath->query( './*[2]//img[contains(@class,"chrnx-character-stage__collage")]', $music_stage )->length );
$this->assertSame( 1, $music_xpath->query( './*[3]//img[@alt="The No Names musician portrait"]', $music_stage )->length );
$this->assertSame( 3, $music_xpath->query( './*[2]/*[self::h2 or self::p]', $music_stage )->length );
$process = $music_xpath->query( './p[contains(.,"El proceso usa generative AI")]', $music_root )->item( 0 );
$releases = $music_xpath->query( './h3[normalize-space()="Releases in progress"]', $music_root )->item( 0 );
$this->assertInstanceOf( DOMElement::class, $process );
$this->assertInstanceOf( DOMElement::class, $releases );
$this->assertSame( $music_stage, $process->previousElementSibling ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
$this->assertSame( $process, $releases->previousElementSibling ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
$this->assertSame( array( 2, 3, 4, 4, 4 ), $this->heading_levels( $music_dom ) );
$podcast = $this->render_pattern( get_theme_file_path( 'patterns/podcast-landing.php' ) );
$podcast_dom = $this->load_html_fragment( $podcast );
$podcast_xpath = new DOMXPath( $podcast_dom );
$podcast_stage = $podcast_xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 );
$this->assertInstanceOf( DOMElement::class, $podcast_stage );
$this->assertSame( 1, substr_count( $podcast, 'podcast-frequency-grunge.png' ) );
$podcast_atmosphere = $podcast_dom->saveHTML( $podcast_xpath->query( './*[1]', $podcast_stage )->item( 0 ) );
$this->assertStringContainsString( '<picture class="chrnx-responsive-atmosphere" aria-hidden="true">', $podcast_atmosphere );
$this->assertStringContainsString( 'alt=""', $podcast_atmosphere );
$podcast_art = $podcast_dom->saveHTML( $podcast_xpath->query( './*[3]', $podcast_stage )->item( 0 ) );
$this->assertStringContainsString( '<picture class="chrnx-responsive-portrait" aria-hidden="true">', $podcast_art );
$this->assertStringContainsString( 'alter-ego-podcasts.png', $podcast_art );
$this->assertStringContainsString( 'alt=""', $podcast_art );
$this->assertSame( 1, substr_count( $podcast, '<!-- wp:chrnx/latest-podcast /-->' ) );
$this->assertSame( 1, substr_count( $podcast, '"metadata":{"name":"chrnx/podcast-show-discovery"}' ) );
$this->assertSame( 1, substr_count( $podcast, '"metadata":{"name":"chrnx/podcast-archive"}' ) );
$this->assertStringNotContainsString( 'chrnx/podcast-latest', $podcast );
$this->assertLessThan( strpos( $podcast, '<!-- wp:chrnx/latest-podcast /-->' ), strpos( $podcast, '<!-- /wp:group -->', strpos( $podcast, 'chrnx-character-stage__art' ) ) );
$pages = json_decode( (string) file_get_contents( get_theme_file_path( 'tests/fixtures/pages.json' ) ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local JSON fixture.
$podcasts = array_values( array_filter( $pages, static fn( $page ) => 'podcasts' === $page['slug'] ) );
$this->assertCount( 7, $pages );
$this->assertCount( 1, $podcasts );
$this->assertSame( '<!-- wp:pattern {"slug":"chrnx/podcast-landing"} /-->', $podcasts[0]['content'] );
}
/** Rendered pattern content survives parse/serialize without block-tree drift. */
public function test_character_led_patterns_preserve_editor_fidelity() {
foreach ( array( 'home-projects', 'home-music', 'music-landing', 'podcast-landing', 'about' ) as $name ) {
@@ -354,6 +411,15 @@ class PatternsTest extends WP_UnitTestCase {
$this->assertContains( $class_name, preg_split( '/\s+/', trim( $element->getAttribute( 'class' ) ) ), $message );
}
/** Return heading levels in document order. */
private function heading_levels( DOMDocument $dom ) {
$levels = array();
foreach ( ( new DOMXPath( $dom ) )->query( '//h1|//h2|//h3|//h4|//h5|//h6' ) as $heading ) {
$levels[] = (int) substr( strtolower( $heading->tagName ), 1 ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property.
}
return $levels;
}
/** Return the ordered nested block-name tree while rejecting non-whitespace freeform nodes. */
private function block_name_tree( array $blocks, $message ) {
$tree = array();
+45
View File
@@ -462,6 +462,51 @@ test( 'character-led openings share the exact stage class contract', () => {
assert.match( read( 'blocks/topic-hero/render.php' ), /chrnx-topic-hero__fallback/ );
} );
test( 'Music and Podcast patterns own one ordered three-layer landing composition', () => {
const music = read( 'patterns/music-landing.php' );
const podcast = read( 'patterns/podcast-landing.php' );
const pages = JSON.parse( read( 'tests/fixtures/pages.json' ) );
const assertLayerOrder = ( source, label ) => {
const stage = source.indexOf( 'className":"chrnx-character-stage"' );
const atmosphere = source.indexOf( 'chrnx-character-stage__atmosphere', stage );
const content = source.indexOf( 'chrnx-character-stage__content', atmosphere );
const art = source.indexOf( 'chrnx-character-stage__art', content );
assert.ok( stage >= 0 && atmosphere > stage && content > atmosphere && art > content, label );
};
assertLayerOrder( music, 'Music layer order' );
assert.equal( ( music.match( /chrnx_get_topic_portrait_markup\( 'music-collage'/g ) || [] ).length, 1 );
assert.equal( ( music.match( /chrnx_get_topic_portrait_markup\( 'music',/g ) || [] ).length, 1 );
assert.doesNotMatch(
music.match( /chrnx-character-stage__atmosphere[\s\S]*?chrnx-character-stage__content/ )?.[ 0 ] ?? '',
/aria-hidden="true"/,
);
assert.ok(
music.indexOf( 'chrnx_get_topic_portrait_markup( \'music-collage\'' ) <
music.indexOf( 'chrnx-character-stage__content' ),
);
assert.ok(
music.indexOf( 'El proceso usa generative AI' ) > music.indexOf( '<!-- /wp:group -->', music.indexOf( 'chrnx-character-stage__art' ) ) &&
music.indexOf( 'El proceso usa generative AI' ) < music.indexOf( 'Releases in progress' ),
);
assertLayerOrder( podcast, 'Podcast layer order' );
assert.equal( ( podcast.match( /chrnx_get_atmosphere_markup\( 'podcast-frequency'/g ) || [] ).length, 1 );
assert.equal( ( podcast.match( /chrnx_get_topic_portrait_markup\( 'podcasts'/g ) || [] ).length, 1 );
assert.equal( ( podcast.match( /<!-- wp:chrnx\/latest-podcast \/-->/g ) || [] ).length, 1 );
assert.match( podcast, /chrnx-character-stage__atmosphere" aria-hidden="true"/ );
assert.match( podcast, /chrnx\/podcast-show-discovery/ );
assert.match( podcast, /chrnx\/podcast-archive/ );
assert.doesNotMatch( podcast, /chrnx\/podcast-latest/ );
assert.equal( pages.length, 7 );
const podcastPage = pages.find( ( page ) => page.slug === 'podcasts' );
assert.equal(
podcastPage?.content,
'<!-- wp:pattern {"slug":"chrnx/podcast-landing"} /-->',
);
} );
test( 'character stages define the shared mockup effect and responsive geometry', () => {
const components = read( 'assets/css/components.css' );
const visualStates = read( 'tests/e2e/visual-states.spec.mjs' );