5 lines
1.7 KiB
JavaScript
5 lines
1.7 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},deviceScaleFactor:2});const page=await context.newPage();
|
|
await page.clock.install();await page.addInitScript(()=>{let seed=785;Math.random=()=>{seed=(seed*1664525+1013904223)>>>0;return seed/4294967296;};});await page.goto('http://localhost:4173');await setDifficulty(page,{speed:3});await page.locator('#start').click();await page.clock.runFor(22000);const s=await page.evaluate(()=>window.shanheDebug.state());for(const name of ['上海','台湾','香港','澳门'])assert.ok(s.labels.some(b=>b.name===name),name+'应有可见标签');for(const box of s.labels){assert.ok(box.x>=3&&box.y>=3&&box.x+box.w<=s.width-3&&box.y+box.h<=s.height-4,box.name+'标签不得贴底或越界');}let collisions=[];for(let i=0;i<s.labels.length;i++)for(let j=0;j<i;j++){let a=s.labels[i],b=s.labels[j];const overlap=Math.max(0,Math.min(a.x+a.w,b.x+b.w)-Math.max(a.x,b.x))*Math.max(0,Math.min(a.y+a.h,b.y+b.h)-Math.max(a.y,b.y));if(overlap>1)collisions.push([a.name,b.name,overlap]);}assert.deepEqual(collisions,[]);await page.screenshot({path:'artifacts/labels-small-regions.png'});fs.writeFileSync('artifacts/label-report.json',JSON.stringify({passed:true,viewport:{width:390,height:844},pieces:s.dropped,labels:s.labels,collisions},null,2));console.log('小地区标签通过:台湾、香港、澳门、上海均可见,无贴底、越界或标签相互遮挡。');await context.close();await browser.close();
|