// Clicking a red line where routes overlap selects the red route, not one hidden beneath it. import { chromium } from 'playwright-core'; import { PAGE } from './paths.mjs'; const b = await chromium.launch({ executablePath: process.env.CH }); const p = await b.newPage({ viewport: { width: 1440, height: 900 } }); const errs = []; p.on('pageerror', e => errs.push(e.message)); await p.goto(PAGE('site/index.html')); await p.waitForTimeout(1800); const pt = await p.evaluate(() => { const ia = LS.findIndex(s => s.name === 'Fortaleza'), ib = LS.findIndex(s => s.name === 'Luanda'); const q = LP.find(x => (x.a === ia && x.b === ib) || (x.a === ib && x.b === ia)); const segs = hits.filter(h => h[0] === q.idx).map(h => h[1]).sort((x, y) => y.length - x.length)[0]; const k = Math.floor(segs.length / 2), r = document.getElementById('cv').getBoundingClientRect(); return { x: r.left + segs[k][0], y: r.top + segs[k][1], want: LS[q.a].name + '–' + LS[q.b].name } }); await p.mouse.move(pt.x, pt.y); await p.waitForTimeout(250); const tip = (await p.innerText('#tip')).replace(/\s+/g, ' '); await p.mouse.click(pt.x, pt.y); await p.waitForTimeout(300); const got = await p.evaluate(() => [LS[LP[S.sel].a].name + '–' + LS[LP[S.sel].b].name, rt(LP[S.sel]).tier]); console.log('clicked SACS line; selected', got, 'expected', pt.want, '| tooltip:', tip.slice(0, 200)); console.log(got[1] === 2 ? 'OK: top (red) route selected' : 'FAIL', 'ERRORS', JSON.stringify(errs)); await b.close();