Merge branch 'feature/character-led-sections' into feature/music-podcast-grunge-stages
This commit is contained in:
20 files changed
+1313
-76
No files matched your search
@@ -8,6 +8,143 @@ const viewports = [
|
||||
{ width: 2560, height: 1440 },
|
||||
];
|
||||
|
||||
const characterSurfaces = [
|
||||
{ name: 'home-projects', path: '/', selector: '.chrnx-home-projects .chrnx-character-stage' },
|
||||
{ name: 'home-music', path: '/', selector: '.chrnx-home-music .chrnx-character-stage' },
|
||||
{ name: 'projects', path: '/projects/', selector: '.chrnx-home-projects .chrnx-character-stage' },
|
||||
{ name: 'music', path: '/music/', selector: '.chrnx-music-landing .chrnx-character-stage' },
|
||||
{
|
||||
name: 'podcasts',
|
||||
path: '/podcasts/',
|
||||
selector: '.chrnx-podcast-landing .chrnx-character-stage',
|
||||
},
|
||||
{ name: 'about', path: '/about/', selector: '.chrnx-about .chrnx-character-stage' },
|
||||
{
|
||||
name: 'show-silicon-ranch',
|
||||
path: '/show/silicon-ranch/',
|
||||
selector: '.chrnx-topic-hero .chrnx-character-stage',
|
||||
},
|
||||
...[ 'research', 'code', 'literature', 'music', 'podcasts', 'life', 'gaming' ].map(
|
||||
( topic ) => ( {
|
||||
name: `topic-${ topic }`,
|
||||
path: `/topic/${ topic }/`,
|
||||
selector: '.chrnx-topic-hero .chrnx-character-stage',
|
||||
} ),
|
||||
),
|
||||
];
|
||||
|
||||
const characterVisibleAlphaBounds = {
|
||||
'alter-ego-code': [ 1122, 1402, 87, 204, 1022, 1172 ],
|
||||
'alter-ego-gaming-half-body': [ 1024, 1536, 15, 79, 948, 1536 ],
|
||||
'alter-ego-life': [ 1122, 1402, 25, 81, 1078, 1402 ],
|
||||
'alter-ego-literature': [ 1122, 1402, 51, 48, 1072, 1359 ],
|
||||
'alter-ego-podcasts': [ 1122, 1402, 62, 110, 1101, 1338 ],
|
||||
'alter-ego-research': [ 1122, 1402, 106, 52, 1074, 1402 ],
|
||||
'the-no-names-musician-cutout': [ 1122, 1402, 0, 46, 1102, 1402 ],
|
||||
};
|
||||
|
||||
async function positionStageBelowStickyHeader( page, stage ) {
|
||||
await stage.scrollIntoViewIfNeeded();
|
||||
await page.evaluate(
|
||||
( element ) => {
|
||||
const header = document.querySelector( 'header.wp-block-template-part' );
|
||||
const overlap = header.getBoundingClientRect().bottom - element.getBoundingClientRect().top;
|
||||
if ( overlap > 0 ) {
|
||||
window.scrollBy( 0, -( overlap + 16 ) );
|
||||
}
|
||||
},
|
||||
await stage.elementHandle(),
|
||||
);
|
||||
await page.evaluate(
|
||||
() =>
|
||||
new Promise( ( resolve ) =>
|
||||
window.requestAnimationFrame( () => window.requestAnimationFrame( resolve ) ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async function setExplicitTheme( page, theme ) {
|
||||
await page.addInitScript( ( value ) => {
|
||||
window.localStorage.setItem( 'chrnx-theme', value );
|
||||
}, theme );
|
||||
}
|
||||
|
||||
async function readCharacterGeometry( stage ) {
|
||||
return stage.evaluate( ( element ) => {
|
||||
const content = element.querySelector( ':scope > .chrnx-character-stage__content' );
|
||||
const art = element.querySelector( ':scope > .chrnx-character-stage__art' );
|
||||
const atmosphere = element.querySelector( ':scope > .chrnx-character-stage__atmosphere' );
|
||||
const picture = art.querySelector( ':scope > picture' );
|
||||
const image = picture?.querySelector( 'img' );
|
||||
const secondary = atmosphere.querySelector( 'picture' );
|
||||
const collage = element
|
||||
.querySelector( '.chrnx-character-stage__collage' )
|
||||
?.closest( 'picture' );
|
||||
const facets = element.parentElement.querySelector( ':scope > .chrnx-character-facets' );
|
||||
const stageRect = element.getBoundingClientRect();
|
||||
const contentRect = content.getBoundingClientRect();
|
||||
const artRect = art.getBoundingClientRect();
|
||||
const pictureRect = picture?.getBoundingClientRect();
|
||||
const imageStyle = image ? window.getComputedStyle( image ) : null;
|
||||
const pictureStyle = picture ? window.getComputedStyle( picture ) : null;
|
||||
const atmosphereStyle = window.getComputedStyle( atmosphere );
|
||||
const secondaryStyle = secondary ? window.getComputedStyle( secondary ) : null;
|
||||
const collageStyle = collage ? window.getComputedStyle( collage ) : null;
|
||||
const facetsStyle = facets ? window.getComputedStyle( facets ) : null;
|
||||
const intersects = ( first, second ) =>
|
||||
first.left < second.right - 1 &&
|
||||
first.right > second.left + 1 &&
|
||||
first.top < second.bottom - 1 &&
|
||||
first.bottom > second.top + 1;
|
||||
const following = [];
|
||||
let branch = element;
|
||||
while ( branch && branch.tagName !== 'MAIN' ) {
|
||||
let sibling = branch.nextElementSibling;
|
||||
while ( sibling ) {
|
||||
following.push( sibling );
|
||||
sibling = sibling.nextElementSibling;
|
||||
}
|
||||
branch = branch.parentElement;
|
||||
}
|
||||
|
||||
return {
|
||||
stageWidth: stageRect.width,
|
||||
artWidth: artRect.width,
|
||||
artBottomGap: Math.abs( stageRect.bottom - artRect.bottom ),
|
||||
contentTop: contentRect.top,
|
||||
contentBottom: contentRect.bottom,
|
||||
artTop: artRect.top,
|
||||
contentArtIntersect: intersects( contentRect, artRect ),
|
||||
followingIntersections: following.filter( ( candidate ) =>
|
||||
intersects( stageRect, candidate.getBoundingClientRect() ),
|
||||
).length,
|
||||
followingCount: following.length,
|
||||
stageOverflow: element.scrollWidth - element.clientWidth,
|
||||
pictureVisible: Boolean(
|
||||
pictureRect && pictureRect.width > 0 && pictureRect.height > 0 && image?.complete,
|
||||
),
|
||||
pictureContained: Boolean(
|
||||
pictureRect &&
|
||||
pictureRect.left >= artRect.left - 1 &&
|
||||
pictureRect.right <= artRect.right + 1 &&
|
||||
pictureRect.top >= artRect.top - 1 &&
|
||||
pictureRect.bottom <= artRect.bottom + 1,
|
||||
),
|
||||
pictureZ: Number.parseInt( pictureStyle?.zIndex || '0', 10 ) || 0,
|
||||
atmosphereZ: Number.parseInt( atmosphereStyle.zIndex, 10 ) || 0,
|
||||
secondaryZ: Number.parseInt( secondaryStyle?.zIndex || '0', 10 ) || 0,
|
||||
collageZ: Number.parseInt( collageStyle?.zIndex || '0', 10 ) || 0,
|
||||
collageLoading: collage?.querySelector( 'img' )?.loading,
|
||||
facetsOpacity: facetsStyle ? Number.parseFloat( facetsStyle.opacity ) : null,
|
||||
facetsZ: Number.parseInt( facetsStyle?.zIndex || '0', 10 ) || 0,
|
||||
effect: imageStyle
|
||||
? `${ imageStyle.filter }|${ imageStyle.boxShadow }|${ imageStyle.maskImage }|${ imageStyle.webkitMaskImage }`
|
||||
: '',
|
||||
loading: image?.loading,
|
||||
};
|
||||
} );
|
||||
}
|
||||
|
||||
async function expectNoHorizontalOverflow( page ) {
|
||||
const overflow = await page.evaluate( () => ( {
|
||||
document: document.documentElement.scrollWidth - window.innerWidth,
|
||||
@@ -34,6 +171,20 @@ function contrastRatio( foreground, background ) {
|
||||
return ( lighter + 0.05 ) / ( darker + 0.05 );
|
||||
}
|
||||
|
||||
function conservativeOverlayContrast( foreground, overlay ) {
|
||||
const channels = overlay.match( /[\d.]+/g ).map( Number );
|
||||
const alpha = channels[ 3 ] ?? 1;
|
||||
const composite = ( underlay ) =>
|
||||
`rgb(${ channels
|
||||
.slice( 0, 3 )
|
||||
.map( ( channel ) => Math.round( channel * alpha + underlay * ( 1 - alpha ) ) )
|
||||
.join( ', ' ) })`;
|
||||
return Math.min(
|
||||
contrastRatio( foreground, composite( 0 ) ),
|
||||
contrastRatio( foreground, composite( 255 ) ),
|
||||
);
|
||||
}
|
||||
|
||||
test( 'home remains coherent at all approved review viewports', async ( { page } ) => {
|
||||
for ( const viewport of viewports ) {
|
||||
await page.setViewportSize( viewport );
|
||||
@@ -672,3 +823,381 @@ test( 'key public surfaces pass automated WCAG 2.2 AA checks', async ( { page },
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'character stage geometry, layering, effects, loading, and inspection captures', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 180_000 );
|
||||
test.skip( testInfo.project.name !== 'chromium', 'Character geometry is reviewed in Chromium.' );
|
||||
|
||||
for ( const theme of [ 'dark', 'light' ] ) {
|
||||
await setExplicitTheme( page, theme );
|
||||
for ( const viewport of viewports ) {
|
||||
await page.setViewportSize( viewport );
|
||||
for ( const surface of characterSurfaces ) {
|
||||
await page.goto( surface.path );
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme );
|
||||
const stage = page.locator( surface.selector ).first();
|
||||
await expect( stage, `${ surface.name } stage` ).toBeVisible();
|
||||
const initial = await stage.evaluate( ( element ) => ( {
|
||||
top: element.getBoundingClientRect().top,
|
||||
loading: element.querySelector( ':scope > .chrnx-character-stage__art picture img' )
|
||||
?.loading,
|
||||
priority: element.querySelector( ':scope > .chrnx-character-stage__art picture img' )
|
||||
?.fetchPriority,
|
||||
} ) );
|
||||
await positionStageBelowStickyHeader( page, stage );
|
||||
await stage
|
||||
.locator( ':scope > .chrnx-character-stage__art picture img' )
|
||||
.evaluate( ( image ) => image.decode() );
|
||||
const geometry = await readCharacterGeometry( stage );
|
||||
const mobile = viewport.width <= 768;
|
||||
const ratio = geometry.artWidth / geometry.stageWidth;
|
||||
|
||||
expect(
|
||||
ratio,
|
||||
`${ surface.name } art ratio at ${ viewport.width }px ${ theme }`,
|
||||
).toBeGreaterThanOrEqual( mobile ? 0.62 : 0.35 );
|
||||
if ( ! mobile ) {
|
||||
expect( ratio ).toBeLessThanOrEqual( 0.48 );
|
||||
}
|
||||
expect( geometry.artBottomGap ).toBeLessThanOrEqual( 2 );
|
||||
if ( mobile ) {
|
||||
expect( geometry.contentTop ).toBeLessThan( geometry.artTop );
|
||||
expect( geometry.contentBottom ).toBeLessThanOrEqual( geometry.artTop + 1 );
|
||||
}
|
||||
expect( geometry.contentArtIntersect ).toBeFalsy();
|
||||
expect( geometry.followingIntersections ).toBe( 0 );
|
||||
if (
|
||||
[ 'home-projects', 'home-music', 'projects', 'music', 'podcasts', 'about' ].includes(
|
||||
surface.name,
|
||||
)
|
||||
) {
|
||||
expect( geometry.followingCount, `${ surface.name } following surfaces` ).toBeGreaterThan(
|
||||
0,
|
||||
);
|
||||
}
|
||||
expect( geometry.stageOverflow ).toBeLessThanOrEqual( 1 );
|
||||
expect( geometry.pictureVisible ).toBeTruthy();
|
||||
expect( geometry.pictureContained ).toBeTruthy();
|
||||
expect( geometry.pictureZ ).toBeGreaterThan( geometry.atmosphereZ );
|
||||
expect( geometry.pictureZ ).toBeGreaterThan( geometry.secondaryZ );
|
||||
expect( geometry.pictureZ ).toBeGreaterThan( geometry.collageZ );
|
||||
expect( geometry.effect ).not.toBe( 'none|none|none|none' );
|
||||
const painted = await stage.evaluate( ( element, boundsByAsset ) => {
|
||||
const image = element.querySelector( ':scope > .chrnx-character-stage__art picture img' );
|
||||
const sourceName = new URL( image.src ).pathname
|
||||
.split( '/' )
|
||||
.pop()
|
||||
.replace( /\.png$/, '' );
|
||||
const [ naturalWidth, naturalHeight, x0, y0, x1, y1 ] = boundsByAsset[ sourceName ];
|
||||
const imageRect = image.getBoundingClientRect();
|
||||
const stageRect = element.getBoundingClientRect();
|
||||
const scale = Math.min(
|
||||
imageRect.width / naturalWidth,
|
||||
imageRect.height / naturalHeight,
|
||||
);
|
||||
const objectWidth = naturalWidth * scale;
|
||||
const objectHeight = naturalHeight * scale;
|
||||
const objectLeft = imageRect.left + ( imageRect.width - objectWidth ) / 2;
|
||||
const objectTop = imageRect.bottom - objectHeight;
|
||||
const visible = {
|
||||
left: objectLeft + x0 * scale,
|
||||
top: objectTop + y0 * scale,
|
||||
right: objectLeft + x1 * scale,
|
||||
bottom: objectTop + y1 * scale,
|
||||
};
|
||||
return {
|
||||
sourceName,
|
||||
widthRatio: ( visible.right - visible.left ) / stageRect.width,
|
||||
heightRatio: ( visible.bottom - visible.top ) / stageRect.height,
|
||||
contained:
|
||||
visible.left >= stageRect.left - 1 &&
|
||||
visible.right <= stageRect.right + 1 &&
|
||||
visible.top >= stageRect.top - 1 &&
|
||||
visible.bottom <= stageRect.bottom + 1,
|
||||
};
|
||||
}, characterVisibleAlphaBounds );
|
||||
expect( painted.widthRatio, `${ surface.name } painted width` ).toBeGreaterThanOrEqual(
|
||||
mobile ? 0.45 : 0.36,
|
||||
);
|
||||
expect( painted.heightRatio ).toBeGreaterThanOrEqual( 0.28 );
|
||||
expect( painted.contained ).toBeTruthy();
|
||||
if ( surface.name === 'topic-gaming' ) {
|
||||
expect( painted.sourceName ).toBe( 'alter-ego-gaming-half-body' );
|
||||
}
|
||||
if ( surface.name === 'home-music' || surface.name === 'music' ) {
|
||||
expect( geometry.collageLoading ).toBe( 'lazy' );
|
||||
}
|
||||
if ( surface.name === 'music' ) {
|
||||
const collage = stage.locator(
|
||||
'.chrnx-character-stage__content > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage)',
|
||||
);
|
||||
const collageContract = await collage.evaluate(
|
||||
( picture, stageElement ) => {
|
||||
const pictureRect = picture.getBoundingClientRect();
|
||||
const stageRect = stageElement.getBoundingClientRect();
|
||||
return {
|
||||
left: Math.abs( pictureRect.left - stageRect.left ),
|
||||
right: Math.abs( pictureRect.right - stageRect.right ),
|
||||
top: Math.abs( pictureRect.top - stageRect.top ),
|
||||
bottom: Math.abs( pictureRect.bottom - stageRect.bottom ),
|
||||
hiddenAncestor: Boolean( picture.closest( '[aria-hidden="true"]' ) ),
|
||||
alt: picture.querySelector( 'img' )?.alt,
|
||||
};
|
||||
},
|
||||
await stage.elementHandle(),
|
||||
);
|
||||
expect( collageContract.left ).toBeLessThanOrEqual( 2 );
|
||||
expect( collageContract.right ).toBeLessThanOrEqual( 2 );
|
||||
expect( collageContract.top ).toBeLessThanOrEqual( 2 );
|
||||
expect( collageContract.bottom ).toBeLessThanOrEqual( 2 );
|
||||
expect( collageContract.hiddenAncestor ).toBeFalsy();
|
||||
expect( collageContract.alt ).toBe( 'The No Names collage' );
|
||||
}
|
||||
if ( surface.name === 'about' ) {
|
||||
expect( geometry.facetsOpacity ).toBeLessThan( 1 );
|
||||
expect( geometry.facetsZ ).toBeLessThan( geometry.pictureZ );
|
||||
}
|
||||
await expectNoHorizontalOverflow( page );
|
||||
|
||||
if ( initial.top >= viewport.height ) {
|
||||
expect( initial.loading ).not.toBe( 'eager' );
|
||||
expect( initial.priority ).not.toBe( 'high' );
|
||||
}
|
||||
const captureContract = await stage.evaluate( ( element ) => {
|
||||
const header = document.querySelector( 'header.wp-block-template-part' );
|
||||
const heading = element.querySelector( 'h1, h2, h3, h4, h5, h6' );
|
||||
const headerRect = header.getBoundingClientRect();
|
||||
const stageRect = element.getBoundingClientRect();
|
||||
const headingRect = heading.getBoundingClientRect();
|
||||
return {
|
||||
headerIntersects:
|
||||
headerRect.bottom > stageRect.top && headerRect.top < stageRect.bottom,
|
||||
headingContained:
|
||||
headingRect.top >= stageRect.top && headingRect.bottom <= stageRect.bottom,
|
||||
};
|
||||
} );
|
||||
expect( captureContract.headerIntersects ).toBeFalsy();
|
||||
expect( captureContract.headingContained ).toBeTruthy();
|
||||
const header = page.locator( 'header.wp-block-template-part' );
|
||||
await header.evaluate( ( element ) => {
|
||||
element.dataset.characterCaptureVisibility = element.style.visibility;
|
||||
element.style.visibility = 'hidden';
|
||||
} );
|
||||
try {
|
||||
await testInfo.attach(
|
||||
`character-stage-${ surface.name }-${ viewport.width }-${ theme }.png`,
|
||||
{ body: await stage.screenshot(), contentType: 'image/png' },
|
||||
);
|
||||
} finally {
|
||||
await header.evaluate( ( element ) => {
|
||||
element.style.visibility = element.dataset.characterCaptureVisibility;
|
||||
delete element.dataset.characterCaptureVisibility;
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'character stage long copy grows safely with AA contrast in both themes', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 120_000 );
|
||||
test.skip( testInfo.project.name !== 'chromium', 'Character geometry is reviewed in Chromium.' );
|
||||
|
||||
for ( const theme of [ 'dark', 'light' ] ) {
|
||||
await setExplicitTheme( page, theme );
|
||||
for ( const width of [ 375, 1440 ] ) {
|
||||
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
|
||||
for ( const surface of characterSurfaces ) {
|
||||
await page.goto( surface.path );
|
||||
const stage = page.locator( surface.selector ).first();
|
||||
await stage.locator( ':scope > .chrnx-character-stage__content' ).evaluate( ( content ) => {
|
||||
const walker = document.createTreeWalker( content, window.NodeFilter.SHOW_TEXT );
|
||||
const nodes = [];
|
||||
while ( walker.nextNode() ) {
|
||||
if ( walker.currentNode.textContent.trim() ) {
|
||||
nodes.push( walker.currentNode );
|
||||
}
|
||||
}
|
||||
for ( const node of nodes ) {
|
||||
node.textContent = `${ node.textContent.trim() } `.repeat( 4 ).trim();
|
||||
}
|
||||
} );
|
||||
|
||||
const result = await stage.evaluate( ( element ) => {
|
||||
const content = element.querySelector( ':scope > .chrnx-character-stage__content' );
|
||||
const art = element.querySelector( ':scope > .chrnx-character-stage__art' );
|
||||
const stageRect = element.getBoundingClientRect();
|
||||
const contentRect = content.getBoundingClientRect();
|
||||
const artRect = art.getBoundingClientRect();
|
||||
const following = [
|
||||
...element.parentElement.querySelectorAll(
|
||||
'.chrnx-release-card, .chrnx-podcast-card, .chrnx-character-facets',
|
||||
),
|
||||
].filter( ( candidate ) => {
|
||||
const rect = candidate.getBoundingClientRect();
|
||||
return ! element.contains( candidate ) && rect.height > 0 && rect.top >= stageRect.top;
|
||||
} );
|
||||
const foregrounds = [ ...content.querySelectorAll( 'h1, h2, h3, h4, h5, h6, p, li, a' ) ]
|
||||
.filter( ( candidate ) => candidate.getClientRects().length > 0 )
|
||||
.map( ( candidate ) => window.getComputedStyle( candidate ).color );
|
||||
const copySurfaceStyle = window.getComputedStyle( content, '::before' );
|
||||
return {
|
||||
stageBottom: stageRect.bottom,
|
||||
contentBottom: contentRect.bottom,
|
||||
artTop: artRect.top,
|
||||
artBottom: artRect.bottom,
|
||||
nextTop: following.length
|
||||
? Math.min(
|
||||
...following.map( ( candidate ) => candidate.getBoundingClientRect().top ),
|
||||
)
|
||||
: Number.POSITIVE_INFINITY,
|
||||
foregrounds,
|
||||
background: copySurfaceStyle.backgroundColor,
|
||||
backgroundImage: copySurfaceStyle.backgroundImage,
|
||||
copySurfaceContent: copySurfaceStyle.content,
|
||||
};
|
||||
} );
|
||||
|
||||
expect( result.stageBottom ).toBeGreaterThanOrEqual( result.contentBottom - 1 );
|
||||
expect( result.stageBottom ).toBeGreaterThanOrEqual( result.artBottom - 1 );
|
||||
expect( result.nextTop ).toBeGreaterThanOrEqual( result.stageBottom - 1 );
|
||||
if ( width === 375 ) {
|
||||
expect( result.artTop ).toBeGreaterThanOrEqual( result.contentBottom - 1 );
|
||||
}
|
||||
expect( result.foregrounds.length ).toBeGreaterThan( 0 );
|
||||
expect( result.copySurfaceContent ).not.toBe( 'none' );
|
||||
const backgroundChannels = result.background.match( /[\d.]+/g ).map( Number );
|
||||
expect( backgroundChannels[ 3 ] ?? 1 ).toBeGreaterThanOrEqual( 0.85 );
|
||||
expect( result.backgroundImage ).toBe( 'none' );
|
||||
for ( const foreground of result.foregrounds ) {
|
||||
expect(
|
||||
conservativeOverlayContrast( foreground, result.background ),
|
||||
`${ surface.name } ${ width }px ${ theme } contrast`,
|
||||
).toBeGreaterThanOrEqual( 4.5 );
|
||||
}
|
||||
await expectNoHorizontalOverflow( page );
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'character stage is static under reduced motion and visible without JavaScript', async ( {
|
||||
browser,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 60_000 );
|
||||
test.skip( testInfo.project.name !== 'chromium', 'Character geometry is reviewed in Chromium.' );
|
||||
const cases = characterSurfaces.filter( ( surface ) =>
|
||||
[ 'home-music', 'about', 'topic-code' ].includes( surface.name ),
|
||||
);
|
||||
|
||||
for ( const surface of cases ) {
|
||||
const regularContext = await browser.newContext( {
|
||||
baseURL: testInfo.project.use.baseURL,
|
||||
viewport: { width: 375, height: 812 },
|
||||
} );
|
||||
const reducedContext = await browser.newContext( {
|
||||
baseURL: testInfo.project.use.baseURL,
|
||||
viewport: { width: 375, height: 812 },
|
||||
reducedMotion: 'reduce',
|
||||
} );
|
||||
const noJavaScriptContext = await browser.newContext( {
|
||||
baseURL: testInfo.project.use.baseURL,
|
||||
viewport: { width: 375, height: 812 },
|
||||
javaScriptEnabled: false,
|
||||
} );
|
||||
const [ regular, reduced, noJavaScript ] = await Promise.all( [
|
||||
regularContext.newPage(),
|
||||
reducedContext.newPage(),
|
||||
noJavaScriptContext.newPage(),
|
||||
] );
|
||||
try {
|
||||
for ( const page of [ regular, reduced, noJavaScript ] ) {
|
||||
await page.goto( surface.path );
|
||||
}
|
||||
const regularStage = regular.locator( surface.selector ).first();
|
||||
const reducedStage = reduced.locator( surface.selector ).first();
|
||||
const noJsStage = noJavaScript.locator( surface.selector ).first();
|
||||
const [ regularBox, reducedBox ] = await Promise.all( [
|
||||
regularStage.boundingBox(),
|
||||
reducedStage.boundingBox(),
|
||||
] );
|
||||
expect( Math.abs( regularBox.width - reducedBox.width ) ).toBeLessThanOrEqual( 1 );
|
||||
expect( Math.abs( regularBox.height - reducedBox.height ) ).toBeLessThanOrEqual( 1 );
|
||||
await expect( noJsStage ).toBeVisible();
|
||||
const noJsGeometry = await readCharacterGeometry( noJsStage );
|
||||
expect( noJsGeometry.pictureVisible ).toBeTruthy();
|
||||
expect( noJsGeometry.stageOverflow ).toBeLessThanOrEqual( 1 );
|
||||
await expectNoHorizontalOverflow( noJavaScript );
|
||||
} finally {
|
||||
await Promise.all( [
|
||||
regularContext.close(),
|
||||
reducedContext.close(),
|
||||
noJavaScriptContext.close(),
|
||||
] );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'character stage below-fold derivatives wait for approach and then load responsively', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
test.setTimeout( 60_000 );
|
||||
test.skip( testInfo.project.name !== 'chromium', 'Character loading is reviewed in Chromium.' );
|
||||
await page.setViewportSize( { width: 375, height: 812 } );
|
||||
const requested = [];
|
||||
page.on( 'request', ( request ) => {
|
||||
if ( /\/assets\/images\/(?:generated\/)?/.test( request.url() ) ) {
|
||||
requested.push( request.url() );
|
||||
}
|
||||
} );
|
||||
await page.goto( '/' );
|
||||
await page.waitForTimeout( 300 );
|
||||
|
||||
const stages = page.locator(
|
||||
'.chrnx-home-projects .chrnx-character-stage, .chrnx-home-music .chrnx-character-stage',
|
||||
);
|
||||
await expect( stages ).toHaveCount( 2 );
|
||||
const expected = [];
|
||||
for ( let stageIndex = 0; stageIndex < 2; stageIndex += 1 ) {
|
||||
const stage = stages.nth( stageIndex );
|
||||
const stageTop = await stage.evaluate( ( element ) => element.getBoundingClientRect().top );
|
||||
expect( stageTop ).toBeGreaterThanOrEqual( 812 );
|
||||
const portraits = await stage.locator( 'picture' ).evaluateAll( ( pictures ) =>
|
||||
pictures
|
||||
.filter(
|
||||
( picture ) =>
|
||||
window.getComputedStyle( picture.querySelector( 'img' ) ).display !== 'none',
|
||||
)
|
||||
.map( ( picture ) => {
|
||||
const source = picture.querySelector( 'source[type="image/avif"]' );
|
||||
return {
|
||||
candidates: source.srcset
|
||||
.split( ',' )
|
||||
.map( ( candidate ) => new URL( candidate.trim().split( /\s+/ )[ 0 ] ).pathname ),
|
||||
};
|
||||
} ),
|
||||
);
|
||||
expected.push( ...portraits );
|
||||
}
|
||||
for ( const portrait of expected ) {
|
||||
expect(
|
||||
requested.some( ( url ) => portrait.candidates.includes( new URL( url ).pathname ) ),
|
||||
).toBeFalsy();
|
||||
}
|
||||
|
||||
for ( let stageIndex = 0; stageIndex < 2; stageIndex += 1 ) {
|
||||
await stages.nth( stageIndex ).scrollIntoViewIfNeeded();
|
||||
}
|
||||
for ( const portrait of expected ) {
|
||||
await expect
|
||||
.poll(
|
||||
() => requested.find( ( url ) => portrait.candidates.includes( new URL( url ).pathname ) ),
|
||||
{ timeout: 10_000 },
|
||||
)
|
||||
.toMatch( /-384\.avif$/ );
|
||||
}
|
||||
} );
|
||||
Reference in new issue
Block a user