Files
wordpress-theme-aksrt/tests/widget-system/frontend-lifecycle-contract.test.cjs
kate522andClaude Opus 5 427968a721 chore(branding): remove leftover upstream theme identifiers
The theme was renamed Zibll/子比 → AKSRT → Jio, but upstream branding
survived the sweeps in CSS classes, the SVG sprite prefix, a persisted
widget field ID, JS events, admin Vue class names, test infrastructure
and docblocks.

Renames:
- zib-widget / zib-widget-wrap / zib-slider → jio-widget-box /
  jio-widget-box-wrap / jio-slider-box (jio-widget is taken by the modern
  widget shell, jio-box-* by the card primitives)
- zib-partners-scroll + zps-* → jio-partners-scroll + jps-*
- zib-combo-info-card + zci-* → jio-combo-info-card + jci-*
- zibsvg- → jiosvg-, including the exported picker helpers and the
  fa-zibsvg- family-prefix guard
- zibpay_type → pay_type; the dual-read fallback in PostQuery collapses
  to a single key
- [zibajax="submit"] dropped (no PHP emitter); zib_ajax.success →
  jio_ajax.success
- aks-* admin Vue classes → jio-*
- zib_palette() → palette()

User-facing vendor traces are gone: the floating "more" button default no
longer ships a zibll.com link or 子比主题 marketing copy, the notice
widget ships no preset promo entries, and the four 官网教程 links are
removed from the post-list admin schema.

Test infrastructure renamed to neutral names (docker-compose.reference.yml,
Caddyfile, article-baseline.json, modern-widgets-contract.test.cjs) with
their DB/volume/env/slug identifiers following.

Kept intentionally, documented in tests/fixtures/README.md: the golden
fixture reference fingerprint (a SHA-256 record of an external directory,
read by validate-widget-golden / generate-widget-golden-fixture /
audit-widget-system), the doesNotMatch guards that prove the old tokens are
gone, and the reference theme's own meta key in the visual fixtures.

No backward-compat or data migration: saved widget configs holding old
icon keys or the old field ID silently lose them, per the project's
rewrite-over-compatibility rule.

Verified: 132/132 node contract tests, php tests/widget-system/run.php
(146 assertions), audit-admin-contracts, audit-psr4-paths and
validate-widget-golden all green; tracked bundles regenerated and in sync.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-02 00:06:54 +08:00

