feat: shake the puzzle tank with single flick gestures
This commit is contained in:
+5
-5
@@ -4,15 +4,15 @@ const watch=p=>{p.on('pageerror',e=>errors.push(e.message));p.on('request',r=>{i
|
||||
const state=p=>p.evaluate(()=>window.shanheDebug.state());
|
||||
const context=await browser.newContext({viewport:{width:1440,height:1000},deviceScaleFactor:1});const page=await context.newPage();watch(page);
|
||||
await page.goto('http://localhost:4173');await page.waitForFunction(()=>window.shanheDebug);assert.equal((await state(page)).status,'entry');assert.equal(await page.locator('#entry-screen').isVisible(),true);assert.equal(await page.locator('#game-screen').isVisible(),false);await page.waitForTimeout(300);assert.equal((await state(page)).dropped,0);await page.screenshot({path:'artifacts/desktop.png',fullPage:true});results.push('入口先选版本/地区/速度,未开局不生成碎片');
|
||||
await page.locator('[data-mode="city"]').click();await page.locator('#province-picker').click();await page.locator('[data-province="440000"]').click();await page.locator('[data-speed="3"]').click();assert.equal((await state(page)).level,'440000');assert.equal((await state(page)).speed,3);await page.locator('#start').click();assert.equal((await state(page)).status,'playing');assert.equal(await page.locator('#entry-screen').isVisible(),false);assert.equal(await page.locator('.controls button').count(),3);assert.equal(await page.locator('#rotate,#drop,#shake,#hint,#shuffle').count(),0);assert.equal(await page.locator('#total').textContent(),'21');results.push('选广东21市和山河起飞后直接开局,游戏包含左晃、上晃、右晃三项操作');
|
||||
await page.locator('[data-mode="city"]').click();await page.locator('#province-picker').click();await page.locator('[data-province="440000"]').click();await page.locator('[data-speed="3"]').click();assert.equal((await state(page)).level,'440000');assert.equal((await state(page)).speed,3);await page.locator('#start').click();assert.equal((await state(page)).status,'playing');assert.equal(await page.locator('#entry-screen').isVisible(),false);assert.equal(await page.locator('.controls button').count(),1);assert.equal(await page.locator('#rotate,#drop,#shake,#hint,#shuffle,#left,#right,#back,#up,#board-name,.game-tools').count(),0);assert.equal(await page.locator('#total').textContent(),'21');results.push('选广东21市和山河起飞后直接开局,底部仅一个圆形暂停图标,旧操作按钮和容器小字已移除');
|
||||
const bounds=await page.locator('#tank').boundingBox();assert.ok(bounds.width<=440);const frameStyle=await page.locator('#tank').evaluate(e=>({left:parseFloat(getComputedStyle(e).borderLeftWidth),bottom:parseFloat(getComputedStyle(e).borderBottomWidth)}));assert.ok(frameStyle.left>=7&&frameStyle.bottom>=9);
|
||||
await page.keyboard.down('ArrowLeft');await page.waitForFunction(()=>{const s=window.shanheDebug.state();return s.shakeOffset<0&&s.shakeCount>=2;});const a=await state(page);assert.ok(a.shakeOffset<0&&a.shakeCount>=2);const x=await page.locator('#tank').evaluate(e=>getComputedStyle(e).transform);assert.notEqual(x,'none');await page.keyboard.up('ArrowLeft');await page.waitForTimeout(350);const released=(await state(page)).shakeCount;await page.waitForTimeout(350);assert.equal((await state(page)).shakeCount,released);await page.keyboard.press('ArrowUp');assert.equal((await state(page)).shakeCount,released+1);await page.keyboard.press('ArrowDown');await page.keyboard.press('s');assert.equal((await state(page)).shakeCount,released+1);assert.ok((await state(page)).regions.every(r=>Math.abs(r.angle)<=.161));results.push('按住左右键驱动整个框,松开停止输入,上键轻颠,旧旋转/加速/S快捷键无效');
|
||||
await page.waitForTimeout(2200);assert.ok((await state(page)).dropped>=2);await page.screenshot({path:'artifacts/city-desktop.png',fullPage:true});
|
||||
await page.locator('#pause').click();assert.equal((await state(page)).status,'paused');const paused=await state(page);await page.mouse.move(bounds.x+bounds.width/2,bounds.y+160);await page.mouse.down();await page.mouse.move(bounds.x+bounds.width/2+60,bounds.y+220);await page.mouse.up();await page.waitForTimeout(200);assert.deepEqual((await state(page)).regions,paused.regions);await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');results.push('暂停冻结物理,棋盘不支持碎片拖动');
|
||||
await page.locator('#back').click();await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');await page.locator('#back').click();await page.getByRole('button',{name:'结束旅程',exact:true}).click();assert.equal((await state(page)).screen,'result');await page.locator('#result-back').click();assert.equal((await state(page)).status,'entry');assert.equal((await state(page)).dropped,0);await page.locator('[data-mode="province"]').click();await page.locator('#start').click();assert.equal((await state(page)).level,'100000');assert.equal(await page.locator('#total').textContent(),'34');await page.locator('#pause').click();await page.getByRole('button',{name:'重新开局',exact:true}).click();assert.equal((await state(page)).dropped,1);assert.equal((await state(page)).shakeCount,0);results.push('返回确认、重新选择、重新开局均清理旧局与按键状态');await context.close();
|
||||
const mobile=await browser.newContext({viewport:{width:390,height:844},deviceScaleFactor:2,isMobile:true,hasTouch:true});const mp=await mobile.newPage();watch(mp);await mp.goto('http://localhost:4173');await mp.waitForFunction(()=>window.shanheDebug);assert.ok(await mp.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await mp.screenshot({path:'artifacts/mobile.png',fullPage:true});await mp.locator('#start').tap();assert.equal((await state(mp)).status,'playing');await mp.locator('#left').tap();await mp.waitForTimeout(90);assert.ok((await state(mp)).shakeCount>0);await mp.screenshot({path:'artifacts/mobile-playing.png',fullPage:true});
|
||||
await page.locator('#pause').click();assert.equal((await state(page)).status,'paused');const paused=await state(page);await page.mouse.move(bounds.x+bounds.width/2,bounds.y+160);await page.mouse.down();await page.mouse.move(bounds.x+bounds.width/2+60,bounds.y+220);await page.mouse.up();await page.waitForTimeout(200);assert.deepEqual((await state(page)).regions,paused.regions);await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');results.push('暂停冻结物理,容器滑动不产生输入');
|
||||
await page.locator('#pause').click();await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');await page.locator('#pause').click();await page.getByRole('button',{name:'结束旅程',exact:true}).click();assert.equal((await state(page)).screen,'result');await page.locator('#result-back').click();assert.equal((await state(page)).status,'entry');assert.equal((await state(page)).dropped,0);await page.locator('[data-mode="province"]').click();await page.locator('#start').click();assert.equal((await state(page)).level,'100000');assert.equal(await page.locator('#total').textContent(),'34');await page.locator('#pause').click();await page.getByRole('button',{name:'重新开局',exact:true}).click();assert.equal((await state(page)).dropped,1);assert.equal((await state(page)).shakeCount,0);results.push('返回确认、重新选择、重新开局均清理旧局与按键状态');await context.close();
|
||||
const mobile=await browser.newContext({viewport:{width:390,height:844},deviceScaleFactor:2,isMobile:true,hasTouch:true});const mp=await mobile.newPage();watch(mp);await mp.goto('http://localhost:4173');await mp.waitForFunction(()=>window.shanheDebug);assert.ok(await mp.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await mp.screenshot({path:'artifacts/mobile.png',fullPage:true});await mp.locator('#start').tap();assert.equal((await state(mp)).status,'playing');const board=await mp.locator('#board').boundingBox();const session=await mobile.newCDPSession(mp);await session.send('Input.dispatchTouchEvent',{type:'touchStart',touchPoints:[{x:board.x+60,y:board.y+board.height*.7}]});await session.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:board.x+160,y:board.y+board.height*.7-30}]});await session.send('Input.dispatchTouchEvent',{type:'touchEnd',touchPoints:[]});await mp.waitForTimeout(90);assert.ok((await state(mp)).swipeCount>0);assert.equal((await state(mp)).swiping,false);await mp.screenshot({path:'artifacts/mobile-playing.png',fullPage:true});
|
||||
for(const viewport of [{width:390,height:844},{width:320,height:568},{width:740,height:390}]){await mp.setViewportSize(viewport);await mp.waitForFunction(()=>{const r=document.querySelector('.controls').getBoundingClientRect();return r.bottom<=innerHeight+1;});const b=await mp.locator('.controls').boundingBox();assert.ok(b.y+b.height<=viewport.height+1,JSON.stringify(viewport)+' controls on screen');assert.ok(await mp.evaluate(()=>document.documentElement.scrollWidth<=innerWidth));const saved=await state(mp);assert.equal(saved.status,'playing');assert.ok(saved.scale>0);}
|
||||
results.push('390/320窄屏及横屏:框体与三个触摸按钮同屏,无横向溢出,缩放保留局面');await mobile.close();
|
||||
results.push('390/320窄屏及横屏:框体与圆形菜单按钮同屏,无横向溢出,缩放保留局面');await mobile.close();
|
||||
const responsive=await browser.newContext({viewport:{width:320,height:568},isMobile:true,hasTouch:true});const rp=await responsive.newPage();watch(rp);await rp.goto('http://localhost:4173');await rp.waitForFunction(()=>window.shanheDebug);
|
||||
for(const viewport of [{width:320,height:568},{width:375,height:667},{width:390,height:844},{width:740,height:390}]){await rp.setViewportSize(viewport);for(const chosen of ['province','city']){await rp.locator('[data-mode="'+chosen+'"]').click();await rp.waitForFunction(()=>document.getElementById('start').getBoundingClientRect().bottom<=innerHeight);const fit=await rp.evaluate(()=>({scroll:document.documentElement.scrollHeight,viewport:innerHeight,start:document.getElementById('start').getBoundingClientRect().bottom}));assert.ok(fit.scroll<=fit.viewport+1,JSON.stringify({viewport,chosen,fit}));}await rp.screenshot({path:'artifacts/entry-'+viewport.width+'x'+viewport.height+'.png'});}
|
||||
await rp.setViewportSize({width:320,height:568});await rp.addStyleTag({content:':root{--safe-area-inset-top:44px;--safe-area-inset-bottom:34px}'});await rp.evaluate(()=>dispatchEvent(new Event('resize')));await rp.waitForFunction(()=>document.documentElement.scrollHeight<=innerHeight+1);await rp.locator('#province-picker').click();assert.equal(await rp.locator('.province-grid button').count(),27);assert.equal(await rp.locator('[data-province="710000"]').count(),0);const picker=await rp.locator('#modal').evaluate(e=>({scroll:e.scrollHeight,client:e.clientHeight}));assert.ok(picker.scroll<=picker.client+1);await rp.screenshot({path:'artifacts/province-picker-mobile.png'});await rp.locator('[data-province="330000"]').click();assert.equal((await state(rp)).level,'330000');results.push('入口省级/地级在320/375/390及横屏一屏显示;含44/34安全区;省区网格27项无需滚动');await responsive.close();
|
||||
|
||||
@@ -34,3 +34,25 @@ test('四档下落速度下,实测上晃分别为轻弹、正常和强弹,
|
||||
|
||||
test('左右晃动会缓存请求,碎片在两次150ms按键之间落地也能颠起',()=>{const l={id:'100000',name:'落地时序',width:1000,height:1000,regions:[square(0,0,0)],edges:[]};for(const delay of [0,25,60,100]){const g=new Game(l,320,590,0,()=>{},()=>.5,1);g.start();g.queue=[];g.clock=delay;const p=g.groups[0],b=p.body;M.Body.translate(b,{x:0,y:g.h-6-b.bounds.max.y});M.Body.setVelocity(b,{x:0,y:1});assert.ok(g.nudge(1));assert.equal(g.hopCount,0,'尚未接触时不在空中加速');for(let i=0;i<9;i++)g.tick(1000/60);assert.equal(g.hopCount,1,'下一次按键前已在落地时触发');assert.ok(b.velocity.y<0);g.destroy();}});
|
||||
test('过期请求、空中长按和暂停不会凭空产生连续上抛',()=>{const l={id:'100000',name:'时序限制',width:1000,height:1000,regions:[square(0,0,0)],edges:[]},g=new Game(l,320,590,0,()=>{},()=>.5,1);g.start();g.queue=[];g.nudge(1);for(let i=0;i<180;i++)g.tick(1000/60);assert.equal(g.hopCount,0,'初始空中请求已过期');g.status='paused';assert.equal(g.nudge(1),false);const count=g.hopCount;g.tick(100);assert.equal(g.hopCount,count);g.destroy();});
|
||||
|
||||
test('容器滑动按位置分配力度:附近更强,远处仍动,没有瞬移或单片抓取',()=>{
|
||||
const l={id:'100000',name:'位置力度',width:1000,height:1000,regions:[square(0,0,0),square(1,300,0)],edges:[]},g=new Game(l,420,560,0,()=>{},()=>.5,1);g.status='playing';g.queue=[];
|
||||
const near=g.createGroup([0],{tx:0,ty:0,angle:0}),far=g.createGroup([1],{tx:0,ty:0,angle:0});M.Body.setPosition(near.body,{x:90,y:200});M.Body.setPosition(far.body,{x:330,y:420});const positions=g.groups.map(p=>({...p.body.position}));
|
||||
assert.ok(g.swipe({x:90,y:200},{x:30,y:-10},32));assert.ok(near.body.velocity.x>far.body.velocity.x*3);assert.ok(far.body.velocity.x>0);assert.ok(near.body.velocity.y<far.body.velocity.y&&far.body.velocity.y<0);assert.deepEqual(g.groups.map(p=>({...p.body.position})),positions);assert.equal(g.swipeCount,1);g.tick(16.67);assert.ok(g.shake.offset>0);assert.ok(g.shake.y<0);g.destroy();
|
||||
});
|
||||
test('同样距离快速划动更有力;轻触、无效输入与暂停不触发晃动',()=>{
|
||||
const run=elapsed=>{const g=game();g.start();g.queue=[];const body=g.groups[0].body,p={...body.position};g.swipe(p,{x:24,y:0},elapsed);const vx=body.velocity.x;g.destroy();return vx;};assert.ok(run(16)>run(64)*1.3);
|
||||
const g=game();g.start();const p={x:200,y:200};assert.equal(g.swipe(p,{x:.1,y:.1},16),false);assert.equal(g.swipe(p,{x:NaN,y:0},16),false);assert.equal(g.swipe(p,{x:20,y:0},Infinity),false);g.status='paused';assert.equal(g.swipe(p,{x:20,y:0},16),false);assert.equal(g.swipeCount,0);g.destroy();
|
||||
});
|
||||
test('三档弹性连续任意方向滑动不超速、穿墙、旋转失控,落地滑动能颠起',()=>{
|
||||
const l={id:'100000',name:'滑动边界',width:1000,height:1000,regions:[square(0,0,0)],edges:[]};for(let bounce=0;bounce<3;bounce++){
|
||||
const g=new Game(l,320,590,0,()=>{},()=>.5,bounce);g.start();g.queue=[];const b=g.groups[0].body;M.Body.translate(b,{x:0,y:g.h-1-b.bounds.max.y});M.Sleeping.set(b,true);g.swipe({...b.position},{x:30,y:0},32);assert.ok(b.velocity.y<0,'落地碎片有上弹反馈');
|
||||
for(let i=0;i<600;i++){g.swipe({x:160,y:450},{x:Math.sin(i*.13)*300,y:Math.cos(i*.17)*300},16.67);g.tick(16.67);const real=M.Bounds.create(b.vertices);assert.ok(Math.abs(b.velocity.x)<=g.bounce.maxX+.001);assert.ok(b.velocity.y<=9.001);assert.ok(Math.abs(b.angle)<=.1601);assert.ok(real.min.x>=-3&&real.max.x<=g.w+3&&real.max.y<=g.h+4);assert.ok(g.impacts.length<=20);}g.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('每次划动只给一次冲量,短间隔限频,地块方向有分散且随后自由运动',()=>{
|
||||
const l={id:'100000',name:'单次惯性',width:1000,height:1000,regions:[square(0,0,0),square(1,300,0)],edges:[]};let seq=0;const g=new Game(l,420,560,0,()=>{},()=>[.1,.9,.9,.1][seq++%4],1);g.status='playing';g.queue=[];
|
||||
const a=g.createGroup([0],{tx:0,ty:100,angle:0}),b=g.createGroup([1],{tx:0,ty:100,angle:0});M.Body.setPosition(a.body,{x:120,y:200});M.Body.setPosition(b.body,{x:260,y:200});assert.ok(g.swipe({x:190,y:200},{x:70,y:0},100));assert.ok(a.body.velocity.x>0&&b.body.velocity.x>0);assert.ok(a.body.velocity.y*b.body.velocity.y<0,'相同大方向下有不同偏转');
|
||||
const pos={...a.body.position};assert.equal(g.swipe({x:120,y:200},{x:-70,y:0},100),false);for(let i=0;i<15;i++)g.tick(16.67);assert.equal(g.swipeCount,1);assert.notDeepEqual(a.body.position,pos);assert.ok(g.swipe({x:120,y:200},{x:70,y:0},100));assert.equal(g.swipeCount,2);g.destroy();
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ const browser=await chromium.launch({executablePath:'/Applications/Google Chrome
|
||||
let tabs=await page.locator('.mode-tabs').boundingBox();await page.mouse.move(tabs.x+tabs.width-25,tabs.y+tabs.height/2);await page.mouse.down();await page.mouse.move(tabs.x+25,tabs.y+tabs.height/2,{steps:10});await page.mouse.up();assert.equal((await state()).level,'330000');assert.equal(await page.locator('[data-mode="city"]').getAttribute('aria-pressed'),'true');await page.waitForTimeout(400);const cityTrack=await page.locator('.mode-tabs').evaluate(e=>getComputedStyle(e,'::before').transform);assert.ok(!cityTrack.endsWith(', 0, 0)'),'滑块到达地级位置');
|
||||
tabs=await page.locator('.mode-tabs').boundingBox();await page.mouse.move(tabs.x+25,tabs.y+tabs.height/2);await page.mouse.down();await page.mouse.move(tabs.x+tabs.width-25,tabs.y+tabs.height/2,{steps:10});await page.mouse.up();assert.equal((await state()).level,'100000');await page.waitForTimeout(400);await page.locator('[data-mode="city"]').tap();assert.equal((await state()).level,'330000');await page.locator('#province-picker').tap();assert.ok((await page.locator('#province-picker').getAttribute('class')).includes('expanded'));await page.locator('[data-province="440000"]').tap();assert.equal((await state()).level,'440000');
|
||||
await page.locator('[data-bounce="2"]').tap();assert.equal((await state()).bounce,2);assert.ok((await page.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));await page.waitForTimeout(600);assert.ok(!(await page.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));assert.ok(await page.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await page.screenshot({path:'artifacts/animated-entry.png'});
|
||||
await page.locator('[data-mode="province"]').tap();await page.locator('[data-speed="3"]').tap();await page.clock.install();await page.locator('#start').tap();await page.clock.runFor(7800);await page.locator('#up').tap();await page.clock.runFor(320);const strong=await state();assert.equal(strong.bounce,2);assert.ok(strong.shakeCount>0);await page.screenshot({path:'artifacts/strong-bounce.png'});
|
||||
await page.locator('[data-mode="province"]').tap();await page.locator('[data-speed="3"]').tap();await page.clock.install();await page.locator('#start').tap();await page.clock.runFor(7800);await page.keyboard.press('ArrowUp');await page.clock.runFor(320);const strong=await state();assert.equal(strong.bounce,2);assert.ok(strong.shakeCount>0);await page.screenshot({path:'artifacts/strong-bounce.png'});
|
||||
let seenContact=false;for(let i=0;i<70;i++){await page.clock.runFor(32);const s=await state();if(s.contactPulse>0){seenContact=true;await page.screenshot({path:'artifacts/contact-feedback.png'});break;}}assert.ok(seenContact,'真实碰撞触发短促反馈');
|
||||
const reduced=await browser.newContext({viewport:{width:320,height:568},reducedMotion:'reduce'});const rp=await reduced.newPage();rp.on('pageerror',e=>errors.push(e.message));await rp.goto('http://localhost:4173');await rp.locator('[data-bounce="2"]').click();assert.ok(!(await rp.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));assert.equal(await rp.locator('.mode-tabs').evaluate(e=>getComputedStyle(e,'::before').transitionDuration),'0s');assert.equal(await rp.locator('[data-bounce="2"]').evaluate(e=>getComputedStyle(e).animationName),'none');await rp.locator('#start').click();await rp.locator('#up').click();assert.equal((await rp.evaluate(()=>shanheDebug.state())).shakeCount,1);assert.deepEqual(errors,[]);
|
||||
const reduced=await browser.newContext({viewport:{width:320,height:568},reducedMotion:'reduce'});const rp=await reduced.newPage();rp.on('pageerror',e=>errors.push(e.message));await rp.goto('http://localhost:4173');await rp.locator('[data-bounce="2"]').click();assert.ok(!(await rp.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));assert.equal(await rp.locator('.mode-tabs').evaluate(e=>getComputedStyle(e,'::before').transitionDuration),'0s');assert.equal(await rp.locator('[data-bounce="2"]').evaluate(e=>getComputedStyle(e).animationName),'none');await rp.locator('#start').click();await rp.keyboard.press('ArrowUp');assert.equal((await rp.evaluate(()=>shanheDebug.state())).shakeCount,1);assert.deepEqual(errors,[]);
|
||||
fs.writeFileSync('artifacts/interactions-report.json',JSON.stringify({passed:true,results:['默认推荐蹦蹦跳','模式左右滑动和点击均更新真实关卡,滑块到位','省区选择与弹性按钮回弹不破坏点击','三向晃动和真实碰撞短反馈','减少动态效果设置禁用装饰动画,游戏仍可操作'],errors},null,2));console.log('滑动选择、回弹点击、强弹试玩、真实碰撞反馈与减少动态效果通过');await browser.close();
|
||||
|
||||
+1
-1
@@ -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('小红书小工具'));
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import {chromium} from 'playwright';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
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=[],results=[];
|
||||
p.on('pageerror',e=>errors.push(e.message));
|
||||
await p.addInitScript(()=>{let seed=785;Math.random=()=>{seed=(seed*1664525+1013904223)>>>0;return seed/4294967296;};});
|
||||
await p.goto('http://localhost:4173');await p.clock.install();
|
||||
await p.locator('[data-speed="3"]').tap();await p.locator('#start').tap();await p.clock.runFor(12000);
|
||||
const state=()=>p.evaluate(()=>shanheDebug.state()),cdp=await context.newCDPSession(p);
|
||||
const touch=async(type,x,y)=>cdp.send('Input.dispatchTouchEvent',{type,touchPoints:x===undefined?[]:[{x,y,id:1}]});
|
||||
let board=await p.locator('#board').boundingBox();
|
||||
assert.equal(await p.locator('#board').evaluate(e=>getComputedStyle(e).touchAction),'none');
|
||||
assert.deepEqual(await p.locator('.controls button').evaluateAll(buttons=>buttons.map(b=>b.id)),['pause']);
|
||||
const row=await p.locator('.controls').boundingBox();
|
||||
for(const id of ['pause']){const r=await p.locator('#'+id).boundingBox();assert.ok(r.y>=row.y&&r.y+r.height<=row.y+row.height+1);}
|
||||
assert.equal(await p.locator('#board-name,.board-tag,#left,#right,#up,#back,.game-tools').count(),0);
|
||||
const icon=await p.locator('#pause').evaluate(e=>({text:e.textContent.trim(),label:e.getAttribute('aria-label'),w:e.offsetWidth,h:e.offsetHeight,r:getComputedStyle(e).borderRadius}));assert.equal(icon.text,'');assert.equal(icon.w,icon.h);assert.equal(icon.r,'50%');assert.ok(icon.label.includes('暂停'));
|
||||
const x=board.x+board.width*.35,y=board.y+board.height*.72;
|
||||
const initial=await state();
|
||||
await touch('touchStart',x,y);await touch('touchMove',x+2,y+1);await p.clock.runFor(32);await touch('touchEnd');
|
||||
assert.equal((await state()).swipeCount,initial.swipeCount,'轻触和手抖不算滑动');
|
||||
// No force is delivered while the finger moves or remains pressed.
|
||||
await touch('touchStart',x,y);
|
||||
for(let i=1;i<=6;i++){await touch('touchMove',x+i*16,y-i*8);await p.clock.runFor(24);}
|
||||
const pending=await state();assert.ok(pending.swiping);assert.equal(pending.swipeCount,initial.swipeCount);assert.equal(pending.shakeCount,initial.shakeCount);
|
||||
await touch('touchEnd');assert.equal((await state()).swipeCount,initial.swipeCount+1);assert.equal((await state()).swiping,false);
|
||||
await p.clock.runFor(48);const released=await state();assert.ok(released.shakeOffset!==0||released.shakeY!==0);await p.screenshot({path:'artifacts/swipe-playing.png'});
|
||||
await p.clock.runFor(600);assert.equal((await state()).swipeCount,released.swipeCount);assert.notDeepEqual((await state()).regions,released.regions,'松手后继续靠惯性和重力运动');
|
||||
results.push('一次轻划仅在松手时触发一次晃动,移动中不施力,松手后自由运动');
|
||||
// A long slow drag cannot steer pieces. Neither can a flick held before release.
|
||||
board=await p.locator('#board').boundingBox();let count=(await state()).swipeCount;
|
||||
await touch('touchStart',x,y);for(let i=1;i<=8;i++){await p.clock.runFor(100);await touch('touchMove',x+i*8,y);}await touch('touchEnd');assert.equal((await state()).swipeCount,count,'慢拖不触发');
|
||||
await touch('touchStart',x,y);await touch('touchMove',x+90,y-20);await p.clock.runFor(600);assert.equal((await state()).swipeCount,count);await touch('touchEnd');assert.equal((await state()).swipeCount,count,'划后按住不能储存冲量');
|
||||
results.push('慢拖、按住以及划后停住再松手均不施力,无持续牵引');
|
||||
board=await p.locator('#board').boundingBox();
|
||||
await touch('touchStart',board.x+80,board.y+board.height*.6);await touch('touchMove',board.x+140,board.y+board.height*.6-20);await p.clock.runFor(32);assert.ok((await state()).swiping);
|
||||
await touch('touchCancel');assert.equal((await state()).swiping,false);const canceled=(await state()).swipeCount;await p.clock.runFor(300);assert.equal((await state()).swipeCount,canceled);
|
||||
results.push('系统取消触摸释放指针捕获并清理待处理输入');
|
||||
board=await p.locator('#board').boundingBox();
|
||||
await touch('touchStart',board.x+80,board.y+board.height*.55);await touch('touchMove',board.x+125,board.y+board.height*.55-25);await p.clock.runFor(32);
|
||||
// A keyboard pause while the finger is still down must discard pending movement.
|
||||
await p.keyboard.press(' ');const paused=await state();assert.equal(paused.status,'paused');assert.equal(paused.swiping,false);await touch('touchMove',board.x+180,board.y+board.height*.5);await touch('touchEnd');await p.clock.runFor(1000);assert.equal((await state()).swipeCount,paused.swipeCount);assert.deepEqual((await state()).regions,paused.regions);
|
||||
await p.getByRole('button',{name:'继续游戏',exact:true}).tap();await p.clock.runFor(100);assert.equal((await state()).swipeCount,paused.swipeCount);await p.locator('#pause').tap();await p.getByRole('button',{name:'结束旅程',exact:true}).tap();assert.equal((await state()).screen,'result');
|
||||
results.push('滑动中暂停清空手势,暂停冻结局面,继续后不重放旧输入;底部旅程操作可结束并生成成绩');
|
||||
assert.deepEqual(errors,[]);fs.writeFileSync('artifacts/swipe-report.json',JSON.stringify({scope:'Modern Chrome / CDP touch input, not native container acceptance',passed:true,results,errors},null,2));
|
||||
console.log(results.join('\n'));await browser.close();
|
||||
Reference in New Issue
Block a user