test: align CHRNX visual regressions

This commit is contained in:
chrnx committed 2026-08-13 11:05:31 -05:00
1 parent 16b6a75b35
commit 6bfe87b64e
1 file changed
+135 -42
+135 -42
View File
@@ -203,7 +203,7 @@ test( 'home remains coherent at all approved review viewports', async ( { page }
} }
} ); } );
test( 'lower home sections form compact, contained editorial panels in both themes', async ( { test( 'lower home sections keep the layered Music stage contained in both themes', async ( {
page, page,
} ) => { } ) => {
const expectedOrder = [ const expectedOrder = [
@@ -224,11 +224,21 @@ test( 'lower home sections form compact, contained editorial panels in both them
); );
await page.reload(); await page.reload();
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme.toLowerCase() ); await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme.toLowerCase() );
const musicStage = page.locator( '.chrnx-home-music > .chrnx-character-stage' );
await expect( musicStage ).toBeVisible();
await positionStageBelowStickyHeader( page, musicStage );
const musicImages = musicStage.locator(
':scope > .chrnx-character-stage__atmosphere img, :scope > .chrnx-character-stage__art img',
);
await expect( musicImages ).toHaveCount( 2 );
await musicImages.evaluateAll( ( images ) =>
Promise.all( images.map( ( image ) => image.decode() ) ),
);
const result = await page.locator( '.chrnx-home' ).evaluate( ( home, order ) => { const result = await page.locator( '.chrnx-home' ).evaluate( ( home, order ) => {
const selectors = [ const selectors = [
'.chrnx-home-projects', '.chrnx-home-projects',
'.chrnx-home-music .wp-block-columns', '.chrnx-home-music > .chrnx-character-stage',
'.chrnx-latest-podcast', '.chrnx-latest-podcast',
'.chrnx-home-about-preview', '.chrnx-home-about-preview',
'.chrnx-subscribe-cta', '.chrnx-subscribe-cta',
@@ -274,10 +284,14 @@ test( 'lower home sections form compact, contained editorial panels in both them
const panelRects = panels.map( ( panel ) => panel.getBoundingClientRect() ); const panelRects = panels.map( ( panel ) => panel.getBoundingClientRect() );
const journalRect = home.querySelector( '.chrnx-journal-stream' ).getBoundingClientRect(); const journalRect = home.querySelector( '.chrnx-journal-stream' ).getBoundingClientRect();
const musicFrame = panels[ 1 ]; const musicFrame = panels[ 1 ];
const collageLayer = musicFrame.querySelector( '.chrnx-home-music__collage-layer' ); const layers = [ ...musicFrame.children ];
const collage = collageLayer?.querySelector( '.chrnx-home-music__collage' ); const collageLayer = musicFrame.querySelector(
const musician = musicFrame.querySelector( '.chrnx-home-music__art' ); ':scope > .chrnx-character-stage__atmosphere',
const musicHeading = musicFrame.querySelector( 'h2' ); );
const contentLayer = musicFrame.querySelector( ':scope > .chrnx-character-stage__content' );
const artLayer = musicFrame.querySelector( ':scope > .chrnx-character-stage__art' );
const collage = collageLayer.querySelector( '.chrnx-character-stage__collage' );
const musician = artLayer.querySelector( '.chrnx-home-music__art' );
const projectPortraits = [ const projectPortraits = [
...panels[ 0 ].querySelectorAll( '.chrnx-section-portrait' ), ...panels[ 0 ].querySelectorAll( '.chrnx-section-portrait' ),
].filter( ( portrait ) => portrait.getClientRects().length > 0 ); ].filter( ( portrait ) => portrait.getClientRects().length > 0 );
@@ -304,23 +318,32 @@ test( 'lower home sections form compact, contained editorial panels in both them
isContained( portrait, panels[ 0 ] ), isContained( portrait, panels[ 0 ] ),
), ),
projectsTreated: projectPortraits.every( isTreated ), projectsTreated: projectPortraits.every( isTreated ),
collageSources: collageLayer layerOrder: layers.map( ( layer ) =>
? [ ...collageLayer.querySelectorAll( 'source' ) ].map( ( source ) => ( { [ 'atmosphere', 'content', 'art' ].find( ( name ) =>
type: source.type, layer.classList.contains( `chrnx-character-stage__${ name }` ),
srcset: source.srcset, ),
} ) ) ),
: [], collageSources: [ ...collageLayer.querySelectorAll( 'source' ) ].map( ( source ) => ( {
collageLazy: collage?.loading, type: source.type,
collageFallback: collage?.getAttribute( 'src' ), srcset: source.srcset,
collageContained: Boolean( collageLayer && isContained( collageLayer, musicFrame ) ), } ) ),
collageTreated: Boolean( collage && isTreated( collage ) ), collageLazy: collage.loading,
collageZIndex: collageLayer collageFallback: collage.getAttribute( 'src' ),
? Number.parseInt( window.getComputedStyle( collageLayer ).zIndex, 10 ) collageContained: isContained( collageLayer, musicFrame ),
: Number.NaN, collageTreated: isTreated( collage ),
copyPosition: window.getComputedStyle( musicHeading ).position, collageZIndex: Number.parseInt( window.getComputedStyle( collageLayer ).zIndex, 10 ),
copyZIndex: Number.parseInt( window.getComputedStyle( musicHeading ).zIndex, 10 ), copyPosition: window.getComputedStyle( contentLayer ).position,
musicianContained: isContained( musician, musicFrame ), copyZIndex: Number.parseInt( window.getComputedStyle( contentLayer ).zIndex, 10 ),
copyContained: isContained( contentLayer, musicFrame ),
artContained: isContained( artLayer, musicFrame ),
artWidthRatio:
artLayer.getBoundingClientRect().width / musicFrame.getBoundingClientRect().width,
musicianContained: isContained( musician, artLayer ),
musicianTreated: isTreated( musician ), musicianTreated: isTreated( musician ),
imagesDecoded: [ collage, musician ].every(
( image ) => image.complete && image.naturalWidth > 0,
),
stageOverflow: musicFrame.scrollWidth - musicFrame.clientWidth,
}; };
}, expectedOrder ); }, expectedOrder );
@@ -337,6 +360,7 @@ test( 'lower home sections form compact, contained editorial panels in both them
).toBeTruthy(); ).toBeTruthy();
expect( result.projectsContained ).toBeTruthy(); expect( result.projectsContained ).toBeTruthy();
expect( result.projectsTreated ).toBeTruthy(); expect( result.projectsTreated ).toBeTruthy();
expect( result.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( result.collageSources ).toEqual( [ expect( result.collageSources ).toEqual( [
expect.objectContaining( { expect.objectContaining( {
type: 'image/avif', type: 'image/avif',
@@ -353,8 +377,16 @@ test( 'lower home sections form compact, contained editorial panels in both them
expect( result.collageTreated ).toBeTruthy(); expect( result.collageTreated ).toBeTruthy();
expect( result.copyPosition ).not.toBe( 'static' ); expect( result.copyPosition ).not.toBe( 'static' );
expect( result.copyZIndex ).toBeGreaterThan( result.collageZIndex ); expect( result.copyZIndex ).toBeGreaterThan( result.collageZIndex );
expect( result.copyContained ).toBeTruthy();
expect( result.artContained ).toBeTruthy();
expect( result.artWidthRatio ).toBeGreaterThanOrEqual( viewport.width <= 768 ? 0.62 : 0.35 );
if ( viewport.width > 768 ) {
expect( result.artWidthRatio ).toBeLessThanOrEqual( 0.48 );
}
expect( result.musicianContained ).toBeTruthy(); expect( result.musicianContained ).toBeTruthy();
expect( result.musicianTreated ).toBeTruthy(); expect( result.musicianTreated ).toBeTruthy();
expect( result.imagesDecoded ).toBeTruthy();
expect( result.stageOverflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page ); await expectNoHorizontalOverflow( page );
} }
} }
@@ -437,36 +469,51 @@ test( 'lower home panels survive missing media and reduced motion', async ( { pa
expect( fallback.cardInPanel ).toBeTruthy(); expect( fallback.cardInPanel ).toBeTruthy();
const musicFallback = await page const musicFallback = await page
.locator( '.chrnx-home-music .wp-block-columns' ) .locator( '.chrnx-home-music > .chrnx-character-stage' )
.evaluate( ( frame ) => { .evaluate( ( frame ) => {
const layer = frame.querySelector( '.chrnx-home-music__collage-layer' ); const layers = [ ...frame.children ];
const copy = frame.querySelector( '.wp-block-column:first-of-type' ); const atmosphere = frame.querySelector( ':scope > .chrnx-character-stage__atmosphere' );
const copy = frame.querySelector( ':scope > .chrnx-character-stage__content' );
const art = frame.querySelector( ':scope > .chrnx-character-stage__art' );
const frameRect = frame.getBoundingClientRect(); const frameRect = frame.getBoundingClientRect();
const copyRect = copy.getBoundingClientRect(); const copyRect = copy.getBoundingClientRect();
const layerRect = layer?.getBoundingClientRect(); const atmosphereRect = atmosphere.getBoundingClientRect();
const artRect = art.getBoundingClientRect();
return { return {
hasLayer: Boolean( layer ), layerOrder: layers.map( ( layer ) =>
decorativeAlt: layer?.querySelector( 'img' )?.getAttribute( 'alt' ), [ 'atmosphere', 'content', 'art' ].find( ( name ) =>
layerCoversFrame: Boolean( layer.classList.contains( `chrnx-character-stage__${ name }` ),
layerRect && ),
Math.abs( layerRect.left - frameRect.left ) <= 1 &&
Math.abs( layerRect.right - frameRect.right ) <= 1 &&
Math.abs( layerRect.top - frameRect.top ) <= 1 &&
Math.abs( layerRect.bottom - frameRect.bottom ) <= 1,
), ),
decorativeAlt: atmosphere.querySelector( 'img' )?.getAttribute( 'alt' ),
atmosphereCoversFrame:
Math.abs( atmosphereRect.left - frameRect.left ) <= 1 &&
Math.abs( atmosphereRect.right - frameRect.right ) <= 1 &&
Math.abs( atmosphereRect.top - frameRect.top ) <= 1 &&
Math.abs( atmosphereRect.bottom - frameRect.bottom ) <= 1,
copyContained: copyContained:
copyRect.left >= frameRect.left - 1 && copyRect.left >= frameRect.left - 1 &&
copyRect.right <= frameRect.right + 1 && copyRect.right <= frameRect.right + 1 &&
copyRect.top >= frameRect.top - 1 && copyRect.top >= frameRect.top - 1 &&
copyRect.bottom <= frameRect.bottom + 1, copyRect.bottom <= frameRect.bottom + 1,
artContained:
artRect.left >= frameRect.left - 1 &&
artRect.right <= frameRect.right + 1 &&
artRect.top >= frameRect.top - 1 &&
artRect.bottom <= frameRect.bottom + 1,
artWidthRatio: artRect.width / frameRect.width,
stageOverflow: frame.scrollWidth - frame.clientWidth,
}; };
} ); } );
expect( musicFallback.hasLayer ).toBeTruthy(); expect( musicFallback.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( musicFallback.decorativeAlt ).toBe( '' ); expect( musicFallback.decorativeAlt ).toBe( '' );
expect( musicFallback.layerCoversFrame ).toBeTruthy(); expect( musicFallback.atmosphereCoversFrame ).toBeTruthy();
expect( musicFallback.copyContained ).toBeTruthy(); expect( musicFallback.copyContained ).toBeTruthy();
expect( musicFallback.artContained ).toBeTruthy();
expect( musicFallback.artWidthRatio ).toBeGreaterThanOrEqual( 0.62 );
expect( musicFallback.stageOverflow ).toBeLessThanOrEqual( 1 );
await expect( page.locator( '.chrnx-home-music h2' ) ).toContainText( 'The No Names' ); await expect( page.locator( '.chrnx-home-music h2' ) ).toContainText( 'The No Names' );
await expect( page.locator( '.chrnx-home-music p' ) ).toHaveCount( 2 ); await expect( page.locator( '.chrnx-home-music p' ) ).toHaveCount( 2 );
await expect( page.locator( '.chrnx-home-projects h3' ) ).toHaveCount( 3 ); await expect( page.locator( '.chrnx-home-projects h3' ) ).toHaveCount( 3 );
@@ -475,7 +522,7 @@ test( 'lower home panels survive missing media and reduced motion', async ( { pa
for ( const selector of [ for ( const selector of [
'.chrnx-home-projects', '.chrnx-home-projects',
'.chrnx-home-music .wp-block-columns', '.chrnx-home-music > .chrnx-character-stage',
'.chrnx-latest-podcast', '.chrnx-latest-podcast',
'.chrnx-home-about-preview', '.chrnx-home-about-preview',
'.chrnx-subscribe-cta', '.chrnx-subscribe-cta',
@@ -602,13 +649,55 @@ test( 'topic, music, podcast, and about surfaces use real content and approved a
page, page,
} ) => { } ) => {
for ( const [ path, heading, asset ] of [ for ( const [ path, heading, asset ] of [
[ '/topic/code/', 'Code', 'alter-ego-code' ], [ '/topic/code/', 'Code', 'alter-ego-code.png' ],
[ '/topic/research/', 'Research', 'alter-ego-research' ], [ '/topic/research/', 'Research', 'alter-ego-research.png' ],
[ '/topic/gaming/', 'Gaming', 'alter-ego-gaming' ], [ '/topic/gaming/', 'Gaming', 'alter-ego-gaming-half-body.png' ],
] ) { ] ) {
await page.goto( path ); await page.goto( path );
await expect( page.getByRole( 'heading', { level: 1, name: heading } ) ).toBeVisible(); await expect( page.getByRole( 'heading', { level: 1, name: heading } ) ).toBeVisible();
await expect( page.locator( `.chrnx-topic-hero img[src*="${ asset }.png"]` ) ).toBeVisible(); const stage = page.locator( '.chrnx-topic-hero .chrnx-character-stage' ).first();
const image = stage.locator( ':scope > .chrnx-character-stage__art img' );
await expect( image ).toBeVisible();
await image.evaluate( ( element ) => element.decode() );
const contract = await stage.evaluate( ( element ) => {
const layers = [ ...element.children ];
const content = element.querySelector( ':scope > .chrnx-character-stage__content' );
const art = element.querySelector( ':scope > .chrnx-character-stage__art' );
const imageElement = art.querySelector( 'img' );
const stageRect = element.getBoundingClientRect();
const contentRect = content.getBoundingClientRect();
const artRect = art.getBoundingClientRect();
const imageRect = imageElement.getBoundingClientRect();
return {
layerOrder: layers.map( ( layer ) =>
[ 'atmosphere', 'content', 'art' ].find( ( name ) =>
layer.classList.contains( `chrnx-character-stage__${ name }` ),
),
),
source: new URL( imageElement.src ).pathname.split( '/' ).pop(),
decoded: imageElement.complete && imageElement.naturalWidth > 0,
copyContained:
contentRect.left >= stageRect.left - 1 &&
contentRect.right <= stageRect.right + 1 &&
contentRect.top >= stageRect.top - 1 &&
contentRect.bottom <= stageRect.bottom + 1,
imageContained:
imageRect.left >= artRect.left - 1 &&
imageRect.right <= artRect.right + 1 &&
imageRect.top >= artRect.top - 1 &&
imageRect.bottom <= artRect.bottom + 1,
artWidthRatio: artRect.width / stageRect.width,
stageOverflow: element.scrollWidth - element.clientWidth,
};
} );
expect( contract.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( contract.source ).toBe( asset );
expect( contract.decoded ).toBeTruthy();
expect( contract.copyContained ).toBeTruthy();
expect( contract.imageContained ).toBeTruthy();
expect( contract.artWidthRatio ).toBeGreaterThanOrEqual( 0.35 );
expect( contract.artWidthRatio ).toBeLessThanOrEqual( 0.48 );
expect( contract.stageOverflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page ); await expectNoHorizontalOverflow( page );
} }
@@ -630,7 +719,11 @@ test( 'topic, music, podcast, and about surfaces use real content and approved a
'href', 'href',
'https://arxiv.org/abs/2603.05352', 'https://arxiv.org/abs/2603.05352',
); );
await expect( page.locator( '.chrnx-about__portraits picture' ) ).toHaveCount( 3 ); await expect( page.locator( '.chrnx-about .chrnx-character-stage__art > picture' ) ).toHaveCount(
1,
);
await expect( page.locator( '.chrnx-about__portraits > picture' ) ).toHaveCount( 2 );
await expect( page.locator( '.chrnx-about picture' ) ).toHaveCount( 3 );
} ); } );
test( 'long, incomplete, empty, and missing states stay usable', async ( { page } ) => { test( 'long, incomplete, empty, and missing states stay usable', async ( { page } ) => {