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>
This commit is contained in:
43
test/layaStatusPresentation.test.js
Normal file
43
test/layaStatusPresentation.test.js
Normal file
@ -0,0 +1,43 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user