feat: shake the puzzle tank with single flick gestures

This commit is contained in:
2026-10-16 23:05:58 +08:00
parent 63dbedf457
commit 465fee1d07
11 changed files with 159 additions and 45 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import {chromium} from 'playwright';import assert from 'node:assert/strict';impo
const browser=await chromium.launch({executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',headless:true});
const context=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true,deviceScaleFactor:2});const p=await context.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));
await p.addInitScript(()=>{let seed=785;Math.random=()=>{seed=(seed*1664525+1013904223)>>>0;return seed/4294967296;};window.calls=[];window.xhs={miniTool:{writeTempFile:async args=>{window.exportData=args.data;window.calls.push('write');return {filePath:'test://fresh-card.png'};},postNote:async args=>{window.posted=args;window.calls.push('post');},saveImageToPhotosAlbum:async args=>{window.saved=args;window.calls.push('save');}}};});
await p.clock.install();await p.goto('http://localhost:4173');await p.waitForFunction(()=>window.shanheDebug);await p.locator('[data-speed="3"]').click();await p.locator('[data-bounce="2"]').click();await p.locator('#start').click();await p.clock.runFor(19500);const before=await p.evaluate(()=>shanheDebug.state());assert.equal(before.status,'playing');await p.locator('#up').tap();await p.clock.runFor(100);assert.ok((await p.evaluate(()=>shanheDebug.state())).shakeY<0);await p.locator('#pause').tap();const paused=await p.evaluate(()=>shanheDebug.state());await p.clock.runFor(60000);assert.equal((await p.evaluate(()=>shanheDebug.state())).elapsed,paused.elapsed);await p.getByRole('button',{name:'结束旅程',exact:true}).tap();const ended=await p.evaluate(()=>shanheDebug.state());assert.equal(ended.screen,'result');assert.equal(ended.status,'ended');assert.equal(ended.result.bounceName,'弹力全开');assert.equal(ended.result.speedName,'山河起飞');assert.equal(ended.result.score,paused.score);assert.equal(ended.result.elapsed,paused.elapsed);assert.equal(ended.result.history.at(-1).ms,paused.elapsed);assert.equal(ended.result.history.at(-1).score,paused.score);assert.ok(ended.result.history.every((v,i,a)=>!i||v.ms>=a[i-1].ms));assert.equal(ended.result.dropped,ended.dropped);assert.ok(ended.dropped<34,'结局截图保留未完成状态');await p.screenshot({path:'artifacts/result-mobile.png'});
await p.clock.install();await p.goto('http://localhost:4173');await p.waitForFunction(()=>window.shanheDebug);await p.locator('[data-speed="3"]').click();await p.locator('[data-bounce="2"]').click();await p.locator('#start').click();await p.clock.runFor(19500);const before=await p.evaluate(()=>shanheDebug.state());assert.equal(before.status,'playing');await p.keyboard.press('ArrowUp');await p.clock.runFor(100);assert.ok((await p.evaluate(()=>shanheDebug.state())).shakeY<0);await p.locator('#pause').tap();const paused=await p.evaluate(()=>shanheDebug.state());await p.clock.runFor(60000);assert.equal((await p.evaluate(()=>shanheDebug.state())).elapsed,paused.elapsed);await p.getByRole('button',{name:'结束旅程',exact:true}).tap();const ended=await p.evaluate(()=>shanheDebug.state());assert.equal(ended.screen,'result');assert.equal(ended.status,'ended');assert.equal(ended.result.bounceName,'弹力全开');assert.equal(ended.result.speedName,'山河起飞');assert.equal(ended.result.score,paused.score);assert.equal(ended.result.elapsed,paused.elapsed);assert.equal(ended.result.history.at(-1).ms,paused.elapsed);assert.equal(ended.result.history.at(-1).score,paused.score);assert.ok(ended.result.history.every((v,i,a)=>!i||v.ms>=a[i-1].ms));assert.equal(ended.result.dropped,ended.dropped);assert.ok(ended.dropped<34,'结局截图保留未完成状态');await p.screenshot({path:'artifacts/result-mobile.png'});
await p.locator('#share-note').tap();await p.waitForFunction(()=>window.posted);const posted=await p.evaluate(()=>window.posted);assert.equal(posted.pageType,'photo_publish');assert.equal(posted.mediaInfo.image_resources[0].url,'test://fresh-card.png');assert.ok(posted.content.includes('弹力全开')&&posted.content.includes('山河起飞'));assert.ok(posted.title.length<=20&&posted.content.length<=1000);const image=await p.evaluate(()=>window.exportData);fs.writeFileSync('artifacts/result-card.png',Buffer.from(image.split(',')[1],'base64'));await p.locator('#save-card').tap();await p.waitForFunction(()=>window.saved);assert.deepEqual(await p.evaluate(()=>window.calls),['write','post','write','save']);
// Failure/cancellation must leave the card usable; no-SDK must not throw.
await p.evaluate(()=>{window.xhs.miniTool.postNote=async()=>{throw Error('cancelled');};});await p.locator('#share-note').tap();await p.waitForFunction(()=>!document.querySelector('#share-note').disabled);assert.equal(await p.locator('#result-screen').isVisible(),true);await p.evaluate(()=>{window.xhs=null;});await p.locator('#share-note').tap();assert.ok((await p.locator('#toast').textContent()).includes('小红书小工具'));