Files
youle_cocos/cocoscreator_projects/framework-tests/platform-login/scene-flow.test.ts
T

24 lines
1.4 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { SceneFlow } from '../../YouleNexus/assets/scripts/platform-login/scene-flow.ts';
test('repeated lobby notifications share one pending transition and bind once',async()=>{
const calls:string[]=[];
const flow=new SceneFlow(async name=>{calls.push(name);});
await Promise.all([flow.enterOnce('Lobby',()=>{calls.push('bind');}),flow.enterOnce('Lobby',()=>{calls.push('duplicate');})]);
await flow.enterOnce('Lobby',()=>{calls.push('duplicate');});
assert.deepEqual(calls,['Lobby','bind']);
await flow.enter('Login',()=>{});
await flow.enterOnce('Lobby',()=>{calls.push('new');});
assert.deepEqual(calls,['Lobby','bind','Login','Lobby','new']);
});
test('scene transitions are sequential and disposal prevents late scene binding',async()=>{
const calls:string[]=[];let finish!:()=>void;
const flow=new SceneFlow(async name=>{calls.push(name);if(name==='Loading')await new Promise<void>(r=>finish=r);});
const loading=flow.enter('Loading',()=>{calls.push('bindLoading');});
const login=flow.enter('Login',()=>{calls.push('bindLogin');});
await Promise.resolve();assert.deepEqual(calls,['Loading']);finish();await loading;await login;
assert.deepEqual(calls,['Loading','bindLoading','Login','bindLogin']);
flow.dispose();await assert.rejects(flow.enter('Login',()=>{}),/disposed/);
});