Current section
Files
Jump to
Current section
Files
priv/combobox-spike/probe2.mjs
import { chromium } from 'playwright';
const b = await chromium.launch(); const p = await (await b.newContext()).newPage();
p.on('pageerror', e => console.log('PAGEERR', String(e).slice(0,200)));
await p.goto('http://127.0.0.1:4127/');
await p.waitForFunction(()=>document.querySelector('[data-phx-main]')?.classList.contains('phx-connected'),null,{timeout:8000});
await p.waitForTimeout(200);
// check internal API availability + popover open
console.log('popoverOpen initial:', await p.evaluate(()=>{try{return document.getElementById('cb-list').matches(':popover-open')}catch(e){return 'err:'+e}}));
console.log('getViewByEl:', await p.evaluate(()=>typeof window.liveSocket.getViewByEl));
// toggle auto off, emit two queries, release out of order
await p.evaluate(()=>document.getElementById('toggle-auto').click());
await p.waitForTimeout(120);
await p.evaluate(()=>window.__cbEmit('a'));
await p.waitForTimeout(120);
await p.evaluate(()=>window.__cbEmit('ba'));
await p.waitForTimeout(120);
const ok = await p.evaluate(()=>{
try {
const view = window.liveSocket.getViewByEl(document.querySelector('[data-phx-main]'));
view.pushEvent('event', document.getElementById('cb-input'), null, 'release', {v:2});
return 'pushed';
} catch(e){ return 'err:'+e; }
});
console.log('pushEvent release v2:', ok);
await p.waitForFunction(()=>document.getElementById('cb-list').getAttribute('data-version')==='2',null,{timeout:4000}).catch(()=>console.log('v2 did not render'));
console.log('after release v2: version=', await p.evaluate(()=>document.getElementById('cb-list').getAttribute('data-version')), 'results=', await p.evaluate(()=>[...document.querySelectorAll('#cb-list [data-item]')].map(n=>n.getAttribute('data-item'))));
await b.close();