feat: integrate platform room entry, UI migration and erqiwang documentation
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { announcementMotion } from '../../YouleNexus/assets/framework/presentation/lobby-model.ts';
|
||||
|
||||
test('announcement follows source byte width, speed, right entry and looping left exit',()=>{
|
||||
const initial=announcementMotion('公告ABC',645,0);
|
||||
assert.equal(initial.textWidth,105); // gblen=7, Game_Config.Notice.width=15
|
||||
assert.equal(initial.duration,7.5); // source speed=0.1 px/ms
|
||||
assert.equal(initial.left,645);
|
||||
assert.equal(announcementMotion('公告ABC',645,1).left,545);
|
||||
assert.ok(announcementMotion('公告ABC',645,7.49).left < -103);
|
||||
assert.equal(announcementMotion('公告ABC',645,7.5).left,645);
|
||||
assert.equal(announcementMotion('公告ABC',645,15).left,645);
|
||||
assert.equal(announcementMotion('',645,0).visible,false);
|
||||
assert.equal(announcementMotion(' ',645,0).visible,true);
|
||||
assert.throws(()=>announcementMotion('公告',0,0),/width/);
|
||||
});
|
||||
@@ -1,84 +1,98 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
import { createRemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
import { resolveLobbyMenuConfig, lobbyMenuState, lobbyTrayState, LOBBY_MENU_ACTIONS, LOBBY_UNAVAILABLE } from '../../YouleNexus/assets/framework/presentation/lobby-menu.ts';
|
||||
|
||||
const identity={agentid:'a',gameid:'g',channelid:'c',marketid:'m',version:1};
|
||||
const remote=(data:Record<string,unknown>)=>createRemoteConfig(data,identity);
|
||||
const source=readFileSync(new URL('../../../projects/Game_Surface_3/js/00_Surface/11_GameUI.js',import.meta.url),'utf8');
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
import { createRemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
import { resolveLobbyMenuConfig, lobbyMenuState, lobbyTrayState, LOBBY_MENU_ACTIONS, LOBBY_UNAVAILABLE, lobbyLockedTip } from '../../YouleNexus/assets/framework/presentation/lobby-menu.ts';
|
||||
|
||||
const identity={agentid:'a',gameid:'g',channelid:'c',marketid:'m',version:1};
|
||||
const remote=(data:Record<string,unknown>)=>createRemoteConfig(data,identity);
|
||||
const source=readFileSync(new URL('../../../projects/Game_Surface_3/js/00_Surface/11_GameUI.js',import.meta.url),'utf8');
|
||||
const ids=[11,12,13,14,17,7,234,483,568,286,287,10,508,496,509,3233,3232,3256,3264,76,3139,679,99,3120,3161,3162,3016,3018];
|
||||
function original(config:ReturnType<typeof resolveLobbyMenuConfig>,versionState:number,launchMode:number) {
|
||||
const visible:Record<number,boolean>=Object.fromEntries(ids.map(id=>[id,true]));
|
||||
const left:Record<number,number>={};
|
||||
const noop=()=>{};
|
||||
const ui=new Proxy({onstate:[],isprepare:[]} as Record<string,any>,{get:(o,k)=>k in o?o[k as string]:noop});
|
||||
const context=vm.createContext({GameUI:ui,GameData:{...config,Scene:1,versionState,LaunchMode:launchMode,
|
||||
hallConfig:config.hall,sysConfig:config.sys,isLocation:true,submitPhoneInfo:true,submitAddressBook:true},
|
||||
Game_Config:{sysConfig:config.template,Max:{},Share:{}},C_Player:{},ConstVal:{isGameHall:config.template.isGameHall,
|
||||
Launch_mode:{from_self:0,from_hall:1},sysNotice:{}},Logic:new Proxy({},{get:()=>noop}),Func:new Proxy({},{get:()=>noop}),
|
||||
Utl:new Proxy({},{get:()=>noop}),Game_Modify:{},gameHallImport:{jumpMenuScene:noop},
|
||||
set_self:(id:number,key:number,value:number)=>{if(key===37)visible[id]=Boolean(value);if(key===18)left[id]=value;},
|
||||
get_self:(id:number,key:number)=>key===37?Number(visible[id]):0,set_group:noop,shareLink:noop,isArray:Array.isArray});
|
||||
for(const name of ['JumpMenuScene','adaptSmartBar','adaptSmartBar2','updateActBtn','showStoreBtn']){
|
||||
const start=source.indexOf(`GameUI.${name} = function`);
|
||||
assert.ok(start>=0,name);
|
||||
const end=source.indexOf('\nGameUI.',start+1);
|
||||
vm.runInContext(source.slice(start,end),context);
|
||||
}
|
||||
ui.JumpMenuScene();
|
||||
return {visible,left};
|
||||
}
|
||||
|
||||
test('menu visibility and visible-only spacing match original JumpMenuScene across configuration combinations',()=>{
|
||||
for(const versionState of [0,1] as const)for(const isGameHall of [false,true])for(const agentmode of [1,2,3])
|
||||
for(const androidPay of [0,1])for(const flags of [0,1,2,3,4,7]){
|
||||
const config=resolveLobbyMenuConfig(remote({agentmode,androidPay,rankList:flags&1,hideTaskBtn:flags&1,
|
||||
hideWxShare:flags&2,miniPro:flags&4,hideRoomCard:flags&2?2:1,cdKey:flags&4?2:1,hall_config:{actData:flags&1?['',0,'','']:0}}),
|
||||
{isGameHall,mainMenuButton:isGameHall,hideNotice:isGameHall,vipInfinite:false});
|
||||
for(const launchMode of [0,1] as const){
|
||||
const expected=original(config,versionState,launchMode);
|
||||
const actual=lobbyMenuState(config,{versionState,launchMode});
|
||||
for(const id of ids){
|
||||
assert.equal(actual.visible[id]??true,expected.visible[id],JSON.stringify({id,versionState,isGameHall,agentmode,androidPay,flags}));
|
||||
assert.equal(actual.left[id],expected.left[id],`spacing ${id}`);
|
||||
}
|
||||
}
|
||||
test('three locked entries preserve source flags and exact click tips',()=>{
|
||||
const closed=resolveLobbyMenuConfig(remote({}));
|
||||
assert.deepEqual(closed.locked,{568:true,483:true,3139:true});
|
||||
assert.equal(lobbyLockedTip(closed,'world-rooms'),'暂未开放,敬请期待');
|
||||
assert.equal(lobbyLockedTip(closed,'match'),'暂未开放,敬请期待');
|
||||
assert.equal(lobbyLockedTip(closed,'official-rooms'),'暂未开放,敬请期待');
|
||||
for(const worldRoomList of [0,1,'0'])for(const vipConfig of [null,[['001234']]])for(const ofcShortCode of [null,'001234']){
|
||||
const config=resolveLobbyMenuConfig(remote({hall_config:{worldRoomList},vipConfig,ofcShortCode}));
|
||||
assert.deepEqual(config.locked,{568:!worldRoomList,483:!vipConfig,3139:!ofcShortCode});
|
||||
assert.equal(lobbyLockedTip(config,'world-rooms'),worldRoomList?null:'暂未开放,敬请期待');
|
||||
assert.equal(lobbyLockedTip(config,'match'),vipConfig?null:'暂未开放,敬请期待');
|
||||
assert.equal(lobbyLockedTip(config,'official-rooms'),ofcShortCode?null:'暂未开放,敬请期待');
|
||||
}
|
||||
});
|
||||
test('source hall merge preserves scoped top-level override and rejects invalid data',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({hall_config:{androidPay:1,rankList:2},rankList:1}));
|
||||
assert.equal(config.hall.androidPay,1);assert.equal(config.hall.rankList,1);
|
||||
assert.throws(()=>resolveLobbyMenuConfig(remote({hall_config:'bad'})),/hall_config/);
|
||||
assert.throws(()=>resolveLobbyMenuConfig(remote({agentmode:'bad'})),/agentmode/);
|
||||
});
|
||||
test('legacy hallConfigName actData colon typo leaves activity sourced only from hall_config',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({actData:['top'],hall_config:{actData:['hall']}}));
|
||||
assert.deepEqual(config.hall.actData,['hall']);
|
||||
assert.equal(resolveLobbyMenuConfig(remote({actData:['top']})).hall.actData,0);
|
||||
});
|
||||
test('source truthiness is preserved for string zero flags rather than coerced to numeric zero',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({hideTaskBtn:'0',hideWxShare:'0',rankList:'0'}));
|
||||
const actual=lobbyMenuState(config,{versionState:0,launchMode:0});
|
||||
const expected=original(config,0,0);
|
||||
for(const id of [17,14,3233])assert.equal(actual.visible[id],expected.visible[id]);
|
||||
assert.equal(actual.visible[17],false);assert.equal(actual.visible[3233],true);
|
||||
});
|
||||
test('main menu override hides all four entries and cdKey runs after review restriction',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({cdKey:2}),{isGameHall:false,mainMenuButton:true,hideNotice:false,vipInfinite:true});
|
||||
const normal=lobbyMenuState(config,{versionState:0,launchMode:0});
|
||||
for(const id of [11,12,483,568,3139,679])assert.equal(normal.visible[id],false);
|
||||
assert.equal(lobbyMenuState(config,{versionState:1,launchMode:0}).visible[3264],true);
|
||||
});
|
||||
test('tray excludes hidden entries from placement and keeps original feedback hidden',()=>{
|
||||
const state=lobbyTrayState(resolveLobbyMenuConfig(remote({agentmode:2,rankList:1,bagUrl:'bag',wareHouse:1,miniPro:1})),{versionState:0,launchMode:0});
|
||||
assert.equal(state.visible[235],false);assert.equal(state.visible[15],false);
|
||||
assert.deepEqual([state.left[604],state.left[3017],state.left[3057],state.left[5]],[216,371,526,681]);
|
||||
});
|
||||
test('every menu entry has an existing local action or an explicit unavailable business description',()=>{
|
||||
const local=['settings','profile','join-room','notice','tray','tasks','share','vip-rooms'];
|
||||
for(const action of Object.values(LOBBY_MENU_ACTIONS))assert.ok(local.includes(action)||LOBBY_UNAVAILABLE[action],action);
|
||||
for(const id of [10,286,287,3161] as const)assert.equal(LOBBY_MENU_ACTIONS[id],'buy-roomcard');
|
||||
for(const id of [508,509,496,3162] as const)assert.equal(LOBBY_MENU_ACTIONS[id],'buy-bean');
|
||||
});
|
||||
function original(config:ReturnType<typeof resolveLobbyMenuConfig>,versionState:number,launchMode:number) {
|
||||
const visible:Record<number,boolean>=Object.fromEntries(ids.map(id=>[id,true]));
|
||||
const left:Record<number,number>={};
|
||||
const noop=()=>{};
|
||||
const ui=new Proxy({onstate:[],isprepare:[]} as Record<string,any>,{get:(o,k)=>k in o?o[k as string]:noop});
|
||||
const context=vm.createContext({GameUI:ui,GameData:{...config,Scene:1,versionState,LaunchMode:launchMode,
|
||||
hallConfig:config.hall,sysConfig:config.sys,isLocation:true,submitPhoneInfo:true,submitAddressBook:true},
|
||||
Game_Config:{sysConfig:config.template,Max:{},Share:{}},C_Player:{},ConstVal:{isGameHall:config.template.isGameHall,
|
||||
Launch_mode:{from_self:0,from_hall:1},sysNotice:{}},Logic:new Proxy({},{get:()=>noop}),Func:new Proxy({},{get:()=>noop}),
|
||||
Utl:new Proxy({},{get:()=>noop}),Game_Modify:{},gameHallImport:{jumpMenuScene:noop},
|
||||
set_self:(id:number,key:number,value:number)=>{if(key===37)visible[id]=Boolean(value);if(key===18)left[id]=value;},
|
||||
get_self:(id:number,key:number)=>key===37?Number(visible[id]):0,set_group:noop,shareLink:noop,isArray:Array.isArray});
|
||||
for(const name of ['JumpMenuScene','adaptSmartBar','adaptSmartBar2','updateActBtn','showStoreBtn']){
|
||||
const start=source.indexOf(`GameUI.${name} = function`);
|
||||
assert.ok(start>=0,name);
|
||||
const end=source.indexOf('\nGameUI.',start+1);
|
||||
vm.runInContext(source.slice(start,end),context);
|
||||
}
|
||||
ui.JumpMenuScene();
|
||||
return {visible,left};
|
||||
}
|
||||
|
||||
test('menu visibility and visible-only spacing match original JumpMenuScene across configuration combinations',()=>{
|
||||
for(const versionState of [0,1] as const)for(const isGameHall of [false,true])for(const agentmode of [1,2,3])
|
||||
for(const androidPay of [0,1])for(const flags of [0,1,2,3,4,7]){
|
||||
const config=resolveLobbyMenuConfig(remote({agentmode,androidPay,rankList:flags&1,hideTaskBtn:flags&1,
|
||||
hideWxShare:flags&2,miniPro:flags&4,hideRoomCard:flags&2?2:1,cdKey:flags&4?2:1,hall_config:{actData:flags&1?['',0,'','']:0}}),
|
||||
{isGameHall,mainMenuButton:isGameHall,hideNotice:isGameHall,vipInfinite:false});
|
||||
for(const launchMode of [0,1] as const){
|
||||
const expected=original(config,versionState,launchMode);
|
||||
const actual=lobbyMenuState(config,{versionState,launchMode});
|
||||
for(const id of ids){
|
||||
assert.equal(actual.visible[id]??true,expected.visible[id],JSON.stringify({id,versionState,isGameHall,agentmode,androidPay,flags}));
|
||||
assert.equal(actual.left[id],expected.left[id],`spacing ${id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
test('source hall merge preserves scoped top-level override and rejects invalid data',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({hall_config:{androidPay:1,rankList:2},rankList:1}));
|
||||
assert.equal(config.hall.androidPay,1);assert.equal(config.hall.rankList,1);
|
||||
assert.throws(()=>resolveLobbyMenuConfig(remote({hall_config:'bad'})),/hall_config/);
|
||||
assert.throws(()=>resolveLobbyMenuConfig(remote({agentmode:'bad'})),/agentmode/);
|
||||
});
|
||||
test('legacy hallConfigName actData colon typo leaves activity sourced only from hall_config',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({actData:['top'],hall_config:{actData:['hall']}}));
|
||||
assert.deepEqual(config.hall.actData,['hall']);
|
||||
assert.equal(resolveLobbyMenuConfig(remote({actData:['top']})).hall.actData,0);
|
||||
});
|
||||
test('source truthiness is preserved for string zero flags rather than coerced to numeric zero',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({hideTaskBtn:'0',hideWxShare:'0',rankList:'0'}));
|
||||
const actual=lobbyMenuState(config,{versionState:0,launchMode:0});
|
||||
const expected=original(config,0,0);
|
||||
for(const id of [17,14,3233])assert.equal(actual.visible[id],expected.visible[id]);
|
||||
assert.equal(actual.visible[17],false);assert.equal(actual.visible[3233],true);
|
||||
});
|
||||
test('main menu override hides all four entries and cdKey runs after review restriction',()=>{
|
||||
const config=resolveLobbyMenuConfig(remote({cdKey:2}),{isGameHall:false,mainMenuButton:true,hideNotice:false,vipInfinite:true});
|
||||
const normal=lobbyMenuState(config,{versionState:0,launchMode:0});
|
||||
for(const id of [11,12,483,568,3139,679])assert.equal(normal.visible[id],false);
|
||||
assert.equal(lobbyMenuState(config,{versionState:1,launchMode:0}).visible[3264],true);
|
||||
});
|
||||
test('tray excludes hidden entries from placement and keeps original feedback hidden',()=>{
|
||||
const state=lobbyTrayState(resolveLobbyMenuConfig(remote({agentmode:2,rankList:1,bagUrl:'bag',wareHouse:1,miniPro:1})),{versionState:0,launchMode:0});
|
||||
assert.equal(state.visible[235],false);assert.equal(state.visible[15],false);
|
||||
assert.deepEqual([state.left[604],state.left[3017],state.left[3057],state.left[5]],[216,371,526,681]);
|
||||
});
|
||||
test('every menu entry has an existing local action or an explicit unavailable business description',()=>{
|
||||
const local=['settings','profile','join-room','notice','tray','tasks','share','vip-rooms','qrcode','rank','cdkey','vip-rank','my-rooms','buy-roomcard','buy-bean'];
|
||||
for(const action of Object.values(LOBBY_MENU_ACTIONS))assert.ok(local.includes(action)||LOBBY_UNAVAILABLE[action],action);
|
||||
for(const id of [10,286,287,3161] as const)assert.equal(LOBBY_MENU_ACTIONS[id],'buy-roomcard');
|
||||
for(const id of [508,509,496,3162] as const)assert.equal(LOBBY_MENU_ACTIONS[id],'buy-bean');
|
||||
});
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {runInNewContext} from 'node:vm';
|
||||
import {validateProfileAuth} from '../../YouleNexus/assets/framework/presentation/profile-auth.ts';
|
||||
|
||||
const root=new URL('../../../projects/Game_Surface_3/js/00_Surface/',import.meta.url);
|
||||
const source=readFileSync(new URL('05_Func.js',root),'utf8');
|
||||
const districts=readFileSync(new URL('03_Banwords.js',root),'utf8');
|
||||
const context:any={};
|
||||
runInNewContext(districts.slice(districts.indexOf('var GB2260 ='),districts.indexOf(';',districts.indexOf('var GB2260 ='))+1)
|
||||
+source.slice(source.indexOf('var IDValidator ='),source.indexOf('Func.subString ='))+';validator=new IDValidator();',context);
|
||||
|
||||
test('auth follows source name check and known checksum outcomes',()=>{
|
||||
assert.equal(validateProfileAuth('张','11010519491231002X'),'name');
|
||||
assert.equal(validateProfileAuth('测试','11010519491231002X'),null);
|
||||
assert.equal(validateProfileAuth('测试','11010519491231002x'),null);
|
||||
assert.equal(validateProfileAuth('测试','110105194912310020'),'id');
|
||||
assert.equal(validateProfileAuth('测试',''),'id');
|
||||
assert.equal(validateProfileAuth('测试','110105491231002'),null);
|
||||
});
|
||||
|
||||
test('ID validation matches the original validator including legacy date and address semantics',()=>{
|
||||
const ids=['','11010519491231002X','110105194912310020','110105491231002','110105491332002','999999491231002',
|
||||
'110199491231002','110105490231002','110105490000002','11010549aa31abc',' 11010519491231002X','11010519491231002X '];
|
||||
for(const base of ['11010519491231002X','110105491231002'])for(let i=0;i<base.length;i++){
|
||||
for(const ch of ['0','9','A','x'])ids.push(base.slice(0,i)+ch+base.slice(i+1));
|
||||
}
|
||||
for(const id of ids)assert.equal(validateProfileAuth('测试',id)===null,context.validator.isValid(id),`parity for ${id}`);
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {parseRankList,parseVipRankList} from '../../YouleNexus/assets/framework/protocol/contracts/rank-list.ts';
|
||||
test('config rank normalizes legacy names and signatures without modifying server entries',()=>{
|
||||
const row={name:'一二三四五六七八九',headimg:'',playerid:'001',star:100,signature:'a#b'};
|
||||
assert.deepEqual(parseRankList([row]),[row]);
|
||||
assert.deepEqual(parseRankList([row],true),[{...row,name:'一二三四五六七八...',signature:'a\nb'}]);
|
||||
assert.equal(parseRankList([{...row,name:'12345678901234567',signature:null}],true)[0].name,'1234567890123456...');
|
||||
assert.deepEqual(parseRankList([]),[]);assert.throws(()=>parseRankList([{}]));
|
||||
});
|
||||
|
||||
test('VIP ranks retain announcement fields and ignore absent optional text',()=>{
|
||||
const row={name:'VIP',headimg:'',playerid:1,star:8,signature:'签名',notice:'公告',destwo:'补充'};
|
||||
assert.deepEqual(parseVipRankList([row]),[row]);
|
||||
assert.deepEqual(parseVipRankList([{...row,notice:null,destwo:null}]),[{...row,notice:'',destwo:''}]);
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {RequestLoading} from '../../YouleNexus/assets/framework/presentation/request-loading.ts';
|
||||
test('request loading closes on matching success or failure independent of payload',()=>{
|
||||
const shown:boolean[]=[];const loading=new RequestLoading(v=>shown.push(v));
|
||||
for(const rpc of ['get_player_task','get_task_award','getVipRankList'] as const){
|
||||
for(const data of [{state:0},{state:1,error:'失败'},null]){loading.begin(rpc);loading.received({route:'agent',rpc,data});assert.deepEqual(shown.splice(0),[true,false]);}
|
||||
}
|
||||
loading.begin('get_player_task');loading.received({route:'agent',rpc:'getVipRankList'});assert.deepEqual(shown,[true]);
|
||||
loading.received({route:'agent',rpc:'show_message'});assert.deepEqual(shown,[true,false]);
|
||||
});
|
||||
test('overlapping requests, cancellation, and duplicate replies do not flicker',()=>{
|
||||
const shown:boolean[]=[];const loading=new RequestLoading(v=>shown.push(v));
|
||||
loading.begin('get_player_task');loading.begin('getVipRankList');loading.received({route:'agent',rpc:'get_player_task'});
|
||||
assert.deepEqual(shown,[true]);loading.cancel('getVipRankList');loading.cancel('getVipRankList');
|
||||
assert.deepEqual(shown,[true,false]);loading.begin('get_task_award');loading.clear();assert.deepEqual(shown,[true,false,true,false]);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {JoinRoomInput} from '../../YouleNexus/assets/framework/presentation/join-room-input.ts';
|
||||
import {TemplateRoomRules} from '../../YouleNexus/assets/games/template/template-room-rules.ts';
|
||||
|
||||
test('keypad preserves display zeros and submits a number at six digits',()=>{
|
||||
const sent:number[]=[];const input=new JoinRoomInput(code=>sent.push(code));
|
||||
for(const digit of [0,1,2,3,4])input.digit(digit);
|
||||
assert.deepEqual(sent,[]);input.digit(5);
|
||||
assert.equal(input.code,'012345');assert.deepEqual(sent,[12345]);
|
||||
input.setBusy(true);input.digit(6);input.remove();input.clear();input.confirm();
|
||||
assert.equal(input.code,'012345');assert.deepEqual(sent,[12345]);
|
||||
input.setBusy(false);input.remove();assert.equal(input.code,'01234');
|
||||
input.clear();input.confirm();assert.deepEqual(sent,[12345]);
|
||||
input.digit(8);input.confirm();assert.deepEqual(sent,[12345,8]);
|
||||
});
|
||||
test('paste strips non-digits, truncates and submits; prefill does not submit',()=>{
|
||||
const sent:number[]=[];const input=new JoinRoomInput(code=>sent.push(code));
|
||||
input.prefill('123456');assert.deepEqual(sent,[]);
|
||||
input.paste('房号:987-654321');assert.equal(input.code,'987654');assert.deepEqual(sent,[987654]);
|
||||
input.paste('12a');assert.equal(input.code,'12');assert.equal(sent.length,1);
|
||||
assert.throws(()=>input.digit(10));assert.throws(()=>input.prefill('corrupt'));
|
||||
});
|
||||
test('template options do not rewrite source fixed sample; each submission is independent',()=>{
|
||||
const rules=new TemplateRoomRules();const expected=[1,4,1,2,2,[1,1,[1,2000,10],null,null,1],[1,0,5]];
|
||||
assert.deepEqual(rules.build(),expected);rules.select(0,1);rules.select(1,1);
|
||||
assert.deepEqual(rules.build(),expected);const packet=rules.build();packet[0]=999;
|
||||
assert.deepEqual(rules.build(),expected);assert.throws(()=>rules.select(0,2));
|
||||
// Original saved array's index 1 is 4: no corresponding Type_2 checkmark.
|
||||
rules.open(expected);assert.deepEqual(rules.selection,[0,3]);
|
||||
assert.equal(rules.seatCount(expected),10);assert.throws(()=>rules.open({}));
|
||||
});
|
||||
@@ -1,14 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
import type { RuntimeConfig } from '../../YouleNexus/assets/framework/config/runtime-config.ts';
|
||||
import { resolveSharePolicy,sharePayload } from '../../YouleNexus/assets/framework/presentation/share-model.ts';
|
||||
test('share reads url_download and preserves original friend and timeline payloads',()=>{
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts';
|
||||
import type { RuntimeConfig } from '../../YouleNexus/assets/framework/config/runtime-config.ts';
|
||||
import { resolveSharePolicy,sharePayload,resolveQrCodePolicy } from '../../YouleNexus/assets/framework/presentation/share-model.ts';
|
||||
|
||||
test('QR entry uses scoped WechatPublicNo_ewm and exact image share parameters',()=>{
|
||||
const identity={agentid:'a',channelid:'c',gameid:'g',marketid:4,version:1};
|
||||
const remoteConfig=createRemoteConfig({url_download:'https://example.test/app',sharename:'标题',hall_config:{shareDesc:'描述',shareType:1,shareImgUrl:'https://example.test/share.png'}},identity);
|
||||
const policy=resolveSharePolicy({identity,remoteConfig} as RuntimeConfig);
|
||||
assert.equal(policy.url,'https://example.test/app?agentid=a&channelid=c&gameid=g&marketid=4');
|
||||
assert.deepEqual(sharePayload(policy,1),{sharefriend:1,type:1,webpageUrl:policy.url,title:'标题',description:'描述',sharetype:0});
|
||||
assert.deepEqual(sharePayload(policy,2),{sharefriend:2,type:3,webpageUrl:'https://example.test/share.png',title:'标题描述',description:undefined,sharetype:0});
|
||||
assert.equal(sharePayload({...policy,imageTimeline:false},2),null);
|
||||
const config=(data:Record<string,unknown>)=>({identity,remoteConfig:createRemoteConfig(data,identity)} as RuntimeConfig);
|
||||
assert.equal(resolveQrCodePolicy(config({})),null);
|
||||
const result=resolveQrCodePolicy(config({WechatPublicNo_ewm:'root.png',agentlist:[{agentid:'a',WechatPublicNo_ewm:'https://example.test/qr.png'}],sharename:'标题',shareDesc:'说明'}));
|
||||
assert.deepEqual(result,{url:'https://example.test/qr.png',share:{sharefriend:1,type:3,webpageUrl:'https://example.test/qr.png',title:'标题说明',description:undefined,sharetype:0}});
|
||||
assert.throws(()=>resolveQrCodePolicy(config({WechatPublicNo_ewm:123})),/WechatPublicNo_ewm/);
|
||||
});
|
||||
test('share reads url_download and preserves original friend and timeline payloads',()=>{
|
||||
const identity={agentid:'a',channelid:'c',gameid:'g',marketid:4,version:1};
|
||||
const remoteConfig=createRemoteConfig({url_download:'https://example.test/app',sharename:'标题',hall_config:{shareDesc:'描述',shareType:1,shareImgUrl:'https://example.test/share.png'}},identity);
|
||||
const policy=resolveSharePolicy({identity,remoteConfig} as RuntimeConfig);
|
||||
assert.equal(policy.url,'https://example.test/app?agentid=a&channelid=c&gameid=g&marketid=4');
|
||||
assert.deepEqual(sharePayload(policy,1),{sharefriend:1,type:1,webpageUrl:policy.url,title:'标题',description:'描述',sharetype:0});
|
||||
assert.deepEqual(sharePayload(policy,2),{sharefriend:2,type:3,webpageUrl:'https://example.test/share.png',title:'标题描述',description:undefined,sharetype:0});
|
||||
assert.equal(sharePayload({...policy,imageTimeline:false},2),null);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {createTemplateGame} from '../../YouleNexus/assets/games/template/template-game.ts';
|
||||
test('template module attaches only when opened and releases its view and subscription',()=>{
|
||||
let unsubscribed=0;const commands:unknown[]=[];const views:unknown[]=[];
|
||||
const snapshot={connection:{phase:'logged-in'},self:{playerId:1,seat:0},room:{roomcode:'123456',roomtype:[],stage:0,needprepare:0,infinite:0},seats:[]};
|
||||
const game=createTemplateGame('g');const probe=game.entry.createModule();probe.dispose();
|
||||
assert.throws(()=>game.mount({render:s=>views.push(s),close(){}}));
|
||||
const module=game.entry.createModule();
|
||||
module.attach({getSnapshot:()=>snapshot,subscribe:()=>()=>unsubscribed++,execute:(c:unknown)=>commands.push(c),seat:{toView:(n:number)=>n,toServer:(n:number)=>n},sendGameMessage(){}} as any);
|
||||
let actions:any;game.mount({render:(s,a)=>{views.push(s);actions=a;},close:()=>views.push('closed')});
|
||||
actions.exit();actions.prepare();assert.deepEqual(commands,[{type:'room.exit'},{type:'room.prepare'}]);
|
||||
const deskinfo={nested:[1,2]};module.restore(deskinfo);assert.equal(game.restoredSnapshot,deskinfo);
|
||||
module.dispose();assert.equal(unsubscribed,1);assert.equal(views.at(-1),'closed');assert.throws(()=>actions.exit());
|
||||
});
|
||||
Reference in New Issue
Block a user