fix: promote approved Gaming character art
This commit is contained in:
13 files changed
+153
-13
No files matched your search
@@ -33,6 +33,36 @@ const characterSurfaces = [
|
||||
),
|
||||
];
|
||||
|
||||
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 );
|
||||
@@ -816,7 +846,7 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt
|
||||
priority: element.querySelector( ':scope > .chrnx-character-stage__art picture img' )
|
||||
?.fetchPriority,
|
||||
} ) );
|
||||
await stage.scrollIntoViewIfNeeded();
|
||||
await positionStageBelowStickyHeader( page, stage );
|
||||
await stage
|
||||
.locator( ':scope > .chrnx-character-stage__art picture img' )
|
||||
.evaluate( ( image ) => image.decode() );
|
||||
@@ -854,6 +884,48 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt
|
||||
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' );
|
||||
}
|
||||
@@ -893,10 +965,37 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt
|
||||
expect( initial.loading ).not.toBe( 'eager' );
|
||||
expect( initial.priority ).not.toBe( 'high' );
|
||||
}
|
||||
await testInfo.attach(
|
||||
`character-stage-${ surface.name }-${ viewport.width }-${ theme }.png`,
|
||||
{ body: await stage.screenshot(), contentType: 'image/png' },
|
||||
);
|
||||
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;
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user