Files
shanhe-puzzle/tests/province-direct.mjs
T
codex-bot 4845826deb
Shanhe source and offline package checks / verify (pull_request) Failing after 5s
feat: sync Shanhe 2.2 source and add remote package verification
2026-11-01 17:13:46 +08:00

24 lines
5.3 KiB
JavaScript

import {chromium} from 'playwright';import assert from 'node:assert/strict';import fs from 'node:fs';import {chooseProvince} from './helpers.mjs';
const browser=await chromium.launch({executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',headless:true}),context=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true,deviceScaleFactor:2}),p=await context.newPage(),errors=[],network=[];p.on('pageerror',e=>errors.push(e.message));p.on('request',r=>{if(!r.url().startsWith('http://localhost:4173'))network.push(r.url());});
const expected={'410000':{total:18,direct:1},'420000':{total:17,direct:4},'460000':{total:19,direct:15},'650000':{total:24,direct:10}},report=[];
try{
await p.clock.install();await p.goto('http://localhost:4173');await p.evaluate(()=>{const start=PuzzleGame.Game.prototype.start;PuzzleGame.Game.prototype.start=function(){start.call(this);window.provinceRun=this;};});
const rects=()=>p.evaluate(()=>['.atlas-scene','.atlas-actions','#start','#difficulty-settings'].map(selector=>{const b=document.querySelector(selector).getBoundingClientRect();return [selector,b.x,b.y,b.width,b.height];}));
for(const viewport of [{width:390,height:844},{width:320,height:568},{width:740,height:390}]){
await p.setViewportSize(viewport);await p.clock.runFor(100);if(await p.locator('#atlas-back').isVisible())await p.locator('#atlas-back').tap();const baseline=await rects();
for(const [code,e] of Object.entries(expected)){
await chooseProvince(p,code);await p.clock.runFor(50);assert.equal(await p.locator('#reference [data-region]').count(),e.total);assert.equal(await p.locator('#atlas-mode').textContent(),'省域拼图');assert.ok((await p.locator('#map-caption').textContent()).includes('省直辖'));assert.ok((await p.locator('#atlas-tip').textContent()).includes(String(e.direct)));assert.ok((await p.locator('#journey-count').textContent()).includes(String(e.total)));assert.deepEqual(await rects(),baseline,'固定地图/开局栏 '+code+' '+JSON.stringify(viewport));assert.ok(await p.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));
const actual=await p.evaluate(()=>{const level=MAP_DATA.levels.find(l=>l.id===shanheDebug.state().level);return level.regions.filter(r=>r.unitType==='province-direct').map(r=>({id:r.id,name:r.name,present:!!document.querySelector('#reference [data-region="'+r.id+'"]')}));});assert.equal(actual.length,e.direct);assert.ok(actual.every(r=>r.present));
if(code==='460000'){assert.ok((await p.locator('#reference .atlas-inset-caption').textContent()).includes('缩放移位示意'));const names=await p.locator('#reference .atlas-label').allTextContents();assert.ok(names.includes('琼中')&&names.includes('保亭')&&names.includes('三沙'));assert.ok(names.every(n=>n.length<=3),'海南显示短地名,避免拥挤');}
if(viewport.width===390){await p.locator('.atlas-scene').screenshot({path:'artifacts/province-direct-'+code+'.png'});report.push({code,...e,actual});}
}
}
await p.setViewportSize({width:390,height:844});
// The newly restored pieces go through ordinary pending/Enter/release controls.
for(const [code,e] of Object.entries(expected)){
await chooseProvince(p,code);await p.locator('#start').tap();await p.evaluate(()=>{const g=provinceRun;g.queue.sort((a,b)=>Number(g.level.regions[b].unitType==='province-direct')-Number(g.level.regions[a].unitType==='province-direct'));g.preparePending();});await p.clock.runFor(100);
const next=await p.locator('#next-name').textContent();const before=await p.evaluate(()=>shanheDebug.state());assert.equal(before.level,code);assert.equal(before.pending.id,await p.evaluate(()=>provinceRun.queue[0]));assert.equal(await p.evaluate(()=>provinceRun.level.regions[provinceRun.pending.id].unitType),'province-direct');await p.locator('#board').focus();await p.keyboard.press('Enter');await p.clock.runFor(100);const after=await p.evaluate(()=>shanheDebug.state());assert.equal(after.dropped,1);assert.ok(await p.evaluate(()=>provinceRun.groups.some(g=>provinceRun.level.regions[g.ids[0]].unitType==='province-direct')));assert.equal(await p.locator('#total').textContent(),String(e.total));assert.ok((await p.locator('#game-title').textContent()).includes('省域拼图'));await p.locator('#pause').tap();await p.getByRole('button',{name:'结束旅程',exact:true}).tap();const result=await p.evaluate(()=>shanheDebug.state().result);assert.equal(result.total,e.total);assert.equal(result.dropped,1);await p.locator('#result-back').tap();report.find(r=>r.code===code).firstReleased=next;
}
await p.locator('#atlas-back').tap();assert.equal(await p.locator('#reference [data-province]').count(),34);for(const code of ['420000','460000','710000','810000','820000'])assert.equal(await p.locator('#reference [data-province="'+code+'"]').count(),1);assert.deepEqual(errors,[]);assert.deepEqual(network,[]);fs.writeFileSync('artifacts/province-direct-browser-report.json',JSON.stringify({passed:true,scope:'Modern Chrome development checks, not native container acceptance',report,viewports:['390x844','320x568','740x390'],errors,network},null,2));console.log('湖北17/海南19/河南18/新疆24块省域关卡、30个新增地区实际出现在地图、正常释放/成绩计数、固定尺寸及一屏布局检查通过');
}finally{await context.close();await browser.close();}