Files
wordpress-theme-aksrt/tests/widget-system/lightbox-contract.test.cjs
T

60 lines
2.5 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
test('runtime exposes the article media settings to the single lightbox owner', () => {
const scripts = read('src/Core/ScriptsPart1c.php');
const enhancements = read('assets/js/enhancements.js');
assert.match(scripts, /Settings::get_post_page_settings\(\)/);
for (const key of ['lightbox', 'lightbox_thumbs', 'lightbox_zoom', 'lightbox_full', 'lightbox_play', 'lightbox_down']) {
assert.match(scripts, new RegExp(`['"]${key}['"]`));
}
assert.doesNotMatch(scripts, /'imgbox'\s*=>\s*false/);
assert.match(enhancements, /window\._win/);
assert.doesNotMatch(enhancements, /aksrtData\.imgbox/);
});
test('the modern lightbox owns content, galleries and explicit links without a hard size gate', () => {
const enhancements = read('assets/js/enhancements.js');
const gallery = read('templates/parts/content-gallery.php');
assert.match(enhancements, /data-aksrt-lightbox-trigger/);
assert.match(enhancements, /data-caption/);
assert.match(enhancements, /data-lazy-src/);
assert.doesNotMatch(enhancements, /img\.width\s*<\s*100/);
assert.doesNotMatch(enhancements, /img\.height\s*<\s*100/);
assert.match(gallery, /data-aksrt-lightbox/);
});
test('legacy overlay and imgbox entry points are no longer enqueued or built', () => {
const scripts = read('src/Core/ScriptsPart1c.php');
const build = read('tools/build-public-assets.mjs');
const loader = read('assets/js/runtime/loader.js');
const part2 = read('inc/core-hooks/part-2.php');
const single = read('single.php');
const page = read('page.php');
assert.doesNotMatch(scripts, /needs_page_template[^\n]*lightbox/);
assert.doesNotMatch(read('assets/js/page-template.js'), /function initLightbox|lightbox-overlay/);
assert.doesNotMatch(build, /assets\/js\/runtime\/imgbox/);
assert.doesNotMatch(loader, /['"]imgbox['"]\s*:/);
assert.doesNotMatch(part2, /aksrt_print_win_var/);
assert.doesNotMatch(single, /id="lightbox-overlay"/);
assert.doesNotMatch(page, /id="lightbox-overlay"/);
});
test('non-navigational page media and carousel images opt into the shared contract', () => {
const page = read('page.php');
const carousel = read('inc/core-hooks/part-3.php');
assert.match(page, /entry-thumb[^>]*data-aksrt-lightbox/);
assert.match(carousel, /data-aksrt-lightbox/);
});