fix: optimize CHRNX editorial media

This commit is contained in:
chrnx committed 2026-08-12 15:52:53 -05:00
1 parent 55e21bca81
commit c5720b21ca
14 files changed
+252 -46

No files matched your search

+131 -10
View File
@@ -123,8 +123,10 @@ test( 'lower home sections form compact, contained editorial panels in both them
const panelRects = panels.map( ( panel ) => panel.getBoundingClientRect() );
const journalRect = home.querySelector( '.chrnx-journal-stream' ).getBoundingClientRect();
const musicFrame = panels[ 1 ];
const collage = window.getComputedStyle( musicFrame, '::before' );
const collageLayer = musicFrame.querySelector( '.chrnx-home-music__collage-layer' );
const collage = collageLayer?.querySelector( '.chrnx-home-music__collage' );
const musician = musicFrame.querySelector( '.chrnx-home-music__art' );
const musicHeading = musicFrame.querySelector( 'h2' );
const projectPortraits = [
...panels[ 0 ].querySelectorAll( '.chrnx-section-portrait' ),
].filter( ( portrait ) => portrait.getClientRects().length > 0 );
@@ -151,13 +153,21 @@ test( 'lower home sections form compact, contained editorial panels in both them
isContained( portrait, panels[ 0 ] ),
),
projectsTreated: projectPortraits.every( isTreated ),
collageBackground: collage.backgroundImage,
collageContent: collage.content,
collageContained:
collage.position === 'absolute' &&
[ collage.inset, collage.top, collage.right, collage.bottom, collage.left ]
.join( ' ' )
.includes( '0px' ),
collageSources: collageLayer
? [ ...collageLayer.querySelectorAll( 'source' ) ].map( ( source ) => ( {
type: source.type,
srcset: source.srcset,
} ) )
: [],
collageLazy: collage?.loading,
collageFallback: collage?.getAttribute( 'src' ),
collageContained: Boolean( collageLayer && isContained( collageLayer, musicFrame ) ),
collageTreated: Boolean( collage && isTreated( collage ) ),
collageZIndex: collageLayer
? Number.parseInt( window.getComputedStyle( collageLayer ).zIndex, 10 )
: Number.NaN,
copyPosition: window.getComputedStyle( musicHeading ).position,
copyZIndex: Number.parseInt( window.getComputedStyle( musicHeading ).zIndex, 10 ),
musicianContained: isContained( musician, musicFrame ),
musicianTreated: isTreated( musician ),
};
@@ -176,9 +186,22 @@ test( 'lower home sections form compact, contained editorial panels in both them
).toBeTruthy();
expect( result.projectsContained ).toBeTruthy();
expect( result.projectsTreated ).toBeTruthy();
expect( result.collageBackground ).toContain( 'the-no-names-collage.jpeg' );
expect( result.collageContent ).not.toBe( 'none' );
expect( result.collageSources ).toEqual( [
expect.objectContaining( {
type: 'image/avif',
srcset: expect.stringContaining( 'the-no-names-collage-384.avif' ),
} ),
expect.objectContaining( {
type: 'image/webp',
srcset: expect.stringContaining( 'the-no-names-collage-384.webp' ),
} ),
] );
expect( result.collageLazy ).toBe( 'lazy' );
expect( result.collageFallback ).toContain( 'the-no-names-collage.jpeg' );
expect( result.collageContained ).toBeTruthy();
expect( result.collageTreated ).toBeTruthy();
expect( result.copyPosition ).not.toBe( 'static' );
expect( result.copyZIndex ).toBeGreaterThan( result.collageZIndex );
expect( result.musicianContained ).toBeTruthy();
expect( result.musicianTreated ).toBeTruthy();
await expectNoHorizontalOverflow( page );
@@ -186,12 +209,110 @@ test( 'lower home sections form compact, contained editorial panels in both them
}
} );
test( 'latest podcast is a compact horizontal panel on desktop', async ( { page } ) => {
await page.setViewportSize( { width: 1440, height: 900 } );
await page.goto( '/' );
const geometry = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
const link = panel.querySelector( '.chrnx-podcast-card__link' );
const media = panel.querySelector(
'.chrnx-podcast-card__image, .chrnx-podcast-card__fallback',
);
const content = panel.querySelector( '.chrnx-podcast-card__content' );
const panelRect = panel.getBoundingClientRect();
const mediaRect = media.getBoundingClientRect();
const contentRect = content.getBoundingClientRect();
return {
display: window.getComputedStyle( link ).display,
panelHeight: panelRect.height,
viewportHeight: window.innerHeight,
mediaHeight: mediaRect.height,
mediaRight: mediaRect.right,
contentLeft: contentRect.left,
};
} );
expect( geometry.display ).toBe( 'grid' );
expect( geometry.panelHeight ).toBeLessThanOrEqual( geometry.viewportHeight * 0.72 );
expect( geometry.mediaHeight ).toBeLessThanOrEqual( geometry.panelHeight * 0.72 );
expect( geometry.mediaRight ).toBeLessThanOrEqual( geometry.contentLeft + 1 );
} );
test( 'lower home panels survive missing media and reduced motion', async ( { page } ) => {
await page.emulateMedia( { reducedMotion: 'reduce' } );
await page.route( /\/assets\/images\//, ( route ) => route.abort() );
await page.setViewportSize( { width: 375, height: 812 } );
await page.goto( '/' );
const fallback = await page.locator( '.chrnx-podcast-card__fallback' ).evaluate( ( media ) => {
const card = media.closest( '.chrnx-podcast-card' );
const panel = media.closest( '.chrnx-latest-podcast' );
const mediaRect = media.getBoundingClientRect();
const cardRect = card.getBoundingClientRect();
const panelRect = panel.getBoundingClientRect();
const style = window.getComputedStyle( media );
return {
width: mediaRect.width,
height: mediaRect.height,
backgroundImage: style.backgroundImage,
inCard:
mediaRect.left >= cardRect.left - 1 &&
mediaRect.right <= cardRect.right + 1 &&
mediaRect.top >= cardRect.top - 1 &&
mediaRect.bottom <= cardRect.bottom + 1,
cardInPanel:
cardRect.left >= panelRect.left - 1 &&
cardRect.right <= panelRect.right + 1 &&
cardRect.top >= panelRect.top - 1 &&
cardRect.bottom <= panelRect.bottom + 1,
};
} );
expect( fallback.width ).toBeGreaterThan( 0 );
expect( fallback.height ).toBeGreaterThan( 0 );
expect( fallback.backgroundImage ).toMatch( /gradient/ );
expect( fallback.inCard ).toBeTruthy();
expect( fallback.cardInPanel ).toBeTruthy();
const musicFallback = await page
.locator( '.chrnx-home-music .wp-block-columns' )
.evaluate( ( frame ) => {
const layer = frame.querySelector( '.chrnx-home-music__collage-layer' );
const copy = frame.querySelector( '.wp-block-column:first-of-type' );
const frameRect = frame.getBoundingClientRect();
const copyRect = copy.getBoundingClientRect();
const layerRect = layer?.getBoundingClientRect();
return {
hasLayer: Boolean( layer ),
decorativeAlt: layer?.querySelector( 'img' )?.getAttribute( 'alt' ),
layerCoversFrame: Boolean(
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,
),
copyContained:
copyRect.left >= frameRect.left - 1 &&
copyRect.right <= frameRect.right + 1 &&
copyRect.top >= frameRect.top - 1 &&
copyRect.bottom <= frameRect.bottom + 1,
};
} );
expect( musicFallback.hasLayer ).toBeTruthy();
expect( musicFallback.decorativeAlt ).toBe( '' );
expect( musicFallback.layerCoversFrame ).toBeTruthy();
expect( musicFallback.copyContained ).toBeTruthy();
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-projects h3' ) ).toHaveCount( 3 );
await expect( page.locator( '.chrnx-home-about-preview p' ) ).not.toBeEmpty();
await expect( page.locator( '.chrnx-subscribe-cta__link' ) ).toBeVisible();
for ( const selector of [
'.chrnx-home-projects',
'.chrnx-home-music .wp-block-columns',