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

46 lines
2.2 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
test('search route keeps the reference Zibll results and empty-state structure', () => {
const template = read('search.php');
const styles = read('assets/css/main.css');
for (const token of ['search-input', 'search-page-ajaxpager', 'search-tab-header', 'search-filter-item', 'post_ajax_loader']) {
assert.match(template + styles, new RegExp(token.replace(/[.*+?^${}()|[\\]\\]/g, '\\$&')));
}
assert.match(template, /aksrt_get_ajax_null\(__\('请输入搜索关键词'/);
assert.match(template, /'null-search\.svg'/);
assert.match(template, /user_query instanceof WP_User_Query/);
assert.equal(fs.existsSync(path.join(root, 'assets/css/routes/search.css')), false);
assert.match(template, /'skip_wrapper' => true/);
assert.match(template, /null-user\.svg/);
assert.match(template, /null-post\.svg/);
assert.match(template, /route-title=/);
for (const image of ['null-search.svg', 'null-user.svg', 'null-post.svg']) {
assert.match(read(`assets/img/${image}`), /<svg\b/);
}
assert.equal(fs.existsSync(path.join(root, 'assets/img/null-search.svg')), true);
assert.equal(fs.existsSync(path.join(root, 'assets/img/null-user.svg')), true);
});
test('search rendering preserves form state, result markup, paging and escaped keywords', () => {
const result = spawnSync(process.env.PHP_BINARY || 'php', [path.join(__dirname, 'search-render-harness.php')], {
cwd: root,
encoding: 'utf8',
});
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.match(result.stdout, /Search render harness passed/);
});
test('search route renders reference fluid widget sidebars in order', () => {
const template = read('search.php');
assert.match(template, /dynamic_sidebar\('all_top_fluid'\)[\s\S]*dynamic_sidebar\('search_top_fluid'\)/);
assert.match(template, /dynamic_sidebar\('search_bottom_fluid'\)[\s\S]*dynamic_sidebar\('all_bottom_fluid'\)/);
});