// Run against preview.cjs; all wallet changes below are local fixture data. const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright'); const assert = require('node:assert/strict'); (async () => { const browser = await chromium.launch({ headless: true, channel: 'msedge' }); try { for (const viewport of [{ width: 394, height: 738 }, { width: 720, height: 1280 }]) { const page = await browser.newPage({ viewport }); const errors = []; page.on('pageerror', error => errors.push(error.message)); await page.goto('http://127.0.0.1:' + (process.env.PORT || 8765)); await page.waitForFunction(() => window.demo && demo.ready); await page.evaluate(async () => { const canvas = cc.director.getScene().getChildByName('Canvas'); let parent = canvas; for (const name of ['Load', 'Top', 'Coin']) { const node = new cc.Node(name); parent.addChild(node); parent = node; } canvas.getChildByName('Load').setPosition(20, 35); canvas.getChildByName('Load').scale = .9; parent.setPosition(170, 535); const label = parent.addComponent(cc.Label); label.string = '1000'; label.fontSize = 24; const Home = cc.Class({ name: 'JiaZai', extends: cc.Component, updateCoin() { label.string = String(cc.fx.GameConfig.GM_INFO.coin); } }); canvas.addComponent(Home); const host = canvas.getComponent('CoinMadnessHost'); const service = { request: async () => { await Promise.resolve(); cc.fx.GameConfig.GM_INFO.coin += 100; return { code: 1 }; } }; await host.requestActivity(service, 'claim', {}); if (label.string !== '1100') throw new Error('Claim did not refresh the HUD'); // A failed delivery confirmation must still show coins already saved locally. await host.requestActivity({ request: async () => { cc.fx.GameConfig.GM_INFO.coin += 200; throw new Error('confirmation failed'); } }, 'claim', {}).catch(() => {}); if (label.string !== '1300') throw new Error('Confirmation failure hid credited coins'); await demo.open(); const panel = demo.panel(); if (panel.api.coinTarget() !== parent) throw new Error('Incorrect home coin target'); panel.showRewardAnimation(0, 100); }); assert.equal(await page.evaluate(() => demo.panel().node.getChildByName('RewardClaimAnimation') .children.filter(n => n.name.startsWith('FlyingCoin')).length), 8); await page.waitForFunction(() => { const panel = demo.panel(), layer = panel.node.getChildByName('RewardClaimAnimation'); const coin = layer && layer.getChildByName('FlyingCoin0'); const target = panel.node.convertToNodeSpaceAR(panel.api.coinTarget().convertToWorldSpaceAR(cc.Vec2.ZERO)); return coin && Math.hypot(coin.x - target.x, coin.y - target.y) < 2; }, null, { timeout: 4000 }); await page.waitForFunction(() => !demo.panel().node.getChildByName('RewardClaimAnimation')); await page.evaluate(() => { demo.panel().showRewardAnimation(0, 100); return demo.close(); }); assert.deepEqual(errors, []); await page.close(); } console.log('PASS: wallet HUD refresh, confirmation failure, eight coins reach transformed home HUD at two viewport sizes, cleanup and close.'); } finally { await browser.close(); } })().catch(error => { console.error(error); process.exit(1); });