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>
/); 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'); });