Files
Nodecast/test/layaStatusPresentation.test.js
blomios d276d3b4c3 fix: show Laya model download progress and surface errors in Settings (#12)
Track download progress in layaService (bytes/total, phase, error
state) and expose it through the laya status route. Render a progress
bar during model download in Settings via a layaStatusPresentation
service, and display download/status errors inline instead of failing
silently. Cover progress tracking and status presentation with tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-02 11:49:36 +02:00

44 lines
1.8 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const { presentLayaStatus } = require('../public/js/services/layaStatusPresentation.js');
test('presents unknown-size downloads as indeterminate with downloaded bytes', () => {
const view = presentLayaStatus({
phase: 'downloading',
downloading: true,
progressPercent: null,
bytesDownloaded: 12 * 1024 * 1024,
totalBytes: null
});
assert.equal(view.progressIndeterminate, true);
assert.equal(view.progressPercent, null);
assert.equal(view.bytesDownloaded, 12 * 1024 * 1024);
assert.equal(view.showDownload, false);
assert.equal(view.showRemove, false);
});
test('presents known progress as a bounded percentage', () => {
const view = presentLayaStatus({ phase: 'downloading', downloading: true, progressPercent: 47.6 });
assert.equal(view.progressIndeterminate, false);
assert.equal(view.progressPercent, 48);
});
test('failed downloads expose retry, safe details and Standard fallback', () => {
const view = presentLayaStatus({
phase: 'failed',
modelPresent: false,
error: { message: 'Model download failed', detail: 'The optional Laya runtime is unavailable.' }
}, 'hybrid');
assert.equal(view.downloadLabel, 'Retry download');
assert.equal(view.showDownload, true);
assert.equal(view.showUseStandard, true);
assert.equal(view.errorMessage, 'Model download failed');
assert.equal(view.errorDetail, 'The optional Laya runtime is unavailable.');
});
test('ready models expose removal without download actions', () => {
const view = presentLayaStatus({ phase: 'ready', modelPresent: true, runtimeAvailable: true });
assert.equal(view.showRemove, true);
assert.equal(view.showDownload, false);
});