59 lines
3.4 KiB
JavaScript
59 lines
3.4 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { loadMembers } = require('./new-player-ab-test-support.cjs');
|
|
const { contentModule } = require('./popup-animation-test-support.cjs');
|
|
|
|
test('paid revival waits for exit before state changes and the win check', async () => {
|
|
const Map = loadMembers('assets/Script/Map.ts', ['revivalPopupDone', 'runRewiveCopy', 'finishRewiveCopy']);
|
|
const map = new Map(), calls = [];
|
|
let finishExit;
|
|
map.isMapRuntimeAlive = () => true;
|
|
map.closeResultPopup = () => new Promise(resolve => finishExit = resolve);
|
|
map.finishPopupRunRewiveCopy = () => calls.push('state');
|
|
map.finishRevivePresentation = () => calls.push('win-check');
|
|
map.runRewiveCopy(); map.finishRewiveCopy();
|
|
assert.deepEqual(calls, []);
|
|
finishExit(); await map.revivalPopupDone; await Promise.resolve();
|
|
assert.deepEqual(calls, ['state', 'win-check']);
|
|
});
|
|
|
|
test('scene destruction during paid revival discards state and presentation', async () => {
|
|
const Map = loadMembers('assets/Script/Map.ts', ['revivalPopupDone', 'runRewiveCopy', 'finishRewiveCopy', 'finishRevivePresentation']);
|
|
const map = new Map(); let finishExit;
|
|
map.closeResultPopup = () => new Promise(resolve => finishExit = resolve);
|
|
map.isMapRuntimeAlive = () => false;
|
|
map.finishPopupRunRewiveCopy = () => assert.fail('destroyed scene must not revive');
|
|
map.runRewiveCopy(); map.finishRewiveCopy(); finishExit();
|
|
await map.revivalPopupDone; await Promise.resolve();
|
|
});
|
|
|
|
test('nested abandon exit animates only content and holds root until completion', async () => {
|
|
let finish, target, starts = 0;
|
|
const Map = loadMembers('assets/Script/Map.ts', ['resultPopupClosing', 'closeResultPopup'], {
|
|
cc: { isValid: value => !!value }, ...contentModule, PopupType: { Bounce: 1 },
|
|
PopupAnimator: {close(content, type, done) {starts++; target = content; finish = done;}}
|
|
});
|
|
const mask = {name:'New Sprite(Splash)'}, card = {name:'card'};
|
|
const confirmation = {active:true, children:[mask,card]};
|
|
const lose = {getChildByName: name => name === 'WinStreak' ? confirmation : null};
|
|
const root = {active:true,getChildByName:()=>lose};
|
|
const map = new Map(); map.getLoseRoot=()=>root; map.getWinRoot=()=>null;
|
|
const first=map.closeResultPopup(), second=map.closeResultPopup();
|
|
assert.equal(first,second); assert.equal(starts,1); assert.equal(root.active,true);
|
|
assert.deepEqual(target,[card]); finish(); await first;
|
|
assert.equal(root.active,false); assert.equal(map.resultPopupClosing,null);
|
|
});
|
|
|
|
test('revive retry popup resolves its sibling and hides only after exit', () => {
|
|
let finish, opened, closed;
|
|
const Revive = loadMembers('assets/Script/Revive.ts', ['openConfirmBox','closeConfirmBox','finishPopupCloseConfirmBox'], {
|
|
cc:{isValid:()=>true}, ...contentModule, PopupType:{Bounce:1},
|
|
PopupAnimator:{open:n=>opened=n,close(n,type,done){closed=n;finish=done;}}
|
|
});
|
|
const card={name:'card'}, mask={name:'New Sprite(Splash)'}, box={active:false,children:[mask,card]};
|
|
const revive=new Revive(); revive.node={parent:{getChildByName:()=>box},getChildByName:()=>null};revive.closeLoad=()=>{};
|
|
revive.openConfirmBox(); assert.equal(box.active,true); assert.deepEqual(opened,[card]);
|
|
revive.closeConfirmBox(); assert.deepEqual(closed,[card]); assert.equal(box.active,true);
|
|
finish(); assert.equal(box.active,false);
|
|
});
|