fix: center CHRNX landing titles
This commit is contained in:
2 files changed
+54
-27
No files matched your search
@@ -1320,6 +1320,11 @@ html[data-theme="light"] .chrnx-music-landing .chrnx-character-stage {
|
|||||||
margin-inline: calc((100% - min(calc(100vw - 2rem), var(--wp--style--global--wide-size))) / 2);
|
margin-inline: calc((100% - min(calc(100vw - 2rem), var(--wp--style--global--wide-size))) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chrnx-entry--page:has(.chrnx-music-landing) > .wp-block-post-title,
|
||||||
|
.chrnx-entry--page:has(.chrnx-podcast-landing) > .wp-block-post-title {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.chrnx-music-landing .chrnx-character-stage__atmosphere > .chrnx-responsive-portrait,
|
.chrnx-music-landing .chrnx-character-stage__atmosphere > .chrnx-responsive-portrait,
|
||||||
.chrnx-podcast-landing .chrnx-character-stage__atmosphere > .chrnx-responsive-portrait {
|
.chrnx-podcast-landing .chrnx-character-stage__atmosphere > .chrnx-responsive-portrait {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ const landings = [
|
|||||||
root: '.chrnx-music-landing',
|
root: '.chrnx-music-landing',
|
||||||
atmosphere: '.chrnx-character-stage__collage',
|
atmosphere: '.chrnx-character-stage__collage',
|
||||||
art: 'img[src*="the-no-names-musician-cutout.png"]',
|
art: 'img[src*="the-no-names-musician-cutout.png"]',
|
||||||
|
internalHeadings: ':scope > h3, .chrnx-release-card h4',
|
||||||
|
internalHeadingCount: 4,
|
||||||
next: ':scope > p',
|
next: ':scope > p',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -16,6 +18,8 @@ const landings = [
|
|||||||
root: '.chrnx-podcast-landing',
|
root: '.chrnx-podcast-landing',
|
||||||
atmosphere: '.chrnx-character-stage__frequency',
|
atmosphere: '.chrnx-character-stage__frequency',
|
||||||
art: 'img[src*="alter-ego-podcasts.png"]',
|
art: 'img[src*="alter-ego-podcasts.png"]',
|
||||||
|
internalHeadings: '.chrnx-podcast-card__title',
|
||||||
|
internalHeadingCount: 1,
|
||||||
next: ':scope > .wp-block-chrnx-latest-podcast',
|
next: ':scope > .wp-block-chrnx-latest-podcast',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -94,43 +98,61 @@ async function readStage( page, landing ) {
|
|||||||
}, landing );
|
}, landing );
|
||||||
}
|
}
|
||||||
|
|
||||||
test( 'Music and Podcast main titles stay centered while internal headings stay aligned', async ( {
|
test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( {
|
||||||
page,
|
page,
|
||||||
} ) => {
|
} ) => {
|
||||||
test.setTimeout( 90_000 );
|
test.setTimeout( 90_000 );
|
||||||
for ( const theme of [ 'dark', 'light' ] ) {
|
for ( const theme of [ 'dark', 'light' ] ) {
|
||||||
await setTheme( page, theme );
|
await setTheme( page, theme );
|
||||||
for ( const width of [ 375, 768, 1440 ] ) {
|
for ( const width of [ 375, 1440 ] ) {
|
||||||
await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } );
|
await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } );
|
||||||
for ( const landing of landings ) {
|
for ( const landing of landings ) {
|
||||||
await page.goto( landing.path );
|
await page.goto( landing.path );
|
||||||
const state = await page.locator( landing.root ).evaluate( ( root, landingName ) => {
|
const state = await page.locator( 'main.chrnx-entry--page' ).evaluate( ( main, value ) => {
|
||||||
const title = root.querySelector( '.chrnx-character-stage__content > h2' );
|
const root = main.querySelector( value.root );
|
||||||
const content = title.parentElement;
|
const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' );
|
||||||
const internal =
|
const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' );
|
||||||
landingName === 'Music'
|
const readTitle = ( title ) => {
|
||||||
? root.querySelector( ':scope > h3' )
|
const range = document.createRange();
|
||||||
: root.querySelector( '.chrnx-podcast-card__title' );
|
range.selectNodeContents( title );
|
||||||
const titleRect = title.getBoundingClientRect();
|
const textRect = range.getBoundingClientRect();
|
||||||
const contentRect = content.getBoundingClientRect();
|
const titleRect = title.getBoundingClientRect();
|
||||||
const titleStyle = window.getComputedStyle( title );
|
const style = window.getComputedStyle( title );
|
||||||
return {
|
return {
|
||||||
alignment: titleStyle.textAlign,
|
alignment: style.textAlign,
|
||||||
centerDelta: Math.abs(
|
centerDelta: Math.abs(
|
||||||
( titleRect.left + titleRect.right ) / 2 -
|
( textRect.left + textRect.right ) / 2 - ( titleRect.left + titleRect.right ) / 2,
|
||||||
( contentRect.left + contentRect.right ) / 2,
|
),
|
||||||
),
|
text: title.textContent.trim(),
|
||||||
marginLeft: Number.parseFloat( titleStyle.marginLeft ),
|
};
|
||||||
marginRight: Number.parseFloat( titleStyle.marginRight ),
|
|
||||||
internalAlignment: window.getComputedStyle( internal ).textAlign,
|
|
||||||
};
|
};
|
||||||
}, landing.name );
|
const internalHeadings = [ ...root.querySelectorAll( value.internalHeadings ) ];
|
||||||
expect( state.alignment, `${ landing.name } ${ theme } ${ width }px title` ).toBe(
|
return {
|
||||||
'center',
|
pageTitle: readTitle( pageTitle ),
|
||||||
|
stageTitle: readTitle( stageTitle ),
|
||||||
|
internalAlignments: internalHeadings.map(
|
||||||
|
( heading ) => window.getComputedStyle( heading ).textAlign,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}, landing );
|
||||||
|
expect( state.pageTitle.text ).toBe( landing.name === 'Music' ? 'Music' : 'Podcasts' );
|
||||||
|
expect( state.stageTitle.text ).toBe(
|
||||||
|
landing.name === 'Music' ? 'The No Names' : 'Podcasts',
|
||||||
);
|
);
|
||||||
expect( state.centerDelta ).toBeLessThanOrEqual( 1 );
|
for ( const [ titleKind, title ] of Object.entries( {
|
||||||
expect( Math.abs( state.marginLeft - state.marginRight ) ).toBeLessThanOrEqual( 1 );
|
'page H1': state.pageTitle,
|
||||||
expect( state.internalAlignment ).toBe( 'start' );
|
'stage H2': state.stageTitle,
|
||||||
|
} ) ) {
|
||||||
|
expect(
|
||||||
|
title.alignment,
|
||||||
|
`${ landing.name } ${ theme } ${ width }px ${ titleKind }`,
|
||||||
|
).toBe( 'center' );
|
||||||
|
expect( title.centerDelta ).toBeLessThanOrEqual( 1 );
|
||||||
|
}
|
||||||
|
expect( state.internalAlignments ).toHaveLength( landing.internalHeadingCount );
|
||||||
|
expect(
|
||||||
|
state.internalAlignments.every( ( alignment ) => alignment === 'start' ),
|
||||||
|
).toBeTruthy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user