import { test } from 'node:test'; import { strict as assert } from 'node:assert'; import { readFileSync, readdirSync } from 'node:fs'; import { StartupProgress } from '../assets/startup/scripts/StartupProgress'; test('waiting progress stays monotonic and below completion, even after long waits', () => { const progress = new StartupProgress(); progress.begin(); let previous = progress.value; for (let i = 0; i < 6000; i++) { const value = progress.tick(.1); assert.ok(value >= previous && value <= .9); previous = value; } assert.equal(progress.phase, 'loading'); const before = progress.value; progress.tick(NaN); progress.tick(-1); progress.tick(Infinity); assert.equal(progress.value, before); }); test('only real completion reaches 100%; retry resets progress and stale finish is ignored', () => { const progress = new StartupProgress(); progress.finish(); assert.equal(progress.phase, 'idle'); progress.begin(); progress.tick(.1); progress.finish(); const first = progress.tick(.1); progress.finish(); assert.ok(first < 1); progress.tick(.1); progress.tick(.1); assert.equal(progress.phase, 'complete'); assert.equal(progress.value, 1); progress.begin(); assert.equal(progress.phase, 'loading'); assert.equal(progress.value, .03); progress.reset(); progress.finish(); progress.tick(.1); assert.equal(progress.phase, 'idle'); assert.equal(progress.value, 0); }); // 场景必须由领域工具保存;测试只读取布局和资源引用。 / Domain tools author the scene; tests only inspect its saved layout and references. type Entry = Record; const scene: Entry[] = JSON.parse(readFileSync('assets/Welcome.scene', 'utf8')); const node = (name: string): Entry => scene.find(item => item.__type__ === 'cc.Node' && item._name === name)!; const components = (name: string): Entry[] => node(name)._components.map((ref: Entry) => scene[ref.__id__]); const component = (name: string, type: string): Entry => components(name).find(item => item.__type__ === type)!; test('loading has independent editable labels and renamed frame/fill resources with preserved caps', () => { assert.ok(node('PreparationPanel')._children.length >= 5); for (const [name, text] of [['PreparationTitle', 'LOADING...'], ['PreparationPercent', '70%'], ['PreparationCaption', 'Getting things ready']]) { assert.equal(component(name, 'cc.Label')._string, text); } assert.equal(component('PreparationFrame', 'cc.UITransform')._contentSize.width, 973); assert.equal(component('PreparationFrame', 'cc.UITransform')._contentSize.height, 168); assert.equal(node('PreparationFrame')._lpos.y, -576); assert.equal(component('PreparationFill', 'cc.UITransform')._anchorPoint.x, 0); assert.equal(component('PreparationFill', 'cc.UITransform')._contentSize.width, 906 * .7); assert.equal(component('PreparationFill', 'cc.Sprite')._type, 1); for (const [name, file] of [['PreparationFrame', 'prep-meter-frame'], ['PreparationFill', 'prep-meter-fill']]) { const meta = JSON.parse(readFileSync(`assets/startup/visuals/${file}.png.meta`, 'utf8')); assert.equal(component(name, 'cc.Sprite')._spriteFrame.__uuid__, meta.uuid + '@f9941'); if (name === 'PreparationFill') { assert.equal(meta.subMetas.f9941.userData.borderLeft, 48); assert.equal(meta.subMetas.f9941.userData.borderRight, 48); } } assert.deepEqual(readdirSync('assets/startup/visuals').filter(file => !file.endsWith('.meta')).sort(), ['prep-meter-fill.png', 'prep-meter-frame.png']); }); test('loading binds the existing login without hiding its request-owning node', () => { const loading = components('Canvas').find(item => item.panel && item.meter)!; assert.ok(loading); assert.equal(scene[loading.panel.__id__]._name, 'PreparationPanel'); assert.equal(scene[loading.login.__id__].node.__id__, scene.indexOf(node('WelcomeComposition'))); assert.equal(scene[loading.meter.__id__].node.__id__, scene.indexOf(node('PreparationFill'))); const hidden = loading.loginControls.map((ref: Entry) => scene[ref.__id__]._name); assert.ok(hidden.includes('GuestAccess')); assert.ok(hidden.includes('PrivacyLink')); assert.ok(!hidden.includes('WelcomeComposition')); assert.ok(!hidden.includes('BrandMark')); });