Files
wordpress-theme-aksrt/tests/widget-system/yiyan-reference-contract.test.cjs
T
kate522 8aa116ec43 fix(theme): align reference layouts and restore passing contracts
Align homepage and category discovery, modern widgets, admin controls, quotes, and comments with the reference theme. Remove superseded paths and add rendering and behavior coverage. Update stale asset and finance contracts; all 760 Node tests and 139 widget assertions pass.
2026-10-29 19:16:03 +08:00

35 lines
1.9 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/aksrt-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_aksrt_yiyan/);
assert.match(helper, /'en'\s*=>\s*\$lines\[\$i\],\s*'cn'\s*=>\s*\$lines\[\$i\s*\+\s*1\]/);
assert.match(helper, /class="yiyan"><div class="en"><\/div><div class="cn">/);
assert.match(client, /REFRESH_MS\s*=\s*30000/);
assert.match(client, /on\('auto_fun\.aksrt-yiyan', function \(\) \{\s*init\(document\)/);
assert.match(client, /event\.key === 'Enter' \|\| event\.key === ' '/);
assert.match(widgetClient, /window\.AksrtYiyan\.init\(figure\)/);
assert.match(renderer, /aksrt_get_yiyan_markup\(\['class' => 'aksrt-widget-quote'\]\)/);
assert.doesNotMatch(rest, /v1\.hitokoto\.cn|function get_quote/);
assert.match(schema, /case 'quote':\s*return \[\];/);
assert.match(widgetStyles, /\.aksrt-widget-quote \.yiyan \.en/);
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');
});