Files
martbost 7873d752d3 My line: section pills and 10-row pages on every list
A sticky pill row at the top of My line jumps to each section (built from
the cards marked data-jump; hidden cards get no pill; the one in view is
lit). Every list on the page pages at 10: your line, downline levels,
holding tank, coach directs, prospects, both link-stats tables; upline
messages at 5. qa/line-pager.mjs checks it in a real browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:56:20 -05:00

62 lines
6.4 KiB
JavaScript

// My line: section pills + 10-row pages (Marty, 2026-09-26). Boots a throwaway server, makes a member
// with 23 prospects, then checks in a real browser that the prospect list pages at 10, the pager moves,
// and a section pill scrolls its card into view. Screenshots in qa/out/line-*.png.
// node qa/line-pager.mjs
import { spawn } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
const PW = process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright/index.js';
const { chromium } = (await import('file:///' + PW.replace(/^\/+/, ''))).default;
const PORT = 8798, B = 'http://127.0.0.1:' + PORT;
const DATA = path.join(os.tmpdir(), 'iap-line-pager-' + Date.now()); fs.mkdirSync(DATA, { recursive: true });
const ok = [], bad = []; const t = (n, c, x) => (c ? ok : bad).push(n + (c || !x ? '' : ' -> ' + x));
const srv = spawn(process.execPath, ['server.js'], { env: { ...process.env, PORT: String(PORT), DATA_DIR: DATA, ADMIN_PASSWORD: 'localtest', ADMIN_EMAIL: 'admin@example.com', NODE_ENV: 'test' }, stdio: 'ignore' });
const bye = c => { try { srv.kill(); } catch (e) {} fs.rmSync(DATA, { recursive: true, force: true }); process.exit(c); };
for (let i = 0; i < 60; i++) { try { if ((await fetch(B + '/api/stats')).ok) break; } catch (e) {} await new Promise(r => setTimeout(r, 500)); }
const DEV = 'c0ffee00c0ffee00c0ffee00c0ffee00';
const jf = async (p, body, cookie) => { const r = await fetch(B + p, { method: body ? 'POST' : 'GET', headers: { 'Content-Type': 'application/json', Cookie: cookie }, body: body ? JSON.stringify(body) : undefined }); return { r, b: await r.json().catch(() => ({})) }; };
const st = await jf('/api/auth/email/start', { email: 'pager@example.com', fts: Date.now() - 20000 }, 'iap.dev=' + DEV);
const code = st.b.devCode || st.b.code; if (!code) { console.log('no dev code'); bye(2); }
const vf = await jf('/api/auth/email/verify', { email: 'pager@example.com', code }, 'iap.dev=' + DEV);
const sc = vf.r.headers.getSetCookie ? vf.r.headers.getSetCookie() : [vf.r.headers.get('set-cookie')];
const jar = ['iap.dev=' + DEV, ...sc.map(c => String(c).split(';')[0])].join('; ');
for (let i = 1; i <= 23; i++) await jf('/api/my/prospects', { name: 'Prospect ' + String(i).padStart(2, '0'), contact: 'p' + i + '@example.com', status: 'talking' }, jar);
const pl = await jf('/api/my/prospects', null, jar); t('23 prospects seeded', (pl.b.prospects || []).length === 23, (pl.b.prospects || []).length);
const br = await chromium.launch(); const ctx = await br.newContext({ viewport: { width: 1280, height: 900 } });
await ctx.addCookies(jar.split('; ').map(kv => { const [name, ...v] = kv.split('='); return { name, value: v.join('='), url: B }; }));
await ctx.addInitScript(() => { try { sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} });
const page = await ctx.newPage();
await page.goto(B + '/my#line', { waitUntil: 'networkidle' }); await page.waitForTimeout(1500);
// any onboarding modal out of the way
for (const sel of ['#unameSkip', '[data-close]', '.modal .x']) { try { await page.click(sel, { timeout: 800 }); } catch (e) {} }
await page.evaluate(() => { document.querySelectorAll('.modal-back,.lgate,.iap-welcome').forEach(m => m.hidden = true); const b = document.querySelector('[data-pane="line"]'); if (b) b.click(); }); await page.waitForTimeout(2500);
const pills = await page.$$eval('#lineJump [data-jumpto]', xs => xs.map(x => x.textContent));
t('section pills are built from the visible cards', pills.length >= 7 && pills.includes('Prospects') && pills.includes('Downline'), JSON.stringify(pills));
t('hidden cards get no pill', !pills.includes('Sponsor') || await page.$eval('#sponsorMsgCard', e => !e.hidden), JSON.stringify(pills));
await page.screenshot({ path: 'qa/out/line-top.png' });
const vis = async () => page.$$eval('#prospectList > .lin-row', xs => xs.filter(x => !x.hidden).map(x => x.querySelector('.nm').textContent.trim()));
const p1 = await vis(); t('prospects: 10 on page 1', p1.length === 10, p1.length);
const bar = await page.$eval('#prospectList .pgr-n', e => e.textContent).catch(() => ''); t('pager says 1-10 of 23', /1.10\s*of 23/.test(bar), bar);
await page.click('#lineJump [data-jumpto="prospectCard"]'); await page.waitForTimeout(1200);
const top = await page.$eval('#prospectCard', e => e.getBoundingClientRect().top); t('the Prospects pill scrolls the card to the top (below the sticky bars)', top > 60 && top < 260, Math.round(top));
const lit = await page.$eval('#lineJump .chip-t.on', e => e.dataset.jumpto).catch(() => ''); t('the Prospects pill is lit', lit === 'prospectCard', lit);
const pillsTop = await page.$eval('#lineJump', e => e.getBoundingClientRect().top); t('the pill row stays stuck at the top while scrolled', pillsTop >= 0 && pillsTop < 120, Math.round(pillsTop));
await page.screenshot({ path: 'qa/out/line-prospects.png' });
await page.click('#prospectList .pgr-btn:last-child'); await page.waitForTimeout(800);
const p2 = await vis(); t('Next shows 11-20', p2.length === 10 && p2[0] !== p1[0], p2[0]);
await page.click('#prospectList .pgr-btn:last-child'); await page.waitForTimeout(800);
const p3 = await vis(); t('the last page shows the remaining 3', p3.length === 3, p3.length);
await page.screenshot({ path: 'qa/out/line-page3.png' });
// phone width: the pill row scrolls sideways, the page does not
const ph = await br.newContext({ viewport: { width: 390, height: 844 } }); await ph.addCookies(jar.split('; ').map(kv => { const [name, ...v] = kv.split('='); return { name, value: v.join('='), url: B }; }));
await ph.addInitScript(() => { try { sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} });
const pp = await ph.newPage(); await pp.goto(B + '/my#line', { waitUntil: 'networkidle' }); await pp.waitForTimeout(1200);
await pp.evaluate(() => { document.querySelectorAll('.modal-back,.lgate,.iap-welcome').forEach(m => m.hidden = true); const b = document.querySelector('[data-pane="line"]'); if (b) b.click(); }); await pp.waitForTimeout(2000);
const over = await pp.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); t('phone: no sideways page scroll', over <= 1, over);
await pp.screenshot({ path: 'qa/out/line-phone.png' });
await br.close();
console.log(ok.map(x => ' ok ' + x).join('\n')); if (bad.length) console.log(bad.map(x => ' FAIL ' + x).join('\n'));
console.log(bad.length ? '\nFAILURES: ' + bad.length : '\nLINE PAGER: ALL PASS'); bye(bad.length ? 1 : 0);