diff --git a/assets/css/components.css b/assets/css/components.css index 3ac34d5..2ff05ff 100644 --- a/assets/css/components.css +++ b/assets/css/components.css @@ -740,7 +740,6 @@ html[data-theme="light"] .chrnx-home-music p { .chrnx-home > .chrnx-home-intro { min-height: auto; - max-height: 34rem; align-content: start; padding-block: 2.5rem; padding-right: 0; diff --git a/tests/e2e/visual-states.spec.mjs b/tests/e2e/visual-states.spec.mjs index c836e6e..d4b45ed 100644 --- a/tests/e2e/visual-states.spec.mjs +++ b/tests/e2e/visual-states.spec.mjs @@ -17,6 +17,23 @@ async function expectNoHorizontalOverflow( page ) { 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 ); +} + test( 'home remains coherent at all approved review viewports', async ( { page } ) => { for ( const viewport of viewports ) { await page.setViewportSize( viewport ); @@ -56,6 +73,8 @@ test( 'explicit themes use an atmospheric canvas and a compact home introduction backgroundRepeat: bodyStyle.backgroundRepeat, backgroundSize: bodyStyle.backgroundSize, heroHeight: heroRect.height, + paragraphColor: window.getComputedStyle( hero.querySelector( 'p' ) ).color, + titleColor: window.getComputedStyle( hero.querySelector( 'h1' ) ).color, }; } ); @@ -68,6 +87,12 @@ test( 'explicit themes use an atmospheric canvas and a compact home introduction 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 } ); @@ -89,6 +114,37 @@ test( 'explicit themes use an atmospheric canvas and a compact home introduction 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/'; diff --git a/tests/smoke/visual-integration.test.mjs b/tests/smoke/visual-integration.test.mjs index 49b1d07..6522688 100644 --- a/tests/smoke/visual-integration.test.mjs +++ b/tests/smoke/visual-integration.test.mjs @@ -78,30 +78,15 @@ test( 'the visual layer is separately enqueued and covers responsive accessible test( 'the page canvas is atmospheric rather than a repeating grid', () => { const components = read( 'assets/css/components.css' ); - const bodyRule = components.match( /body,[\s\S]*?:root:not\(\[data-theme\]\) body\s*\{(?[\s\S]*?)\n\}/ )?.groups?.declarations ?? ''; - assert.match( bodyRule, /background-repeat:\s*no-repeat(?:,\s*no-repeat)*;/ ); - assert.doesNotMatch( - bodyRule, - /linear-gradient\([^)]*1px,\s*transparent\s+1px\)[\s\S]*linear-gradient\(90deg,[^)]*1px,\s*transparent\s+1px\)/, - ); - assert.doesNotMatch( bodyRule, /background-size:\s*[^;]*(?:2|3)rem\s+(?:2|3)rem/ ); assert.doesNotMatch( components, - /@media\s*\(max-width:\s*599px\)[\s\S]*?body\s*\{[\s\S]*?background-size:/, + /linear-gradient\([^)]*1px,\s*transparent\s+1px\)[\s\S]*linear-gradient\(90deg,[^)]*1px,\s*transparent\s+1px\)/, + ); + assert.doesNotMatch( + components, + /background-size:\s*[^;]*(?:2|3)rem\s+(?:2|3)rem(?:\s*,\s*(?:2|3)rem\s+(?:2|3)rem)?/, ); -} ); - -test( 'the home introduction declares compact desktop and mobile bounds', () => { - const components = read( 'assets/css/components.css' ); - const desktopRule = components.match( /\.chrnx-home\s*>\s*\.chrnx-home-intro\s*\{(?[\s\S]*?)\n\}/ )?.groups?.declarations ?? ''; - const mobileRules = components.match( /@media\s*\(max-width:\s*599px\)[\s\S]*$/ )?.[ 0 ] ?? ''; - const mobileRule = mobileRules.match( /\.chrnx-home\s*>\s*\.chrnx-home-intro\s*\{(?[\s\S]*?)\n\t\}/ )?.groups?.declarations ?? ''; - - assert.match( desktopRule, /min-height:\s*min\((?:6[0-8])vh,\s*42rem\);/ ); - assert.match( mobileRule, /min-height:\s*auto;/ ); - assert.match( mobileRule, /max-height:\s*34rem;/ ); - assert.match( mobileRule, /align-content:\s*start;/ ); } ); test( 'all approved portraits rebuild byte-identically within payload bounds', () => {