Files
youle_cocos/cocoscreator_projects/framework-tests/presentation/apply-vote-model.test.ts
T
joywayer 35216f75e7 feat: integrate room framework and isolated subgame bundles
Complete room UI and protocol integration, move game definitions and resources behind bundle entries, publish authoritative version XML, and document single-game builds. Include all current resource changes and experiment artifacts.
2026-09-09 03:13:18 +08:00

33 lines
2.0 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {selectApplyVote} from '../../YouleNexus/assets/scripts/platform-login/apply-vote-model.ts';
function state(count=4):any {
const participants=Array.from({length:count},(_,seat)=>({seat,playerid:seat+10,nickname:`玩家${seat}`,state:seat===0?0:seat===1?1:-1}));
return {app:{phase:'logged-in'},dissolution:{kind:'active',roomcode:'123456',selfSeat:Math.min(2,count-1),initiator:participants[0],participants,deadline:120000}};
}
test('dynamic rows follow participant seats, excluding the initiator shown in the header',()=>{
for(const count of [2,4,8,12]){
const result=selectApplyVote(state(count),0)!;
assert.equal(result.rows.length,count-1);
assert.equal(result.rows[0].nickname,'【玩家1】');assert.equal(result.rows[0].status,'同意');
assert.match(result.message,/发起投票:【玩家0】/);
}
});
test('deadline only controls countdown and controls require an unvoted connected self',()=>{
const input=state();assert.equal(selectApplyVote(input,118100)!.seconds,2);
assert.equal(selectApplyVote(input,125000)!.seconds,0);
assert.equal(selectApplyVote(input,125000)!.canVote,true);
input.dissolution.selfSeat=0;assert.equal(selectApplyVote(input,0)!.canVote,false);
input.dissolution.selfSeat=1;assert.equal(selectApplyVote(input,0)!.canVote,false);
input.dissolution.selfSeat=2;input.app.phase='reconnecting';assert.equal(selectApplyVote(input,0)!.canVote,false);
});
test('server refusal produces the named result and hides voting/countdown',()=>{
const input=state();input.dissolution={...input.dissolution,kind:'result',passed:false,refusedSeat:2,freeNow:false};
const result=selectApplyVote(input,0)!;
assert.match(result.message,/拒绝解散玩家:【玩家2】/);assert.equal(result.seconds,null);
assert.equal(result.canVote,false);assert.equal(result.result,true);
input.dissolution.freeNow=true;assert.equal(selectApplyVote(input,0),null);
input.dissolution=null;assert.equal(selectApplyVote(input,0),null);
});