RezinaLMS-CustomerEnd/tools/preview/smoke.mjs
kirukib c6dc5d46a8 feat: guided tour, course cards with enrolled counts, abstract steps, grouped payments, SEO, founder link
- After sign-in a 7-step spotlight tour shows students around (replay from the menu); ends on Esc or navigation
- Course cards: edge-to-edge photo, student count (Course.enrolledCount), arrow that inverts on hover
  (fixes white-on-white hover in dark mode)
- Landing: stats removed; How it works uses abstract CSS art; payment card grouped by mobile money,
  bank cards and from abroad; step 2 copy covers local and international payment
- SEO: metadata (title template, description, keywords, canonical, Open Graph, Twitter), per-route titles,
  EducationalOrganization JSON-LD with founder Rezina Brhane and her TikTok, robots.txt, sitemap.xml;
  same tags on the waitlist page
- Footers link the founder's TikTok
- Backend issue drafted: design/issues/enrollment-counts.md
- Smoke test: blocks third-party requests (Vimeo iframe stalled unloads), tolerates a missed load event;
  it caught a hook-order crash on the course page, fixed here

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 15:05:39 +03:00

61 lines
4.7 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');
// The app rewrites the hash while booting, and Puppeteer sometimes misses that load's lifecycle event and
// waits forever. If the document did load, carry on; if it didn't, fail as before.
await p.goto('file://' + file + hash, { waitUntil: 'domcontentloaded', timeout: 15000 })
.catch(async (e) => { if ((await p.evaluate(() => document.readyState).catch(() => '')) === 'loading' || !(await p.evaluate(() => !!document.body).catch(() => false))) throw e; }); 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));
// Offline run: block third-party requests (the Vimeo placeholder iframe can stall unloading the player page).
await p.setRequestInterception(true); p.on('request', (r) => (/^(file|data|about|blob):/.test(r.url()) || /fonts\.(googleapis|gstatic)\.com/.test(r.url()) ? r.continue() : r.abort()));
await p.evaluateOnNewDocument((s) => { window.__SEED__ = s; }, seed);
await p.evaluateOnNewDocument(mock);
await p.evaluateOnNewDocument(() => { try { localStorage.setItem('lms.langChosen', '1'); localStorage.setItem('lms.tourDone', '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');