85 lines
3.1 KiB
JavaScript
85 lines
3.1 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { loadMembers } = require('./new-player-ab-test-support.cjs');
|
|
|
|
function setup(avatarAuthorized = true) {
|
|
const storage = {};
|
|
const scenes = [];
|
|
const overlay = { active: true };
|
|
let locationCallback, avatarCallback;
|
|
let alive = true;
|
|
const cc = {
|
|
fx: {
|
|
GameConfig: { GM_INFO: { address: '其他' } },
|
|
StorageMessage: {
|
|
getStorage: key => storage[key],
|
|
setStorage: (key, value) => { storage[key] = value; },
|
|
},
|
|
GameTool: {
|
|
shushu_Track() {},
|
|
getAuthorizationAvatar: () => avatarAuthorized,
|
|
getUserAvatar: callback => { avatarCallback = callback; },
|
|
},
|
|
},
|
|
director: { loadScene: name => { scenes.push(name); return true; } },
|
|
error: assert.fail,
|
|
warn: assert.fail,
|
|
};
|
|
const SceneManager = loadMembers('assets/Script/SceneManager.ts', ['returnHomeScene'], { cc });
|
|
const manager = new SceneManager();
|
|
manager.isPopupRuntimeAlive = () => alive;
|
|
const Map = loadMembers('assets/Script/Map.ts', ['openPosition', 'runAuthorize'], {
|
|
cc,
|
|
MiniGameSdk: { API: { getWechatCityInfo: callback => { locationCallback = callback; } } },
|
|
Utils: { setCityInfo() {}, setFailCityInfo() {} },
|
|
});
|
|
const map = Object.assign(new Map(), {
|
|
SceneManager: manager,
|
|
getWinRoot: () => ({ getChildByName: () => overlay }),
|
|
});
|
|
return {
|
|
map, cc, storage, scenes, overlay,
|
|
finishLocation: success => locationCallback(success, success ? '浙江' : null),
|
|
finishAvatar: () => avatarCallback(false),
|
|
destroyScene: () => { alive = false; },
|
|
};
|
|
}
|
|
|
|
test('first location authorization returns from Win to Home without a second click', () => {
|
|
const state = setup();
|
|
state.map.openPosition();
|
|
assert.equal(state.overlay.active, false);
|
|
assert.deepEqual(state.scenes, []);
|
|
state.finishLocation(true);
|
|
assert.equal(state.storage.address.authorize, true);
|
|
assert.equal(state.cc.fx.GameConfig.GM_INFO.address, '浙江');
|
|
assert.equal(state.cc.fx.GameConfig.locatePositionOnHome, true);
|
|
assert.deepEqual(state.scenes, ['HomeScene']);
|
|
});
|
|
|
|
test('location success continues the existing avatar flow and returns Home only once', () => {
|
|
const state = setup(false);
|
|
state.map.openPosition();
|
|
state.finishLocation(true);
|
|
assert.deepEqual(state.scenes, []);
|
|
state.finishAvatar();
|
|
state.finishAvatar();
|
|
assert.deepEqual(state.scenes, ['HomeScene']);
|
|
});
|
|
|
|
test('location rejection retains the existing behavior without returning Home', () => {
|
|
const state = setup();
|
|
state.map.openPosition();
|
|
state.finishLocation(false);
|
|
assert.equal(state.storage.address.authorize, false);
|
|
assert.deepEqual(state.scenes, []);
|
|
});
|
|
|
|
test('location callback from a departed scene cannot navigate Home', () => {
|
|
const state = setup();
|
|
state.map.openPosition();
|
|
state.destroyScene();
|
|
state.finishLocation(true);
|
|
assert.deepEqual(state.scenes, []);
|
|
});
|