Files
wordpress-theme-aksrt/tests/widget-system/front-submit-editor-contract.test.cjs
T
2026-08-25 19:59:43 +08:00

37 lines
1.7 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
test('front submit enqueues the WordPress editor before wp_head is rendered', () => {
const source = read('templates/pages/page-submit.php');
const enqueueAt = source.indexOf('wp_enqueue_editor();');
const headerAt = source.indexOf('\nget_header();');
assert.notEqual(enqueueAt, -1, 'front submit must explicitly enqueue the editor runtime');
assert.notEqual(headerAt, -1, 'front submit must render the theme header');
assert.ok(enqueueAt < headerAt, 'editor assets must be queued before get_header()/wp_head');
});
test('published post content reaches the front submit editor unchanged', () => {
const context = read('templates/parts/submit/context.php');
const editor = read('templates/parts/submit/editor-main.php');
assert.match(context, /\$current_content\s*=\s*\$edit_post\s*\?\s*\$edit_post->post_content\s*:\s*'';/);
assert.match(editor, /wp_editor\(\(string\) \$ctx\['current_content'\], 'post_content', \$editor_settings\);/);
});
test('front submit uses the WordPress registered jQuery runtime', () => {
const source = read('src/Core/ScriptsPart1b.php');
assert.match(source, /wp_enqueue_script\('jquery'\);/);
assert.match(source, /registered\['jquery'\]->deps\s*=\s*\['jquery-core'\]/);
assert.doesNotMatch(source, /wp_deregister_script\('jquery'\)/);
assert.doesNotMatch(source, /wp_register_script\(\s*'jquery'/);
assert.doesNotMatch(source, /jquery-migrate/);
assert.doesNotMatch(source, /runtime\/libs\/jquery\.min\.js|['"]1\.9\.1['"]/);
});