← back to Dw Photo Capture
5x/tools/history-scroll-check.cjs
19 lines
// Scroll every /captures thumbnail into view (lazy-loaded) in each engine, then assert naturalWidth>0.
const pw = require(process.env.PW || '/Users/macstudio3/Projects/carnegie-internal/node_modules/playwright');
const BASE = process.env.BASE || 'http://127.0.0.1:9987';
(async () => { let bad = 0;
for (const e of (process.env.ENGINES || 'chromium,webkit,firefox').split(',')) {
const b = await pw[e].launch(); const ctx = await b.newContext({ httpCredentials: { username: 'admin', password: 'DW2024!' }, viewport: { width: 430, height: 932 } });
const p = await ctx.newPage(); const errs = []; p.on('pageerror', x => errs.push(x.message));
await p.goto(BASE + '/captures', { waitUntil: 'load' }); await p.waitForSelector('.card');
const n = await p.locator('.card .pair img').count();
for (let i = 0; i < n; i++) { await p.locator('.card .pair img').nth(i).scrollIntoViewIfNeeded(); }
await p.waitForFunction(() => [...document.querySelectorAll('.card .pair img')].every(i => i.complete), null, { timeout: 15000 }).catch(() => {});
const r = await p.$$eval('.card .pair img', l => l.map(i => ({ w: i.naturalWidth, src: i.currentSrc.slice(-50) })));
const broken = r.filter(x => !x.w); bad += broken.length + errs.length;
console.log(`${broken.length || errs.length ? 'FAIL' : 'PASS'} ${e}: ${r.length - broken.length}/${r.length} history thumbs loaded after scroll${broken.length ? ' broken=' + JSON.stringify(broken) : ''}${errs.length ? ' errs=' + JSON.stringify(errs) : ''}`);
await b.close();
}
process.exit(bad ? 1 : 0);
})();