test: require CHRNX podcast media
This commit is contained in:
2 files changed
+59
-9
No files matched your search
@@ -1220,23 +1220,23 @@ const musicPodcastLandingCases = [
|
|||||||
copy: 'Conversations about the work behind software, research, music, and games.',
|
copy: 'Conversations about the work behind software, research, music, and games.',
|
||||||
atmosphere: 'img[src*="podcast-frequency-grunge.png"]',
|
atmosphere: 'img[src*="podcast-frequency-grunge.png"]',
|
||||||
art: 'img[src*="alter-ego-podcasts.png"]',
|
art: 'img[src*="alter-ego-podcasts.png"]',
|
||||||
latestMedia: '.chrnx-latest-podcast img',
|
latestMedia:
|
||||||
|
'.chrnx-latest-podcast .chrnx-podcast-card__image, .chrnx-latest-podcast .chrnx-podcast-card__fallback',
|
||||||
supporting: '.chrnx-latest-podcast',
|
supporting: '.chrnx-latest-podcast',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
async function waitForDecodedLandingImages( page, landing, { awaitDecode = true } = {} ) {
|
async function waitForDecodedLandingImages( page, landing, { awaitDecode = true } = {} ) {
|
||||||
const selectors = [ landing.atmosphere, landing.art ];
|
const root = page.locator( landing.root );
|
||||||
if ( landing.latestMedia ) {
|
const imageExpectations = [
|
||||||
selectors.push( landing.latestMedia );
|
{ name: 'atmosphere', selector: landing.atmosphere, count: 1 },
|
||||||
}
|
{ name: 'art', selector: landing.art, count: 1 },
|
||||||
const images = page.locator( landing.root ).locator( selectors.join( ', ' ) );
|
];
|
||||||
|
|
||||||
|
const decodeImages = async ( images ) => {
|
||||||
await expect
|
await expect
|
||||||
.poll( () =>
|
.poll( () =>
|
||||||
images.evaluateAll(
|
images.evaluateAll( ( elements ) =>
|
||||||
( elements ) =>
|
|
||||||
elements.length >= 2 &&
|
|
||||||
elements.every(
|
elements.every(
|
||||||
( image ) => image.complete && image.naturalWidth > 0 && image.naturalHeight > 0,
|
( image ) => image.complete && image.naturalWidth > 0 && image.naturalHeight > 0,
|
||||||
),
|
),
|
||||||
@@ -1270,6 +1270,49 @@ async function waitForDecodedLandingImages( page, landing, { awaitDecode = true
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
};
|
||||||
|
|
||||||
|
for ( const imageExpectation of imageExpectations ) {
|
||||||
|
const images = root.locator( imageExpectation.selector );
|
||||||
|
await expect( images, `${ landing.name } ${ imageExpectation.name } image` ).toHaveCount(
|
||||||
|
imageExpectation.count,
|
||||||
|
);
|
||||||
|
await decodeImages( images );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! landing.latestMedia ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const latestMedia = root.locator( landing.latestMedia );
|
||||||
|
await expect( latestMedia, `${ landing.name } latest media` ).toHaveCount( 1 );
|
||||||
|
const latestMediaKind = await latestMedia.evaluate( ( media ) => media.tagName );
|
||||||
|
if ( latestMediaKind === 'IMG' ) {
|
||||||
|
await expect( latestMedia ).not.toHaveAttribute( 'aria-hidden', 'true' );
|
||||||
|
await decodeImages( latestMedia );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect( latestMediaKind ).toBe( 'SPAN' );
|
||||||
|
await expect( latestMedia ).toHaveClass( /chrnx-podcast-card__fallback/ );
|
||||||
|
await expect( latestMedia ).toHaveAttribute( 'aria-hidden', 'true' );
|
||||||
|
await expect( latestMedia ).not.toHaveAttribute( 'role', /.+/ );
|
||||||
|
await expect( root.locator( '.chrnx-latest-podcast img' ) ).toHaveCount( 0 );
|
||||||
|
const fallbackState = await latestMedia.evaluate( ( media ) => {
|
||||||
|
const bounds = media.getBoundingClientRect();
|
||||||
|
const style = window.getComputedStyle( media );
|
||||||
|
return {
|
||||||
|
height: bounds.height,
|
||||||
|
visible:
|
||||||
|
style.display !== 'none' &&
|
||||||
|
style.visibility !== 'hidden' &&
|
||||||
|
Number.parseFloat( style.opacity ) > 0,
|
||||||
|
width: bounds.width,
|
||||||
|
};
|
||||||
|
} );
|
||||||
|
expect( fallbackState.visible ).toBeTruthy();
|
||||||
|
expect( fallbackState.width ).toBeGreaterThan( 0 );
|
||||||
|
expect( fallbackState.height ).toBeGreaterThan( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readMusicPodcastLandingState( page, landing ) {
|
async function readMusicPodcastLandingState( page, landing ) {
|
||||||
|
|||||||
@@ -533,6 +533,13 @@ test( 'Music and Podcast visual states decode every relevant image before measur
|
|||||||
const visualStates = read( 'tests/e2e/visual-states.spec.mjs' );
|
const visualStates = read( 'tests/e2e/visual-states.spec.mjs' );
|
||||||
|
|
||||||
assert.match( visualStates, /async function waitForDecodedLandingImages/ );
|
assert.match( visualStates, /async function waitForDecodedLandingImages/ );
|
||||||
|
assert.doesNotMatch( visualStates, /elements\.length >= 2/ );
|
||||||
|
assert.match( visualStates, /for \( const imageExpectation of imageExpectations \)/ );
|
||||||
|
assert.match( visualStates, /toHaveCount\(\s*imageExpectation\.count/ );
|
||||||
|
assert.match( visualStates, /latestMedia[^]*?toHaveCount\( 1 \)/ );
|
||||||
|
assert.match( visualStates, /latestMediaKind === 'IMG'[^]*?decodeImages\( latestMedia \)/ );
|
||||||
|
assert.match( visualStates, /chrnx-podcast-card__fallback[^]*?aria-hidden[^]*?'true'/ );
|
||||||
|
assert.match( visualStates, /chrnx-latest-podcast img' \) \)\.toHaveCount\( 0 \)/ );
|
||||||
assert.match( visualStates, /image\.complete/ );
|
assert.match( visualStates, /image\.complete/ );
|
||||||
assert.match( visualStates, /image\.naturalWidth > 0/ );
|
assert.match( visualStates, /image\.naturalWidth > 0/ );
|
||||||
assert.match( visualStates, /image\.naturalHeight > 0/ );
|
assert.match( visualStates, /image\.naturalHeight > 0/ );
|
||||||
|
|||||||
Reference in new issue
Block a user