refactor: compose CHRNX music and podcast stages
This commit is contained in:
8 files changed
+543
-19
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
Reference in new issue
Block a user