346 lines
15 KiB
JavaScript
346 lines
15 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 },
|
|
];
|
|
|
|
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 );
|
|
}
|
|
|
|
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( '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,
|
|
};
|
|
} );
|
|
|
|
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 );
|
|
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( '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( [] );
|
|
}
|
|
}
|
|
} );
|