File size: 3,904 Bytes
41235a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { chromium } from 'playwright-core'
import { writeFileSync } from 'node:fs'

const BASE_URL = process.env.APP_URL ?? 'http://localhost:4173/'
const results = {
  timestamp: new Date().toISOString(),
  baseUrl: BASE_URL,
  checks: [],
}
const check = (name, passed, details) => {
  results.checks.push({ name, passed, details })
  console.log(`${passed ? 'PASS' : 'FAIL'}  ${name} — ${details}`)
}

const browser = await chromium.launch({
  args: ['--no-sandbox', '--disable-dev-shm-usage', '--force-device-scale-factor=1'],
})
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 } })
const errors = []
page.on('pageerror', (err) => errors.push(String(err)))
page.on('console', (msg) => msg.type() === 'error' && errors.push(msg.text()))

await page.goto(BASE_URL, { waitUntil: 'networkidle', timeout: 60000 })

const root = await page.$eval('#root', (el) => el.children.length)
check('react-mounted', root > 0, `#root has ${root} child node(s)`)

const sections = await page.$$eval('.project', (els) => els.length)
check('project-sections', sections === 9, `${sections} project sections (expected 9)`)

const cells = await page.$$eval('.cell', (els) => els.length)
check('grid-cells', cells === 72, `${cells} grid cells (expected 72)`)

const hatch = await page.$$eval('.cell .hatch', (els) => els.length)
check('hatch-cells', hatch === 33, `${hatch} hatched placeholder cells (expected 33)`)

const imgs = await page.$$eval('.cell img', (els) => ({
  total: els.length,
  loaded: els.filter((img) => img.complete && img.naturalWidth > 0).length,
}))
check('images-loaded', imgs.total === 39 && imgs.loaded === 39, `${imgs.loaded}/${imgs.total} images loaded (expected 39/39)`)

const navLinks = await page.$$eval('.site-nav .nav-link', (els) => els.map((a) => a.textContent.trim()))
check('nav-links', navLinks.length === 5, `nav: ${navLinks.join(' | ')}`)

const height = await page.evaluate(() => document.documentElement.scrollHeight)
const target = 12474
const heightOk = Math.abs(height - target) / target < 0.05
check('page-height', heightOk, `rendered ${height}px vs reference ~${target}px (${((height / target - 1) * 100).toFixed(1)}% diff)`)

// interaction: grid density toggle switches first section to 2 columns
await page.click('#polestar .view-btn:first-child')
const tracks = await page.$eval('#polestar .grid', (el) => getComputedStyle(el).gridTemplateColumns.split(' ').length)
check('view-toggle-interaction', tracks === 2, `after clicking 2-col toggle, grid has ${tracks} columns`)
await page.click('#polestar .view-btn:last-child')

// interaction: card hover feedback (opacity transition defined)
const hoverFx = await page.$eval('.cell', (el) => getComputedStyle(el).transition)
check('card-feedback', /opacity|transform/.test(hoverFx), `card transition: ${hoverFx}`)

// responsive snapshots
for (const [w, h, name] of [[900, 900, 'tablet-900'], [420, 900, 'mobile-420']]) {
  await page.setViewportSize({ width: w, height: h })
  await page.waitForTimeout(250)
  await page.screenshot({ path: `screenshots/${name}.png`, fullPage: false })
  const cols = await page.$eval('#polestar .grid', (el) => getComputedStyle(el).gridTemplateColumns.split(' ').length)
  check(`responsive-${w}`, w <= 480 ? cols === 1 : cols === 2, `${w}px viewport renders ${cols} column(s)`)
}

check('no-console-errors', errors.length === 0, errors.length ? errors.join('; ').slice(0, 300) : 'no page/console errors')

await browser.close()

results.passed = results.checks.filter((c) => c.passed).length
results.failed = results.checks.filter((c) => !c.passed).length
results.status = results.failed === 0 ? 'passed' : 'failed'
writeFileSync('/workspace/artifacts/validation-results.json', JSON.stringify(results, null, 2))
console.log(`\n${results.status.toUpperCase()}: ${results.passed}/${results.checks.length} checks passed`)
if (results.failed > 0) process.exit(1)