64 lines
2.8 KiB
JavaScript
64 lines
2.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import test from 'node:test';
|
|
|
|
test( 'Related Stories metadata exposes only the approved server attributes', async () => {
|
|
const metadata = JSON.parse( await readFile( 'blocks/related-posts/block.json', 'utf8' ) );
|
|
|
|
assert.deepEqual( metadata.attributes.limit, {
|
|
type: 'integer',
|
|
default: 3,
|
|
enum: [ 3, 5 ],
|
|
} );
|
|
assert.deepEqual( metadata.attributes.layout, {
|
|
type: 'string',
|
|
default: 'adaptive',
|
|
enum: [ 'adaptive', 'grid', 'carousel' ],
|
|
} );
|
|
} );
|
|
|
|
test( 'Related Stories owns one exact local progressive controller', async () => {
|
|
const metadata = JSON.parse( await readFile( 'blocks/related-posts/block.json', 'utf8' ) );
|
|
|
|
assert.equal( metadata.viewScript, 'file:../../assets/js/related-posts.js' );
|
|
assert.equal( Object.hasOwn( metadata, 'viewScriptModule' ), false );
|
|
await readFile( 'assets/js/related-posts.js', 'utf8' );
|
|
} );
|
|
|
|
test( 'Related Stories CSS owns responsive grid and rail contracts', async () => {
|
|
const css = await readFile( 'blocks/related-posts/style.css', 'utf8' );
|
|
|
|
for ( const selector of [
|
|
'.chrnx-related-posts.is-layout-adaptive',
|
|
'.chrnx-related-posts.is-layout-grid',
|
|
'.chrnx-related-posts.is-layout-carousel',
|
|
] ) {
|
|
assert.match( css, new RegExp( selector.replaceAll( '.', '\\.' ) ) );
|
|
}
|
|
assert.match( css, /@media \(max-width: 900px\)/ );
|
|
assert.match( css, /@media \(min-width: 901px\)/ );
|
|
assert.match( css, /overflow-x:\s*auto/ );
|
|
assert.match( css, /scroll-snap-type:\s*x mandatory/ );
|
|
assert.match( css, /scroll-snap-align:\s*start/ );
|
|
assert.match( css, /flex:\s*0 0 calc\(100% - clamp\(3rem, 12vw, 7rem\)\)/ );
|
|
assert.match( css, /grid-template-columns:\s*repeat\(3, minmax\(0, 1fr\)\)/ );
|
|
assert.match( css, /\[hidden\][^{]*\{[^}]*display:\s*none\s*!important/s );
|
|
assert.match( css, /min-width:\s*45px/ );
|
|
assert.match( css, /min-height:\s*45px/ );
|
|
assert.match( css, /html\[data-theme="dark"\][^{]*\{[^}]*--chrnx-related-focus-ring:\s*var\(--wp--preset--color--green\)/s );
|
|
assert.match( css, /html\[data-theme="light"\][^{]*\{[^}]*--chrnx-related-focus-ring:\s*var\(--wp--preset--color--light-green\)/s );
|
|
assert.match( css, /:focus-visible[^}]*var\(--chrnx-related-focus-ring\)/s );
|
|
assert.match( css, /@media \(prefers-reduced-motion: reduce\)[^{]*\{[\s\S]*scroll-behavior:\s*auto/ );
|
|
|
|
assert.doesNotMatch( css, /animation(?:-\w+)?:|autoplay/i );
|
|
assert.doesNotMatch( css, /scrollbar-width:\s*none|::-webkit-scrollbar|-ms-overflow-style/i );
|
|
assert.doesNotMatch(
|
|
css,
|
|
/(?:^|[},])\s*(?:html|body|\.wp-site-blocks)[^{]*\{[^}]*overflow-x:\s*hidden/is,
|
|
);
|
|
assert.doesNotMatch(
|
|
css,
|
|
/\.chrnx-related-card[^{]*\{[^}]*(?:width|flex-basis):\s*\d+(?:\.\d+)?px/is,
|
|
);
|
|
} );
|