← back to Dw Theme Boost Fix

verify/preview-gate.mjs

35 lines

import { chromium } from 'playwright';
const PREVIEW = 'https://www.designerwallcoverings.com/collections/grasscloth-wallpaper-collection?preview_theme_id=143947038771';
const b = await chromium.launch();
const ctx = await b.newContext();
const p = await ctx.newPage();
const hits = [];
p.on('response', r => { const u = r.url(); if (u.includes('bc-solutions') || u.includes('mybcapps')) hits.push({ u: u.split('?')[0], s: r.status() }); });
await p.goto(PREVIEW, { waitUntil: 'load', timeout: 60000 });
await p.waitForTimeout(12000);
const staging = hits.filter(h => h.u.includes('staging'));
const prod200 = hits.filter(h => h.u.includes('mybcapps') && h.s === 200);
const facets = await p.locator('.boost-sd__filter-option-item, [class*="boost-sd__filter"] li').count().catch(() => 0);
const toggle = await p.locator('#dw-page-mode').count();
console.log('HARD GATE — staging requests:', staging.length, '| prod 200s:', prod200.length);
console.log('facets:', facets, '| toggle pill present:', toggle);
// switch to paged mode
if (toggle) {
  await p.evaluate(() => { const btns = document.querySelectorAll('#dw-page-mode button'); for (const b of btns) if (b.textContent.includes('Pages')) b.click(); });
  await p.waitForLoadState('load');
  await p.waitForTimeout(12000);
  const mode = await p.evaluate(() => localStorage.getItem('dwPaginationMode'));
  const pagType = await p.evaluate(() => {
    const c = window.boostSDAppConfig || {};
    return JSON.stringify({ gs: c.generalSettings && c.generalSettings.paginationType, lim: c.generalSettings && c.generalSettings.limit });
  });
  const pagination = await p.locator('[class*="boost-sd__pagination"], .boost-sd__pagination-button, [class*="pagination"] button').count().catch(() => 0);
  const products = await p.locator('.boost-sd__product-item, [class*="boost-sd__product"]').count().catch(() => 0);
  console.log('PAGED MODE — localStorage:', mode, '| config:', pagType);
  console.log('pagination controls:', pagination, '| products rendered:', products);
}
await b.close();
const pass = staging.length === 0 && prod200.length > 0 && facets > 0 && toggle > 0;
console.log('VERDICT:', pass ? 'PASS' : 'FAIL');
process.exit(pass ? 0 : 1);