4ae7a318da
qa/theme-contrast.mjs (bash qa/run.sh theme) mirrors LinkSpin's: signs in one account per theme (the account value wins at sign-in), walks every member pane, 24 public pages and the admin panes in light and dark with Playwright, samples the main text/background pairs with composited ancestor backgrounds and gradient averages, injects one probe per variant so every pair is measured even when a page has no live example, and reports the ratio per pair with pass/fail at 4.5:1 (3:1 for large text). Result today: 8,169 pairs, 0 fails, worst 4.76:1 (the ok badge in light), worst dark 5.76:1. qa/walk.mjs honours QA_THEME=light|dark|auto (localStorage iap.theme set before the first navigation; screenshots carry a -<theme> suffix so both sets survive), asserts the header and Profile switch (applies at once, saves to the account, repaints the other control, never touches the username), screenshots the public home, the member's wall and the join page from the local copy, and returns to /my with waitUntil load (a signed-in member area keeps polling, so networkidle never settles). Requests the page cancels by navigating away (net::ERR_ABORTED) no longer count as failures, and the local-only /api/qr 404 (no qrcode module in a checkout) is ignored for images. Both QA_THEME walks: 0 bugs. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
160 lines
15 KiB
JavaScript
160 lines
15 KiB
JavaScript
// Theme contrast check (2026-11-01, mirrored from LinkSpin's qa/theme-contrast.mjs): loads the public pages and the member
|
|
// area in both themes with Playwright, samples the main text/background pairs (body text, muted text, links, buttons, chips,
|
|
// badges, table text, card headings, stage pills, fields) with composited ancestor backgrounds and gradient averages, and
|
|
// reports the WCAG ratio per pair, pass/fail at 4.5:1 (3:1 for large text: 24px+, or 18.66px+ bold). Probes inject one
|
|
// element per variant so a pair is measured even when the page has no live example. Runs against a local copy:
|
|
// bash qa/run.sh theme (boots server.js on :8797 with throwaway data, signs in, walks both themes)
|
|
// Env: LOCAL (default http://127.0.0.1:8797), OUT (default qa/out), PW (playwright dir). Exit 1 when any pair fails.
|
|
import { pathToFileURL } from 'node:url';
|
|
import fs from 'node:fs';
|
|
const PW = process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright';
|
|
const { chromium } = (await import(pathToFileURL(PW + '/index.js').href)).default;
|
|
const LOCAL = process.env.LOCAL || 'http://127.0.0.1:8797';
|
|
const OUT = process.env.OUT || 'qa/out';
|
|
fs.mkdirSync(OUT, { recursive: true });
|
|
|
|
// selectors sampled on every page (text element -> its effective background)
|
|
const SAMPLE = ['body', 'p', 'li', 'td', 'th', 'label', 'small', 'h1', 'h2', 'h3', 'h4', 'a', 'button', '.btn', '.muted', '.small', '.eyebrow', 'summary',
|
|
'.badge', '.chip', '.chip-t', '.pill', '.lchip', '.lin-chip', '.lin-verdict', '.tk-tier', '.tk-tier b', '.tk-tier .lock', '.angle-hook', '.angle-tag', '.pb-note', '.pb-size', '.promo-block', '.pb-net',
|
|
'.stat .n', '.stat .l', '.statx .nv', '.statx .lb', '.card h3', '.card-head .sub', '.cmp th', '.cmp td', '.tile .name', '.tile .price', '.tile .cr', '.tile .bonus', '.tile .pol', '.tile.hot::before',
|
|
'.feed .row', '.feed .when', '.ticker .inner span', '.hero .lead', '.hero-note', '.byline', 'nav .links a', '.bo-menu button', '.bo-menu a', '.bo-links a', '.bo-cap', '.bo-top h2', '.bo-pagefoot a',
|
|
'.subtab', '.subnav button', '.seg button', '.theme-seg button', '.gs-step', '.gs-step .n', '.nc-step .lb', '.nc-step .dot', '.lt-you', '.lt-node', '.lt-cap', '.lin-row .nm', '.lin-row .em', '.lin-row .id', '.lin-row .dt',
|
|
'.wall-pos', '.wc-check', '.wc-timer', '.bio-meta p', '.bio-socials a', '.chat-thread .ct-name', '.chat-thread .ct-last', '.ch-m', '.obj summary', '.obj .lab', '.spend-banner .lbl', '.spend-banner .sub', '.rehearsal',
|
|
'.checks li', '.platecard p', '.closer p', 'footer', 'footer a', '.fdf', '.fdf a', '.pgr-n', '.pgr-pg', '.pgr-btn', '.lst-chip', '.lst-sort', '.lst-n', '.pipe-col h4', '.pipe-col .hint', '.pipe-card .nm', '.pipe-card .sub',
|
|
'.rg-n', '.rg-chip', '.rg-box', '.rg-rule', '.rg-coach', '.cg-flow li', '.howbox', '.gcard .pays', '.wl-grid .tag', '.lw-rule', '.pl-rule', '.wl-rule', '.note', '.st', '.house-tag', '.sup-row', '.sup-st', 'input', 'textarea', 'select'];
|
|
// probes injected once per page so every variant gets a reading (class list, text)
|
|
const PROBES = [
|
|
['badge', 'Badge'], ['badge amber', 'Badge amber'], ['chip', 'Chip'], ['chip flat', 'Chip flat'], ['chip warm', 'Chip warm'], ['chip-t', 'Chip-t'], ['chip-t on', 'Chip-t on'], ['lchip', 'lchip'], ['lchip on', 'lchip on'], ['lchip warn', 'lchip warn'],
|
|
['lin-chip', 'lin chip'], ['lin-chip warn', 'lin chip warn'], ['lin-verdict', 'verdict'], ['lin-verdict on', 'verdict on'], ['tk-tier', 'tier'], ['tk-tier reached', 'tier reached'], ['tk-tier current', 'tier current'], ['angle-hook', 'hook'], ['angle-tag', 'angle tag'],
|
|
['btn', 'Button'], ['btn sec', 'Sec'], ['btn small sec', 'Small sec'], ['btn quiet', 'Quiet'], ['subtab', 'subtab'], ['subtab on', 'subtab on'], ['lst-chip', 'list chip'], ['lst-chip on', 'list chip on'], ['pgr-btn', 'Next'],
|
|
['muted', 'Muted text'], ['small muted', 'small muted'], ['hero-note', 'hero note'], ['bo-cap', 'cap'], ['wall-pos', 'position 1'], ['wc-check', 'check'], ['wc-timer', '0:12'], ['lt-you', 'You'], ['lt-node', 'node'], ['lt-node deep', 'deep'], ['lt-node qualified', 'qualified'], ['lt-node open', 'open'],
|
|
['gs-step', 'step'], ['gs-step done', 'step done'], ['gs-step now', 'step now'], ['fdf', 'Friday strip'], ['pgr-n', 'Showing 25'], ['pgr-pg', 'page 1 of 2'], ['promo-block', 'promo block'], ['pb-net', 'facebook'], ['rehearsal', 'rehearsal'],
|
|
['ch-m bot', 'bot bubble'], ['ch-m me', 'me bubble'], ['cbub them', 'them'], ['cbub me', 'me'], ['chat-day', 'today'], ['chat-empty', 'empty'], ['pipe-card nm', 'name'], ['pipe-card sub', 'sub'], ['pipe-col hint', 'hint'],
|
|
['st active', 'active'], ['st paused', 'paused'], ['st out', 'out'], ['house-tag', 'house'], ['sup-st open', 'open'], ['sup-st waiting_on_member', 'waiting'], ['sup-st closed', 'closed'],
|
|
['tile bonus', 'bonus'], ['tile pol', 'pol'], ['tile name', 'name'], ['spend-banner lbl', 'label'], ['split s50', '50%'], ['split sa', 'admin'], ['nc-step lb', 'step'], ['bo-rehearsal small', 'rehearsal'],
|
|
['theme-seg-probe', 'seg'], ['ok-probe', 'ok text'], ['warn-probe', 'warn text'], ['bad-probe', 'bad text'], ['gold-probe', 'gold text'], ['okbadge-probe', 'Ready to activate'], ['goldbadge-probe', 'Pass active'], ['amberpill-probe', '3'],
|
|
];
|
|
|
|
const browser = await chromium.launch();
|
|
const results = [];
|
|
async function sample(page, label) {
|
|
const rows = await page.evaluate(({ SAMPLE, PROBES }) => {
|
|
const parse = c => { const m = String(c).match(/rgba?\(([^)]+)\)/); if (!m) return null; const p = m[1].split(/[,\s/]+/).filter(Boolean).map(Number); return { r: p[0], g: p[1], b: p[2], a: p.length > 3 ? p[3] : 1 }; };
|
|
const over = (fg, bg) => ({ r: fg.r * fg.a + bg.r * (1 - fg.a), g: fg.g * fg.a + bg.g * (1 - fg.a), b: fg.b * fg.a + bg.b * (1 - fg.a), a: 1 });
|
|
const lum = c => { const f = v => { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); }; return 0.2126 * f(c.r) + 0.7152 * f(c.g) + 0.0722 * f(c.b); };
|
|
const ratio = (a, b) => { const l1 = lum(a), l2 = lum(b); return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05); };
|
|
const hex = c => '#' + [c.r, c.g, c.b].map(v => Math.round(v).toString(16).padStart(2, '0')).join('');
|
|
// gradients: average the non-transparent colour stops (a transparent stop is not a colour the text sits on)
|
|
const gradColour = img => { const stops = [...img.matchAll(/rgba?\([^)]+\)/g)].map(m => parse(m[0])).filter(c => c && c.a > 0); if (!stops.length) return null; const n = stops.length; return { r: stops.reduce((s, c) => s + c.r, 0) / n, g: stops.reduce((s, c) => s + c.g, 0) / n, b: stops.reduce((s, c) => s + c.b, 0) / n, a: stops.reduce((s, c) => s + c.a, 0) / n }; };
|
|
const bgOf = el => { // walk up, compositing translucent layers over what lies beneath
|
|
const layers = []; let e = el;
|
|
while (e && e !== document.documentElement.parentNode) {
|
|
const cs = getComputedStyle(e); const bc = parse(cs.backgroundColor); const bi = cs.backgroundImage;
|
|
let c = null;
|
|
if (bi && bi !== 'none' && /gradient/.test(bi) && !/radial-gradient\(/.test(bi)) c = gradColour(bi);
|
|
if (bc && bc.a > 0) c = c && c.a < 1 ? over(c, bc) : (c || bc);
|
|
if (c && c.a > 0) { layers.push(c); if (c.a >= 1) break; }
|
|
e = e.parentElement;
|
|
}
|
|
let out = { r: 255, g: 255, b: 255, a: 1 };
|
|
const body = parse(getComputedStyle(document.body).backgroundColor); if (body && body.a > 0 && !layers.some(l => l.a >= 1)) out = body;
|
|
for (let i = layers.length - 1; i >= 0; i--) out = over(layers[i], out);
|
|
return out;
|
|
};
|
|
const vis = el => { const r = el.getBoundingClientRect(); const cs = getComputedStyle(el); return r.width > 0 && r.height > 0 && cs.visibility !== 'hidden' && cs.display !== 'none' && el.closest('[hidden]') === null; };
|
|
const hasText = el => [...el.childNodes].some(n => n.nodeType === 3 && n.textContent.trim().length > 0) || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName);
|
|
// probes
|
|
const host = document.createElement('div'); host.id = 'contrastProbes'; host.style.cssText = 'position:absolute;left:0;top:0;padding:8px;display:flex;flex-wrap:wrap;gap:6px;z-index:9999;background:var(--panel,transparent)';
|
|
const panel = document.querySelector('.card,.stat,.tile,.wall-card') || document.body; panel.appendChild(host);
|
|
const hasSeg = !!document.querySelector('.theme-seg'); // the switch lives on the member area and admin
|
|
const SPECIAL = {
|
|
'theme-seg-probe': el => { el.className = 'seg theme-seg'; el.innerHTML = '<button data-theme="x" class="on">On</button><button data-theme="y">Off</button>'; },
|
|
'ok-probe': el => { el.className = 'small'; el.style.color = 'var(--ok)'; }, 'warn-probe': el => { el.className = 'small'; el.style.color = 'var(--warn)'; },
|
|
'bad-probe': el => { el.className = 'small'; el.style.color = 'var(--bad)'; }, 'gold-probe': el => { el.className = 'small'; el.style.color = 'var(--gold)'; },
|
|
'okbadge-probe': el => { el.className = 'badge'; el.style.cssText = 'background:var(--ok-soft);border-color:var(--ok);color:var(--ok)'; },
|
|
'goldbadge-probe': el => { el.className = 'badge'; el.style.cssText = 'background:var(--gold);color:var(--gold-ink)'; },
|
|
'amberpill-probe': el => { el.className = 'pill'; el.style.cssText = 'background:var(--amber);color:var(--amber-ink);font-size:11px;font-weight:800;border-radius:999px;padding:1px 8px'; },
|
|
};
|
|
for (const [cls, text] of PROBES) {
|
|
if (cls === 'theme-seg-probe' && !hasSeg) continue;
|
|
const el = document.createElement(cls.startsWith('btn') || cls.startsWith('subtab') || cls.startsWith('lst-chip') || cls.startsWith('pgr-btn') ? 'button' : 'span');
|
|
el.className = cls; el.textContent = text;
|
|
if (SPECIAL[cls]) SPECIAL[cls](el);
|
|
el.setAttribute('data-probe', cls); host.appendChild(el);
|
|
}
|
|
const out = []; const seen = new Set();
|
|
const els = [];
|
|
for (const sel of SAMPLE) { if (sel.includes('::')) continue; for (const el of document.querySelectorAll(sel)) els.push([sel, el]); }
|
|
for (const el of host.querySelectorAll('[data-probe],[data-theme]')) els.push(['probe ' + (el.getAttribute('data-probe') || el.parentElement.getAttribute('data-probe') + ' ' + el.className), el]);
|
|
for (const [sel, el] of els) {
|
|
if (!vis(el) || !hasText(el)) continue;
|
|
const cs = getComputedStyle(el); const fg = parse(cs.color); if (!fg) continue;
|
|
if (cs.opacity !== '' && parseFloat(cs.opacity) < 0.5) continue; // disabled / ghosted (the ghost wordmark is color:transparent)
|
|
if (fg.a === 0) continue;
|
|
let bg = bgOf(el);
|
|
const fgc = fg.a < 1 ? over(fg, bg) : fg;
|
|
const size = parseFloat(cs.fontSize), weight = parseInt(cs.fontWeight, 10) || 400;
|
|
const large = size >= 24 || (size >= 18.66 && weight >= 700);
|
|
const r = ratio(fgc, bg);
|
|
const key = sel + '|' + hex(fgc) + '|' + hex(bg) + '|' + large;
|
|
if (seen.has(key)) continue; seen.add(key);
|
|
out.push({ sel, text: (el.textContent || el.placeholder || '').trim().slice(0, 28), fg: hex(fgc), bg: hex(bg), ratio: Math.round(r * 100) / 100, size: Math.round(size * 10) / 10, weight, large, need: large ? 3 : 4.5 });
|
|
}
|
|
host.remove();
|
|
return out;
|
|
}, { SAMPLE, PROBES });
|
|
for (const r of rows) results.push(Object.assign({ page: label }, r));
|
|
}
|
|
|
|
const hide = page => page.evaluate(() => { document.querySelectorAll('.modal-back,.lgate,.iap-welcome').forEach(m => m.hidden = true); });
|
|
async function run(theme) {
|
|
const ctx = await browser.newContext({ viewport: { width: 1280, height: 950 } });
|
|
await ctx.addInitScript(t => { try { localStorage.setItem('iap.theme', t); sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} }, theme);
|
|
const page = await ctx.newPage(); page.on('dialog', d => d.accept());
|
|
const T = theme.toUpperCase() + ' ';
|
|
// member sign-in first, so the wall and join pages below have a real member to show
|
|
await page.goto(LOCAL + '/my', { waitUntil: 'networkidle' });
|
|
const user = 'qac' + theme; // one account per theme: the account value wins over the local one at sign-in
|
|
if (await page.$('#mcEmail')) {
|
|
await page.fill('#mcEmail', 'qa-contrast-' + theme + '@example.com'); await page.click('#mcSendBtn');
|
|
await page.waitForSelector('#mcVerifyBtn:not([hidden])', { timeout: 15000 }); await page.click('#mcVerifyBtn'); await page.waitForTimeout(2000);
|
|
if (await page.$('#onboardModal:not([hidden])')) { await page.fill('#obUsername', user); await page.click('#obSave'); await page.waitForTimeout(1500); }
|
|
await page.evaluate(t => fetch('/api/my/profile', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ theme: t }) }).then(r => r.json()), theme);
|
|
}
|
|
await hide(page);
|
|
const PANES = ['overview', 'line', 'pipeline', 'buy', 'campaigns', 'earn', 'earnings', 'promo', 'training', 'help', 'wallet', 'profile'];
|
|
for (const pn of PANES) {
|
|
await page.click('.bo-menu [data-pane="' + pn + '"]').catch(() => {}); await page.waitForTimeout(900); await hide(page);
|
|
const applied = await page.evaluate(() => document.documentElement.getAttribute('data-theme')); if (applied !== theme) results.push({ page: T + '/my#' + pn, sel: 'THEME', text: 'data-theme=' + applied, fg: '-', bg: '-', ratio: 0, size: 0, weight: 0, large: false, need: 1 });
|
|
await sample(page, T + '/my#' + pn);
|
|
}
|
|
await page.screenshot({ path: OUT + '/contrast-' + theme + '-my.png' }).catch(() => {});
|
|
// public pages (same browser, signed in: the nav shows the member)
|
|
for (const p of ['/', '/join/' + user, '/join/' + user + '?v=instant', '/wall/' + user, '/ledger', '/contract', '/games', '/wallets', '/support', '/leaderboard', '/whats-new', '/facts', '/terms', '/earning', '/friday', '/wednesday', '/refuel-guide', '/conversion-tracking', '/plays', '/launch', '/partners', '/presentation', '/shorts', '/blog']) {
|
|
await page.goto(LOCAL + p, { waitUntil: 'domcontentloaded' }).catch(() => {}); await page.waitForTimeout(1200); await hide(page);
|
|
await sample(page, T + p);
|
|
}
|
|
// admin
|
|
await page.goto(LOCAL + '/admin', { waitUntil: 'networkidle' });
|
|
if (await page.$('#adEmail')) {
|
|
await page.fill('#adEmail', process.env.ADMIN_EMAIL || 'martybostick@gmail.com'); await page.click('#adSend'); await page.waitForSelector('#adVerify:not([hidden])', { timeout: 15000 }); await page.click('#adVerify'); await page.waitForTimeout(1500);
|
|
}
|
|
for (const pn of ['overview', 'house', 'campaigns', 'members', 'support', 'reports', 'settings']) {
|
|
await page.click('.bo-menu [data-pane="' + pn + '"]').catch(() => {}); await page.waitForTimeout(900);
|
|
await sample(page, T + '/admin#' + pn);
|
|
}
|
|
await ctx.close();
|
|
}
|
|
await run('light');
|
|
await run('dark');
|
|
await browser.close();
|
|
|
|
const fails = results.filter(r => r.ratio < r.need);
|
|
const lines = ['===== THEME CONTRAST ' + new Date().toISOString() + ' =====', 'pairs: ' + results.length + ' | fail: ' + fails.length,
|
|
'', 'FAILS (ratio < need):', ...fails.sort((a, b) => a.ratio - b.ratio).map(f => `[fail] ${f.page} :: ${f.sel} "${f.text}" ${f.fg} on ${f.bg} = ${f.ratio}:1 (need ${f.need}, ${f.size}px/${f.weight})`),
|
|
'', 'WORST 25 OVERALL:', ...results.slice().sort((a, b) => a.ratio - b.ratio).slice(0, 25).map(f => `${f.ratio}:1 ${f.page} :: ${f.sel} "${f.text}" ${f.fg} on ${f.bg} (${f.size}px/${f.weight}${f.large ? ' large' : ''})`),
|
|
'', 'ALL PAIRS:', ...results.map(f => `${f.ratio < f.need ? 'FAIL' : 'ok '} ${f.ratio}:1 ${f.page} :: ${f.sel} "${f.text}" ${f.fg} on ${f.bg} (${f.size}px/${f.weight}${f.large ? ' large' : ''})`)];
|
|
fs.writeFileSync(OUT + '/theme-contrast.txt', lines.join('\n') + '\n');
|
|
console.log(lines.slice(0, Math.min(lines.length, 60 + fails.length)).join('\n'));
|
|
process.exit(fails.length ? 1 : 0);
|