Files
advent-of-slop-04-flaeskesteg/scripts/smoke4.py
T

110 lines
4.5 KiB
Python

# Smoke-test the built Day 4 flæskesteg site: interactions, timer, persistence, win overlay.
import http.server, threading, functools, sys, os
DIST = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else 'dist')
httpd = http.server.ThreadingHTTPServer(('127.0.0.1', 8766), functools.partial(http.server.SimpleHTTPRequestHandler, directory=DIST))
threading.Thread(target=httpd.serve_forever, daemon=True).start()
from playwright.sync_api import sync_playwright
errs, msgs = [], []
with sync_playwright() as p:
b = p.chromium.launch(
executable_path='/home/hermeswebui/.hermes/home/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome',
args=['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'])
pg = b.new_page(viewport={'width': 1200, 'height': 630})
pg.on('pageerror', lambda e: errs.append(str(e)))
pg.on('console', lambda m: msgs.append(f"{m.type}: {m.text}"))
pg.goto('http://127.0.0.1:8766/', wait_until='networkidle')
pg.wait_for_timeout(600)
print('title:', pg.title())
assert 'Day 4' in pg.title()
# step list rendered
n_steps = pg.locator('#steps .step').count()
print('steps rendered:', n_steps)
assert n_steps == 10
# click step 6 (Brun the potatoes, 8 min) -> scene + timer box update
pg.locator('#steps .step').nth(5).click()
pg.wait_for_timeout(300)
assert 'Brun the potatoes' in pg.locator('#now-title').inner_text()
t0 = pg.locator('#timer-display').inner_text()
print('timer display initial:', t0)
# start timer (demo mode default: 60x -> 8 min finishes in 8s)
pg.locator('#timer-btn').click()
pg.wait_for_timeout(1500)
t1 = pg.locator('#timer-display').inner_text()
print('timer after 1.5s demo:', t1)
assert t1 != t0, 'timer did not count down'
pg.wait_for_timeout(7500)
done_txt = pg.locator('#timer-display').inner_text()
print('timer at end:', done_txt)
assert 'færdig' in done_txt
# checkbox -> progress updates
pg.locator('#steps .step').nth(0).locator('.done').check()
pg.locator('#steps .step').nth(1).locator('.done').check()
pg.wait_for_timeout(300)
prog = pg.locator('#progress-text').inner_text()
print('progress:', prog)
assert '2 / 10' in prog
# servings slider scales ingredients
pg.locator('#servings').fill('8')
pg.wait_for_timeout(200)
ing0 = pg.locator('#ing-list li').nth(0).inner_text()
print('ingredient at 8 servings:', ing0)
assert '3 kg' in ing0
# persistence across reload
pg.reload(wait_until='networkidle')
pg.wait_for_timeout(500)
prog2 = pg.locator('#progress-text').inner_text()
checked = pg.locator('#steps .step .done:checked').count()
serv = pg.locator('#servings').input_value()
print('after reload -> progress:', prog2, 'checked:', checked, 'servings:', serv)
assert checked == 2 and serv == '8'
# no-timer step shows disabled button
pg.locator('#steps .step').nth(0).click()
pg.wait_for_timeout(200)
assert pg.locator('#timer-btn').is_disabled()
# complete everything -> win overlay + confetti
for i in range(10):
cb = pg.locator('#steps .step').nth(i).locator('.done')
if not cb.is_checked():
cb.check()
pg.wait_for_timeout(400)
assert pg.locator('#win').is_visible(), 'win overlay missing'
print('win overlay visible, confetti:', pg.locator('.confetti').count())
pg.locator('#win-close').click()
pg.wait_for_timeout(200)
assert not pg.locator('#win').is_visible()
# reset button clears storage (test then restore clean state)
# -> instead just clear storage for a clean preview screenshot
pg.evaluate("localStorage.clear()")
pg.reload(wait_until='networkidle')
pg.wait_for_timeout(400)
assert pg.locator('#steps .step .done:checked').count() == 0
# preview screenshot: pick the 'serve' step, canvas fully visible at 1200x630
pg.locator('#steps .step').nth(9).click()
pg.wait_for_timeout(1200)
pg.evaluate("window.scrollTo(0,0)")
box = pg.locator('#scene').bounding_box()
print('canvas box:', box)
assert box['y'] + box['height'] <= 630, 'canvas clipped at 630px viewport'
pg.screenshot(path=os.path.join(os.path.dirname(DIST), 'preview_shot.png'))
# also a mid-recipe shot (oven) for reference
pg.locator('#steps .step').nth(2).click()
pg.wait_for_timeout(800)
pg.screenshot(path=os.path.join(os.path.dirname(DIST), 'check_full.png'))
print('pageerrors:', errs)
print('console errors:', [m for m in msgs if m.startswith('error')])
assert not errs
b.close()
httpd.shutdown()
print('SMOKE OK')