import test from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { runInNewContext } from 'node:vm'; import ts from 'typescript'; test('login busy state starts Animation once, hides on completion and restarts on retry', () => { const exports: any = {}; const source = readFileSync(new URL('../../YouleNexus/assets/scripts/platform-login/login-panel.ts', import.meta.url), 'utf8'); runInNewContext(ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText, { exports, require(name: string) { if (name === './node-bindings.ts') return { requireNode(root: any, path: string) { const result = root.paths[path]; if (!result) throw Error(`Missing ${path}`); return result; } }; return {}; } }); const children = Object.fromEntries(['登录中遮罩','登录头像背景框','登录中头像','登录中昵称','登录中动画','登录中头像框'] .map(name => [name, {active:false}])); const group = {active:false, paths:children}; let playing = false, starts = 0, stops = 0; const panel = Object.create(exports.LoginPanel.prototype); panel.root = {paths:{'group-2/Logining':group}}; panel.loadingAnimation = {defaultClip:{name:'LoginLoading'}, getState:()=>({isPlaying:playing}), play(name: string){assert.equal(name,'LoginLoading');playing=true;starts++;}, stop(){playing=false;stops++;}}; panel.setBusy(true); panel.setBusy(true); assert.equal(starts,1); assert.equal(group.active,true); assert.ok(Object.values(children).every(node=>node.active)); panel.setBusy(false); assert.equal(stops,1); assert.equal(group.active,false); assert.equal(playing,false); panel.setBusy(true); assert.equal(starts,2); });