fix: harden CHRNX stage reflow

This commit is contained in:
chrnx committed 2026-08-13 09:54:36 -05:00
1 parent d9d187a631
commit f276e6b2ea
4 files changed
+351 -199

No files matched your search

+2
View File
@@ -1360,6 +1360,8 @@ html[data-theme="light"] .chrnx-music-landing .chrnx-character-stage {
.chrnx-music-landing .chrnx-character-stage__content, .chrnx-music-landing .chrnx-character-stage__content,
.chrnx-podcast-landing .chrnx-character-stage__content { .chrnx-podcast-landing .chrnx-character-stage__content {
min-width: 0; min-width: 0;
overflow-wrap: anywhere;
word-break: normal;
} }
.chrnx-music-landing .chrnx-character-stage__content > h2, .chrnx-music-landing .chrnx-character-stage__content > h2,
+3 -2
View File
@@ -11,7 +11,8 @@
.chrnx-podcast-card__content { .chrnx-podcast-card__content {
min-width: 0; min-width: 0;
overflow-wrap: normal; overflow-wrap: anywhere;
word-break: normal;
} }
.chrnx-podcast-card__image, .chrnx-podcast-card__image,
@@ -29,7 +30,7 @@
.chrnx-podcast-card__title, .chrnx-podcast-card__title,
.chrnx-podcast-card__excerpt, .chrnx-podcast-card__excerpt,
.chrnx-podcast-card__badge { .chrnx-podcast-card__badge {
overflow-wrap: normal; overflow-wrap: anywhere;
word-break: normal; word-break: normal;
} }
+344 -195
View File
@@ -24,8 +24,27 @@ const landings = [
}, },
]; ];
async function setTheme( page, theme ) { async function openIsolatedThemedPage( browser, testInfo, { height, path, theme, width } ) {
await page.addInitScript( ( value ) => localStorage.setItem( 'chrnx-theme', value ), theme ); const baseURL = testInfo.project.use.baseURL;
expect( new URL( baseURL ).origin ).toBe( 'http://localhost:8908' );
const context = await browser.newContext( {
baseURL,
colorScheme: theme,
viewport: { width, height },
} );
const page = await context.newPage();
await page.goto( path );
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 ) { async function expectNoHorizontalOverflow( page ) {
@@ -99,92 +118,110 @@ async function readStage( page, landing ) {
} }
test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( { test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await setTheme( page, theme );
for ( const width of [ 375, 1440 ] ) { for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } );
for ( const landing of landings ) { for ( const landing of landings ) {
await page.goto( landing.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
const state = await page.locator( 'main.chrnx-entry--page' ).evaluate( ( main, value ) => { height: width === 375 ? 812 : 1024,
const root = main.querySelector( value.root ); path: landing.path,
const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' ); theme,
const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' ); width,
const readTitle = ( title ) => { } );
const range = document.createRange(); try {
range.selectNodeContents( title ); const state = await page
const textRect = range.getBoundingClientRect(); .locator( 'main.chrnx-entry--page' )
const titleRect = title.getBoundingClientRect(); .evaluate( ( main, value ) => {
const style = window.getComputedStyle( title ); const root = main.querySelector( value.root );
return { const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' );
alignment: style.textAlign, const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' );
centerDelta: Math.abs( const readTitle = ( title ) => {
( textRect.left + textRect.right ) / 2 - ( titleRect.left + titleRect.right ) / 2, const range = document.createRange();
), range.selectNodeContents( title );
text: title.textContent.trim(), const textRect = range.getBoundingClientRect();
}; const titleRect = title.getBoundingClientRect();
}; const style = window.getComputedStyle( title );
const internalHeadings = [ ...root.querySelectorAll( value.internalHeadings ) ]; return {
return { alignment: style.textAlign,
pageTitle: readTitle( pageTitle ), centerDelta: Math.abs(
stageTitle: readTitle( stageTitle ), ( textRect.left + textRect.right ) / 2 -
internalAlignments: internalHeadings.map( ( titleRect.left + titleRect.right ) / 2,
( heading ) => window.getComputedStyle( heading ).textAlign, ),
), text: title.textContent.trim(),
}; };
}, landing ); };
expect( state.pageTitle.text ).toBe( landing.name === 'Music' ? 'Music' : 'Podcasts' ); const internalHeadings = [ ...root.querySelectorAll( value.internalHeadings ) ];
expect( state.stageTitle.text ).toBe( return {
landing.name === 'Music' ? 'The No Names' : 'Podcasts', pageTitle: readTitle( pageTitle ),
); stageTitle: readTitle( stageTitle ),
for ( const [ titleKind, title ] of Object.entries( { internalAlignments: internalHeadings.map(
'page H1': state.pageTitle, ( heading ) => window.getComputedStyle( heading ).textAlign,
'stage H2': state.stageTitle, ),
} ) ) { };
}, 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( expect(
title.alignment, state.internalAlignments.every( ( alignment ) => alignment === 'start' ),
`${ landing.name } ${ theme } ${ width }px ${ titleKind }`, ).toBeTruthy();
).toBe( 'center' ); } finally {
expect( title.centerDelta ).toBeLessThanOrEqual( 1 ); await context.close();
} }
expect( state.internalAlignments ).toHaveLength( landing.internalHeadingCount );
expect(
state.internalAlignments.every( ( alignment ) => alignment === 'start' ),
).toBeTruthy();
} }
} }
} }
} ); } );
test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both themes', async ( { test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both themes', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 90_000 );
await page.setViewportSize( { width: 1440, height: 900 } );
for ( const theme of [ 'dark', 'light' ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await setTheme( page, theme );
for ( const landing of landings ) { for ( const landing of landings ) {
await page.goto( landing.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
const state = await readStage( page, landing ); height: 900,
expect( state.stage.height, `${ landing.name } ${ theme } stage height` ).toBeLessThanOrEqual( path: landing.path,
Math.min( 900, REM_46 ) + 1, theme,
); width: 1440,
expect( state.atmosphereContained ).toBeTruthy(); } );
expect( state.atmosphereFit ).toBe( 'cover' ); try {
expect( state.artContained ).toBeTruthy(); const state = await readStage( page, landing );
expect( state.artBottomGap ).toBeLessThanOrEqual( 1 ); expect(
expect( state.contentArtOverlap ).toBeFalsy(); state.stage.height,
expect( state.next.top ).toBeGreaterThanOrEqual( state.stage.bottom - 1 ); `${ landing.name } ${ theme } stage height`,
expect( state.nextOverlap ).toBeFalsy(); ).toBeLessThanOrEqual( Math.min( 900, REM_46 ) + 1 );
expect( state.stageOverflow ).toBeLessThanOrEqual( 1 ); expect( state.atmosphereContained ).toBeTruthy();
expect( state.rootOverflow ).toBeLessThanOrEqual( 1 ); expect( state.atmosphereFit ).toBe( 'cover' );
if ( landing.name === 'Podcast' ) { expect( state.artContained ).toBeTruthy();
expect( state.atmosphereHidden ).toBe( 'true' ); 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();
} }
await expectNoHorizontalOverflow( page );
} }
} }
} ); } );
@@ -290,58 +327,162 @@ test( 'latest podcast stacks at 720px and becomes two columns at 721px', async (
} }
} ); } );
test( '200 percent zoom contains Music copy and Podcast card at narrow and wide viewports', async ( { test( '200 percent reflow models physical viewport halving and doubled root text cross-engine', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 180_000 );
for ( const width of [ 375, 1440 ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); for ( const physicalWidth of [ 750, 1440 ] ) {
for ( const landing of landings ) { const cssWidth = physicalWidth / 2;
await page.goto( landing.path ); for ( const landing of landings ) {
await page.evaluate( () => { const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
document.documentElement.style.zoom = '2'; height: physicalWidth === 750 ? 812 : 900,
} ); path: landing.path,
expect( theme,
await page.evaluate( () => window.getComputedStyle( document.documentElement ).zoom ), width: cssWidth,
).toBe( '2' ); } );
const result = await page.locator( landing.root ).evaluate( ( root ) => { try {
const readRect = ( element ) => { const baselineRootFont = await page.evaluate( () =>
const bounds = element.getBoundingClientRect(); Number.parseFloat( window.getComputedStyle( document.documentElement ).fontSize ),
return { );
bottom: bounds.bottom, await page.evaluate( ( doubledRootFont ) => {
height: bounds.height, document.documentElement.style.fontSize = `${ doubledRootFont }px`;
left: bounds.left, }, baselineRootFont * 2 );
right: bounds.right, const model = await page.evaluate(
top: bounds.top, ( expectedCssWidth ) => ( {
width: bounds.width, cssViewportWidth: window.innerWidth,
}; doubledRootFont: Number.parseFloat(
}; window.getComputedStyle( document.documentElement ).fontSize,
const stage = root.querySelector( '.chrnx-character-stage' ); ),
const content = stage.querySelector( '.chrnx-character-stage__content' ); stackMediaActive: window.matchMedia( '(max-width: 720px)' ).matches,
const title = root.querySelector( 'h2, h3, .chrnx-podcast-card__title' ); expectedCssWidth,
const card = root.querySelector( '.chrnx-latest-podcast' ); } ),
const isContained = ( child, parent ) => { cssWidth,
const childRect = readRect( child ); );
const parentRect = readRect( parent ); expect( model.cssViewportWidth ).toBe( model.expectedCssWidth );
return childRect.left >= parentRect.left - 1 && childRect.right <= parentRect.right + 1; expect( model.doubledRootFont ).toBe( baselineRootFont * 2 );
}; expect( model.stackMediaActive ).toBeTruthy();
return { const result = await page.locator( landing.root ).evaluate( ( root, landingName ) => {
copyContained: isContained( content, stage ), const stage = root.querySelector( '.chrnx-character-stage' );
titleClip: title.scrollWidth - title.clientWidth, const content = stage.querySelector( '.chrnx-character-stage__content' );
cardClip: card ? card.scrollWidth - card.clientWidth : 0, const stageTitle = content.querySelector( 'h2' );
stageClip: stage.scrollWidth - stage.clientWidth, const pageTitle = document.querySelector(
}; 'main.chrnx-entry--page > h1.wp-block-post-title',
} ); );
expect( result.copyContained ).toBeTruthy(); const card = root.querySelector( '.chrnx-latest-podcast' );
expect( result.titleClip ).toBeLessThanOrEqual( 1 ); const cardTitle = card?.querySelector( '.chrnx-podcast-card__title' );
expect( result.cardClip ).toBeLessThanOrEqual( 1 ); const unbroken = `https://chrnx.dev/${ 'reflow-safe-token-'.repeat( 18 ) }`;
expect( result.stageClip ).toBeLessThanOrEqual( 1 ); if ( landingName === 'Music' ) {
await expectNoHorizontalOverflow( page ); 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( 'DOM-only long Podcast copy wraps normally without clipping', async ( { page } ) => { 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 ] ) { for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
await page.goto( '/podcasts/' ); await page.goto( '/podcasts/' );
@@ -391,7 +532,7 @@ test( 'DOM-only long Podcast copy wraps normally without clipping', async ( { pa
if ( state.columns === 2 ) { if ( state.columns === 2 ) {
expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 ); expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 );
} }
expect( state.overflowWrap ).toBe( 'normal' ); expect( state.overflowWrap ).toBe( 'anywhere' );
expect( state.wordBreak ).toBe( 'normal' ); expect( state.wordBreak ).toBe( 'normal' );
expect( state.titleClip ).toBeLessThanOrEqual( 1 ); expect( state.titleClip ).toBeLessThanOrEqual( 1 );
expect( state.excerptClip ).toBeLessThanOrEqual( 1 ); expect( state.excerptClip ).toBeLessThanOrEqual( 1 );
@@ -438,85 +579,93 @@ const immutableSurfaces = [
]; ];
test( 'Projects and About assets, copy, layering, and geometry remain immutable', async ( { test( 'Projects and About assets, copy, layering, and geometry remain immutable', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await setTheme( page, theme );
for ( const width of [ 375, 1440 ] ) { for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
for ( const surface of immutableSurfaces ) { for ( const surface of immutableSurfaces ) {
await page.goto( surface.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
const root = page.locator( surface.root ); height: width === 375 ? 812 : 900,
for ( const heading of surface.headings ) { path: surface.path,
await expect( root.getByRole( 'heading', { name: heading, exact: true } ) ).toHaveCount( theme,
1, width,
);
}
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' ] ); try {
expect( state.atmospherePictures ).toBe( surface.atmosphereCount ); const root = page.locator( surface.root );
expect( state.artFrameContained ).toBeTruthy(); for ( const heading of surface.headings ) {
expect( state.artImageContained ).toBeTruthy(); await expect( root.getByRole( 'heading', { name: heading, exact: true } ) ).toHaveCount(
if ( width === 1440 ) { 1,
expect( state.artRatio ).toBeGreaterThanOrEqual( 0.35 ); );
expect( state.artRatio ).toBeLessThanOrEqual( 0.48 ); }
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();
} }
expect( state.overflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page );
} }
} }
} }
+2 -2
View File
@@ -583,7 +583,7 @@ test( 'latest podcast owns a content-aware 720px card contract', () => {
); );
assert.match( assert.match(
podcast, podcast,
/\.chrnx-podcast-card__content\s*\{[\s\S]*?min-width:\s*0;[\s\S]*?overflow-wrap:\s*normal;/, /\.chrnx-podcast-card__content\s*\{[\s\S]*?min-width:\s*0;[\s\S]*?overflow-wrap:\s*anywhere;/,
); );
assert.match( assert.match(
podcast, podcast,
@@ -591,7 +591,7 @@ test( 'latest podcast owns a content-aware 720px card contract', () => {
); );
assert.match( assert.match(
podcast, podcast,
/\.chrnx-podcast-card__title,[\s\S]*?\.chrnx-podcast-card__excerpt,[\s\S]*?\.chrnx-podcast-card__badge\s*\{[\s\S]*?overflow-wrap:\s*normal;[\s\S]*?word-break:\s*normal;/, /\.chrnx-podcast-card__title,[\s\S]*?\.chrnx-podcast-card__excerpt,[\s\S]*?\.chrnx-podcast-card__badge\s*\{[\s\S]*?overflow-wrap:\s*anywhere;[\s\S]*?word-break:\s*normal;/,
); );
assert.match( assert.match(
podcast, podcast,