fix: harden CHRNX stage reflow
This commit is contained in:
4 files changed
+351
-199
No files matched your search
@@ -1360,6 +1360,8 @@ html[data-theme="light"] .chrnx-music-landing .chrnx-character-stage {
|
||||
.chrnx-music-landing .chrnx-character-stage__content,
|
||||
.chrnx-podcast-landing .chrnx-character-stage__content {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.chrnx-music-landing .chrnx-character-stage__content > h2,
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
.chrnx-podcast-card__content {
|
||||
min-width: 0;
|
||||
overflow-wrap: normal;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.chrnx-podcast-card__image,
|
||||
@@ -29,7 +30,7 @@
|
||||
.chrnx-podcast-card__title,
|
||||
.chrnx-podcast-card__excerpt,
|
||||
.chrnx-podcast-card__badge {
|
||||
overflow-wrap: normal;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,27 @@ const landings = [
|
||||
},
|
||||
];
|
||||
|
||||
async function setTheme( page, theme ) {
|
||||
await page.addInitScript( ( value ) => localStorage.setItem( 'chrnx-theme', value ), theme );
|
||||
async function openIsolatedThemedPage( browser, testInfo, { height, path, theme, width } ) {
|
||||
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 ) {
|
||||
@@ -99,92 +118,110 @@ async function readStage( page, landing ) {
|
||||
}
|
||||
|
||||
test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
test.setTimeout( 90_000 );
|
||||
browser,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 180_000 );
|
||||
for ( const theme of [ 'dark', 'light' ] ) {
|
||||
await setTheme( page, theme );
|
||||
for ( const width of [ 375, 1440 ] ) {
|
||||
await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } );
|
||||
for ( const landing of landings ) {
|
||||
await page.goto( landing.path );
|
||||
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,
|
||||
} ) ) {
|
||||
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(
|
||||
title.alignment,
|
||||
`${ landing.name } ${ theme } ${ width }px ${ titleKind }`,
|
||||
).toBe( 'center' );
|
||||
expect( title.centerDelta ).toBeLessThanOrEqual( 1 );
|
||||
state.internalAlignments.every( ( alignment ) => alignment === 'start' ),
|
||||
).toBeTruthy();
|
||||
} finally {
|
||||
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 ( {
|
||||
page,
|
||||
} ) => {
|
||||
browser,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 90_000 );
|
||||
await page.setViewportSize( { width: 1440, height: 900 } );
|
||||
|
||||
for ( const theme of [ 'dark', 'light' ] ) {
|
||||
await setTheme( page, theme );
|
||||
for ( const landing of landings ) {
|
||||
await page.goto( landing.path );
|
||||
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' );
|
||||
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();
|
||||
}
|
||||
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 ( {
|
||||
page,
|
||||
} ) => {
|
||||
test.setTimeout( 90_000 );
|
||||
for ( const width of [ 375, 1440 ] ) {
|
||||
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
|
||||
for ( const landing of landings ) {
|
||||
await page.goto( landing.path );
|
||||
await page.evaluate( () => {
|
||||
document.documentElement.style.zoom = '2';
|
||||
} );
|
||||
expect(
|
||||
await page.evaluate( () => window.getComputedStyle( document.documentElement ).zoom ),
|
||||
).toBe( '2' );
|
||||
const result = await page.locator( landing.root ).evaluate( ( root ) => {
|
||||
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 content = stage.querySelector( '.chrnx-character-stage__content' );
|
||||
const title = root.querySelector( 'h2, h3, .chrnx-podcast-card__title' );
|
||||
const card = root.querySelector( '.chrnx-latest-podcast' );
|
||||
const isContained = ( child, parent ) => {
|
||||
const childRect = readRect( child );
|
||||
const parentRect = readRect( parent );
|
||||
return childRect.left >= parentRect.left - 1 && childRect.right <= parentRect.right + 1;
|
||||
};
|
||||
return {
|
||||
copyContained: isContained( content, stage ),
|
||||
titleClip: title.scrollWidth - title.clientWidth,
|
||||
cardClip: card ? card.scrollWidth - card.clientWidth : 0,
|
||||
stageClip: stage.scrollWidth - stage.clientWidth,
|
||||
};
|
||||
} );
|
||||
expect( result.copyContained ).toBeTruthy();
|
||||
expect( result.titleClip ).toBeLessThanOrEqual( 1 );
|
||||
expect( result.cardClip ).toBeLessThanOrEqual( 1 );
|
||||
expect( result.stageClip ).toBeLessThanOrEqual( 1 );
|
||||
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( '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 ] ) {
|
||||
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
|
||||
await page.goto( '/podcasts/' );
|
||||
@@ -391,7 +532,7 @@ test( 'DOM-only long Podcast copy wraps normally without clipping', async ( { pa
|
||||
if ( state.columns === 2 ) {
|
||||
expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 );
|
||||
}
|
||||
expect( state.overflowWrap ).toBe( 'normal' );
|
||||
expect( state.overflowWrap ).toBe( 'anywhere' );
|
||||
expect( state.wordBreak ).toBe( 'normal' );
|
||||
expect( state.titleClip ).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 ( {
|
||||
page,
|
||||
} ) => {
|
||||
test.setTimeout( 90_000 );
|
||||
browser,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 180_000 );
|
||||
for ( const theme of [ 'dark', 'light' ] ) {
|
||||
await setTheme( page, theme );
|
||||
for ( const width of [ 375, 1440 ] ) {
|
||||
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
|
||||
for ( const surface of immutableSurfaces ) {
|
||||
await page.goto( surface.path );
|
||||
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,
|
||||
};
|
||||
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
|
||||
height: width === 375 ? 812 : 900,
|
||||
path: surface.path,
|
||||
theme,
|
||||
width,
|
||||
} );
|
||||
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 );
|
||||
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();
|
||||
}
|
||||
expect( state.overflow ).toBeLessThanOrEqual( 1 );
|
||||
await expectNoHorizontalOverflow( page );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,7 +583,7 @@ test( 'latest podcast owns a content-aware 720px card contract', () => {
|
||||
);
|
||||
assert.match(
|
||||
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(
|
||||
podcast,
|
||||
@@ -591,7 +591,7 @@ test( 'latest podcast owns a content-aware 720px card contract', () => {
|
||||
);
|
||||
assert.match(
|
||||
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(
|
||||
podcast,
|
||||
|
||||
Reference in new issue
Block a user