1204 lines
51 KiB
JavaScript
1204 lines
51 KiB
JavaScript
import { expect, test } from '@playwright/test';
|
|
import { injectAxe } from 'axe-playwright';
|
|
|
|
const viewports = [
|
|
{ width: 375, height: 812 },
|
|
{ width: 768, height: 1024 },
|
|
{ width: 1440, height: 900 },
|
|
{ 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,
|
|
body: document.body.scrollWidth - window.innerWidth,
|
|
} ) );
|
|
expect( overflow.document ).toBeLessThanOrEqual( 1 );
|
|
expect( overflow.body ).toBeLessThanOrEqual( 1 );
|
|
}
|
|
|
|
function relativeLuminance( color ) {
|
|
const channels = color
|
|
.match( /[\d.]+/g )
|
|
.slice( 0, 3 )
|
|
.map( ( channel ) => {
|
|
const value = Number( channel ) / 255;
|
|
return value <= 0.04045 ? value / 12.92 : ( ( value + 0.055 ) / 1.055 ) ** 2.4;
|
|
} );
|
|
return 0.2126 * channels[ 0 ] + 0.7152 * channels[ 1 ] + 0.0722 * channels[ 2 ];
|
|
}
|
|
|
|
function contrastRatio( foreground, background ) {
|
|
const lighter = Math.max( relativeLuminance( foreground ), relativeLuminance( background ) );
|
|
const darker = Math.min( relativeLuminance( foreground ), relativeLuminance( 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 );
|
|
await page.goto( '/' );
|
|
await expect( page.getByRole( 'banner' ) ).toBeVisible();
|
|
await expect( page.locator( 'main#chrnx-main' ) ).toBeVisible();
|
|
await expect( page.getByRole( 'contentinfo' ) ).toBeVisible();
|
|
await expect( page.getByRole( 'heading', { level: 1 } ) ).toHaveCount( 1 );
|
|
await expect( page.getByText( 'Selected work', { exact: true } ) ).toBeVisible();
|
|
await expect( page.getByText( 'The No Names', { exact: true } ).first() ).toBeVisible();
|
|
await expect( page.locator( 'picture source[type="image/avif"]' ).first() ).toHaveAttribute(
|
|
'srcset',
|
|
/384\.avif 384w/,
|
|
);
|
|
await expectNoHorizontalOverflow( page );
|
|
}
|
|
} );
|
|
|
|
test( 'lower home sections form compact, contained editorial panels in both themes', async ( {
|
|
page,
|
|
} ) => {
|
|
const expectedOrder = [
|
|
'chrnx-home-projects',
|
|
'chrnx-home-music',
|
|
'wp-block-chrnx-latest-podcast',
|
|
'chrnx-home-about-preview',
|
|
'wp-block-chrnx-subscribe-cta',
|
|
];
|
|
|
|
for ( const theme of [ 'Dark', 'Light' ] ) {
|
|
for ( const viewport of viewports ) {
|
|
await page.setViewportSize( viewport );
|
|
await page.goto( '/' );
|
|
await page.evaluate(
|
|
( value ) => window.localStorage.setItem( 'chrnx-theme', value ),
|
|
theme.toLowerCase(),
|
|
);
|
|
await page.reload();
|
|
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme.toLowerCase() );
|
|
|
|
const result = await page.locator( '.chrnx-home' ).evaluate( ( home, order ) => {
|
|
const selectors = [
|
|
'.chrnx-home-projects',
|
|
'.chrnx-home-music .wp-block-columns',
|
|
'.chrnx-latest-podcast',
|
|
'.chrnx-home-about-preview',
|
|
'.chrnx-subscribe-cta',
|
|
];
|
|
const panels = selectors.map( ( selector ) => home.querySelector( selector ) );
|
|
const bodyStyle = window.getComputedStyle( document.body );
|
|
const canvas = `${ bodyStyle.backgroundColor }|${ bodyStyle.backgroundImage }`;
|
|
const spacingProbe = document.createElement( 'div' );
|
|
spacingProbe.style.cssText =
|
|
'position:absolute;visibility:hidden;width:var(--wp--preset--spacing--70);height:1px';
|
|
document.body.append( spacingProbe );
|
|
const xl = spacingProbe.getBoundingClientRect().width;
|
|
spacingProbe.remove();
|
|
const signature = ( element ) => {
|
|
const style = window.getComputedStyle( element );
|
|
return `${ style.backgroundColor }|${ style.backgroundImage }|${ style.borderTopColor }|${ style.boxShadow }`;
|
|
};
|
|
const hasOpaqueSurface = ( element ) => {
|
|
const style = window.getComputedStyle( element );
|
|
return (
|
|
style.backgroundColor !== 'rgba(0, 0, 0, 0)' && style.backgroundColor !== 'transparent'
|
|
);
|
|
};
|
|
const isTreated = ( element ) => {
|
|
const style = window.getComputedStyle( element );
|
|
return (
|
|
style.filter !== 'none' ||
|
|
style.boxShadow !== 'none' ||
|
|
style.maskImage !== 'none' ||
|
|
style.webkitMaskImage !== 'none'
|
|
);
|
|
};
|
|
const isContained = ( child, frame ) => {
|
|
const childRect = child.getBoundingClientRect();
|
|
const frameRect = frame.getBoundingClientRect();
|
|
return (
|
|
childRect.left >= frameRect.left - 1 &&
|
|
childRect.right <= frameRect.right + 1 &&
|
|
childRect.top >= frameRect.top - 1 &&
|
|
childRect.bottom <= frameRect.bottom + 1
|
|
);
|
|
};
|
|
const panelRects = panels.map( ( panel ) => panel.getBoundingClientRect() );
|
|
const journalRect = home.querySelector( '.chrnx-journal-stream' ).getBoundingClientRect();
|
|
const musicFrame = panels[ 1 ];
|
|
const collageLayer = musicFrame.querySelector( '.chrnx-home-music__collage-layer' );
|
|
const collage = collageLayer?.querySelector( '.chrnx-home-music__collage' );
|
|
const musician = musicFrame.querySelector( '.chrnx-home-music__art' );
|
|
const musicHeading = musicFrame.querySelector( 'h2' );
|
|
const projectPortraits = [
|
|
...panels[ 0 ].querySelectorAll( '.chrnx-section-portrait' ),
|
|
].filter( ( portrait ) => portrait.getClientRects().length > 0 );
|
|
|
|
return {
|
|
directOrder: [ ...home.children ]
|
|
.filter( ( child ) =>
|
|
order.some( ( className ) => child.classList.contains( className ) ),
|
|
)
|
|
.map( ( child ) =>
|
|
order.find( ( className ) => child.classList.contains( className ) ),
|
|
),
|
|
signatures: panels.map( signature ),
|
|
opaqueSurfaces: panels.map( hasOpaqueSurface ),
|
|
canvas,
|
|
xl,
|
|
gaps: [
|
|
panelRects[ 0 ].top - journalRect.bottom,
|
|
...panelRects
|
|
.slice( 1 )
|
|
.map( ( rect, index ) => rect.top - panelRects[ index ].bottom ),
|
|
],
|
|
projectsContained: projectPortraits.every( ( portrait ) =>
|
|
isContained( portrait, panels[ 0 ] ),
|
|
),
|
|
projectsTreated: projectPortraits.every( isTreated ),
|
|
collageSources: collageLayer
|
|
? [ ...collageLayer.querySelectorAll( 'source' ) ].map( ( source ) => ( {
|
|
type: source.type,
|
|
srcset: source.srcset,
|
|
} ) )
|
|
: [],
|
|
collageLazy: collage?.loading,
|
|
collageFallback: collage?.getAttribute( 'src' ),
|
|
collageContained: Boolean( collageLayer && isContained( collageLayer, musicFrame ) ),
|
|
collageTreated: Boolean( collage && isTreated( collage ) ),
|
|
collageZIndex: collageLayer
|
|
? Number.parseInt( window.getComputedStyle( collageLayer ).zIndex, 10 )
|
|
: Number.NaN,
|
|
copyPosition: window.getComputedStyle( musicHeading ).position,
|
|
copyZIndex: Number.parseInt( window.getComputedStyle( musicHeading ).zIndex, 10 ),
|
|
musicianContained: isContained( musician, musicFrame ),
|
|
musicianTreated: isTreated( musician ),
|
|
};
|
|
}, expectedOrder );
|
|
|
|
expect( result.directOrder ).toEqual( expectedOrder );
|
|
expect( result.xl ).toBeGreaterThan( 0 );
|
|
expect(
|
|
result.gaps.every( ( gap ) => gap >= -1 && gap <= result.xl + 1 ),
|
|
`gaps ${ result.gaps.join( ', ' ) }; XL ${ result.xl } at ${ viewport.width }px ${ theme }`,
|
|
).toBeTruthy();
|
|
expect( new Set( result.signatures ).size ).toBe( result.signatures.length );
|
|
expect( result.opaqueSurfaces.every( Boolean ) ).toBeTruthy();
|
|
expect(
|
|
result.signatures.every( ( signature ) => signature !== result.canvas ),
|
|
).toBeTruthy();
|
|
expect( result.projectsContained ).toBeTruthy();
|
|
expect( result.projectsTreated ).toBeTruthy();
|
|
expect( result.collageSources ).toEqual( [
|
|
expect.objectContaining( {
|
|
type: 'image/avif',
|
|
srcset: expect.stringContaining( 'the-no-names-collage-384.avif' ),
|
|
} ),
|
|
expect.objectContaining( {
|
|
type: 'image/webp',
|
|
srcset: expect.stringContaining( 'the-no-names-collage-384.webp' ),
|
|
} ),
|
|
] );
|
|
expect( result.collageLazy ).toBe( 'lazy' );
|
|
expect( result.collageFallback ).toContain( 'the-no-names-collage.jpeg' );
|
|
expect( result.collageContained ).toBeTruthy();
|
|
expect( result.collageTreated ).toBeTruthy();
|
|
expect( result.copyPosition ).not.toBe( 'static' );
|
|
expect( result.copyZIndex ).toBeGreaterThan( result.collageZIndex );
|
|
expect( result.musicianContained ).toBeTruthy();
|
|
expect( result.musicianTreated ).toBeTruthy();
|
|
await expectNoHorizontalOverflow( page );
|
|
}
|
|
}
|
|
} );
|
|
|
|
test( 'latest podcast is a compact horizontal panel on desktop', async ( { page } ) => {
|
|
await page.setViewportSize( { width: 1440, height: 900 } );
|
|
await page.goto( '/' );
|
|
|
|
const geometry = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
|
|
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 panelRect = panel.getBoundingClientRect();
|
|
const mediaRect = media.getBoundingClientRect();
|
|
const contentRect = content.getBoundingClientRect();
|
|
|
|
return {
|
|
display: window.getComputedStyle( link ).display,
|
|
panelHeight: panelRect.height,
|
|
viewportHeight: window.innerHeight,
|
|
mediaHeight: mediaRect.height,
|
|
mediaRight: mediaRect.right,
|
|
contentLeft: contentRect.left,
|
|
};
|
|
} );
|
|
|
|
expect( geometry.display ).toBe( 'grid' );
|
|
expect( geometry.panelHeight ).toBeLessThanOrEqual( geometry.viewportHeight * 0.72 );
|
|
expect( geometry.mediaHeight ).toBeLessThanOrEqual( geometry.panelHeight * 0.72 );
|
|
expect( geometry.mediaRight ).toBeLessThanOrEqual( geometry.contentLeft + 1 );
|
|
} );
|
|
|
|
test( 'lower home panels survive missing media and reduced motion', async ( { page } ) => {
|
|
await page.emulateMedia( { reducedMotion: 'reduce' } );
|
|
await page.route( /\/assets\/images\//, ( route ) => route.abort() );
|
|
await page.setViewportSize( { width: 375, height: 812 } );
|
|
await page.goto( '/' );
|
|
|
|
const fallback = await page.locator( '.chrnx-podcast-card__fallback' ).evaluate( ( media ) => {
|
|
const card = media.closest( '.chrnx-podcast-card' );
|
|
const panel = media.closest( '.chrnx-latest-podcast' );
|
|
const mediaRect = media.getBoundingClientRect();
|
|
const cardRect = card.getBoundingClientRect();
|
|
const panelRect = panel.getBoundingClientRect();
|
|
const style = window.getComputedStyle( media );
|
|
|
|
return {
|
|
width: mediaRect.width,
|
|
height: mediaRect.height,
|
|
backgroundImage: style.backgroundImage,
|
|
inCard:
|
|
mediaRect.left >= cardRect.left - 1 &&
|
|
mediaRect.right <= cardRect.right + 1 &&
|
|
mediaRect.top >= cardRect.top - 1 &&
|
|
mediaRect.bottom <= cardRect.bottom + 1,
|
|
cardInPanel:
|
|
cardRect.left >= panelRect.left - 1 &&
|
|
cardRect.right <= panelRect.right + 1 &&
|
|
cardRect.top >= panelRect.top - 1 &&
|
|
cardRect.bottom <= panelRect.bottom + 1,
|
|
};
|
|
} );
|
|
|
|
expect( fallback.width ).toBeGreaterThan( 0 );
|
|
expect( fallback.height ).toBeGreaterThan( 0 );
|
|
expect( fallback.backgroundImage ).toMatch( /gradient/ );
|
|
expect( fallback.inCard ).toBeTruthy();
|
|
expect( fallback.cardInPanel ).toBeTruthy();
|
|
|
|
const musicFallback = await page
|
|
.locator( '.chrnx-home-music .wp-block-columns' )
|
|
.evaluate( ( frame ) => {
|
|
const layer = frame.querySelector( '.chrnx-home-music__collage-layer' );
|
|
const copy = frame.querySelector( '.wp-block-column:first-of-type' );
|
|
const frameRect = frame.getBoundingClientRect();
|
|
const copyRect = copy.getBoundingClientRect();
|
|
const layerRect = layer?.getBoundingClientRect();
|
|
|
|
return {
|
|
hasLayer: Boolean( layer ),
|
|
decorativeAlt: layer?.querySelector( 'img' )?.getAttribute( 'alt' ),
|
|
layerCoversFrame: Boolean(
|
|
layerRect &&
|
|
Math.abs( layerRect.left - frameRect.left ) <= 1 &&
|
|
Math.abs( layerRect.right - frameRect.right ) <= 1 &&
|
|
Math.abs( layerRect.top - frameRect.top ) <= 1 &&
|
|
Math.abs( layerRect.bottom - frameRect.bottom ) <= 1,
|
|
),
|
|
copyContained:
|
|
copyRect.left >= frameRect.left - 1 &&
|
|
copyRect.right <= frameRect.right + 1 &&
|
|
copyRect.top >= frameRect.top - 1 &&
|
|
copyRect.bottom <= frameRect.bottom + 1,
|
|
};
|
|
} );
|
|
|
|
expect( musicFallback.hasLayer ).toBeTruthy();
|
|
expect( musicFallback.decorativeAlt ).toBe( '' );
|
|
expect( musicFallback.layerCoversFrame ).toBeTruthy();
|
|
expect( musicFallback.copyContained ).toBeTruthy();
|
|
await expect( page.locator( '.chrnx-home-music h2' ) ).toContainText( 'The No Names' );
|
|
await expect( page.locator( '.chrnx-home-music p' ) ).toHaveCount( 2 );
|
|
await expect( page.locator( '.chrnx-home-projects h3' ) ).toHaveCount( 3 );
|
|
await expect( page.locator( '.chrnx-home-about-preview p' ) ).not.toBeEmpty();
|
|
await expect( page.locator( '.chrnx-subscribe-cta__link' ) ).toBeVisible();
|
|
|
|
for ( const selector of [
|
|
'.chrnx-home-projects',
|
|
'.chrnx-home-music .wp-block-columns',
|
|
'.chrnx-latest-podcast',
|
|
'.chrnx-home-about-preview',
|
|
'.chrnx-subscribe-cta',
|
|
] ) {
|
|
await expect( page.locator( selector ) ).toBeVisible();
|
|
}
|
|
await expectNoHorizontalOverflow( page );
|
|
} );
|
|
|
|
test( 'explicit themes use an atmospheric canvas and a compact home introduction', async ( {
|
|
page,
|
|
} ) => {
|
|
const canvases = new Map();
|
|
|
|
for ( const theme of [ 'Dark', 'Light' ] ) {
|
|
await page.setViewportSize( { width: 1440, height: 900 } );
|
|
await page.goto( '/' );
|
|
await page.getByRole( 'radio', { name: theme, exact: true } ).check();
|
|
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme.toLowerCase() );
|
|
|
|
const desktop = await page.evaluate( () => {
|
|
const hero = document.querySelector( '.chrnx-home-intro' );
|
|
const bodyStyle = window.getComputedStyle( document.body );
|
|
const heroRect = hero.getBoundingClientRect();
|
|
return {
|
|
backgroundColor: bodyStyle.backgroundColor,
|
|
backgroundImage: bodyStyle.backgroundImage,
|
|
backgroundRepeat: bodyStyle.backgroundRepeat,
|
|
backgroundSize: bodyStyle.backgroundSize,
|
|
heroHeight: heroRect.height,
|
|
paragraphColor: window.getComputedStyle( hero.querySelector( 'p' ) ).color,
|
|
titleColor: window.getComputedStyle( hero.querySelector( 'h1' ) ).color,
|
|
};
|
|
} );
|
|
|
|
expect( desktop.backgroundImage ).toMatch( /(?:radial|linear)-gradient/ );
|
|
expect( desktop.backgroundImage ).not.toBe( 'none' );
|
|
expect(
|
|
desktop.backgroundRepeat.split( ', ' ).every( ( value ) => value === 'no-repeat' ),
|
|
).toBeTruthy();
|
|
expect( desktop.backgroundSize ).not.toMatch( /(?:32|48)px\s+(?:32|48)px/ );
|
|
expect( desktop.heroHeight ).toBeGreaterThanOrEqual( 900 * 0.6 - 1 );
|
|
expect( desktop.heroHeight ).toBeLessThanOrEqual( 900 * 0.68 + 1 );
|
|
expect( desktop.heroHeight ).toBeLessThanOrEqual( 42 * 16 + 1 );
|
|
expect( contrastRatio( desktop.titleColor, desktop.backgroundColor ) ).toBeGreaterThanOrEqual(
|
|
4.5,
|
|
);
|
|
expect(
|
|
contrastRatio( desktop.paragraphColor, desktop.backgroundColor ),
|
|
).toBeGreaterThanOrEqual( 4.5 );
|
|
canvases.set( theme, `${ desktop.backgroundColor } ${ desktop.backgroundImage }` );
|
|
|
|
await page.setViewportSize( { width: 375, height: 812 } );
|
|
const mobile = await page.locator( '.chrnx-home-intro' ).evaluate( ( hero ) => {
|
|
const heroRect = hero.getBoundingClientRect();
|
|
const paragraphRect = hero.querySelector( 'p' ).getBoundingClientRect();
|
|
const style = window.getComputedStyle( hero );
|
|
return {
|
|
height: heroRect.height,
|
|
trailingSpace: heroRect.bottom - paragraphRect.bottom,
|
|
sectionSpacing: Number.parseFloat( style.paddingBottom ),
|
|
};
|
|
} );
|
|
|
|
expect( mobile.height ).toBeLessThanOrEqual( 34 * 16 + 1 );
|
|
expect( mobile.trailingSpace ).toBeLessThanOrEqual( mobile.sectionSpacing + 1 );
|
|
}
|
|
|
|
expect( canvases.get( 'Dark' ) ).not.toBe( canvases.get( 'Light' ) );
|
|
} );
|
|
|
|
test( 'mobile home introduction grows with long content without overlapping the next section', async ( {
|
|
page,
|
|
} ) => {
|
|
await page.setViewportSize( { width: 375, height: 812 } );
|
|
await page.addInitScript( () => window.localStorage.setItem( 'chrnx-theme', 'dark' ) );
|
|
await page.goto( '/' );
|
|
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
|
await page.locator( '.chrnx-home-intro' ).evaluate( ( hero ) => {
|
|
const title = hero.querySelector( 'h1' );
|
|
const paragraph = hero.querySelector( 'p' );
|
|
title.textContent = `${ title.textContent } `.repeat( 4 );
|
|
paragraph.textContent = `${ paragraph.textContent } `.repeat( 8 );
|
|
} );
|
|
|
|
const layout = await page.locator( '.chrnx-home-intro' ).evaluate( ( hero ) => {
|
|
const heroRect = hero.getBoundingClientRect();
|
|
const lastChildRect = hero.lastElementChild.getBoundingClientRect();
|
|
const nextSectionRect = hero.nextElementSibling.getBoundingClientRect();
|
|
return {
|
|
heroBottom: heroRect.bottom,
|
|
heroHeight: heroRect.height,
|
|
lastChildBottom: lastChildRect.bottom,
|
|
nextSectionTop: nextSectionRect.top,
|
|
};
|
|
} );
|
|
|
|
expect( layout.heroBottom ).toBeGreaterThanOrEqual( layout.lastChildBottom - 1 );
|
|
expect( layout.nextSectionTop ).toBeGreaterThanOrEqual( layout.lastChildBottom - 1 );
|
|
expect( layout.heroHeight ).toBeGreaterThan( 34 * 16 );
|
|
} );
|
|
|
|
test( 'seeded post permalink resolves its single template', async ( { page } ) => {
|
|
const title = 'The save file remembers what the hero pretends to forget';
|
|
const expectedPath = '/the-save-file-remembers-what-the-hero-pretends-to-forget/';
|
|
await page.goto( '/' );
|
|
const fixtureCard = page.locator( '.chrnx-featured-story', { hasText: title } );
|
|
await expect( fixtureCard.getByRole( 'heading', { name: title, exact: true } ) ).toBeVisible();
|
|
const fixtureLink = fixtureCard.getByRole( 'link' );
|
|
|
|
const [ navigationResponse ] = await Promise.all( [
|
|
page.waitForNavigation(),
|
|
fixtureLink.click(),
|
|
] );
|
|
|
|
expect( navigationResponse ).not.toBeNull();
|
|
expect( navigationResponse.status() ).toBe( 200 );
|
|
await expect( page ).toHaveURL( new RegExp( `${ expectedPath }$` ) );
|
|
await expect( page.locator( 'main.chrnx-entry--single' ) ).toBeVisible();
|
|
await expect( page.getByRole( 'heading', { level: 1, name: title, exact: true } ) ).toBeVisible();
|
|
} );
|
|
|
|
test( 'topic, music, podcast, and about surfaces use real content and approved art', async ( {
|
|
page,
|
|
} ) => {
|
|
for ( const [ path, heading, asset ] of [
|
|
[ '/topic/code/', 'Code', 'alter-ego-code' ],
|
|
[ '/topic/research/', 'Research', 'alter-ego-research' ],
|
|
[ '/topic/gaming/', 'Gaming', 'alter-ego-gaming' ],
|
|
] ) {
|
|
await page.goto( path );
|
|
await expect( page.getByRole( 'heading', { level: 1, name: heading } ) ).toBeVisible();
|
|
await expect( page.locator( `.chrnx-topic-hero img[src*="${ asset }.png"]` ) ).toBeVisible();
|
|
await expectNoHorizontalOverflow( page );
|
|
}
|
|
|
|
await page.goto( '/music/' );
|
|
await expect( page.getByRole( 'heading', { level: 1, name: 'Music' } ) ).toBeVisible();
|
|
await expect( page.getByText( 'Grunge mexicano para cerebros que no se callan.' ) ).toBeVisible();
|
|
await expect(
|
|
page.locator( 'picture img[src*="the-no-names-musician-cutout.png"]' ),
|
|
).toBeVisible();
|
|
|
|
await page.goto( '/podcasts/' );
|
|
await expect( page.getByRole( 'heading', { level: 1, name: 'Podcasts' } ) ).toBeVisible();
|
|
await expect( page.locator( 'picture img[src*="alter-ego-podcasts.png"]' ) ).toBeVisible();
|
|
await expect( page.locator( 'iframe, audio' ) ).toHaveCount( 0 );
|
|
|
|
await page.goto( '/about/' );
|
|
await expect( page.getByRole( 'heading', { level: 1, name: 'About' } ) ).toBeVisible();
|
|
await expect( page.getByRole( 'link', { name: 'arXiv:2603.05352' } ) ).toHaveAttribute(
|
|
'href',
|
|
'https://arxiv.org/abs/2603.05352',
|
|
);
|
|
await expect( page.locator( '.chrnx-about__portraits picture' ) ).toHaveCount( 3 );
|
|
} );
|
|
|
|
test( 'long, incomplete, empty, and missing states stay usable', async ( { page } ) => {
|
|
await page.goto( '/?s=fixture-that-cannot-exist' );
|
|
await expect( page.getByText( 'No journal entries match these filters yet.' ) ).toBeVisible();
|
|
await expect( page.getByRole( 'link', { name: 'Browse the full Journal' } ) ).toBeVisible();
|
|
|
|
await page.goto( '/conversacion-pendiente-de-datos-editoriales/' );
|
|
await expect(
|
|
page.getByRole( 'heading', {
|
|
level: 1,
|
|
name: 'Conversación pendiente de datos editoriales',
|
|
} ),
|
|
).toBeVisible();
|
|
await expect( page.locator( '.chrnx-podcast-meta' ) ).toHaveCount( 0 );
|
|
await expect( page.locator( '.taxonomy-chrnx_topic' ) ).toContainText( 'Podcasts' );
|
|
await expect( page.locator( '.taxonomy-chrnx_language' ) ).toContainText( 'Español' );
|
|
await expect( page.getByText( 'Estado de prueba para un episodio sin show' ) ).toHaveCount( 0 );
|
|
|
|
await page.goto( '/emotion-is-not-a-slider-designing-expressive-systems-that-can-hesitate/' );
|
|
await expect( page.locator( 'pre code' ) ).toContainText( 'const state' );
|
|
await expect( page.locator( 'pre code' ) ).toContainText(
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
|
|
);
|
|
await expectNoHorizontalOverflow( page );
|
|
|
|
for ( const [ path, title ] of [
|
|
[
|
|
'/long-title-night-writing-fixture/',
|
|
'Escribir cuando la casa por fin se queda en silencio',
|
|
],
|
|
[
|
|
'/una-cuerda-rota-tambien-puede-decidir-el-arreglo/',
|
|
'Una cuerda rota también puede decidir el arreglo',
|
|
],
|
|
] ) {
|
|
await page.goto( path );
|
|
await expect( page.getByRole( 'heading', { level: 1 } ) ).toContainText( title );
|
|
await expectNoHorizontalOverflow( page );
|
|
}
|
|
await expect( page.locator( '.chrnx-entry__meta a', { hasText: 'English' } ) ).toHaveCount( 0 );
|
|
|
|
await page.goto( '/journal/?chrnx_topic=..%2F..%2Fcode&chrnx_language%5B%5D=en&s%5B%5D=x' );
|
|
await expect( page.locator( 'select[name="chrnx_topic"]' ) ).toHaveValue( '' );
|
|
await expect( page.locator( 'select[name="chrnx_language"]' ) ).toHaveValue( '' );
|
|
await expect( page.locator( '.chrnx-journal-stream__filters input[name="s"]' ) ).toHaveValue(
|
|
'',
|
|
);
|
|
await expectNoHorizontalOverflow( page );
|
|
|
|
await page.goto( '/this-route-does-not-exist/' );
|
|
await expect( page ).toHaveTitle( /Page not found/i );
|
|
await expect( page.getByRole( 'heading', { level: 1, name: 'Page not found' } ) ).toBeVisible();
|
|
} );
|
|
|
|
test( 'cards without featured media use CSS-only topic treatments', async ( { page } ) => {
|
|
await page.goto( '/' );
|
|
const fallbacks = page.locator(
|
|
'.chrnx-featured-story__fallback, .chrnx-journal-card__fallback, .chrnx-podcast-card__fallback',
|
|
);
|
|
await expect( fallbacks.first() ).toBeVisible();
|
|
expect( await fallbacks.locator( 'img' ).count() ).toBe( 0 );
|
|
for ( const fallback of await fallbacks.all() ) {
|
|
const background = await fallback.evaluate(
|
|
( element ) => window.getComputedStyle( element ).backgroundImage,
|
|
);
|
|
expect( background ).not.toMatch( /alter-ego-|the-no-names-musician-cutout/ );
|
|
}
|
|
} );
|
|
|
|
test( 'podcast canonical metadata is safe and missing metadata never invents a player or link', async ( {
|
|
page,
|
|
} ) => {
|
|
await page.goto( '/silicon-ranch-conversaciones-sin-diapositivas/' );
|
|
await expect( page.getByRole( 'link', { name: 'Open canonical episode page' } ) ).toHaveAttribute(
|
|
'href',
|
|
'https://example.test/local-podcast-episode',
|
|
);
|
|
await expect( page.locator( 'iframe, audio' ) ).toHaveCount( 0 );
|
|
await page.goto( '/conversacion-pendiente-de-datos-editoriales/' );
|
|
await expect( page.locator( '.chrnx-podcast-meta, iframe, audio' ) ).toHaveCount( 0 );
|
|
await expect( page.getByRole( 'link', { name: 'Open canonical episode page' } ) ).toHaveCount(
|
|
0,
|
|
);
|
|
} );
|
|
|
|
test( 'incomplete podcast remains journal-visible but excluded from show and latest surfaces', async ( {
|
|
page,
|
|
} ) => {
|
|
const title = 'Conversación pendiente de datos editoriales';
|
|
await page.goto( `/?s=${ encodeURIComponent( title ) }` );
|
|
await expect( page.locator( '.chrnx-journal-card', { hasText: title } ) ).toHaveCount( 1 );
|
|
|
|
await page.goto( '/podcasts/' );
|
|
await expect( page.locator( '.chrnx-latest-podcast', { hasText: title } ) ).toHaveCount( 0 );
|
|
|
|
await page.goto( '/show/silicon-ranch/' );
|
|
await expect( page.locator( 'main', { hasText: title } ) ).toHaveCount( 0 );
|
|
} );
|
|
|
|
test( 'site routes preserve heading order, named landmarks, and skip-link keyboard flow', async ( {
|
|
page,
|
|
}, testInfo ) => {
|
|
for ( const path of [ '/', '/music/', '/podcasts/', '/about/', '/topic/code/', '/journal/' ] ) {
|
|
await page.goto( path );
|
|
const headings = await page
|
|
.locator( 'h1, h2, h3, h4, h5, h6' )
|
|
.evaluateAll( ( nodes ) => nodes.map( ( node ) => Number( node.tagName.slice( 1 ) ) ) );
|
|
expect( headings.filter( ( level ) => level === 1 ) ).toHaveLength( 1 );
|
|
for ( let index = 1; index < headings.length; index += 1 ) {
|
|
expect(
|
|
headings[ index ] - headings[ index - 1 ],
|
|
`${ path } heading sequence`,
|
|
).toBeLessThanOrEqual( 1 );
|
|
}
|
|
await expect( page.getByRole( 'banner' ) ).toHaveCount( 1 );
|
|
await expect( page.getByRole( 'main' ) ).toHaveCount( 1 );
|
|
await expect( page.getByRole( 'contentinfo' ) ).toHaveCount( 1 );
|
|
const landmarkNames = await page
|
|
.locator( 'nav' )
|
|
.evaluateAll( ( nodes ) => nodes.map( ( node ) => node.getAttribute( 'aria-label' ) ) );
|
|
expect( landmarkNames.every( Boolean ) ).toBeTruthy();
|
|
expect( new Set( landmarkNames ).size ).toBe( landmarkNames.length );
|
|
if ( testInfo.project.name === 'chromium' ) {
|
|
await page.keyboard.press( 'Tab' );
|
|
const skip = page.getByRole( 'link', { name: 'Skip to content' } );
|
|
await expect( skip ).toBeFocused();
|
|
await skip.press( 'Enter' );
|
|
await expect( page.locator( 'main#chrnx-main' ) ).toBeFocused();
|
|
}
|
|
}
|
|
} );
|
|
|
|
test( 'search and not-found recovery navigation landmarks have unique names', async ( {
|
|
page,
|
|
} ) => {
|
|
for ( const [ path, expected ] of [
|
|
[ '/?s=fixture-that-cannot-exist', 'Search recovery navigation' ],
|
|
[ '/this-route-does-not-exist/', 'Page not found recovery navigation' ],
|
|
] ) {
|
|
await page.goto( path );
|
|
await expect( page.getByRole( 'navigation', { name: expected } ) ).toHaveCount( 1 );
|
|
const names = await page
|
|
.locator( 'nav' )
|
|
.evaluateAll( ( nodes ) => nodes.map( ( node ) => node.getAttribute( 'aria-label' ) ) );
|
|
expect( names.every( Boolean ) ).toBeTruthy();
|
|
expect( new Set( names ).size ).toBe( names.length );
|
|
}
|
|
} );
|
|
|
|
test( 'reduced motion removes card transitions while theme preference remains user-controlled', async ( {
|
|
page,
|
|
} ) => {
|
|
await page.emulateMedia( {
|
|
reducedMotion: 'reduce',
|
|
colorScheme: 'light',
|
|
} );
|
|
await page.goto( '/' );
|
|
const card = page.locator( '.chrnx-featured-story' ).first();
|
|
const duration = await card.evaluate( ( element ) =>
|
|
Number.parseFloat( window.getComputedStyle( element ).transitionDuration ),
|
|
);
|
|
expect( duration ).toBeLessThanOrEqual( 0.001 );
|
|
await expect( page.locator( '.chrnx-home-music h2' ) ).toHaveCSS( 'color', 'rgb(230, 237, 243)' );
|
|
await page.getByRole( 'radio', { name: 'Dark', exact: true } ).check();
|
|
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
|
} );
|
|
|
|
test( 'key public surfaces pass automated WCAG 2.2 AA checks', async ( { page }, testInfo ) => {
|
|
test.skip(
|
|
testInfo.project.name !== 'chromium',
|
|
'One engine is sufficient for deterministic axe rules.',
|
|
);
|
|
const tags = [ 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa' ];
|
|
for ( const viewport of viewports ) {
|
|
await page.setViewportSize( viewport );
|
|
for ( const path of [
|
|
'/',
|
|
'/music/',
|
|
'/podcasts/',
|
|
'/about/',
|
|
'/topic/code/',
|
|
'/?s=fixture-that-cannot-exist',
|
|
'/this-route-does-not-exist/',
|
|
] ) {
|
|
await page.goto( path );
|
|
await injectAxe( page );
|
|
const violations = await page.evaluate( async ( runOnly ) => {
|
|
const result = await globalThis.axe.run( document, {
|
|
runOnly: { type: 'tag', values: runOnly },
|
|
} );
|
|
return result.violations.map( ( violation ) => ( {
|
|
id: violation.id,
|
|
impact: violation.impact,
|
|
nodes: violation.nodes.map( ( node ) => node.target ),
|
|
} ) );
|
|
}, tags );
|
|
expect( violations, `${ path } at ${ viewport.width }px` ).toEqual( [] );
|
|
}
|
|
}
|
|
} );
|
|
|
|
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$/ );
|
|
}
|
|
} );
|