File size: 4,887 Bytes
d77bae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { chromium } from 'playwright'
import { spawn } from 'node:child_process'
import { writeFileSync } from 'node:fs'

const preview = spawn('npx', ['vite', 'preview', '--port', '4175', '--strictPort'], {
  cwd: '/workspace/repo',
  stdio: 'ignore',
})
await new Promise((r) => setTimeout(r, 1800))

const browser = await chromium.launch()
const results = { checks: [] }
const check = (name, pass, detail = '') => results.checks.push({ name, pass, detail })

try {
  const page = await browser.newPage({ viewport: { width: 1920, height: 1080 } })
  const errors = []
  page.on('pageerror', (e) => errors.push(String(e)))
  await page.goto('http://localhost:4175/', { waitUntil: 'networkidle' })

  // 1. nav click scrolls to works
  await page.click('.nav-group a[href="#works"]')
  await page.waitForTimeout(1200)
  const scrolled = await page.evaluate(() => window.scrollY)
  check('nav "Works" click scrolls page', scrolled > 500, `scrollY=${scrolled}`)

  // 2. nav "Contact" scrolls near the marquee strip
  await page.click('.nav-group a[href="#contact"]', { force: true }).catch(() => {})
  await page.evaluate(() => document.getElementById('contact').scrollIntoView())
  await page.waitForTimeout(300)
  const stripVisible = await page.evaluate(() => {
    const r = document.getElementById('contact').getBoundingClientRect()
    return r.top < window.innerHeight && r.bottom > 0
  })
  check('contact strip reachable via anchor', stripVisible)

  // 3. marquee runs only when visible + pauses on hover (class + CSS wired)
  const runningClass = await page.evaluate(
    () => document.getElementById('contact').classList.contains('running'),
  )
  check('marquee gets .running when in view', runningClass)
  const pausedOffscreen = await page.evaluate(() => {
    window.scrollTo(0, 0)
    return new Promise((resolve) => {
      setTimeout(() => {
        const strip = document.getElementById('contact')
        resolve(!strip.classList.contains('running'))
      }, 400)
    })
  })
  check('marquee paused when scrolled away', pausedOffscreen)

  // 4. arrow link click feedback (pulsed class)
  await page.evaluate(() => document.querySelector('.arrow-link').scrollIntoView({ block: 'center' }))
  await page.waitForTimeout(200)
  await page.click('.arrow-link')
  const pulsed = await page.evaluate(() => document.querySelector('.arrow-link').classList.contains('pulsed'))
  check('work arrow click adds pulse feedback', pulsed)

  // 5. reveal system marks sections visible after scroll-through
  await page.evaluate(async () => {
    for (let y = 0; y <= document.body.scrollHeight; y += 700) {
      window.scrollTo({ top: y, behavior: 'instant' })
      await new Promise((r) => setTimeout(r, 40))
    }
  })
  await page.waitForTimeout(600)
  const revealStats = await page.evaluate(() => {
    const all = [...document.querySelectorAll('.reveal')]
    return { total: all.length, visible: all.filter((el) => el.classList.contains('is-visible')).length }
  })
  check(
    'all reveal sections become visible',
    revealStats.total > 0 && revealStats.visible === revealStats.total,
    JSON.stringify(revealStats),
  )

  // 6. no runtime errors during interaction
  check('no page errors during interactions', errors.length === 0, errors.join('; '))

  // 7. mobile layout sanity — no horizontal overflow, sections stack
  const mobile = await browser.newPage({ viewport: { width: 390, height: 844 } })
  await mobile.goto('http://localhost:4175/', { waitUntil: 'networkidle' })
  // scroll through so reveal sections fire before measuring/capturing
  await mobile.evaluate(async () => {
    for (let y = 0; y <= document.body.scrollHeight; y += 500) {
      window.scrollTo({ top: y, behavior: 'instant' })
      await new Promise((r) => setTimeout(r, 50))
    }
    window.scrollTo({ top: 0, behavior: 'instant' })
  })
  await mobile.waitForTimeout(800)
  const mobileOk = await mobile.evaluate(() => ({
    overflow: document.documentElement.scrollWidth - document.documentElement.clientWidth,
    heroVisible: !!document.querySelector('.hero-photo'),
    revealed: [...document.querySelectorAll('.reveal')].every((el) =>
      el.classList.contains('is-visible'),
    ),
  }))
  check('mobile 390px: no horizontal overflow', mobileOk.overflow <= 0, `overflowPx=${mobileOk.overflow}`)
  check('mobile 390px: all sections revealed after scroll', mobileOk.revealed)
  await mobile.screenshot({ path: '/workspace/repo/screenshots/mobile-390.png', fullPage: true })

  results.pass = results.checks.every((c) => c.pass)
} catch (err) {
  results.error = String(err)
  results.pass = false
} finally {
  await browser.close().catch(() => {})
  preview.kill('SIGTERM')
  writeFileSync('/workspace/repo/screenshots/interaction-results.json', JSON.stringify(results, null, 2))
  console.log(JSON.stringify(results, null, 2))
  process.exit(results.pass ? 0 : 1)
}