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);
|
||||
}
|
||||
|
||||
.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-podcast-landing .chrnx-character-stage__atmosphere > .chrnx-responsive-portrait {
|
||||
position: absolute;
|
||||
|
||||
@@ -8,6 +8,8 @@ const landings = [
|
||||
root: '.chrnx-music-landing',
|
||||
atmosphere: '.chrnx-character-stage__collage',
|
||||
art: 'img[src*="the-no-names-musician-cutout.png"]',
|
||||
internalHeadings: ':scope > h3, .chrnx-release-card h4',
|
||||
internalHeadingCount: 4,
|
||||
next: ':scope > p',
|
||||
},
|
||||
{
|
||||
@@ -16,6 +18,8 @@ const landings = [
|
||||
root: '.chrnx-podcast-landing',
|
||||
atmosphere: '.chrnx-character-stage__frequency',
|
||||
art: 'img[src*="alter-ego-podcasts.png"]',
|
||||
internalHeadings: '.chrnx-podcast-card__title',
|
||||
internalHeadingCount: 1,
|
||||
next: ':scope > .wp-block-chrnx-latest-podcast',
|
||||
},
|
||||
];
|
||||
@@ -94,43 +98,61 @@ async function readStage( page, 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,
|
||||
} ) => {
|
||||
test.setTimeout( 90_000 );
|
||||
for ( const theme of [ 'dark', 'light' ] ) {
|
||||
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 } );
|
||||
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,
|
||||
const state = await page.locator( 'main.chrnx-entry--page' ).evaluate( ( main, value ) => {
|
||||
const root = main.querySelector( value.root );
|
||||
const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' );
|
||||
const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' );
|
||||
const readTitle = ( title ) => {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents( title );
|
||||
const textRect = range.getBoundingClientRect();
|
||||
const titleRect = title.getBoundingClientRect();
|
||||
const style = window.getComputedStyle( title );
|
||||
return {
|
||||
alignment: style.textAlign,
|
||||
centerDelta: Math.abs(
|
||||
( textRect.left + textRect.right ) / 2 - ( titleRect.left + titleRect.right ) / 2,
|
||||
),
|
||||
text: title.textContent.trim(),
|
||||
};
|
||||
};
|
||||
}, landing.name );
|
||||
expect( state.alignment, `${ landing.name } ${ theme } ${ width }px title` ).toBe(
|
||||
'center',
|
||||
const internalHeadings = [ ...root.querySelectorAll( value.internalHeadings ) ];
|
||||
return {
|
||||
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 );
|
||||
expect( Math.abs( state.marginLeft - state.marginRight ) ).toBeLessThanOrEqual( 1 );
|
||||
expect( state.internalAlignment ).toBe( 'start' );
|
||||
for ( const [ titleKind, title ] of Object.entries( {
|
||||
'page H1': state.pageTitle,
|
||||
'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