Files
chrnx-dev-wp/tests/e2e/music-podcast-stages.spec.mjs
T
2026-08-15 16:19:25 -05:00

675 lines
29 KiB
JavaScript

import { expect, test } from '@playwright/test';
const REM_46 = 46 * 16;
const landings = [
{
name: 'Music',
path: '/music/',
root: '.chrnx-music-landing',
atmosphere: '.chrnx-character-stage__collage',
art: 'img[src*="the-no-names-musician-cutout-768.webp"]',
internalHeadings: ':scope > h3, .chrnx-release-card h4',
internalHeadingCount: 4,
next: ':scope > p',
},
{
name: 'Podcast',
path: '/podcasts/',
root: '.chrnx-podcast-landing',
atmosphere: '.chrnx-character-stage__frequency',
art: 'img[src*="alter-ego-podcasts-768.webp"]',
internalHeadings: '.chrnx-podcast-card__title',
internalHeadingCount: 1,
next: ':scope > .wp-block-chrnx-latest-podcast',
},
];
async function openIsolatedThemedPage( browser, testInfo, { height, path, theme, width } ) {
const baseURL = testInfo.project.use.baseURL;
const expectedOrigin = new URL( baseURL ).origin;
const context = await browser.newContext( {
baseURL,
colorScheme: theme,
viewport: { width, height },
} );
const page = await context.newPage();
await page.goto( path );
const resolvedOrigin = new URL( page.url() ).origin;
expect( resolvedOrigin ).toBe( expectedOrigin );
const resolvedTheme = await page.evaluate( ( value ) => {
window.localStorage.clear();
window.localStorage.setItem( 'chrnx-theme', value );
document.documentElement.dataset.theme = value;
return {
attribute: document.documentElement.dataset.theme,
stored: window.localStorage.getItem( 'chrnx-theme' ),
};
}, theme );
expect( resolvedTheme ).toEqual( { attribute: theme, stored: theme } );
return { context, page };
}
async function expectNoHorizontalOverflow( page ) {
const overflow = await page.evaluate( () =>
Math.max(
document.documentElement.scrollWidth - window.innerWidth,
document.body.scrollWidth - window.innerWidth,
),
);
expect( overflow ).toBeLessThanOrEqual( 1 );
}
async function readStage( page, landing ) {
return page.locator( landing.root ).evaluate( ( root, value ) => {
const readRect = ( element ) => {
const bounds = element.getBoundingClientRect();
return {
bottom: bounds.bottom,
height: bounds.height,
left: bounds.left,
right: bounds.right,
top: bounds.top,
width: bounds.width,
};
};
const stage = root.querySelector( '.chrnx-character-stage' );
const atmosphereLayer = stage.querySelector( '.chrnx-character-stage__atmosphere' );
const atmosphere = stage.querySelector( value.atmosphere );
const content = stage.querySelector( '.chrnx-character-stage__content' );
const artLayer = stage.querySelector( '.chrnx-character-stage__art' );
const art = stage.querySelector( value.art );
const next = root.querySelector( value.next );
const stageRect = readRect( stage );
const atmosphereLayerRect = readRect( atmosphereLayer );
const atmosphereRect = readRect( atmosphere );
const contentRect = readRect( content );
const artLayerRect = readRect( artLayer );
const artRect = readRect( art );
const nextRect = readRect( next );
const contained = ( child, parent ) =>
child.left >= parent.left - 1 &&
child.right <= parent.right + 1 &&
child.top >= parent.top - 1 &&
child.bottom <= parent.bottom + 1;
const overlaps = ( first, second ) =>
first.left < second.right - 1 &&
first.right > second.left + 1 &&
first.top < second.bottom - 1 &&
first.bottom > second.top + 1;
return {
stage: stageRect,
atmosphere: atmosphereRect,
atmosphereLayer: atmosphereLayerRect,
atmosphereFit: window.getComputedStyle( atmosphere ).objectFit,
atmosphereHidden: atmosphereLayer.getAttribute( 'aria-hidden' ),
atmosphereContained: contained( atmosphereRect, stageRect ),
content: contentRect,
contentMinWidth: window.getComputedStyle( content ).minWidth,
art: artRect,
artLayer: artLayerRect,
artContained: contained( artRect, artLayerRect ) && contained( artLayerRect, stageRect ),
artBottomGap: Math.abs( stageRect.bottom - artLayerRect.bottom ),
contentArtOverlap: overlaps( contentRect, artLayerRect ),
next: nextRect,
nextOverlap: overlaps( stageRect, nextRect ),
stageOverflow: stage.scrollWidth - stage.clientWidth,
rootOverflow: root.scrollWidth - root.clientWidth,
};
}, landing );
}
test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) {
for ( const width of [ 375, 1440 ] ) {
for ( const landing of landings ) {
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: width === 375 ? 812 : 1024,
path: landing.path,
theme,
width,
} );
try {
const state = await page
.locator( 'main.chrnx-entry--page' )
.evaluate( ( main, value ) => {
const root = main.querySelector( value.root );
const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' );
const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' );
const readTitle = ( title ) => {
const range = document.createRange();
range.selectNodeContents( title );
const textRect = range.getBoundingClientRect();
const titleRect = title.getBoundingClientRect();
const style = window.getComputedStyle( title );
return {
alignment: style.textAlign,
centerDelta: Math.abs(
( textRect.left + textRect.right ) / 2 -
( titleRect.left + titleRect.right ) / 2,
),
text: title.textContent.trim(),
};
};
const internalHeadings = [ ...root.querySelectorAll( value.internalHeadings ) ];
return {
pageTitle: readTitle( pageTitle ),
stageTitle: readTitle( stageTitle ),
internalAlignments: internalHeadings.map(
( heading ) => window.getComputedStyle( heading ).textAlign,
),
};
}, landing );
expect( state.pageTitle.text ).toBe( landing.name === 'Music' ? 'Music' : 'Podcasts' );
expect( state.stageTitle.text ).toBe(
landing.name === 'Music' ? 'The No Names' : 'Podcasts',
);
for ( const [ titleKind, title ] of Object.entries( {
'page H1': state.pageTitle,
'stage H2': state.stageTitle,
} ) ) {
expect(
title.alignment,
`${ landing.name } ${ theme } ${ width }px ${ titleKind }`,
).toBe( 'center' );
expect( title.centerDelta ).toBeLessThanOrEqual( 1 );
}
expect( state.internalAlignments ).toHaveLength( landing.internalHeadingCount );
expect(
state.internalAlignments.every( ( alignment ) => alignment === 'start' ),
).toBeTruthy();
} finally {
await context.close();
}
}
}
}
} );
test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both themes', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 90_000 );
for ( const theme of [ 'dark', 'light' ] ) {
for ( const landing of landings ) {
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: 900,
path: landing.path,
theme,
width: 1440,
} );
try {
const state = await readStage( page, landing );
expect(
state.stage.height,
`${ landing.name } ${ theme } stage height`,
).toBeLessThanOrEqual( Math.min( 900, REM_46 ) + 1 );
expect( state.atmosphereContained ).toBeTruthy();
expect( state.atmosphereFit ).toBe( 'cover' );
expect( state.artContained ).toBeTruthy();
expect( state.artBottomGap ).toBeLessThanOrEqual( 1 );
expect( state.contentArtOverlap ).toBeFalsy();
expect( state.next.top ).toBeGreaterThanOrEqual( state.stage.bottom - 1 );
expect( state.nextOverlap ).toBeFalsy();
expect( state.stageOverflow ).toBeLessThanOrEqual( 1 );
expect( state.rootOverflow ).toBeLessThanOrEqual( 1 );
if ( landing.name === 'Podcast' ) {
expect( state.atmosphereHidden ).toBe( 'true' );
}
await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
}
}
} );
test( 'latest podcast preserves a real 28ch content column and bounded media', async ( {
page,
} ) => {
await page.setViewportSize( { width: 1440, height: 900 } );
await page.goto( '/podcasts/' );
const state = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
const readRect = ( element ) => {
const bounds = element.getBoundingClientRect();
return {
bottom: bounds.bottom,
height: bounds.height,
left: bounds.left,
right: bounds.right,
top: bounds.top,
width: bounds.width,
};
};
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 title = content.querySelector( '.chrnx-podcast-card__title' );
const probe = document.createElement( 'span' );
const titleStyle = window.getComputedStyle( title );
Object.assign( probe.style, {
fontFamily: titleStyle.fontFamily,
fontSize: titleStyle.fontSize,
fontWeight: titleStyle.fontWeight,
position: 'fixed',
visibility: 'hidden',
width: '28ch',
} );
document.body.append( probe );
const probeWidth = probe.getBoundingClientRect().width;
probe.remove();
const panelRect = readRect( panel );
const linkRect = readRect( link );
const mediaRect = readRect( media );
const contentRect = readRect( content );
return {
display: window.getComputedStyle( link ).display,
columns: window.getComputedStyle( link ).gridTemplateColumns,
contentMinWidth: window.getComputedStyle( content ).minWidth,
contentWidth: contentRect.width,
probeWidth,
mediaRatio: mediaRect.width / linkRect.width,
mediaContained: mediaRect.left >= linkRect.left - 1 && mediaRect.right <= linkRect.right + 1,
panelOverflow: panel.scrollWidth - panel.clientWidth,
linkOverflow: link.scrollWidth - link.clientWidth,
contentOverflow: content.scrollWidth - content.clientWidth,
panelHeight: panelRect.height,
};
} );
expect( state.display ).toBe( 'grid' );
expect( state.columns.split( ' ' ) ).toHaveLength( 2 );
expect( state.contentMinWidth ).toBe( '0px' );
expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 );
expect( state.mediaRatio ).toBeGreaterThanOrEqual( 0.28 );
expect( state.mediaRatio ).toBeLessThanOrEqual( 0.42 );
expect( state.mediaContained ).toBeTruthy();
expect( state.panelOverflow ).toBeLessThanOrEqual( 1 );
expect( state.linkOverflow ).toBeLessThanOrEqual( 1 );
expect( state.contentOverflow ).toBeLessThanOrEqual( 1 );
} );
test( 'mobile and tablet preserve text then art then following content', async ( { page } ) => {
for ( const width of [ 375, 768 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } );
for ( const landing of landings ) {
await page.goto( landing.path );
const state = await readStage( page, landing );
expect( state.content.height ).toBeGreaterThan( 0 );
expect( state.art.height ).toBeGreaterThan( 0 );
expect( state.content.bottom ).toBeLessThanOrEqual( state.artLayer.top + 1 );
expect( state.artLayer.bottom ).toBeLessThanOrEqual( state.next.top + 1 );
expect( state.contentArtOverlap ).toBeFalsy();
expect( state.nextOverlap ).toBeFalsy();
expect( state.stageOverflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page );
}
}
} );
test( 'latest podcast stacks at 720px and becomes two columns at 721px', async ( { page } ) => {
for ( const [ width, expectedColumns ] of [
[ 720, 1 ],
[ 721, 2 ],
] ) {
await page.setViewportSize( { width, height: 1024 } );
await page.goto( '/podcasts/' );
const columns = await page
.locator( '.chrnx-podcast-card__link' )
.evaluate(
( link ) => window.getComputedStyle( link ).gridTemplateColumns.split( ' ' ).length,
);
expect( columns, `${ width }px columns` ).toBe( expectedColumns );
await expectNoHorizontalOverflow( page );
}
} );
test( '200 percent reflow models physical viewport halving and doubled root text cross-engine', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) {
for ( const physicalWidth of [ 750, 1440 ] ) {
const cssWidth = physicalWidth / 2;
for ( const landing of landings ) {
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: physicalWidth === 750 ? 812 : 900,
path: landing.path,
theme,
width: cssWidth,
} );
try {
const baselineRootFont = await page.evaluate( () =>
Number.parseFloat( window.getComputedStyle( document.documentElement ).fontSize ),
);
await page.evaluate( ( doubledRootFont ) => {
document.documentElement.style.fontSize = `${ doubledRootFont }px`;
}, baselineRootFont * 2 );
const model = await page.evaluate(
( expectedCssWidth ) => ( {
cssViewportWidth: window.innerWidth,
doubledRootFont: Number.parseFloat(
window.getComputedStyle( document.documentElement ).fontSize,
),
stackMediaActive: window.matchMedia( '(max-width: 720px)' ).matches,
expectedCssWidth,
} ),
cssWidth,
);
expect( model.cssViewportWidth ).toBe( model.expectedCssWidth );
expect( model.doubledRootFont ).toBe( baselineRootFont * 2 );
expect( model.stackMediaActive ).toBeTruthy();
const result = await page.locator( landing.root ).evaluate( ( root, landingName ) => {
const stage = root.querySelector( '.chrnx-character-stage' );
const content = stage.querySelector( '.chrnx-character-stage__content' );
const stageTitle = content.querySelector( 'h2' );
const pageTitle = document.querySelector(
'main.chrnx-entry--page > h1.wp-block-post-title',
);
const card = root.querySelector( '.chrnx-latest-podcast' );
const cardTitle = card?.querySelector( '.chrnx-podcast-card__title' );
const unbroken = `https://chrnx.dev/${ 'reflow-safe-token-'.repeat( 18 ) }`;
if ( landingName === 'Music' ) {
content.querySelector( 'p:last-of-type' ).textContent += ` ${ unbroken }`;
} else {
cardTitle.textContent = unbroken;
}
return {
pageTitleClip: pageTitle.scrollWidth - pageTitle.clientWidth,
stageTitleClip: stageTitle.scrollWidth - stageTitle.clientWidth,
copyClip: content.scrollWidth - content.clientWidth,
cardClip: card ? card.scrollWidth - card.clientWidth : 0,
cardTitleClip: cardTitle ? cardTitle.scrollWidth - cardTitle.clientWidth : 0,
stageClip: stage.scrollWidth - stage.clientWidth,
cardColumns: card
? window
.getComputedStyle( card.querySelector( '.chrnx-podcast-card__link' ) )
.gridTemplateColumns.split( ' ' ).length
: null,
};
}, landing.name );
expect( result.pageTitleClip ).toBeLessThanOrEqual( 1 );
expect( result.stageTitleClip ).toBeLessThanOrEqual( 1 );
expect( result.copyClip ).toBeLessThanOrEqual( 1 );
expect( result.cardClip ).toBeLessThanOrEqual( 1 );
expect( result.cardTitleClip ).toBeLessThanOrEqual( 1 );
expect( result.stageClip ).toBeLessThanOrEqual( 1 );
if ( landing.name === 'Podcast' ) {
expect( result.cardColumns ).toBe( 1 );
}
await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
}
}
}
} );
test( 'unbroken Podcast title and excerpt tokens wrap in stack and grid without clipping', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) {
for ( const width of [ 375, 721, 1440 ] ) {
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: width === 375 ? 812 : 1024,
path: '/podcasts/',
theme,
width,
} );
try {
const state = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
const link = panel.querySelector( '.chrnx-podcast-card__link' );
const content = panel.querySelector( '.chrnx-podcast-card__content' );
const title = panel.querySelector( '.chrnx-podcast-card__title' );
const excerpt = panel.querySelector( '.chrnx-podcast-card__excerpt' );
const beforeHeight = panel.getBoundingClientRect().height;
const titleToken = `https://chrnx.dev/${ 'title-token-'.repeat( 22 ) }`;
const excerptToken = `sha256:${ '0123456789abcdef'.repeat( 16 ) }`;
title.textContent = titleToken;
excerpt.textContent = excerptToken;
const afterHeight = panel.getBoundingClientRect().height;
const titleStyle = window.getComputedStyle( title );
const excerptStyle = window.getComputedStyle( excerpt );
return {
columns: window.getComputedStyle( link ).gridTemplateColumns.split( ' ' ).length,
contentOverflowWrap: window.getComputedStyle( content ).overflowWrap,
titleOverflowWrap: titleStyle.overflowWrap,
excerptOverflowWrap: excerptStyle.overflowWrap,
titleWordBreak: titleStyle.wordBreak,
excerptWordBreak: excerptStyle.wordBreak,
titleClip: title.scrollWidth - title.clientWidth,
excerptClip: excerpt.scrollWidth - excerpt.clientWidth,
contentClip: content.scrollWidth - content.clientWidth,
linkClip: link.scrollWidth - link.clientWidth,
panelClip: panel.scrollWidth - panel.clientWidth,
beforeHeight,
afterHeight,
linkReadable:
link.tagName === 'A' &&
Boolean( link.getAttribute( 'href' ) ) &&
window.getComputedStyle( link ).visibility === 'visible',
titleLength: titleToken.length,
excerptLength: excerptToken.length,
};
} );
expect( state.titleLength ).toBeGreaterThan( 200 );
expect( state.excerptLength ).toBeGreaterThan( 200 );
expect( state.columns ).toBe( width <= 720 ? 1 : 2 );
expect( state.contentOverflowWrap ).toBe( 'anywhere' );
expect( state.titleOverflowWrap ).toBe( 'anywhere' );
expect( state.excerptOverflowWrap ).toBe( 'anywhere' );
expect( state.titleWordBreak ).toBe( 'normal' );
expect( state.excerptWordBreak ).toBe( 'normal' );
expect( state.titleClip ).toBeLessThanOrEqual( 1 );
expect( state.excerptClip ).toBeLessThanOrEqual( 1 );
expect( state.contentClip ).toBeLessThanOrEqual( 1 );
expect( state.linkClip ).toBeLessThanOrEqual( 1 );
expect( state.panelClip ).toBeLessThanOrEqual( 1 );
expect( state.afterHeight ).toBeGreaterThan( state.beforeHeight );
expect( state.linkReadable ).toBeTruthy();
await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
}
}
} );
test( 'DOM-only long Podcast prose preserves its 28ch column without clipping', async ( {
page,
} ) => {
for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
await page.goto( '/podcasts/' );
const state = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
const title = panel.querySelector( '.chrnx-podcast-card__title' );
const excerpt = panel.querySelector( '.chrnx-podcast-card__excerpt' );
const content = panel.querySelector( '.chrnx-podcast-card__content' );
title.textContent =
'Conversaciones profundamente humanas sobre software música investigación juegos y comunidad '.repeat(
3,
);
excerpt.textContent =
'Una conversación extensa que conserva palabras reales y espacios normales para comprobar el ajuste editorial. '.repeat(
10,
);
const link = panel.querySelector( '.chrnx-podcast-card__link' );
const titleStyle = window.getComputedStyle( title );
const probe = document.createElement( 'span' );
Object.assign( probe.style, {
fontFamily: titleStyle.fontFamily,
fontSize: titleStyle.fontSize,
fontWeight: titleStyle.fontWeight,
position: 'fixed',
visibility: 'hidden',
width: '28ch',
} );
document.body.append( probe );
const probeWidth = probe.getBoundingClientRect().width;
probe.remove();
return {
titleLength: title.textContent.length,
minWidth: window.getComputedStyle( content ).minWidth,
columns: window.getComputedStyle( link ).gridTemplateColumns.split( ' ' ).length,
contentWidth: content.getBoundingClientRect().width,
probeWidth,
overflowWrap: titleStyle.overflowWrap,
wordBreak: titleStyle.wordBreak,
titleClip: title.scrollWidth - title.clientWidth,
excerptClip: excerpt.scrollWidth - excerpt.clientWidth,
contentClip: content.scrollWidth - content.clientWidth,
linkClip: link.scrollWidth - link.clientWidth,
panelClip: panel.scrollWidth - panel.clientWidth,
};
} );
expect( state.titleLength ).toBeGreaterThan( 120 );
expect( state.minWidth ).toBe( '0px' );
if ( state.columns === 2 ) {
expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 );
}
expect( state.overflowWrap ).toBe( 'anywhere' );
expect( state.wordBreak ).toBe( 'normal' );
expect( state.titleClip ).toBeLessThanOrEqual( 1 );
expect( state.excerptClip ).toBeLessThanOrEqual( 1 );
expect( state.contentClip ).toBeLessThanOrEqual( 1 );
expect( state.linkClip ).toBeLessThanOrEqual( 1 );
expect( state.panelClip ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page );
}
} );
const immutableSurfaces = [
{
name: 'Projects',
path: '/projects/',
root: '.chrnx-home-projects',
art: 'img[src*="alter-ego-code-768.webp"]',
atmosphereCount: 2,
imageSources: [
'projects-grunge-1536.webp',
'alter-ego-research-768.webp',
'alter-ego-code-768.webp',
],
headings: [ 'Proyectos' ],
paragraphs: [ 'Lo que sobrevive a la loquera nocturna, con su repo y su estado real.' ],
contentText: 'Proyectos Lo que sobrevive a la loquera nocturna, con su repo y su estado real.',
},
{
name: 'About',
path: '/about/',
root: '.chrnx-about',
art: 'img[src*="alter-ego-life-768.webp"]',
atmosphereCount: 1,
imageSources: [ 'about-grunge-1536.webp', 'alter-ego-life-768.webp' ],
headings: [ 'About', 'Beyond the work' ],
paragraphs: [
'I work as Lead Developer @Expressive Tea, building full-stack software with JavaScript and Python. I am also an independent researcher exploring emotion modeling and game AI; my practice includes open source work and amateur data science.',
'I am a published researcher. My current paper is available on arXiv:2603.05352.',
'I am an autistic Level 1 software developer and researcher.',
'I am the father of three wonderful children, a musician, a gamer, and pet-friendly.',
],
contentText:
'About I work as Lead Developer @Expressive Tea, building full-stack software with JavaScript and Python. I am also an independent researcher exploring emotion modeling and game AI; my practice includes open source work and amateur data science. I am a published researcher. My current paper is available on arXiv:2603.05352. I am an autistic Level 1 software developer and researcher. Beyond the work I am the father of three wonderful children, a musician, a gamer, and pet-friendly.',
},
];
test( 'Projects and About assets, copy, layering, and geometry remain immutable', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) {
for ( const width of [ 375, 1440 ] ) {
for ( const surface of immutableSurfaces ) {
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: width === 375 ? 812 : 900,
path: surface.path,
theme,
width,
} );
try {
const root = page.locator( surface.root );
for ( const heading of surface.headings ) {
await expect( root.getByRole( 'heading', { name: heading, exact: true } ) ).toHaveCount(
1,
);
}
await expect( root.locator( surface.art ) ).toHaveCount( 1 );
await expect( root.locator( 'picture img' ) ).toHaveCount( surface.imageSources.length );
for ( const source of surface.imageSources ) {
await expect( root.locator( `picture img[src*="${ source }"]` ) ).toHaveCount( 1 );
}
const approvedCopy = await root
.locator( '.chrnx-character-stage__content' )
.evaluate( ( content ) => ( {
contentText: content.textContent.trim().replace( /\s+/g, ' ' ),
paragraphs: [ ...content.querySelectorAll( ':scope > p' ) ].map( ( paragraph ) =>
paragraph.textContent.trim().replace( /\s+/g, ' ' ),
),
} ) );
expect( approvedCopy.contentText ).toBe( surface.contentText );
expect( approvedCopy.paragraphs ).toEqual( surface.paragraphs );
const state = await root.evaluate( ( element ) => {
const readRect = ( target ) => {
const bounds = target.getBoundingClientRect();
return {
bottom: bounds.bottom,
height: bounds.height,
left: bounds.left,
right: bounds.right,
top: bounds.top,
width: bounds.width,
};
};
const stage = element.querySelector( '.chrnx-character-stage' );
const children = [ ...stage.children ].map( ( child ) => child.className );
const art = stage.querySelector( '.chrnx-character-stage__art' );
const artImage = art.querySelector( 'img' );
const stageRect = readRect( stage );
const artRect = readRect( art );
const imageRect = readRect( artImage );
const contained = ( child, parent ) =>
child.left >= parent.left - 1 &&
child.right <= parent.right + 1 &&
child.top >= parent.top - 1 &&
child.bottom <= parent.bottom + 1;
return {
layerOrder: children.map( ( classes ) =>
[ 'atmosphere', 'content', 'art' ].find( ( layer ) =>
classes.includes( `chrnx-character-stage__${ layer }` ),
),
),
atmospherePictures: stage.querySelectorAll(
'.chrnx-character-stage__atmosphere picture',
).length,
artRatio: artRect.width / stageRect.width,
artFrameContained: contained( artRect, stageRect ),
artImageContained:
contained( imageRect, artRect ) && contained( imageRect, stageRect ),
overflow: stage.scrollWidth - stage.clientWidth,
};
} );
expect( state.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] );
expect( state.atmospherePictures ).toBe( surface.atmosphereCount );
expect( state.artFrameContained ).toBeTruthy();
expect( state.artImageContained ).toBeTruthy();
if ( width === 1440 ) {
expect( state.artRatio ).toBeGreaterThanOrEqual( 0.35 );
expect( state.artRatio ).toBeLessThanOrEqual( 0.48 );
}
expect( state.overflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
}
}
}
} );