RezinaLMS-CustomerEnd/tools/preview/smoke.mjs
kirukib 4a3561bcb5 feat: menu sheet, first-visit language picker, social sign-in, profile progress, history page
- Header keeps logo, links, bell/avatar or Get started; theme, language and feedback move into
  a menu sheet (native dialog) with large numbered links
- First visit asks for a language, prompt shown in all four
- Sign-in: Google / Apple / Telegram / Facebook buttons (simulated, like the phone code)
- One footer on every page (compact variant removed)
- Profile: identity header, stats, per-course progress with Continue and the lesson/quiz list,
  recent activity; /progress now opens the profile
- History page: dated timeline of lessons, purchases and reports

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 14:16:11 +03:00

56 lines
3.9 KiB
JavaScript

// Click-everything smoke test (SPEC §13.5, L3) against the inlined demo with an in-memory runtime.
// Usage: node packages/db/seed/demo-seed.mjs /tmp/seed && node tools/preview/smoke.mjs "$PWD/dist/demo.html" /tmp/seed
// Needs puppeteer-core and a local Chrome (not wired into CI yet; W1-14 replaces this with Playwright).
import puppeteer from 'puppeteer-core'; import fs from 'fs'; import path from 'path';
const [file, seedDir] = process.argv.slice(2);
const seed = {}; for (const col of fs.readdirSync(seedDir)) for (const f of fs.readdirSync(path.join(seedDir, col))) seed[`${col}/${f.replace('.json', '')}`] = JSON.parse(fs.readFileSync(path.join(seedDir, col, f), 'utf8'));
seed['students/u_reviewer'] = { ...seed['students/sample-2'], id: 'u_reviewer', name: 'Kirubel Kibru', isSample: false };
const mock = fs.readFileSync(new URL('./runtime-mock.js', import.meta.url), 'utf8');
const routes = [
['', 1], ['#/am/signin', 1], ['#/am'], ['#/am/courses'], ['#/en/course/makeup-foundations'], ['#/am/course/bridal-makeup'], ['#/am/learn/makeup-foundations/les-f3'],
['#/am/learn/bridal-makeup/les-b4'], ['#/am/checkout/bridal-makeup'], ['#/am/my'], ['#/am/progress'], ['#/am/notifications'], ['#/am/help'], ['#/am/profile'],
];
const b = await puppeteer.launch({ executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', headless: true });
const problems = []; let clicks = 0;
async function open(p, hash, signedOut) {
await p.goto('about:blank');
await p.goto('file://' + file + hash, { waitUntil: 'domcontentloaded' }); await new Promise((r) => setTimeout(r, 500));
}
async function worker(list) {
const p = await b.newPage(); await p.setViewport({ width: 1280, height: 900 });
let errs = []; p.on('pageerror', (e) => errs.push(e.message));
await p.evaluateOnNewDocument((s) => { window.__SEED__ = s; }, seed);
await p.evaluateOnNewDocument(mock);
await p.evaluateOnNewDocument(() => { try { localStorage.setItem('lms.langChosen', '1'); } catch {} });
for (const [hash, signedOut] of list) {
await p.evaluateOnNewDocument((so) => { try { so ? localStorage.setItem('lms.signedOut', '1') : localStorage.removeItem('lms.signedOut'); } catch {} }, !!signedOut);
await open(p, hash, signedOut);
if (errs.length) { problems.push(`${hash} LOAD ERROR ${errs}`); errs = []; }
const main = await p.evaluate(() => (document.querySelector('main')?.innerText ?? '').trim().length);
if (main < 20) problems.push(`${hash} blank main region`);
const n = await p.evaluate(() => [...document.querySelectorAll('button, a[href^="#"]')].filter((e) => e.offsetParent && !e.disabled).length);
for (let i = 0; i < Math.min(n, 60); i++) {
await open(p, hash, signedOut); errs = [];
const res = await p.evaluate(async (i) => {
const els = [...document.querySelectorAll('button, a[href^="#"]')].filter((e) => e.offsetParent && !e.disabled);
const el = els[i]; if (!el) return null;
const label = (el.getAttribute('aria-label') || el.innerText || '').trim().slice(0, 40);
if (/feedback|አስተያየት/i.test(label) || el.closest('.s-tabs')) return { label, skip: true };
const before = document.body.innerHTML.length + location.hash + document.body.innerText;
el.click(); await new Promise((r) => setTimeout(r, 350));
const after = document.body.innerHTML.length + location.hash + document.body.innerText;
return { label, changed: before !== after };
}, i);
clicks++;
if (!res || res.skip) continue;
if (errs.length) problems.push(`${hash} [${res.label}] ERROR ${errs[0]}`);
else if (!res.changed) problems.push(`${hash} [${res.label}] no visible change`);
}
}
await p.close();
}
const chunks = [[], [], [], []]; routes.forEach((r, i) => chunks[i % 4].push(r));
await Promise.all(chunks.map(worker));
await b.close();
console.log(`clicked ${clicks} controls on ${routes.length} routes`); console.log(problems.length ? problems.join('\n') : 'no problems');