Files
youle_cocos/cocoscreator_projects/framework-tests/adapters/owned-room-history.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

21 lines
1.6 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {OwnedRoomHistory} from '../../YouleNexus/assets/framework/adapters/native/owned-room-history.ts';
test('owned rooms use legacy cache, order, and server outcome lifecycle',()=>{
const data=new Map<string,string>();const history=new OwnedRoomHistory({getItem:k=>data.get(k)??null,setItem:(k,v)=>{data.set(k,v);}},'g','a');
assert.deepEqual(history.read(),[]);assert.equal(data.get('tsgame_roomlist_ga'),'{{}}'.replace('{{}}','{"data":[]}'));
history.exited({isowner:1,roomcode:'123456'},0);history.exited({isowner:1,roomcode:'654321'},0);
history.exited({isowner:1,roomcode:'123456'},0);assert.deepEqual(history.read(),[654321,123456]);
history.exited({isowner:0,roomcode:333333},0);history.exited({isowner:1,roomcode:333333},1);assert.equal(history.read().length,2);
history.joined({state:2,roomcode:123456});assert.equal(history.read().length,2);
history.joined({state:99,roomcode:123456});assert.deepEqual(history.read(),[654321]);
history.joined({state:0,isowner:1,roomcode:654321});assert.deepEqual(history.read(),[]);
data.set('tsgame_roomlist_ga','bad');assert.throws(()=>history.read());
});
test('confirmed break removes only returned roomcode and absent roomcode leaves cache intact',()=>{
const data=new Map<string,string>();const history=new OwnedRoomHistory({getItem:k=>data.get(k)??null,setItem:(k,v)=>{data.set(k,v);}},'g','a');
history.exited({isowner:1,roomcode:'123456'},0);history.exited({isowner:1,roomcode:'654321'},0);
history.broken({});assert.deepEqual(history.read(),[654321,123456]);history.broken({roomcode:'123456'});assert.deepEqual(history.read(),[654321]);
});