The 搜索框 and 一言 sidebar widgets fell into the generic renderer branch, so they rendered a .jio-panel card wrapping a second bespoke card (.jio-widget-search / .jio-widget-quote). In-article 一言 also used divergent modifier classes and an extra hover rule. - search: render through the shared jio_get_search_box() (legacy keyword, history and category pickers) inside one reference card, mirroring the reference widget's markup and title default 「搜索」 - quote: render the reference .yiyan-box card itself as the click root; the shell now emits only the reference widget-container/title wrapper - article 一言: adopt the reference class lists for header, footer and the standalone after-article box; drop the invented yiyan--* modifiers and the duplicate hover/opacity rules - client: fill .cn/.en in the reference order (first line .cn, second .en) and drop the stale window.JioYiyan bridge plus the dead qv-yiyan.php AJAX path in runtime main.js - schema: replace the ad-hoc search_style radio with the reference switches (keywords, history, input category, more_cats) and default title - assets: enqueue assets/js/yiyan.js through the quote widget's asset list Tests: widget-system suite 820/821 (the one failure is the pre-existing frontend-lifecycle theme-init stub); new search/quote card contracts pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
42 lines
2.4 KiB
JavaScript
42 lines
2.4 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const root = path.resolve(__dirname, '..', '..');
|
|
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
|
|
|
test('article and modern widget yiyan use the reference bilingual quote source and interactions', () => {
|
|
const helper = read('inc/helpers/jio-yiyan.php');
|
|
const client = read('assets/js/yiyan.js');
|
|
const widgetClient = read('assets/widgets/frontend.js');
|
|
const renderer = read('src/WidgetSystem/Renderers/GeneralRenderer.php');
|
|
const rest = read('src/WidgetSystem/RestController.php');
|
|
const schema = read('src/WidgetSystem/WidgetSchemas.php');
|
|
const widgetStyles = read('assets/widgets/frontend.css');
|
|
const catalog = read('yiyan/qv-yiyan.txt').split(/\r?\n/).filter(Boolean);
|
|
|
|
assert.match(helper, /WP_CONTENT_DIR\s*\.\s*'\/yiyan\.txt'/);
|
|
assert.match(helper, /\/yiyan\/qv-yiyan\.txt/);
|
|
assert.match(helper, /wp_ajax_nopriv_jio_yiyan/);
|
|
assert.match(helper, /'en'\s*=>\s*\$lines\[\$i\],\s*'cn'\s*=>\s*\$lines\[\$i\s*\+\s*1\]/);
|
|
// 参考结构:.yiyan 初始为空,由脚本写入 .cn/.en。
|
|
assert.match(helper, /class="yiyan"><\/div>/);
|
|
// 参考主题:句库首行进 .cn(正文尺寸),次行进 .en(0.8em)。
|
|
assert.match(client, /lineCn\.textContent = quote\.en/);
|
|
assert.match(client, /lineEn\.textContent = quote\.cn/);
|
|
assert.match(client, /REFRESH_MS\s*=\s*30000/);
|
|
assert.match(client, /on\('auto_fun\.jio-yiyan', function \(\) \{\s*init\(document\)/);
|
|
assert.match(client, /event\.key === 'Enter' \|\| event\.key === ' '/);
|
|
// 小工具端不再单独初始化:yiyan.js 直接监听 [data-jio-yiyan]。
|
|
assert.match(widgetClient, /scope\.querySelectorAll\('\.jio-widget-video\[data-video-url\]'\)/);
|
|
assert.doesNotMatch(widgetClient, /JioYiyan/);
|
|
assert.match(renderer, /yiyan-box main-bg text-center box-body radius8 main-shadow/);
|
|
assert.match(renderer, /jio_get_yiyan_markup/);
|
|
assert.doesNotMatch(rest, /v1\.hitokoto\.cn|function get_quote/);
|
|
assert.match(schema, /case 'quote':\s*return \[\];/);
|
|
assert.doesNotMatch(widgetStyles, /\.jio-widget-quote/);
|
|
assert.ok(catalog.length > 10, 'the bundled quote file should contain a useful quote set');
|
|
assert.equal((catalog.length - 1) % 2, 0, 'after the title, quote lines must form English/Chinese pairs');
|
|
});
|