← back to Dw Theme Patches

TK-12166/verify.mjs

45 lines

// TK-12166 post-deploy check (READ-ONLY): 3 Brand McKenzie PDPs show a "Lead Time" spec row = "3-5 Weeks";
// 1 Thibaut PDP has NO Lead Time row; no Liquid errors on any page. Screenshots -> ./shots/
// Usage: node verify.mjs      (exit 0 = PASS, 1 = FAIL)
import { createRequire } from 'module';
import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url';
const require = createRequire(import.meta.url);
const PW = process.env.PW_PATH || '/Users/macstudio3/Projects/astek-landing/node_modules/playwright';
const { chromium } = require(PW);
const HERE = path.dirname(fileURLToPath(import.meta.url)); const SHOTS = path.join(HERE, 'shots'); fs.mkdirSync(SHOTS, { recursive: true });
const BASE = 'https://www.designerwallcoverings.com/products/';
const CASES = [
  { h: 'dwbm-260059', expect: '3-5 Weeks' },
  { h: 'dwbm-260001', expect: '3-5 Weeks' },
  { h: 'brand-mckenzie-groove-inferno-bmgi006-03a-wallcovering-sancarwallcoverings', expect: '3-5 Weeks' },
  { h: 'dwtt-70112-designer-wallcoverings-los-angeles', expect: null }, // Thibaut: must have NO Lead Time row
];
const b = await chromium.launch();
const pg = await b.newPage({ userAgent: 'Mozilla/5.0 (Macintosh) AppleWebKit/537.36 Chrome/128 Safari/537.36', viewport: { width: 1400, height: 1000 } });
let fail = 0;
for (const c of CASES) {
  const url = BASE + c.h + '?_tk12166=' + Date.now(); // cache-bust
  const resp = await pg.goto(url, { waitUntil: 'load', timeout: 90000 }); await pg.waitForTimeout(5000);
  const r = await pg.evaluate(() => {
    const rows = [...document.querySelectorAll('.dw-specs .dw-spec-row')].map(e => ({
      label: e.querySelector('.dw-spec-label')?.innerText.trim(), value: e.querySelector('.dw-spec-value')?.innerText.trim(), vis: e.offsetParent !== null }));
    const specsPresent = !!document.querySelector('.dw-specs');
    const liquidErr = /Liquid (syntax )?error|Liquid error/i.test(document.body.innerText);
    const vendor = (window.ShopifyAnalytics?.meta?.product?.vendor) || null;
    return { rows, specsPresent, liquidErr, vendor };
  });
  const lt = r.rows.find(x => /^lead time$/i.test(x.label || ''));
  let ok, why;
  if (resp.status() !== 200) { ok = false; why = 'HTTP ' + resp.status(); }
  else if (r.liquidErr) { ok = false; why = 'Liquid error on page'; }
  else if (!r.specsPresent) { ok = false; why = 'NOT-MEASURED: .dw-specs block absent (cannot judge)'; }
  else if (c.expect) { ok = !!lt && lt.vis && lt.value === c.expect; why = lt ? `Lead Time row = "${lt.value}" visible=${lt.vis}` : 'no Lead Time row'; }
  else { ok = !lt; why = lt ? `UNEXPECTED Lead Time row "${lt.value}"` : `no Lead Time row (${r.rows.length} spec rows)`; }
  const shot = path.join(SHOTS, c.h.slice(0, 40) + '.png');
  const el = await pg.$('.dw-specs'); if (el) await el.screenshot({ path: shot }).catch(() => pg.screenshot({ path: shot })); else await pg.screenshot({ path: shot });
  console.log(`${ok ? 'PASS' : 'FAIL'}  ${c.h}  vendor=${r.vendor}  ${why}  shot=${shot}`);
  if (!ok) fail++;
}
await b.close();
console.log(fail ? `VERDICT: FAIL (${fail})` : 'VERDICT: PASS'); process.exit(fail ? 1 : 0);