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, /\$initial_content\s*=\s*\(string\) \$ctx\['current_content'\]/); assert.match(editor, /wp_editor\(\$initial_content, 'post_content', \$editor_settings\);/); }); test('front submit restores published content when TinyMCE initializes empty', () => { const editor = read('templates/parts/submit/editor-main.php'); const runtime = read('assets/js/front-submit.js'); const styles = read('assets/css/frontend/pages/submit.css'); assert.match(editor, /'quicktags'\s*=>\s*true/); assert.match(editor, /id="aksrt-initial-post-content"/); assert.match(runtime, /hydrateEditor:\s*function/); assert.match(runtime, /editor\.setContent\(initialContent\)/); assert.match(runtime, /switchEditors\.go\('post_content', 'html'\)/); assert.match(styles, /textarea\.wp-editor-area\s*\{[^}]*opacity:\s*1/s); });