79 lines
3.0 KiB
JavaScript
79 lines
3.0 KiB
JavaScript
// Data components + animation test: verify charts/table/progress/etc render.
|
|
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 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(400);
|
|
console.log('app:', window.QUX_MODEL.name);
|
|
console.log('-- 数据组件渲染 --');
|
|
check('BarChart SVG', document.querySelectorAll('svg.qchart').length >= 3, 'svg count');
|
|
check('表格渲染(表头+数据行)', (() => {
|
|
const t = document.querySelector('table.qtable');
|
|
if (!t) return false;
|
|
const th = t.querySelectorAll('th').length;
|
|
const tr = t.querySelectorAll('tbody tr').length;
|
|
return th === 3 && tr === 3;
|
|
})());
|
|
check('ProgressBar 填充72%', (() => {
|
|
const f = document.querySelector('.qprogress .qfill');
|
|
return !!f && f.style.width === '72%';
|
|
})());
|
|
check('Rating 4/5星亮起', (() => {
|
|
const s = document.querySelectorAll('.qstars .qstar');
|
|
return s.length === 5 && document.querySelectorAll('.qstars .qstar.qux-on').length === 4;
|
|
})());
|
|
check('Stepper 3步且第2步高亮', (() => {
|
|
const st = document.querySelectorAll('.qstepper .qstep');
|
|
return st.length === 3 && st[1].classList.contains('qux-on');
|
|
})());
|
|
check('HSlider range 控件', (() => {
|
|
const i = document.querySelector('.qslider input[type=range]');
|
|
return !!i && i.value === '60';
|
|
})());
|
|
check('QDate date 输入', (() => {
|
|
const i = document.querySelector('input[type=date]');
|
|
return !!i;
|
|
})());
|
|
check('IFrame 渲染', (() => {
|
|
const f = document.querySelector('iframe');
|
|
return !!f;
|
|
})());
|
|
check('NavBar 4个菜单项', (() => {
|
|
const n = document.querySelector('.qux-widget');
|
|
// find navbar by checking all widgets for text content 首页
|
|
let found = false;
|
|
document.querySelectorAll('.qux-widget').forEach(el => {
|
|
if (el.textContent.indexOf('首页') >= 0 && el.textContent.indexOf('我的') >= 0) found = true;
|
|
});
|
|
return found;
|
|
})());
|
|
check('LineChart 折线(svg polyline)', (() => {
|
|
const pl = document.querySelectorAll('svg.qchart polyline');
|
|
return pl.length >= 1;
|
|
})());
|
|
check('PieChart 扇区(path)', (() => {
|
|
return document.querySelectorAll('svg.qchart path').length >= 3;
|
|
})());
|
|
|
|
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); });
|