9 lines
3.3 KiB
JavaScript
9 lines
3.3 KiB
JavaScript
import {chooseProvince,setDifficulty} from './helpers.mjs';
|
|
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 page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));await page.goto('http://localhost:4173');const state=()=>page.evaluate(()=>shanheDebug.state());assert.equal((await state()).bounce,1);
|
|
await chooseProvince(page,'330000');assert.equal((await state()).level,'330000');await chooseProvince(page,'440000');assert.equal((await state()).level,'440000');await page.locator('#difficulty-settings').tap();assert.equal(await page.locator('[data-bounce="1"]').getAttribute('aria-pressed'),'true');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'));await page.getByRole('button',{name:'完成设置',exact:true}).tap();assert.ok(await page.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await page.screenshot({path:'artifacts/animated-entry.png'});
|
|
await chooseProvince(page,null);await setDifficulty(page,{speed:3});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('#difficulty-settings').click();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('[data-bounce="2"]').evaluate(e=>getComputedStyle(e).animationName),'none');await rp.getByRole('button',{name:'完成设置',exact:true}).click();assert.equal(await rp.locator('#reference').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();
|