69 lines
3.0 KiB
JavaScript
69 lines
3.0 KiB
JavaScript
// Comprehensive consistency test for engine v2: verifies every online
|
|
// interactive behavior exists in the exported HTML.
|
|
const fs = require('fs');
|
|
const { JSDOM, VirtualConsole } = require('jsdom');
|
|
|
|
const file = process.argv[2];
|
|
const html = fs.readFileSync(file, 'utf-8');
|
|
const errors = [];
|
|
const vc = new VirtualConsole();
|
|
vc.on('jsdomError', (e) => errors.push('jsdomError: ' + e.message));
|
|
|
|
const dom = new JSDOM(html, { runScripts: 'dangerously', pretendToBeVisual: true, virtualConsole: vc });
|
|
const window = dom.window;
|
|
const document = dom.window.document;
|
|
const model = window.QUX_MODEL;
|
|
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
let pass = 0, fail = 0;
|
|
function check(name, ok, detail) {
|
|
if (ok) { pass++; console.log(' PASS', name); }
|
|
else { fail++; console.log(' FAIL', name, detail || ''); }
|
|
}
|
|
|
|
async function main() {
|
|
await sleep(300);
|
|
console.log('app:', model.name);
|
|
console.log('-- 控件渲染与交互 --');
|
|
|
|
// TextBox editable
|
|
const tb = document.querySelector('input[type="text"]');
|
|
check('TextBox 存在且可输入(非readOnly)', tb && !tb.readOnly && tb.type === 'text');
|
|
if (tb) { tb.value = '测试输入'; check('TextBox 可以输入值', tb.value === '测试输入'); }
|
|
|
|
const pw = document.querySelector('input[type="password"]');
|
|
check('Password 存在且可输入', pw && !pw.readOnly && pw.type === 'password');
|
|
|
|
const cb = document.querySelector('.qux-check');
|
|
check('CheckBox 存在', !!cb);
|
|
if (cb) { cb.dispatchEvent(new window.MouseEvent('click', {bubbles:true})); check('CheckBox 点击切换选中', cb.classList.contains('qux-on')); }
|
|
|
|
const rb = document.querySelector('.qux-radio');
|
|
check('RadioBox 存在', !!rb);
|
|
if (rb) { rb.dispatchEvent(new window.MouseEvent('click', {bubbles:true})); check('RadioBox 点击切换', rb.classList.contains('qux-on')); }
|
|
|
|
const sw = document.querySelector('.qux-switch');
|
|
check('Switch 存在', !!sw);
|
|
if (sw) { sw.dispatchEvent(new window.MouseEvent('click', {bubbles:true})); check('Switch 点击切换', sw.classList.contains('qux-on')); }
|
|
|
|
const sel = document.querySelector('select.qux-select');
|
|
check('DropDown 存在且有3个选项', !!sel && sel.options.length >= 3);
|
|
if (sel) { sel.selectedIndex = 2; check('DropDown 可选中选项', sel.selectedIndex === 2); }
|
|
|
|
// 连线跳转
|
|
const wired = document.querySelectorAll('.qux-clickable');
|
|
check('有可点击元素(按钮连线)', wired.length >= 1);
|
|
const nameEl = document.getElementById('screenName');
|
|
const before = nameEl.textContent;
|
|
if (wired.length) {
|
|
wired[0].dispatchEvent(new window.MouseEvent('click', {bubbles:true, cancelable:true}));
|
|
await sleep(300);
|
|
const after = nameEl.textContent;
|
|
check('点击按钮跳转屏幕', after !== before, `${before} -> ${after}`);
|
|
}
|
|
|
|
if (errors.length) { console.log('RUNTIME ERRORS:'); errors.slice(0,5).forEach(e => console.log(' -', e)); fail++; }
|
|
console.log(`\n结果: ${pass} 通过, ${fail} 失败`);
|
|
process.exit(fail ? 1 : 0);
|
|
}
|
|
main().catch(e => { console.error('TEST CRASH:', e); process.exit(1); });
|