feat(altitude): auto-advance one altitude per minute when idle

After the dial sits idle for 60s the altitude drifts one step deeper (descend;
wraps past the deepest back to the top), like a slow kiosk tour. Any manual
interaction (drag/wheel/arrow-key/knob) restarts the idle countdown; a mid-morph
or mid-drag beat is skipped and retried. A default-on 'Auto-advance' toggle in
the Altitude panel disables it. Interval is injectable for tests via
window.__hefAutoAdvanceMs. i18n for 4 langs. +3 e2e (auto-advance.spec.ts).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
BenStullsBets
2026-07-02 05:44:41 -07:00
parent 88ebb07578
commit 9d42ed7fc4
4 changed files with 87 additions and 2 deletions
+52
View File
@@ -0,0 +1,52 @@
import { test, expect, Page } from "@playwright/test";
// Auto-advance: after the dial sits idle for the interval, the altitude drifts one
// step deeper (descend), wrapping past the deepest. A default-on toggle disables it.
// The e2e injects a short interval via window.__hefAutoAdvanceMs before load.
async function boot(page: Page, intervalMs: number) {
await page.addInitScript((ms) => { (window as any).__hefAutoAdvanceMs = ms; }, intervalMs);
await page.goto("/");
await page.waitForFunction(() => (window as any).__hefReady === true, null, { timeout: 45_000 });
await page.locator("#welcome-launch").click();
await page.waitForSelector("#welcome", { state: "detached", timeout: 10_000 });
}
const idx = (page: Page) => page.evaluate(() => (window as any).__hefState().ringIndex as number);
test("auto-advances one altitude (descending) after the idle interval", async ({ page }) => {
await boot(page, 1200);
const n = await page.evaluate(() => (window as any).__hefState && (document.querySelectorAll(".dial-label").length));
const start = await idx(page);
// Wait past the interval + the morph animation for the landing.
await page.waitForFunction((s) => (window as any).__hefState().ringIndex !== s, start, { timeout: 8000 });
const after = await idx(page);
expect(after).toBe((start + 1) % n); // descended exactly one, wraps
});
test("toggling Auto-advance off keeps the altitude parked", async ({ page }) => {
await boot(page, 1000);
await page.evaluate(() => {
const c = document.querySelector("#auto-advance") as HTMLInputElement;
c.checked = false;
c.dispatchEvent(new Event("change", { bubbles: true }));
});
const start = await idx(page);
await page.waitForTimeout(2600); // well past two intervals
expect(await idx(page)).toBe(start); // never moved
});
test("the idle countdown resets on interaction (no advance right after a manual turn)", async ({ page }) => {
await boot(page, 1500);
// Immediately before the first interval elapses, interact (keyboard step). That step
// itself advances by 1; the reset then means no AUTO advance fires for another
// full interval — so shortly after, we should still be at exactly that +1.
await page.waitForTimeout(900);
const before = await idx(page);
await page.locator("#dial").focus();
await page.locator("#dial").press("ArrowDown"); // manual descend + reset
await page.waitForFunction((b) => (window as any).__hefState().ringIndex !== b, before, { timeout: 4000 });
const manual = await idx(page);
await page.waitForTimeout(900); // < the 1500ms interval
expect(await idx(page)).toBe(manual); // countdown reset → no extra auto step yet
});