← back to CelebritySignatures
verification/lincoln-campaign.e2e.cjs
42 lines
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { chromium } = require('/Users/macstudio3/Projects/Designer-Wallcoverings/node_modules/playwright');
const base = process.env.STORE_PROOF_URL || 'http://127.0.0.1:9956';
const artifacts = fs.mkdtempSync(path.join(os.tmpdir(), 'tk10286-campaign-'));
(async () => {
const browser = await chromium.launch({ channel:'chrome' });
const checks = [];
try {
for (const [device, viewport] of [['desktop',{width:1280,height:900}],['mobile',{width:390,height:844}]]) {
const context = await browser.newContext({viewport});
await context.route('**/*', r => ['GET','HEAD'].includes(r.request().method()) ? r.continue() : r.abort());
const page = await context.newPage();
const errors = []; page.on('pageerror', e => errors.push(e.message));
for (const selector of ['.campaign .clink', '.hero-ctas a[href="/wear?qid=Q91"]']) {
await page.goto(base, {waitUntil:'domcontentloaded'});
const img = page.locator('.campaign img');
await img.scrollIntoViewIfNeeded();
await page.waitForFunction(()=>{const i=document.querySelector('.campaign img');return i.complete&&i.naturalWidth>0;},{},{timeout:20000});
const shape=await img.evaluate(i=>({shown:i.clientWidth/i.clientHeight,natural:i.naturalWidth/i.naturalHeight}));
assert.ok(Math.abs(shape.shown-shape.natural)<0.01,'full hat-to-socks image preserves its natural aspect ratio');
assert.match(await img.getAttribute('src'), /campaign-lincoln-products-v2\.png$/);
assert.ok(await page.locator('.campaign .rendering').isVisible());
await page.locator('.campaign').screenshot({path:path.join(artifacts,device+'-campaign.png')});
await page.locator(selector).click();
await page.waitForURL('**/wear?qid=Q91',{waitUntil:'domcontentloaded'});
await page.locator('#scrim.on').waitFor();
assert.equal(await page.locator('#pName').textContent(), 'Abraham Lincoln');
for (const name of ['Classic Tee','Bucket Hat','Crew Socks']) assert.ok((await page.locator('#garments').textContent()).includes(name));
}
assert.deepEqual(errors,[]);
checks.push({device,verdict:'PASS',paths:['corrected campaign image','disclosure visible','campaign CTA selects Lincoln','hero CTA selects Lincoln'],pageErrors:errors});
await context.close();
}
} finally { await browser.close(); }
const result={base,artifacts,checks,externalMutations:0};
fs.writeFileSync(path.join(artifacts,'result.json'),JSON.stringify(result,null,2));
console.log(JSON.stringify(result,null,2));
})().catch(e=>{console.error(e);process.exitCode=1;});