fix: let mobile hero grow with content
This commit is contained in:
3 files changed
+61
-21
No files matched your search
@@ -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/';
|
||||
|
||||
Reference in new issue
Block a user