// terrain.mjs — elevation profile along a measure path, probe marker, hover quick-info
const P = acts => [{ type: 'pointer', id: 'mouse', parameters: { pointerType: 'mouse' }, actions: acts }];
export const steps = [
{ name: 'two measure points → chart', wait: 4000, expect: v => v.chart && v.len > 100 && /Highest/.test(v.text),
js: `const a = window.mapViewer; a.showTab('measure'); a.measure.add({ lat: 40, lon: 0 }); a.measure.add({ lat: 45, lon: 20 });
a.measureChanged(); let c = null; for (let i = 0; i < 40 && !c; i++) { await new Promise(r => setTimeout(r, 250)); c = document.querySelector('#tab-measure svg.profile'); }
return { chart: !!c, len: c?.querySelector('path.line')?.getAttribute('d').length, text: document.querySelector('.profile-box').textContent };` },
{ name: 'hovering the chart drops a probe marker', expect: ([n, t]) => n === 1 && / km · /.test(t),
js: `const c = document.querySelector('#tab-measure svg.profile'), r = c.getBoundingClientRect();
c.dispatchEvent(new PointerEvent('pointermove', { clientX: r.left + r.width / 2, clientY: r.top + 30, bubbles: true }));
return [document.querySelectorAll('.marker.probe').length, document.querySelector('.readout').textContent];` },
{ name: 'an antipodal leg shows a warning, not a chart', expect: v => /antipodal/.test(v),
js: `const a = window.mapViewer; a.measure.clear(); a.measure.add({ lat: 0, lon: 0 }); a.measure.add({ lat: 0, lon: 180 }); a.measureChanged();
await new Promise(r => setTimeout(r, 800)); return document.querySelector('.profile-box').textContent;` },
{ name: 'hover quick-info in the status bar', wait: 300,
actions: P([{ type: 'pointerMove', x: 600, y: 400 }, { type: 'pointerMove', x: 602, y: 401, duration: 50 }]), settle: 1000,
js: `window.mapViewer.measure.clear(); window.mapViewer.measureChanged(); return document.getElementById('hover').textContent;`,
expect: v => /^· .* m/.test(v) },
{ name: 'hover text comes back after the pointer leaves the map and returns', expect: v => /^· .* m/.test(v),
js: `const a = window.mapViewer, p = { lat: 20, lon: 0 }; await a.hover(p); await a.hover(null); await a.hover(p);
return document.getElementById('hover').textContent;` },
];