46 lines
1.5 KiB
JavaScript
46 lines
1.5 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 editorPages = [
|
|
'profile-article-edit.html',
|
|
'profile-feed-edit.html',
|
|
'profile-gift-edit.html',
|
|
'profile-growth-edit.html',
|
|
'profile-merit-edit.html'
|
|
];
|
|
|
|
function read(relativePath) {
|
|
return fs.readFileSync(path.join(root, relativePath), 'utf8');
|
|
}
|
|
|
|
test('所有富文本页面统一加载 wangEditor v5', () => {
|
|
editorPages.forEach((page) => {
|
|
const source = read(page);
|
|
|
|
assert.match(source, /public\/js\/wangeditor5\/css\/style\.css/);
|
|
assert.match(source, /public\/js\/wangeditor5\/index\.js/);
|
|
assert.match(source, /class="js-rich-editor"/);
|
|
assert.doesNotMatch(source, /kindeditor|public\/js\/ke\//i);
|
|
});
|
|
});
|
|
|
|
test('公共富文本适配层只使用 wangEditor 并在提交前同步 textarea', () => {
|
|
const source = read('public/js/rich-editor.js');
|
|
|
|
assert.match(source, /root\.wangEditor/);
|
|
assert.match(source, /wangEditor\.createEditor/);
|
|
assert.match(source, /wangEditor\.createToolbar/);
|
|
assert.match(source, /button\[data-tooltip\]/);
|
|
assert.match(source, /setAttribute\('aria-label'/);
|
|
assert.match(source, /MutationObserver/);
|
|
assert.match(source, /documentRef\.addEventListener\('submit'/);
|
|
assert.doesNotMatch(source, /KindEditor/);
|
|
});
|
|
|
|
test('旧 KindEditor 资源已移除', () => {
|
|
assert.equal(fs.existsSync(path.join(root, 'public/js/ke/kindeditor.min.js')), false);
|
|
});
|