| 1 | """t1199: gravity >= 2 and % display; t1200: +x% combo-only. Usage: python3 test/t1199-gravity-playwright.py ROOT [tag]""" |
| 2 | import sys, re |
| 3 | from playwright.sync_api import sync_playwright |
| 4 | URL = sys.argv[1].rstrip("/") + "/" |
| 5 | TAG = sys.argv[2] if len(sys.argv) > 2 else "live" |
| 6 | fails = [] |
| 7 | def check(ok, msg): |
| 8 | print(("OK " if ok else "FAIL ") + msg) |
| 9 | if not ok: fails.append(msg) |
| 10 | |
| 11 | with sync_playwright() as p: |
| 12 | br = p.chromium.launch() |
| 13 | for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)): |
| 14 | ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=2 if mobile else 1) |
| 15 | page = ctx.new_page(); errs = [] |
| 16 | page.on("pageerror", lambda e: errs.append(str(e))) |
| 17 | page.goto(URL + "index.html", wait_until="networkidle") |
| 18 | pre = f"/workspace/meteors-shots/t1199-{TAG}-{name}-" |
| 19 | # planet cards |
| 20 | page.click("#btn-survival"); page.wait_for_selector("#planet-select:not([hidden])") |
| 21 | cards = page.evaluate("() => [...document.querySelectorAll('#planet-grid [data-planet]')].map(c => [c.dataset.planet, (c.querySelector('.planet-nums')||{}).textContent])") |
| 22 | nums = dict(cards) |
| 23 | check(all(re.match(r"g (\d+)% \((\d+\.\d\d)g\)", t or "") for _, t in cards), f"{name}: every card shows g N% (x.xxg): {len(cards)} cards") |
| 24 | check(nums.get("terra", "").startswith("g 100% (9.81g)"), f"{name}: Terra {nums.get('terra')}") |
| 25 | check(nums.get("cinder", "").startswith("g 300% (29.43g)"), f"{name}: Cinder {nums.get('cinder')}") |
| 26 | for pid in ("aurel", "lunara", "zephyr"): |
| 27 | check(nums.get(pid, "").startswith("g 100% (9.81g)"), f"{name}: {pid} raised to 100% ({nums.get(pid)})") |
| 28 | low = [pid for pid, t in cards if int(re.match(r"g (\d+)%", t).group(1)) < 100] |
| 29 | check(not low, f"{name}: no card below 100% {low}") |
| 30 | page.screenshot(path=pre + "planet-cards.png", full_page=True) |
| 31 | # HUD |
| 32 | page.click('#planet-grid [data-planet="cinder"]'); page.click("#btn-planet-go") |
| 33 | page.wait_for_function("() => app.mode === 'playing'") |
| 34 | hud = page.inner_text("#planet-stats") |
| 35 | check(hud.startswith("g 300% (29.43g)"), f"{name}: HUD {hud!r}") |
| 36 | page.wait_for_timeout(500) |
| 37 | page.screenshot(path=pre + "hud.png") |
| 38 | # t1200: combo-only number (landing chain excluded) |
| 39 | r = page.evaluate("""() => { const g = app.core; g.noSpawn = true; g.combo = 4; g.lastChainIndicator = { chain: 2, bonusPct: 54 }; return g.comboBonusPct(); }""") |
| 40 | page.wait_for_timeout(200) |
| 41 | txt = page.evaluate("() => { const e = document.getElementById('chain-indicator'); return e.hidden ? null : e.textContent; }") |
| 42 | check(r == 4 and txt == "+4%", f"{name}: +x% shows only the combo ({txt!r}, not the +54% chain total)") |
| 43 | page.evaluate("() => { app.core.combo = 0; }"); page.wait_for_timeout(200) |
| 44 | check(page.evaluate("() => document.getElementById('chain-indicator').hidden"), f"{name}: +x% hidden when combo is 0") |
| 45 | page.goto(URL + "index.html", wait_until="networkidle") |
| 46 | # designer slider (designer is login-only; open the real editor screen directly) |
| 47 | page.evaluate("""() => { hideEl('menu'); Designer.openEdit(null); document.getElementById('designer-edit').hidden = false; }""") |
| 48 | page.wait_for_selector("#designer-edit:not([hidden])") |
| 49 | mn = page.get_attribute("#des-gravity", "min") |
| 50 | check(mn == "2", f"{name}: designer slider min = {mn}") |
| 51 | vals = {} |
| 52 | for v in ("2", "3", "4", "1"): |
| 53 | page.evaluate(f"() => {{ const s = document.getElementById('des-gravity'); s.value = '{v}'; s.dispatchEvent(new Event('input', {{bubbles: true}})); }}") |
| 54 | vals[v] = page.inner_text("#des-gravity-val") |
| 55 | check(vals["2"] == "100% (9.81g)" and vals["3"] == "200% (19.62g)" and vals["4"] == "300% (29.43g)" and vals["1"] == "100% (9.81g)", f"{name}: designer labels {vals}") |
| 56 | page.evaluate("() => { const s = document.getElementById('des-gravity'); s.value = '2'; s.dispatchEvent(new Event('input', {bubbles: true})); }") |
| 57 | page.locator("#des-gravity").scroll_into_view_if_needed() |
| 58 | page.screenshot(path=pre + "designer.png") |
| 59 | page.evaluate("() => I18n.setLocale('nl')"); page.wait_for_timeout(200) |
| 60 | page.evaluate("() => { const s = document.getElementById('des-gravity'); s.value = '3'; s.dispatchEvent(new Event('input', {bubbles: true})); }") |
| 61 | check(page.inner_text("#des-gravity-val") == "200% (19.62g)", f"{name}: nl label {page.inner_text('#des-gravity-val')!r}") |
| 62 | check(not errs, f"{name}: no page errors {errs}") |
| 63 | ctx.close() |
| 64 | br.close() |
| 65 | print("ALL OK" if not fails else f"{len(fails)} FAILED") |
| 66 | sys.exit(1 if fails else 0) |
projects-timfalken-com meteors