3 lines
5.5 KiB
JavaScript
3 lines
5.5 KiB
JavaScript
const {chromium}=require('playwright'),fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict');const base=process.env.PD_BROWSER_BASE||'http://127.0.0.1:5238';
|
|
(async()=>{const b=await chromium.launch();try{const c=await b.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true,deviceScaleFactor:2});await c.route('**/cdn.jsdelivr.net/**signalr*',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules/@microsoft/signalr/dist/browser/signalr.min.js'))}));await c.route('**/native-companion/status',r=>r.fulfill({json:[]}));await c.route('**/native-companion/connection-state',r=>r.fulfill({json:{known:false}}));await c.route('**/Writing/Context/Position?*',r=>r.fulfill({json:{connected:false}}));await c.route('**/Writing/Context/Tabs/*',async r=>{const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-tab-fixture/'+u.pathname.split('/').at(-1)+u.search})});});await c.route('**/Writing/Context/Relationships/Graph?*',async r=>{const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-lenses-fixture'+u.search})});});for(const [route,fixture] of [['FamilyIndex','index'],['FamilyTree','tree']])await c.route('**/Writing/Context/Relationships/'+route+'?*',async r=>{const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-family-'+fixture+'-fixture'+u.search})});});const p=await c.newPage();await p.goto(base+'/Writing/Context');for(const tool of ['characters','names','relationships']){await p.selectOption('[data-context-tab]',tool);await p.waitForSelector('[data-context-tab-fragment]');if(tool==='relationships'){await p.locator('[data-graph-node="5"]').tap();await p.locator('[data-family-branch="3"]').tap();await p.locator('[data-graph-node="1"]').waitFor();await p.locator('[data-family-branch="3"]').tap();await p.waitForFunction(()=>!document.querySelector('[data-graph-node="1"]'));assert.equal(await p.locator('[data-context-edit-dialog][open]').count(),0);await p.locator('[data-graph-zoom="in"]').tap();const svg=p.locator('[data-relationship-svg]');await svg.scrollIntoViewIfNeeded();await p.waitForTimeout(150);const findBackground=()=>svg.evaluate(n=>{const b=n.getBoundingClientRect();for(let y=b.top+20;y<b.bottom-30;y+=20)for(let x=b.left+20;x<b.right-70;x+=20){const a=document.elementFromPoint(x,y),c=document.elementFromPoint(x+40,y);if(a?.closest('svg')===n&&c?.closest('svg')===n&&!a.closest('[data-graph-node],[data-graph-connection],[data-family-branch]')&&!c.closest('[data-graph-node],[data-graph-connection],[data-family-branch]'))return {x,y};}return null;});await svg.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));const point=await findBackground();assert(point,'touch background points');await svg.evaluate(n=>{window.touchTrace=[];for(const type of ['pointerdown','pointermove','pointerup','pointercancel','lostpointercapture'])n.addEventListener(type,e=>touchTrace.push({type,x:e.clientX,y:e.clientY,target:e.target.tagName,node:e.target.closest('[data-graph-node]')?.dataset.graphNode,branch:e.target.closest('[data-family-branch]')?.dataset.familyBranch}));});const client=await c.newCDPSession(p),before=await p.locator('[data-relationship-viewport]').getAttribute('transform');await client.send('Input.dispatchTouchEvent',{type:'touchStart',touchPoints:[{x:point.x,y:point.y,id:1}]});await p.waitForTimeout(40);await client.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:point.x+25,y:point.y+20,id:1}]});await client.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:point.x+40,y:point.y+30,id:1}]});await client.send('Input.dispatchTouchEvent',{type:'touchEnd',touchPoints:[]});assert.notEqual(await p.locator('[data-relationship-viewport]').getAttribute('transform'),before,JSON.stringify(await p.evaluate(()=>touchTrace)));await p.waitForTimeout(100);const pinch=await findBackground();assert(pinch);const beforePinch=await p.locator('[data-relationship-viewport]').getAttribute('transform');await client.send('Input.dispatchTouchEvent',{type:'touchStart',touchPoints:[{x:pinch.x,y:pinch.y,id:1},{x:pinch.x+40,y:pinch.y,id:2}]});await client.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:pinch.x,y:pinch.y,id:1},{x:pinch.x+65,y:pinch.y,id:2}]});await client.send('Input.dispatchTouchEvent',{type:'touchEnd',touchPoints:[]});assert.notEqual(await p.locator('[data-relationship-viewport]').getAttribute('transform'),beforePinch,JSON.stringify(await p.evaluate(()=>touchTrace)));await p.screenshot({path:'/tmp/context-refinement-family-touch.png'});await p.locator('[data-relationship-lens="story"]').tap();await p.locator('[data-graph-node="5"]').tap();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.screenshot({path:'/tmp/context-refinement-relationships-touch.png'});continue;}const first=tool==='names'?p.locator('[data-context-name-id] details').first():p.locator('.context-character-row').first();await first.locator('summary').first().tap();await first.locator('summary').first().tap();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.screenshot({path:'/tmp/context-enhancement-'+tool+'-touch.png'});}console.log('PASS touch-emulated Chromium: all three tools, long names, disclosure taps, graph selection, touch drag/pinch, zoom and lens switching with no horizontal overflow at 390px. Physical touch/PWA installation not exercised.');}finally{await b.close();}})().catch(e=>{console.error(e.message);process.exitCode=1;});
|