Files

62 lines
6.4 KiB
JavaScript

/** Cocos Game View verification: mocked wire, no real ranking/card requests. */
export async function verifyOwnedVipPreview(){
const e=await System.import('cc'),modules=Array.from(System.entries()).map(([,m])=>m);
const exported=name=>{const m=modules.find(m=>m[name]);if(!m)throw Error(`Missing ${name}`);return m[name];};
const source=e.director.getScene().getChildByName('PlatformServices').getComponent('PlatformStartup');
const config=source.config,assets=source.getComponent('LobbyAssets');
source.unsubscribe?.();source.runtime?.stop();source.panel?.dispose();source.panel=null;
await new Promise((resolve,reject)=>e.director.loadScene('PlatformLobby',err=>err?reject(err):resolve()));
const sent=[],tips=[],checks=[];let receive,panel;
const assert=(ok,msg)=>{if(!ok)throw Error(msg);checks.push(msg);};
const runtime=new (exported('PlatformRuntime'))({
gameEntry:exported('createLoginStageGameEntry')(config.identity.gameid,()=>{}),resolveRuntimeConfig:async()=>config,
createWireClient:()=>({subscribe:cb=>{receive=cb;return ()=>{};},start:()=>{},stop:()=>{},send:p=>sent.push(p),switchServer:()=>{},reconnectCurrent:()=>{}}),
scene:{showLoading:()=>{},showLogin:()=>{},showLobby:()=>{},showRoom:()=>{},showReconnect:()=>{},showKicked:()=>{},showServerDenial:()=>{},showFatal:err=>{throw err;},
showTips:(msg,time,kind)=>{if(kind==='show_message')panel?.cancelRankRequest();tips.push(msg);}},
loadResources:async()=>{},waitForMinimumDisplay:async()=>{},getLoginDeviceSnapshot:()=>{throw Error('Fixture only');},
});
await runtime.start();receive({type:'open',server:config.servers[0]});
const packet=(rpc,data)=>receive({type:'message',message:{route:'agent',rpc,data}});
packet('player_login',{state:0,playerid:7,nickname:'接线验证',avatar:'',sex:0,bean:0,roomcard:3,taskstate:0,score:0,sign:null,ip:'127.0.0.1',openid:'test',unionid:'test',invitecode:null});
const canvas=e.director.getScene().getChildByName('Canvas'),popup=new e.Node('OwnedVipTestPopup');popup.parent=canvas;popup.layer=canvas.layer;popup.addComponent(e.UITransform).setContentSize(1600,720);
const remote=exported('createRemoteConfig')({gameNoticeShow:-1,rankList:2,cdKey:2,vipRankLimit:3},config.identity);
panel=new (exported('LobbyPanel'))(canvas,popup,assets,config,exported('resolveLobbyPolicy')(remote),runtime.state,msg=>tips.push(msg),()=>{},()=>null,()=>{},
exported('resolveLobbyMenuConfig')(remote),{versionState:0,launchMode:0},()=>{},()=>{},()=>{},undefined,undefined,
{rank:()=>runtime.getTreasureList(),redeem:card=>runtime.redeemCard(card),paste:async()=>'00Ab-12',loading:()=>{},vipRank:limit=>runtime.getVipRankList(limit),joinOwned:code=>runtime.joinOwnedRoom(code,{city:'test'})});
popup.setSiblingIndex(canvas.children.length-1);
const off=runtime.subscribeState(state=>panel.render(state),err=>{throw err;});
const click=id=>panel.menuNodes.get(id).emit(e.Button.EventType.CLICK);
const key='tsgame_roomlist_'+config.identity.gameid+config.identity.agentid,previous=localStorage.getItem(key);
try{
const before=tips.length;for(const id of [10,286,287,3161,508,509,496,3162])click(id);
assert(tips.length===before&&sent.length===0&&panel.modal===null,'retired payment entries neither notify nor send');
localStorage.setItem(key,JSON.stringify({data:[100001,100002,100003,100004,100005,100006]}));
click(99);assert(panel.modalKind==='my-rooms','Spirit99 opens authored owned room panel');
let group=panel.modal.getChildByName('group-98');const rows=panel.modal.getComponent('OwnerRoomListView').content.children;
assert(rows.length===6,'owned rooms show all cached entries');
assert(rows[0].getChildByName('Digits').children.length===6,'owned room uses six original digit sprites');
rows[1].emit(e.Button.EventType.CLICK);assert(panel.modal===null,'owned room click closes list');
const join=sent.at(-1);assert(join.rpc==='self_join_room'&&join.data.roomcode===100002&&join.data.joinmode===1,'owned room click sends original join mode');
assert(join.data.location.city==='test'&&join.data.ip==='127.0.0.1','owned room join retains native location and login IP');
localStorage.setItem(key,JSON.stringify({data:[]}));click(99);assert(panel.modalKind==='my-rooms','empty owned room list still opens');
panel.modal.getChildByPath('group-98/Spirit103').emit(e.Button.EventType.CLICK);assert(panel.modal===null,'owned room shade closes');
const count=sent.length;click(3232);click(3232);
assert(sent.length===count+1&&sent.at(-1).rpc==='getVipRankList','VIP rank suppresses duplicate request');
assert(JSON.stringify(sent.at(-1).data)===JSON.stringify({agentid:config.identity.agentid,limit:3}),'VIP rank uses configured limit and exact fields');
packet('get_treasurelist',{list:[]});assert(panel.rankPending==='vip-rank','wealth response cannot consume pending VIP request');
const list=[{name:'VIP一',headimg:'',playerid:1,star:88,signature:'签名一',destwo:'附注',notice:'公告一'},{name:'VIP二',headimg:'',playerid:2,star:66,signature:'签名二',notice:'公告二'}];
packet('getVipRankList',{list});assert(panel.modalKind==='vip-rank','VIP response opens shared rank view');
group=panel.modal.getChildByName('group-84');assert(group.getChildByName('Spirit3234').getComponent(e.Sprite).spriteFrame===assets.vipRankTitle,'VIP title uses original frame');
assert(group.getChildByName('Spirit640').getComponent(e.Label).string==='公告:\n(附注)\n公告一','VIP detail renders notice and supplemental text');
group.getComponentInChildren(e.ScrollView).content.children[1].emit(e.Button.EventType.CLICK);
assert(group.getChildByName('Spirit640').getComponent(e.Label).string==='公告:\n公告二','VIP row selection updates announcement');
panel.close();click(3232);packet('getVipRankList',{});assert(panel.modal===null&&!panel.rankPending,'missing VIP list completes silently like legacy');
click(3232);packet('getVipRankList',{list:[]});assert(panel.modal===null&&!panel.rankPending,'empty VIP list stays closed');
click(3232);packet('getVipRankList',{list});
await new Promise(resolve=>e.director.once(e.Director.EVENT_AFTER_DRAW,resolve));
globalThis.__ownedVipVerification={panel,runtime,checks,close:()=>{off();panel.dispose();runtime.stop();popup.destroy();}};
return {checks,packets:sent.map(p=>({rpc:p.rpc,fields:Object.keys(p.data)}))};
}finally{if(previous===null)localStorage.removeItem(key);else localStorage.setItem(key,previous);}
}