225 lines
10 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 vm = require('node:vm');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
function sourceFiles(directory) {
const files = [];
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
if (['.git', 'build', 'node_modules', 'runtime', 'third-party', 'vendor'].includes(entry.name)) continue;
if (/\.min\.js$/.test(entry.name)) continue;
const full = path.join(directory, entry.name);
if (entry.isDirectory()) files.push(...sourceFiles(full));
else if (/\.(?:js|cjs|mjs|php)$/.test(entry.name)) files.push(full);
}
return files;
}
const routed = [
'assets/js/auth.js',
'assets/js/author.js',
'assets/js/credits.js',
'assets/js/order-center.js',
'assets/js/routes/user-center.js',
'assets/js/signin.js',
'assets/js/section-navs.js',
];
test('loader maps and boots the single main module', () => {
const loader = read('assets/js/runtime/loader.js');
assert.match(loader, /['"]main['"]\s*:\s*['"]main\.min['"]/);
assert.match(loader, /tbquire\(\[['"]main['"]\]\)/);
assert.equal((loader.match(/tbquire\(\[['"]main['"]\]\)/g) || []).length, 1);
});
test('main owns the one global auto_fun boot', () => {
const main = read('assets/js/runtime/main.js');
assert.match(main, /window\.auto_fun\s*=\s*debounce\(/);
assert.match(main, /jQuery\(document\)\.trigger\(['"]auto_fun['"]\)/);
});
test('theme and comments do not depend on the removed jio namespace APIs', () => {
const theme = read('assets/js/core/theme.js');
const comments = read('assets/js/comment-ajax.js');
const runtime = read('assets/js/runtime/main.min.js');
assert.match(theme, /window\.jioData\.themeMode/);
assert.doesNotMatch(theme, /(?:window\.)?jio\.toggleTheme/);
assert.doesNotMatch(comments, /(?:window\.)?jio\.(?:__|confirm)/);
assert.doesNotMatch(runtime, /(?:window\.)?jio\.(?:toggleTheme|__|confirm)/);
});
test('theme initializes when the removed jio namespace is absent', () => {
const classList = { toggle() {}, contains() { return false; } };
const document = {
readyState: 'complete',
cookie: '',
body: { classList, setAttribute() {} },
documentElement: { classList, setAttribute() {} },
head: { appendChild() {} },
querySelector() { return null; },
querySelectorAll() { return []; },
getElementById() { return null; },
createElement() { return { setAttribute() {} }; },
dispatchEvent() {},
};
const window = {
document,
location: { protocol: 'https:' },
localStorage: { getItem() { return null; }, setItem() {} },
matchMedia() { return { matches: false }; },
setTimeout,
innerWidth: 1280,
innerHeight: 720,
};
assert.doesNotThrow(() => vm.runInNewContext(read('assets/js/core/theme.js'), {
window,
document,
localStorage: window.localStorage,
CustomEvent: class {},
Date,
Math,
}));
assert.equal(window.jio, undefined);
});
test('routed modules use one namespaced auto_fun owner and no registry', () => {
for (const file of routed) {
const source = read(file);
assert.match(source, /\.off\(['"]auto_fun\.[^'"]+['"]\)\.on\(['"]auto_fun\.[^'"]+['"]/, file);
assert.doesNotMatch(source, /JioFrontend|jio\.autoFun|jio:(?:ready|rehydrated)/, file);
}
});
test('wallet reward content opens in the shared modal runtime once', () => {
const reward = read('assets/js/reward.js');
const helper = read('inc/helpers/jio-rewards.php');
const authorBar = read('templates/parts/single-author-bar.php');
const singleActions = read('inc/helpers/jio-single-render.php');
const scripts = read('src/Core/ScriptsPart1b.php');
const scriptsPart1c = read('src/Core/ScriptsPart1c.php');
assert.match(reward, /runtime\.open\(\{/);
assert.match(reward, /className: 'jio-reward-modal modal-mini full-sm'/);
assert.match(reward, /mobileBottom: true/);
assert.match(reward, /shell\.setAttribute\('aria-labelledby', title\.id\)/);
assert.match(reward, /'Idempotency-Key': key/);
assert.equal((reward.match(/document\.addEventListener\('click'/g) || []).length, 1);
assert.doesNotMatch(reward, /auto_fun|reward-modal\.is-open/);
assert.equal((helper.match(/<template\b/g) || []).length, 1);
assert.match(helper, /data-template-id="%2\$s"/);
assert.match(helper, /static \$done = \[\]/);
assert.match(helper, /isset\(\$done\[\$key\]\)/);
assert.match(helper, /modal-colorful-header colorful-bg jb-blue/);
assert.match(helper, /data-jio-modal-close/);
assert.match(helper, /data-jio-reward-submit/);
assert.match(authorBar, /jio_render_rewards_template_for_user/);
assert.match(singleActions, /jio_render_rewards_template_for_user/);
assert.match(scriptsPart1c, /\$requirements\['needs_reward'\]\s*=\s*\$is_article && !empty\(\$settings\['rewards_enabled'\]\)/);
assert.match(scriptsPart1c, /\$singular_assets\['needs_reward'\][\s\S]*?\$reward_js[\s\S]*?'jio-reward'/);
assert.doesNotMatch(helper + authorBar + singleActions, /jio_render_rewards_modal_for_user|reward-modal__qr/);
});
test('user center navigation initializes once across auto_fun rescans', () => {
const source = read('assets/js/routes/user-center.js');
const initAt = source.indexOf('function initDashboardNavigation()');
const guardAt = source.indexOf('jioUserCenterNavigationInitialized', initAt);
const initialActivateAt = source.indexOf('activate(initialTab, false)', initAt);
assert.ok(initAt >= 0);
assert.ok(guardAt > initAt && guardAt < initialActivateAt);
assert.match(source.slice(initAt, initialActivateAt), /if \(document\.documentElement\.dataset\.jioUserCenterNavigationInitialized === 'true'\) return;/);
assert.match(source.slice(initAt, initialActivateAt), /document\.documentElement\.dataset\.jioUserCenterNavigationInitialized = 'true';/);
assert.doesNotMatch(source, /name === 'vip' && !forceLoad\) forceLoad = true/);
});
test('homepage tabs refresh the original pane DOM through the runtime post_ajax pipeline', () => {
const layout = read('inc/helpers/homepage/layout.php')
const homepage = read('inc/helpers/jio-homepage.php')
const controller = read('src/Admin/GlobalController.php')
// 栏目链接契约:data-toggle="tab" + data-ajax。
assert.match(layout, /<a data-toggle="tab" data-ajax="/)
assert.match(layout, /href="#index-tab-main"/)
assert.match(layout, /class="index-tab affix-header-sm relative home-tab-nav-box mb10" offset-top="-8"/)
// pane 本身是原位刷新容器。
assert.match(layout, /class="posts-row ajaxpager tab-pane fade in active" id="index-tab-main"/)
assert.match(layout, /class="ajaxpager tab-pane fade" id="index-tab-/)
assert.match(layout, /<span class="post_ajax_trigger"><a class="ajax_load ajax-next ajax-open" href="/)
assert.match(layout, /<div class="post_ajax_loader">/)
// nofilter:栏目页响应不再输出筛选菜单,避免 win-ajax-replace 串页。
assert.match(layout, /'nofilter' => 'true'/)
// 不再有旁路刷新:REST 面板、骨架屏、面板 footer 全部移除。
assert.equal(fs.existsSync(path.join(root, 'assets/js/homepage-fixed.js')), false)
assert.doesNotMatch(layout, /data-home-tab-panel|jio-homepage__panel|jio-homepage__tab|requestHomepagePanel|data-sticky-tabs/)
assert.doesNotMatch(controller, /homepage\/tab-posts|rest_homepage_tab_posts/)
// 排序菜单契约:win-ajax-replace="filter" + ajax-next 链接。
assert.match(homepage, /function jio_homepage_render_ajax_option_menu/)
assert.match(homepage, /win-ajax-replace="filter"/)
assert.match(homepage, /ajax-replace="true" class="' \. esc_attr\(\$_class\)/)
assert.match(homepage, /!empty\(\$_GET\['nofilter'\]\)/)
// 主查询吃 ?orderby=,排序原位刷新才有效。
assert.match(homepage, /function jio_homepage_get_request_sort/)
assert.match(read('inc/helpers/homepage/content.php'), /jio_homepage_get_request_sort\(\)/)
// runtime 是 tab/排序的唯一引擎。
const runtime = read('assets/js/runtime/main.js')
assert.match(runtime, /_win\.bd\.on\('show\.bs\.tab', 'a\[data-ajax\]'/)
assert.match(runtime, /function post_ajax\(/)
// ajax-list.js 让出 runtime 管辖的控件,避免双请求。
assert.match(read('assets/js/core/ajax-list.js'), /link\.closest\("\.ajax-option, \.post_ajax_trigger"\)/)
})
test('archive streams nest pagination inside the ajaxpager for tab extraction', () => {
const archive = read('inc/helpers/jio-archive.php')
assert.match(archive, /append_inner_html/)
assert.doesNotMatch(archive, /content-stream__footer/)
assert.match(read('inc/helpers/posts-renderer/markup.php'), /append_inner_html/)
assert.doesNotMatch(read('assets/js/core/pagination.js'), /data-home-tab-panel|content-stream__footer/)
})
test('HTML fragment injection announces post_ajax before auto_fun', () => {
for (const file of ['assets/js/core/pagination.js', 'assets/js/author.js', 'assets/js/credits.js', 'assets/js/routes/user-center.js']) {
const source = read(file);
assert.match(source, /post_ajax\.ed[\s\S]*?window\.auto_fun\(\)/, file);
}
});
test('modal fragment lifecycle reruns auto_fun after loaded.bs.modal', () => {
const source = read('assets/js/runtime/main.js');
assert.match(source, /loaded\.bs\.modal[\s\S]*?auto_fun/);
});
test('JSON success lifecycle remains jio_ajax.success', () => {
const source = read('assets/js/runtime/main.js');
assert.match(source, /jio_ajax\.success/);
});
test('Miniimgbox owns data-imgbox and lazySizes has one integration owner', () => {
const imgbox = read('assets/js/runtime/imgbox.js');
const lazy = read('assets/js/runtime/main.js');
assert.match(imgbox, /Miniimgbox/);
assert.match(imgbox, /data-imgbox/);
assert.match(lazy, /lazybeforeunveil/);
assert.match(lazy, /MutationObserver/);
});
test('non-generated first-party sources contain no deprecated lifecycle API', () => {
const files = sourceFiles(root).filter((file) => {
const relative = path.relative(root, file).replaceAll('\\', '/');
return relative !== 'tests/widget-system/frontend-lifecycle-contract.test.cjs';
});
for (const file of files) {
const source = fs.readFileSync(file, 'utf8');
assert.doesNotMatch(source, /JioFrontend|jio\.autoFun|jio:(?:ready|rehydrated)/, path.relative(root, file));
}
});