import { expect, test } from '@playwright/test'; const REM_46 = 46 * 16; const landings = [ { name: 'Music', path: '/music/', root: '.chrnx-music-landing', atmosphere: '.chrnx-character-stage__collage', art: 'img[src*="the-no-names-musician-cutout.png"]', next: ':scope > p', }, { name: 'Podcast', path: '/podcasts/', root: '.chrnx-podcast-landing', atmosphere: '.chrnx-character-stage__frequency', art: 'img[src*="alter-ego-podcasts.png"]', next: ':scope > .wp-block-chrnx-latest-podcast', }, ]; async function setTheme( page, theme ) { await page.addInitScript( ( value ) => localStorage.setItem( 'chrnx-theme', value ), theme ); } async function expectNoHorizontalOverflow( page ) { const overflow = await page.evaluate( () => Math.max( document.documentElement.scrollWidth - window.innerWidth, document.body.scrollWidth - window.innerWidth, ), ); expect( overflow ).toBeLessThanOrEqual( 1 ); } async function readStage( page, landing ) { return page.locator( landing.root ).evaluate( ( root, value ) => { const readRect = ( element ) => { const bounds = element.getBoundingClientRect(); return { bottom: bounds.bottom, height: bounds.height, left: bounds.left, right: bounds.right, top: bounds.top, width: bounds.width, }; }; const stage = root.querySelector( '.chrnx-character-stage' ); const atmosphereLayer = stage.querySelector( '.chrnx-character-stage__atmosphere' ); const atmosphere = stage.querySelector( value.atmosphere ); const content = stage.querySelector( '.chrnx-character-stage__content' ); const artLayer = stage.querySelector( '.chrnx-character-stage__art' ); const art = stage.querySelector( value.art ); const next = root.querySelector( value.next ); const stageRect = readRect( stage ); const atmosphereLayerRect = readRect( atmosphereLayer ); const atmosphereRect = readRect( atmosphere ); const contentRect = readRect( content ); const artLayerRect = readRect( artLayer ); const artRect = readRect( art ); const nextRect = readRect( next ); const contained = ( child, parent ) => child.left >= parent.left - 1 && child.right <= parent.right + 1 && child.top >= parent.top - 1 && child.bottom <= parent.bottom + 1; const overlaps = ( first, second ) => first.left < second.right - 1 && first.right > second.left + 1 && first.top < second.bottom - 1 && first.bottom > second.top + 1; return { stage: stageRect, atmosphere: atmosphereRect, atmosphereLayer: atmosphereLayerRect, atmosphereFit: window.getComputedStyle( atmosphere ).objectFit, atmosphereHidden: atmosphereLayer.getAttribute( 'aria-hidden' ), atmosphereContained: contained( atmosphereRect, stageRect ), content: contentRect, contentMinWidth: window.getComputedStyle( content ).minWidth, art: artRect, artLayer: artLayerRect, artContained: contained( artRect, artLayerRect ) && contained( artLayerRect, stageRect ), artBottomGap: Math.abs( stageRect.bottom - artLayerRect.bottom ), contentArtOverlap: overlaps( contentRect, artLayerRect ), next: nextRect, nextOverlap: overlaps( stageRect, nextRect ), stageOverflow: stage.scrollWidth - stage.clientWidth, rootOverflow: root.scrollWidth - root.clientWidth, }; }, landing ); } test( 'Music and Podcast main titles stay centered while internal headings stay aligned', async ( { page, } ) => { test.setTimeout( 90_000 ); for ( const theme of [ 'dark', 'light' ] ) { await setTheme( page, theme ); for ( const width of [ 375, 768, 1440 ] ) { await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } ); for ( const landing of landings ) { await page.goto( landing.path ); const state = await page.locator( landing.root ).evaluate( ( root, landingName ) => { const title = root.querySelector( '.chrnx-character-stage__content > h2' ); const content = title.parentElement; const internal = landingName === 'Music' ? root.querySelector( ':scope > h3' ) : root.querySelector( '.chrnx-podcast-card__title' ); const titleRect = title.getBoundingClientRect(); const contentRect = content.getBoundingClientRect(); const titleStyle = window.getComputedStyle( title ); return { alignment: titleStyle.textAlign, centerDelta: Math.abs( ( titleRect.left + titleRect.right ) / 2 - ( contentRect.left + contentRect.right ) / 2, ), marginLeft: Number.parseFloat( titleStyle.marginLeft ), marginRight: Number.parseFloat( titleStyle.marginRight ), internalAlignment: window.getComputedStyle( internal ).textAlign, }; }, landing.name ); expect( state.alignment, `${ landing.name } ${ theme } ${ width }px title` ).toBe( 'center', ); expect( state.centerDelta ).toBeLessThanOrEqual( 1 ); expect( Math.abs( state.marginLeft - state.marginRight ) ).toBeLessThanOrEqual( 1 ); expect( state.internalAlignment ).toBe( 'start' ); } } } } ); test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both themes', async ( { page, } ) => { test.setTimeout( 90_000 ); await page.setViewportSize( { width: 1440, height: 900 } ); for ( const theme of [ 'dark', 'light' ] ) { await setTheme( page, theme ); for ( const landing of landings ) { await page.goto( landing.path ); const state = await readStage( page, landing ); expect( state.stage.height, `${ landing.name } ${ theme } stage height` ).toBeLessThanOrEqual( Math.min( 900, REM_46 ) + 1, ); expect( state.atmosphereContained ).toBeTruthy(); expect( state.atmosphereFit ).toBe( 'cover' ); expect( state.artContained ).toBeTruthy(); expect( state.artBottomGap ).toBeLessThanOrEqual( 1 ); expect( state.contentArtOverlap ).toBeFalsy(); expect( state.next.top ).toBeGreaterThanOrEqual( state.stage.bottom - 1 ); expect( state.nextOverlap ).toBeFalsy(); expect( state.stageOverflow ).toBeLessThanOrEqual( 1 ); expect( state.rootOverflow ).toBeLessThanOrEqual( 1 ); if ( landing.name === 'Podcast' ) { expect( state.atmosphereHidden ).toBe( 'true' ); } await expectNoHorizontalOverflow( page ); } } } ); test( 'latest podcast preserves a real 28ch content column and bounded media', async ( { page, } ) => { await page.setViewportSize( { width: 1440, height: 900 } ); await page.goto( '/podcasts/' ); const state = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => { const readRect = ( element ) => { const bounds = element.getBoundingClientRect(); return { bottom: bounds.bottom, height: bounds.height, left: bounds.left, right: bounds.right, top: bounds.top, width: bounds.width, }; }; const 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 title = content.querySelector( '.chrnx-podcast-card__title' ); const probe = document.createElement( 'span' ); const titleStyle = window.getComputedStyle( title ); Object.assign( probe.style, { fontFamily: titleStyle.fontFamily, fontSize: titleStyle.fontSize, fontWeight: titleStyle.fontWeight, position: 'fixed', visibility: 'hidden', width: '28ch', } ); document.body.append( probe ); const probeWidth = probe.getBoundingClientRect().width; probe.remove(); const panelRect = readRect( panel ); const linkRect = readRect( link ); const mediaRect = readRect( media ); const contentRect = readRect( content ); return { display: window.getComputedStyle( link ).display, columns: window.getComputedStyle( link ).gridTemplateColumns, contentMinWidth: window.getComputedStyle( content ).minWidth, contentWidth: contentRect.width, probeWidth, mediaRatio: mediaRect.width / linkRect.width, mediaContained: mediaRect.left >= linkRect.left - 1 && mediaRect.right <= linkRect.right + 1, panelOverflow: panel.scrollWidth - panel.clientWidth, linkOverflow: link.scrollWidth - link.clientWidth, contentOverflow: content.scrollWidth - content.clientWidth, panelHeight: panelRect.height, }; } ); expect( state.display ).toBe( 'grid' ); expect( state.columns.split( ' ' ) ).toHaveLength( 2 ); expect( state.contentMinWidth ).toBe( '0px' ); expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 ); expect( state.mediaRatio ).toBeGreaterThanOrEqual( 0.28 ); expect( state.mediaRatio ).toBeLessThanOrEqual( 0.42 ); expect( state.mediaContained ).toBeTruthy(); expect( state.panelOverflow ).toBeLessThanOrEqual( 1 ); expect( state.linkOverflow ).toBeLessThanOrEqual( 1 ); expect( state.contentOverflow ).toBeLessThanOrEqual( 1 ); } ); test( 'mobile and tablet preserve text then art then following content', async ( { page } ) => { for ( const width of [ 375, 768 ] ) { await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } ); for ( const landing of landings ) { await page.goto( landing.path ); const state = await readStage( page, landing ); expect( state.content.height ).toBeGreaterThan( 0 ); expect( state.art.height ).toBeGreaterThan( 0 ); expect( state.content.bottom ).toBeLessThanOrEqual( state.artLayer.top + 1 ); expect( state.artLayer.bottom ).toBeLessThanOrEqual( state.next.top + 1 ); expect( state.contentArtOverlap ).toBeFalsy(); expect( state.nextOverlap ).toBeFalsy(); expect( state.stageOverflow ).toBeLessThanOrEqual( 1 ); await expectNoHorizontalOverflow( page ); } } } ); test( 'latest podcast stacks at 720px and becomes two columns at 721px', async ( { page } ) => { for ( const [ width, expectedColumns ] of [ [ 720, 1 ], [ 721, 2 ], ] ) { await page.setViewportSize( { width, height: 1024 } ); await page.goto( '/podcasts/' ); const columns = await page .locator( '.chrnx-podcast-card__link' ) .evaluate( ( link ) => window.getComputedStyle( link ).gridTemplateColumns.split( ' ' ).length, ); expect( columns, `${ width }px columns` ).toBe( expectedColumns ); await expectNoHorizontalOverflow( page ); } } ); test( '200 percent zoom contains Music copy and Podcast card at narrow and wide viewports', async ( { page, } ) => { test.setTimeout( 90_000 ); for ( const width of [ 375, 1440 ] ) { await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); for ( const landing of landings ) { await page.goto( landing.path ); await page.evaluate( () => { document.documentElement.style.zoom = '2'; } ); expect( await page.evaluate( () => window.getComputedStyle( document.documentElement ).zoom ), ).toBe( '2' ); const result = await page.locator( landing.root ).evaluate( ( root ) => { const readRect = ( element ) => { const bounds = element.getBoundingClientRect(); return { bottom: bounds.bottom, height: bounds.height, left: bounds.left, right: bounds.right, top: bounds.top, width: bounds.width, }; }; const stage = root.querySelector( '.chrnx-character-stage' ); const content = stage.querySelector( '.chrnx-character-stage__content' ); const title = root.querySelector( 'h2, h3, .chrnx-podcast-card__title' ); const card = root.querySelector( '.chrnx-latest-podcast' ); const isContained = ( child, parent ) => { const childRect = readRect( child ); const parentRect = readRect( parent ); return childRect.left >= parentRect.left - 1 && childRect.right <= parentRect.right + 1; }; return { copyContained: isContained( content, stage ), titleClip: title.scrollWidth - title.clientWidth, cardClip: card ? card.scrollWidth - card.clientWidth : 0, stageClip: stage.scrollWidth - stage.clientWidth, }; } ); expect( result.copyContained ).toBeTruthy(); expect( result.titleClip ).toBeLessThanOrEqual( 1 ); expect( result.cardClip ).toBeLessThanOrEqual( 1 ); expect( result.stageClip ).toBeLessThanOrEqual( 1 ); await expectNoHorizontalOverflow( page ); } } } ); test( 'DOM-only long Podcast copy wraps normally without clipping', async ( { page } ) => { for ( const width of [ 375, 1440 ] ) { await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); await page.goto( '/podcasts/' ); const state = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => { const title = panel.querySelector( '.chrnx-podcast-card__title' ); const excerpt = panel.querySelector( '.chrnx-podcast-card__excerpt' ); const content = panel.querySelector( '.chrnx-podcast-card__content' ); title.textContent = 'Conversaciones profundamente humanas sobre software música investigación juegos y comunidad '.repeat( 3, ); excerpt.textContent = 'Una conversación extensa que conserva palabras reales y espacios normales para comprobar el ajuste editorial. '.repeat( 10, ); const link = panel.querySelector( '.chrnx-podcast-card__link' ); const titleStyle = window.getComputedStyle( title ); const probe = document.createElement( 'span' ); Object.assign( probe.style, { fontFamily: titleStyle.fontFamily, fontSize: titleStyle.fontSize, fontWeight: titleStyle.fontWeight, position: 'fixed', visibility: 'hidden', width: '28ch', } ); document.body.append( probe ); const probeWidth = probe.getBoundingClientRect().width; probe.remove(); return { titleLength: title.textContent.length, minWidth: window.getComputedStyle( content ).minWidth, columns: window.getComputedStyle( link ).gridTemplateColumns.split( ' ' ).length, contentWidth: content.getBoundingClientRect().width, probeWidth, overflowWrap: titleStyle.overflowWrap, wordBreak: titleStyle.wordBreak, titleClip: title.scrollWidth - title.clientWidth, excerptClip: excerpt.scrollWidth - excerpt.clientWidth, contentClip: content.scrollWidth - content.clientWidth, linkClip: link.scrollWidth - link.clientWidth, panelClip: panel.scrollWidth - panel.clientWidth, }; } ); expect( state.titleLength ).toBeGreaterThan( 120 ); expect( state.minWidth ).toBe( '0px' ); if ( state.columns === 2 ) { expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 ); } expect( state.overflowWrap ).toBe( 'normal' ); expect( state.wordBreak ).toBe( 'normal' ); expect( state.titleClip ).toBeLessThanOrEqual( 1 ); expect( state.excerptClip ).toBeLessThanOrEqual( 1 ); expect( state.contentClip ).toBeLessThanOrEqual( 1 ); expect( state.linkClip ).toBeLessThanOrEqual( 1 ); expect( state.panelClip ).toBeLessThanOrEqual( 1 ); await expectNoHorizontalOverflow( page ); } } ); const immutableSurfaces = [ { name: 'Projects', path: '/projects/', root: '.chrnx-home-projects', art: 'img[src*="alter-ego-code.png"]', atmosphereCount: 1, imageSources: [ 'alter-ego-research.png', 'alter-ego-code.png' ], headings: [ 'Selected work', 'Expressive Tea', 'Ailed', 'Published research' ], paragraphs: [], contentText: 'Selected work Expressive Tea Ailed Published research', }, { name: 'About', path: '/about/', root: '.chrnx-about', art: 'img[src*="alter-ego-life.png"]', atmosphereCount: 0, imageSources: [ 'alter-ego-life.png', 'alter-ego-literature.png', 'alter-ego-gaming-half-body.png', ], headings: [ 'About', 'Beyond the work' ], paragraphs: [ 'I work as Lead Developer @Expressive Tea, building full-stack software with JavaScript and Python. I am also an independent researcher exploring emotion modeling and game AI; my practice includes open source work and amateur data science.', 'I am a published researcher. My current paper is available on arXiv:2603.05352.', 'I am an autistic Level 1 software developer and researcher.', 'I am the father of three wonderful children, a musician, a gamer, and pet-friendly.', ], contentText: 'About I work as Lead Developer @Expressive Tea, building full-stack software with JavaScript and Python. I am also an independent researcher exploring emotion modeling and game AI; my practice includes open source work and amateur data science. I am a published researcher. My current paper is available on arXiv:2603.05352. I am an autistic Level 1 software developer and researcher. Beyond the work I am the father of three wonderful children, a musician, a gamer, and pet-friendly.', }, ]; test( 'Projects and About assets, copy, layering, and geometry remain immutable', async ( { page, } ) => { test.setTimeout( 90_000 ); for ( const theme of [ 'dark', 'light' ] ) { await setTheme( page, theme ); for ( const width of [ 375, 1440 ] ) { await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); for ( const surface of immutableSurfaces ) { await page.goto( surface.path ); const root = page.locator( surface.root ); for ( const heading of surface.headings ) { await expect( root.getByRole( 'heading', { name: heading, exact: true } ) ).toHaveCount( 1, ); } await expect( root.locator( surface.art ) ).toHaveCount( 1 ); await expect( root.locator( 'picture img' ) ).toHaveCount( surface.imageSources.length ); for ( const source of surface.imageSources ) { await expect( root.locator( `picture img[src*="${ source }"]` ) ).toHaveCount( 1 ); } const approvedCopy = await root .locator( '.chrnx-character-stage__content' ) .evaluate( ( content ) => ( { contentText: content.textContent.trim().replace( /\s+/g, ' ' ), paragraphs: [ ...content.querySelectorAll( ':scope > p' ) ].map( ( paragraph ) => paragraph.textContent.trim().replace( /\s+/g, ' ' ), ), } ) ); expect( approvedCopy.contentText ).toBe( surface.contentText ); expect( approvedCopy.paragraphs ).toEqual( surface.paragraphs ); const state = await root.evaluate( ( element ) => { const readRect = ( target ) => { const bounds = target.getBoundingClientRect(); return { bottom: bounds.bottom, height: bounds.height, left: bounds.left, right: bounds.right, top: bounds.top, width: bounds.width, }; }; const stage = element.querySelector( '.chrnx-character-stage' ); const children = [ ...stage.children ].map( ( child ) => child.className ); const art = stage.querySelector( '.chrnx-character-stage__art' ); const artImage = art.querySelector( 'img' ); const stageRect = readRect( stage ); const artRect = readRect( art ); const imageRect = readRect( artImage ); const contained = ( child, parent ) => child.left >= parent.left - 1 && child.right <= parent.right + 1 && child.top >= parent.top - 1 && child.bottom <= parent.bottom + 1; return { layerOrder: children.map( ( classes ) => [ 'atmosphere', 'content', 'art' ].find( ( layer ) => classes.includes( `chrnx-character-stage__${ layer }` ), ), ), atmospherePictures: stage.querySelectorAll( '.chrnx-character-stage__atmosphere picture', ).length, artRatio: artRect.width / stageRect.width, artFrameContained: contained( artRect, stageRect ), artImageContained: contained( imageRect, artRect ) && contained( imageRect, stageRect ), overflow: stage.scrollWidth - stage.clientWidth, }; } ); expect( state.layerOrder ).toEqual( [ 'atmosphere', 'content', 'art' ] ); expect( state.atmospherePictures ).toBe( surface.atmosphereCount ); expect( state.artFrameContained ).toBeTruthy(); expect( state.artImageContained ).toBeTruthy(); if ( width === 1440 ) { expect( state.artRatio ).toBeGreaterThanOrEqual( 0.35 ); expect( state.artRatio ).toBeLessThanOrEqual( 0.48 ); } expect( state.overflow ).toBeLessThanOrEqual( 1 ); await expectNoHorizontalOverflow( page ); } } } } );