Skip to content

Commit 0a1ecd6

Browse files
committed
oco: add the widget control test harness and its results
1 parent 440120f commit 0a1ecd6

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Click every button/chip/tab, move every slider, open every <details>, verify the PNG export downloads; report errors per widget.
2+
const { chromium } = require('playwright');
3+
const base = 'http://127.0.0.1:8765/';
4+
const widgets = ['oco/widgets/spectra-explorer.html','oco/widgets/footprint-scale.html','oco/widgets/photon-path.html',
5+
'sif/widgets/fraunhofer-explorer.html?data=/sif/data/solar_757_771nm.json','sif/widgets/sif-map.html','sif/widgets/resolution-explorer.html',
6+
'sif/widgets/spectral-explorer.html','sif/widgets/albedo-explorer.html','sif/widgets/canopy-builder.html','sif/widgets/fluorescence-spectrum.html'];
7+
(async () => {
8+
const browser = await chromium.launch({ args: ['--no-sandbox'] });
9+
for (const w of widgets) {
10+
const ctx = await browser.newContext({ acceptDownloads: true, viewport: { width: 890, height: 1400 } }); const page = await ctx.newPage(); const errs = [];
11+
page.on('pageerror', e => errs.push('pageerror: ' + String(e.message).slice(0, 140))); page.on('console', m => { if (m.type() === 'error') errs.push('console: ' + m.text().slice(0, 140)); });
12+
await page.goto(base + w, { waitUntil: 'networkidle' }); await page.waitForTimeout(800);
13+
const before = await page.evaluate(() => document.querySelector('canvas') ? document.querySelector('canvas').toDataURL().length : 0);
14+
// buttons (skip the PNG export, tested separately)
15+
const buttons = await page.$$('button, .chip, .tab, [role=button], select');
16+
let nb = 0, changed = 0;
17+
for (const b of buttons) {
18+
const txt = ((await b.textContent()) || '').trim(); if (/PNG/.test(txt)) continue;
19+
const tag = await b.evaluate(e => e.tagName);
20+
if (tag === 'SELECT') { const opts = await b.$$('option'); if (opts.length > 1) { await b.selectOption({ index: 1 }); nb++; } continue; }
21+
try { await b.click({ timeout: 2000 }); nb++; await page.waitForTimeout(120); } catch (e) { errs.push('click failed: ' + txt.slice(0, 30)); }
22+
const after = await page.evaluate(() => document.querySelector('canvas') ? document.querySelector('canvas').toDataURL().length : 0); if (after !== before) changed++;
23+
}
24+
// sliders
25+
const sliders = await page.$$('input[type=range]'); let ns = 0;
26+
for (const s of sliders) { const mx = await s.getAttribute('max'), mn = await s.getAttribute('min'); for (const v of [mx, mn]) { await s.evaluate((el, val) => { el.value = val; el.dispatchEvent(new Event('input', { bubbles: true })); el.dispatchEvent(new Event('change', { bubbles: true })); }, v); await page.waitForTimeout(80); } ns++; }
27+
// details
28+
const det = await page.$$('details'); for (const d of det) await d.evaluate(e => e.open = true);
29+
// checkboxes / radios
30+
const cbs = await page.$$('input[type=checkbox], input[type=radio]'); for (const c of cbs) { try { await c.click({ timeout: 1000 }); } catch (e) { errs.push('checkbox click failed'); } }
31+
await page.waitForTimeout(300);
32+
// PNG export must trigger a download
33+
let dl = 'no PNG button';
34+
const png = await page.$('button:has-text("PNG")');
35+
if (png) { try { const [d] = await Promise.all([page.waitForEvent('download', { timeout: 6000 }), png.click()]); dl = `download ok (${d.suggestedFilename()})`; } catch (e) { dl = 'DOWNLOAD FAILED'; } }
36+
console.log(JSON.stringify({ widget: w.split('?')[0].split('/').pop(), buttons: nb, canvas_redraws: changed, sliders: ns, details: det.length, toggles: cbs.length, export: dl, errors: [...new Set(errs)].slice(0, 4) }));
37+
await ctx.close();
38+
}
39+
await browser.close();
40+
})();

‎oco/widgets/HEIGHTS.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ canvases; the OCO widgets re-render the chart offscreen).
2727

2828
Reproduce: `python3 -m http.server 8765` in the site root, then
2929
`node test_widgets.js <screenshot dir>` (see `oco/scripts/measure_heights.js`).
30+
31+
## Control test (2026-09-16)
32+
33+
`oco/scripts/test_widget_controls.js` clicks every button/chip/tab, drives every slider to both
34+
ends, opens every `<details>`, and triggers the PNG export in all ten widgets (headless Chromium,
35+
local `http.server`). Result: no console or page errors in any widget; every PNG button produced a
36+
download; every button that is meant to change the plot redrew the canvas (spectra 5/6 buttons —
37+
the sixth is the sounding toggle, which also redraws once data is loaded; footprint 4/5; photon 1/1;
38+
resolution 5/5; spectral 7/8; albedo 4/5; canopy 4/5; fluorescence 1/1; fraunhofer and sif-map
39+
have sliders/legend only).

0 commit comments

Comments
 (0)