// export.mjs — Export tab: the square around the map centre, export it, progress, the list, the square goes away
const wait = `const a = window.mapViewer; for (let i = 0; i < 300; i++) { await new Promise(r => setTimeout(r, 500));
if (['done', 'failed'].includes(a.exports.status?.state)) break; }
return { state: a.exports.status?.state, n: a.exports.list.length, text: document.getElementById('tab-export').textContent };`;
export const steps = [
{ name: 'the Export tab shows the square and the sample count', wait: 4000,
expect: v => v.line && /257 × 257/.test(v.info),
js: `const a = window.mapViewer; a.view.setState({ lat: 46.5, lon: 9.8, alt: 0.02 }); a.showTab('export');
const box = document.getElementById('tab-export'), set = (n, v) => { const s = box.querySelector('select[name=' + n + ']');
s.value = v; s.dispatchEvent(new Event('change')); };
set('size', '5'); set('res', '20'); await new Promise(r => setTimeout(r, 300));
return { line: a.view.lines.objects.has('export-square'), info: box.textContent };` },
{ name: 'export runs and lists the result', expect: v => v.state === 'done' && v.n === 1 && /n46\.500-e9\.800-5km-20m/.test(v.text),
js: `[...document.querySelectorAll('#tab-export button')].find(b => b.textContent.startsWith('Export here')).click();
await new Promise(r => setTimeout(r, 500));` + wait },
{ name: 'leaving the tab hides the square', expect: v => v === false,
js: `window.mapViewer.showTab('inspector'); return window.mapViewer.view.lines.objects.has('export-square');` },
];