23 lines
5.5 KiB
JavaScript
23 lines
5.5 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 p=await browser.newPage({viewport:{width:390,height:844},isMobile:true,hasTouch:true}),errors=[],external=[];
|
|
p.on('pageerror',e=>errors.push(e.message));p.on('request',r=>{if(!r.url().startsWith('http://localhost:4173'))external.push(r.url());});await p.goto('http://localhost:4173');
|
|
const state=()=>p.evaluate(()=>shanheDebug.state());
|
|
assert.equal((await state()).entryProvince,null);assert.equal(await p.locator('#atlas-back').isVisible(),false);assert.equal(await p.locator('#reference [data-province]').count(),34);for(const code of ['710000','810000','820000'])assert.ok(await p.locator('#reference [data-province="'+code+'"] .atlas-land').count());assert.ok(await p.locator('#reference').evaluate(svg=>window.MAP_DATA.levels[0].regions.every(r=>{const path=svg.querySelector('[data-province="'+r.id+'"] .atlas-land');return path&&(path.getAttribute('d').match(/M/g)||[]).length===r.rings.length;})&&(svg.querySelector('.atlas-maritime').getAttribute('d').match(/M/g)||[]).length===10),'全部省级外环和海域线实际出现在地图中');assert.equal(await p.locator('.mode-tabs,.setup').count(),0);assert.equal(await p.locator('#entry-screen [data-speed],#entry-screen [data-bounce]').count(),0);
|
|
// Direct national start is available without opening another panel.
|
|
await p.locator('#start').tap();assert.equal((await state()).level,'100000');assert.equal((await state()).dropped,0);await p.locator('#pause').tap();await p.getByRole('button',{name:'结束旅程',exact:true}).tap();await p.locator('#result-back').tap();
|
|
const rects=()=>p.evaluate(()=>['.atlas-scene','.atlas-actions','#start','#difficulty-settings','footer'].map(s=>{const r=document.querySelector(s).getBoundingClientRect();return {selector:s,x:r.x,y:r.y,w:r.width,h:r.height};}));const baseline=await rects();
|
|
const codes=await p.locator('#reference [data-province]').evaluateAll(es=>es.map(e=>e.getAttribute('data-province')));let playable=0,unavailable=0;
|
|
for(const code of codes){
|
|
// Keyboard activation also makes tiny islands and narrow regions accessible.
|
|
const target=p.locator('#reference [data-province="'+code+'"]');await target.focus();await p.keyboard.press('Enter');assert.equal((await state()).entryProvince,code);assert.equal(await p.locator('#atlas-back').isVisible(),true);assert.deepEqual(await rects(),baseline,'选省后尺寸/位置完全不变 '+code);
|
|
if((await state()).entryPlayable){playable++;const details=await p.locator('#reference [data-region]').count();assert.ok(details>1);assert.ok((await p.locator('#journey-count').textContent()).includes(String(details)));assert.equal(await p.locator('#start').isEnabled(),true);}else{unavailable++;assert.equal(await p.locator('#start').isDisabled(),true);assert.ok((await p.locator('#map-caption').textContent()).includes('暂未开放'));}
|
|
await p.locator('#atlas-back').tap();assert.equal((await state()).entryProvince,null);assert.equal(await p.locator('#atlas-back').isVisible(),false);assert.deepEqual(await rects(),baseline,'返回全国后尺寸/位置完全不变');
|
|
}
|
|
assert.equal(playable,34);assert.equal(unavailable,0);
|
|
for(const [code,count,label] of [['110000',16,'县区拼图'],['120000',16,'县区拼图'],['310000',16,'县区拼图'],['500000',38,'县区拼图'],['710000',20,'县市拼图'],['810000',18,'分区拼图'],['820000',8,'分区拼图']]){await chooseProvince(p,code);assert.equal(await p.locator('#atlas-mode').textContent(),label);assert.equal(await p.locator('#reference [data-region]').count(),count);await p.screenshot({path:'artifacts/detail-'+code+'.png'});await p.locator('#start').tap();assert.equal((await state()).level,code);assert.equal(await p.locator('#total').textContent(),String(count));assert.ok((await p.locator('#game-title').textContent()).includes(label));await p.locator('#pause').tap();await p.getByRole('button',{name:'结束旅程',exact:true}).tap();await p.locator('#result-back').tap();assert.equal(await p.locator('#atlas-back').isVisible(),true);assert.deepEqual(await rects(),baseline);}
|
|
await chooseProvince(p,'710000');assert.ok((await p.locator('#atlas-tip').textContent()).includes('移位示意'));assert.equal(await p.locator('#reference [data-region="TW-65000"] path').getAttribute('fill-rule'),'evenodd');
|
|
await chooseProvince(p,'330000');await setDifficulty(p,{speed:2,bounce:2});assert.equal((await state()).level,'330000');assert.equal((await state()).speed,2);assert.equal((await state()).bounce,2);assert.deepEqual(await rects(),baseline);await p.screenshot({path:'artifacts/atlas-zhejiang-mobile.png'});await p.locator('#start').tap();assert.equal((await state()).level,'330000');assert.equal((await state()).dropped,0);assert.equal(await p.locator('#total').textContent(),'11');assert.deepEqual(errors,[]);assert.deepEqual(external,[]);
|
|
fs.writeFileSync('artifacts/atlas-report.json',JSON.stringify({passed:true,scope:'Modern browser development regression, not real mini-tool container acceptance',playable,unavailable,all34Present:true,fixedRects:baseline,errors,external},null,2));console.log('地图入口:全国直接开局、34省区逐一钻入/返回、34细分关可玩、县区/县市/分区标注与实际开局、全国隐藏返回按钮、设置生效,所有切换均不改变主体和开局栏尺寸/位置');await p.context().close();await browser.close();
|