63 lines
2.3 KiB
JavaScript
63 lines
2.3 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
|
|
global.window = {PYTORRENT_DISABLE_AUTOSTART: true};
|
|
const app = await import('../pytorrent/static/js/app.js');
|
|
const source = app.buildRuntimeSource();
|
|
|
|
assert.equal(app.moduleSources.length, 18, 'all frontend module chunks are loaded');
|
|
assert.doesNotThrow(() => Function('io', source), 'assembled frontend runtime compiles');
|
|
|
|
for (const marker of [
|
|
'function renderRow',
|
|
'function renderTable',
|
|
'function scheduleRender',
|
|
'async function post',
|
|
'async function loadRss',
|
|
'async function loadSmartQueue',
|
|
'function ensurePlannerToolsUI',
|
|
'function loadPlannerPreview',
|
|
'function pollerPayload',
|
|
'function pollerDiagnostics',
|
|
'function renderHealthDashboard',
|
|
'function recordNotification',
|
|
'function drawTrafficHistory',
|
|
"socket.on('connect'",
|
|
'/api/download-planner/preview',
|
|
'plannerProfileName',
|
|
'pollerTorrentList',
|
|
]) {
|
|
assert.ok(source.includes(marker), `runtime contains ${marker}`);
|
|
}
|
|
|
|
function extractFunction(src, name){
|
|
const start = src.indexOf(`function ${name}`);
|
|
assert.ok(start >= 0, `found function ${name}`);
|
|
const open = src.indexOf('{', start);
|
|
let depth = 0;
|
|
for(let i=open; i<src.length; i++){
|
|
const ch = src[i];
|
|
if(ch === '{') depth++;
|
|
if(ch === '}') depth--;
|
|
if(depth === 0) return src.slice(start, i + 1);
|
|
}
|
|
throw new Error(`unterminated function ${name}`);
|
|
}
|
|
|
|
const escLine = source.match(/const esc = .*?;\n/)?.[0];
|
|
assert.ok(escLine, 'found esc helper');
|
|
|
|
const renderHarness = new Function(`${escLine}
|
|
${extractFunction(source, 'progressBar')}
|
|
${extractFunction(source, 'compactCell')}
|
|
${extractFunction(source, 'table')}
|
|
${extractFunction(source, 'smartQueueToastMessage')}
|
|
return {esc, progressBar, compactCell, table, smartQueueToastMessage};`)();
|
|
|
|
assert.equal(renderHarness.esc('<tag>&"'), '<tag>&"', 'esc escapes HTML');
|
|
assert.ok(renderHarness.progressBar(42).includes('42%'), 'progressBar renders percentage');
|
|
assert.ok(renderHarness.compactCell('x'.repeat(200)).includes('title='), 'compactCell renders title for long text');
|
|
assert.ok(renderHarness.table(['A'], [['B']]).includes('<table'), 'table renders HTML table');
|
|
assert.ok(renderHarness.smartQueueToastMessage({stopped:[1,2], started:[3], max_active_downloads:5}).includes('Smart Queue:'), 'smartQueue toast renders');
|
|
|
|
console.log('frontend module tests passed');
|