fix(client): usable GM column and phone HUD (#89)
This commit is contained in:
@@ -13,6 +13,7 @@ test('GM token create defaults X/Y to the viewport centre', { timeout: 120000 },
|
||||
await waitForVisible(page, '#signin')
|
||||
await signIn(page, gmKey)
|
||||
await waitForVisible(page, '#stage canvas')
|
||||
await page.click('#gm-token-create-section > summary')
|
||||
await page.waitForFunction(() => {
|
||||
const x = document.querySelector('#token-x')
|
||||
const y = document.querySelector('#token-y')
|
||||
|
||||
@@ -87,6 +87,9 @@ test('GM roster, keys and token panel drive the real server', { timeout: 240000
|
||||
await waitForText(gm, '#gm-roster-list', /GM/)
|
||||
await waitForText(gm, '#gm-roster-list', /connected/)
|
||||
assert.equal(await gm.locator('#gm-panels').isVisible(), true)
|
||||
// The create form and the 50-row token list start folded (M4 UX); open both for this flow.
|
||||
await gm.click('#gm-token-create-section > summary')
|
||||
await gm.click('#gm-token-list-section > summary')
|
||||
|
||||
// ---- key.create through the panel, key visible only in the GM DOM ----------------------
|
||||
await gm.click('#gm-key-create')
|
||||
|
||||
@@ -82,6 +82,9 @@ test('GM characters, reveals, encountered remove and who-sees-it', { timeout: 24
|
||||
await signIn(gm, gmKey)
|
||||
await waitForVisible(gm, '#gm-panels')
|
||||
await waitForVisible(gm, '#gm-cast')
|
||||
// Characters and the per-player encountered lists start folded (M4 UX).
|
||||
await gm.click('#gm-characters > summary')
|
||||
await gm.click('#gm-encountered-section > summary')
|
||||
|
||||
// ---- character.create through the panel (owner defaults to the GM) --------------------
|
||||
await gm.fill('#character-name', 'a cloaked figure')
|
||||
|
||||
@@ -70,6 +70,9 @@ async function createSightedToken(origin, gmKey, player, { pos, name, radius, vi
|
||||
await signIn(page, gmKey)
|
||||
await waitForVisible(page, '#gm-panels')
|
||||
await waitForText(page, '#gm-roster-list', new RegExp(name))
|
||||
// The create form and the token list start folded (M4 UX).
|
||||
await page.click('#gm-token-create-section > summary')
|
||||
await page.click('#gm-token-list-section > summary')
|
||||
await page
|
||||
.locator(`#token-controller option[value="${player.id}"]`)
|
||||
.waitFor({ state: 'attached', timeout: 20000 })
|
||||
|
||||
@@ -16,11 +16,9 @@ test('e2e: headless chromium loads the real client build and the page reports h2
|
||||
const errors = []
|
||||
page.on('pageerror', error => errors.push(error.message))
|
||||
page.on('console', message => {
|
||||
// The boot probe's refused WebSocket upgrade is the expected no-session path (the browser
|
||||
// logs it); it is not a page error. Everything else must be silent.
|
||||
if (message.type() === 'error' && !message.text().includes('WebSocket connection')) {
|
||||
errors.push(message.text())
|
||||
}
|
||||
// A fresh visitor no longer probes `/ws` before signing in (M4 UX), so a healthy load has
|
||||
// no refused-upgrade noise: every console error is a real error here.
|
||||
if (message.type() === 'error') errors.push(message.text())
|
||||
})
|
||||
|
||||
await page.goto(`${origin}/`, { waitUntil: 'load' })
|
||||
|
||||
@@ -260,8 +260,9 @@ test('clamps: player stops at 0.5 and 4, the GM goes below 0.5 and stops at 4',
|
||||
await signIn(gmPage, gmKey)
|
||||
await waitForVisible(gmPage, canvas)
|
||||
await waitTilesReady(gmPage)
|
||||
// 0.25 is below the player's 0.5 floor: the GM's survey zoom is not clamped there.
|
||||
await gmPage.mouse.move(80, 80)
|
||||
// 0.25 is below the player's 0.5 floor: the GM's survey zoom is not clamped there. Wheel
|
||||
// over the left edge: the GM column (Walls first) now owns the right side of this tiny view.
|
||||
await gmPage.mouse.move(20, 80)
|
||||
await gmPage.mouse.wheel(0, 924)
|
||||
await gmPage.waitForFunction(() => {
|
||||
const zoom = Number(document.querySelector('#stage canvas')?.dataset.zoom)
|
||||
|
||||
@@ -13,6 +13,9 @@ test('protocol mismatch: the client shows reload and does not reconnect', { time
|
||||
const browser = await launchBrowser()
|
||||
try {
|
||||
const { page } = await newPage(browser)
|
||||
// The client only dials on boot when its session marker exists (M4 UX). This test is about
|
||||
// the upgrade outcome, so tell the page a session may exist before it loads.
|
||||
await page.addInitScript(() => localStorage.setItem('fff-vtt.session', '1'))
|
||||
let sockets = 0
|
||||
await page.routeWebSocket(/\/ws\?proto=2$/, ws => {
|
||||
sockets += 1
|
||||
|
||||
@@ -36,7 +36,7 @@ test('perf overlay: absent by default, `?perf=1` shows fps/frame/JS/tokens/zoom'
|
||||
assert.match(text, /fps \d+\.\d/)
|
||||
assert.match(text, /frame p50 \d+\.\d p95 \d+\.\d ms/)
|
||||
assert.match(text, /JS p50 \d+\.\d\d p95 \d+\.\d\d ms/)
|
||||
assert.match(text, /tokens \d+/)
|
||||
assert.match(text, /tokens visible \d+ \/ total \d+/)
|
||||
assert.match(text, /zoom \d+\.\d\d/)
|
||||
await perf.context.close()
|
||||
} finally {
|
||||
|
||||
@@ -93,7 +93,8 @@ test('first sign-in asks once for a name and shows a taken name', { timeout: 120
|
||||
await waitForVisible(page, '#hud')
|
||||
await waitForVisible(page, '#stage canvas')
|
||||
await waitForText(page, '#me', /^Bob$/)
|
||||
await waitForText(page, '#roster', /Bob/)
|
||||
// The HUD roster lists the other players; this connection's own name is #me.
|
||||
await waitForText(page, '#roster', /GM/)
|
||||
await waitForBadge(page, 'connected')
|
||||
await waitForHidden(page, '#name')
|
||||
|
||||
@@ -188,7 +189,7 @@ test('a killed server under a live player: badge reconnecting, then a full resyn
|
||||
assert.equal(full('encountered')?.full, true, 'the encountered list comes back full')
|
||||
assert.ok(after.some(frame => frame.t === 'token'), 'tokens come back')
|
||||
assert.ok(after.some(frame => frame.t === 'vision'), 'fog/vision comes back')
|
||||
assert.match(await page.textContent('#roster'), /Ann/)
|
||||
assert.match(await page.textContent('#roster'), /GM/)
|
||||
assert.equal(await page.locator('#hud').isVisible(), true)
|
||||
} finally {
|
||||
if (restarted) await stopServer(restarted)
|
||||
@@ -274,7 +275,7 @@ test('two connections of one player are both live and stay in sync', { timeout:
|
||||
assert.equal(renamed.ok, true)
|
||||
gm.ws.close()
|
||||
for (const view of [first, second]) {
|
||||
await waitForText(view.page, '#roster', /Dee Two/)
|
||||
await waitForText(view.page, '#me', /Dee Two/)
|
||||
await waitForBadge(view.page, 'connected')
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -70,17 +70,20 @@ test('GM and player: join -> canvas -> hello and roster; revoked returns to sign
|
||||
await gmView.page.goto(`${origin}/`)
|
||||
await waitForVisible(gmView.page, '#signin')
|
||||
await signIn(gmView.page, gmKey)
|
||||
const gmRoster = await canvasAndRoster(gmView.page, ['GM', 'Alice'])
|
||||
// The HUD names this connection separately and lists the other players (no self row).
|
||||
const gmRoster = await canvasAndRoster(gmView.page, ['Alice'])
|
||||
assert.equal(await gmView.page.textContent('#role'), 'GM')
|
||||
assert.match(gmRoster, /connected/)
|
||||
// Alice has a key but no live connection yet: the other-player row says offline.
|
||||
assert.match(gmRoster, /offline/)
|
||||
|
||||
const playerView = await newPage(browser)
|
||||
await playerView.page.goto(`${origin}/`)
|
||||
await waitForVisible(playerView.page, '#signin')
|
||||
await signIn(playerView.page, player.key)
|
||||
await canvasAndRoster(playerView.page, ['GM', 'Alice'])
|
||||
const playerRoster = await canvasAndRoster(playerView.page, ['GM'])
|
||||
assert.equal(await playerView.page.textContent('#role'), 'Player')
|
||||
assert.equal(await playerView.page.textContent('#me'), 'Alice')
|
||||
assert.match(playerRoster, /connected/)
|
||||
|
||||
// Story 10: the GM replaces the key, the server revokes the session, and the browser stops
|
||||
// at the sign-in door instead of hammering a dead socket.
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
// M4 UX dry-run (issue: GM panel and phone HUD usability). Real stack, real browser:
|
||||
// - a 390x844 phone viewport keeps the HUD inside the screen (no clipped "…Pl…" row) and folds
|
||||
// the player lists to two summary rows, with a capped scroll when opened;
|
||||
// - the GM column puts Walls at the top, selection brings the token editor into view, and every
|
||||
// long section collapses;
|
||||
// - the rendered DOM has no duplicate ids (the old per-row `#gm-token-name` etc.).
|
||||
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { createPlayer, namePlayer, sleep } from '../../tools/lib.mjs'
|
||||
import { openAs } from '../../tools/withserver.mjs'
|
||||
import {
|
||||
launchBrowser,
|
||||
newPage,
|
||||
signIn,
|
||||
waitForText,
|
||||
waitForVisible,
|
||||
withStack,
|
||||
} from './stack.mjs'
|
||||
|
||||
test('M4 UX: phone HUD, collapsible GM column, unique ids', { timeout: 240000 }, async () => {
|
||||
await withStack(async ({ origin, gmKey }) => {
|
||||
const browser = await launchBrowser()
|
||||
const raw = await openAs(origin, gmKey)
|
||||
const hello = await raw.ws.waitText('hello')
|
||||
const scene = hello.scene?.id ?? (await raw.ws.waitText('walls')).scene
|
||||
try {
|
||||
// One named player with a sighted token (so the phone's encountered list has 20+ rows) and
|
||||
// 49 NPCs, the playtest shape that made the column 8k px tall.
|
||||
const alice = await createPlayer(raw.ws)
|
||||
await namePlayer(origin, alice.key, 'Alice')
|
||||
const own = await raw.ws.request({
|
||||
t: 'token.create',
|
||||
scene,
|
||||
kind: 'pc',
|
||||
pos: [960, 540],
|
||||
descriptive_name: 'Alice',
|
||||
actual_name: 'Alice',
|
||||
controller: alice.id,
|
||||
flags: { vision: true },
|
||||
vision_radius: 5000,
|
||||
radius: 20,
|
||||
})
|
||||
assert.equal(own.ok, true, JSON.stringify(own))
|
||||
for (let i = 0; i < 49; i += 1) {
|
||||
const ack = await raw.ws.request({
|
||||
t: 'token.create',
|
||||
scene,
|
||||
kind: 'npc',
|
||||
pos: [120 + (i % 7) * 240, 120 + Math.floor(i / 7) * 120],
|
||||
descriptive_name: `T${i}`,
|
||||
actual_name: `T${i}`,
|
||||
})
|
||||
assert.equal(ack.ok, true, JSON.stringify(ack))
|
||||
}
|
||||
|
||||
// ---- phone -----------------------------------------------------------------------------
|
||||
const phoneContext = await browser.newContext({
|
||||
ignoreHTTPSErrors: true,
|
||||
viewport: { width: 390, height: 844 },
|
||||
})
|
||||
const phone = await phoneContext.newPage()
|
||||
await phone.goto(`${origin}/`)
|
||||
await waitForVisible(phone, '#signin')
|
||||
await signIn(phone, alice.key)
|
||||
await waitForVisible(phone, '#hud')
|
||||
await waitForText(phone, '#me', /^Alice$/)
|
||||
await phone.waitForFunction(() => document.querySelectorAll('#encountered li').length > 20, null, {
|
||||
timeout: 20000,
|
||||
})
|
||||
|
||||
const hud = await phone.evaluate(() => {
|
||||
const node = document.querySelector('#hud')
|
||||
const rect = node.getBoundingClientRect()
|
||||
return {
|
||||
left: rect.left,
|
||||
right: rect.right,
|
||||
width: rect.width,
|
||||
scrollWidth: node.scrollWidth,
|
||||
clientWidth: node.clientWidth,
|
||||
innerWidth: window.innerWidth,
|
||||
children: [...node.children].map(child => {
|
||||
const r = child.getBoundingClientRect()
|
||||
return { id: child.id, left: r.left, right: r.right, height: r.height }
|
||||
}),
|
||||
}
|
||||
})
|
||||
assert.equal(hud.left, 0, 'the HUD starts at the left edge')
|
||||
assert.ok(hud.right <= hud.innerWidth + 0.5, `the HUD ends inside the screen: ${JSON.stringify(hud)}`)
|
||||
assert.ok(
|
||||
hud.scrollWidth <= hud.clientWidth + 1,
|
||||
`the HUD scrolls horizontally (clipped text): ${JSON.stringify(hud)}`,
|
||||
)
|
||||
for (const child of hud.children) {
|
||||
if (child.height === 0) continue // a hidden span (e.g. #me when the name equals the role)
|
||||
assert.ok(child.left >= 0, `${child.id} starts inside the screen`)
|
||||
assert.ok(child.right <= hud.innerWidth + 0.5, `${child.id} ends inside the screen: ${JSON.stringify(child)}`)
|
||||
}
|
||||
|
||||
const folded = await phone.evaluate(() => ({
|
||||
characters: document.querySelector('#characters-panel')?.open,
|
||||
encountered: document.querySelector('#encountered-panel')?.open,
|
||||
}))
|
||||
assert.equal(folded.characters, false, 'My characters starts folded on a phone')
|
||||
assert.equal(folded.encountered, false, 'Encountered starts folded on a phone')
|
||||
await phone.click('#encountered-panel > summary')
|
||||
const cap = await phone.evaluate(() => {
|
||||
const list = document.querySelector('#encountered')
|
||||
const style = getComputedStyle(list)
|
||||
return {
|
||||
maxHeight: style.maxHeight,
|
||||
overflowY: style.overflowY,
|
||||
height: list.getBoundingClientRect().height,
|
||||
}
|
||||
})
|
||||
assert.equal(cap.overflowY, 'auto', 'an opened list scrolls on its own')
|
||||
assert.ok(parseFloat(cap.maxHeight) > 0 && parseFloat(cap.maxHeight) <= 300, `capped: ${cap.maxHeight}`)
|
||||
assert.ok(cap.height <= parseFloat(cap.maxHeight) + 1, `the list is capped: ${JSON.stringify(cap)}`)
|
||||
|
||||
// ---- GM --------------------------------------------------------------------------------
|
||||
const gmView = await newPage(browser)
|
||||
const gm = gmView.page
|
||||
await gm.goto(`${origin}/`)
|
||||
await waitForVisible(gm, '#signin')
|
||||
await signIn(gm, gmKey)
|
||||
await waitForVisible(gm, '#gm-panels')
|
||||
await waitForVisible(gm, '#gm-walls')
|
||||
await waitForText(gm, '#gm-token-list-section > summary', /Tokens/)
|
||||
|
||||
// Walls are the first block in the column (reachable without scrolling past the lists).
|
||||
const wallsTop = await gm.evaluate(() => {
|
||||
const wall = document.querySelector('#gm-walls').getBoundingClientRect()
|
||||
const panel = document.querySelector('#panels').getBoundingClientRect()
|
||||
return { wall: wall.top, panel: panel.top, viewport: window.innerHeight }
|
||||
})
|
||||
assert.ok(wallsTop.wall < wallsTop.panel + 40, `Walls is at the top: ${JSON.stringify(wallsTop)}`)
|
||||
assert.ok(wallsTop.wall < wallsTop.viewport / 2, `Walls is on the first screen: ${JSON.stringify(wallsTop)}`)
|
||||
|
||||
// Selecting a token (from the folded list) brings its editor into view.
|
||||
await gm.click('#gm-token-list-section > summary')
|
||||
const first = gm.locator('#gm-token-list li[data-token]').first()
|
||||
const tokenId = await first.getAttribute('data-token')
|
||||
await gm.click(`#gm-token-select-${tokenId}`)
|
||||
await waitForVisible(gm, '#gm-token-editor')
|
||||
const editor = await gm.evaluate(() => {
|
||||
const node = document.querySelector('#gm-token-editor')
|
||||
const rect = node.getBoundingClientRect()
|
||||
return { top: rect.top, bottom: rect.bottom, viewport: window.innerHeight }
|
||||
})
|
||||
assert.ok(editor.top >= 0, `the selected token editor starts on screen: ${JSON.stringify(editor)}`)
|
||||
assert.ok(
|
||||
editor.bottom <= editor.viewport + 0.5,
|
||||
`the selected token editor fits on one screen: ${JSON.stringify(editor)}`,
|
||||
)
|
||||
|
||||
// Sections collapse: closing the token list hides its rows.
|
||||
await gm.click('#gm-token-list-section > summary')
|
||||
assert.equal(await gm.locator('#gm-token-list').isVisible(), false, 'the token list collapsed')
|
||||
|
||||
// ---- ids -------------------------------------------------------------------------------
|
||||
const duplicates = await gm.evaluate(() => {
|
||||
const seen = new Set()
|
||||
const repeated = new Set()
|
||||
for (const node of document.querySelectorAll('[id]')) {
|
||||
if (seen.has(node.id)) repeated.add(node.id)
|
||||
seen.add(node.id)
|
||||
}
|
||||
return [...repeated]
|
||||
})
|
||||
assert.deepEqual(duplicates, [], `duplicate DOM ids: ${duplicates.join(', ')}`)
|
||||
|
||||
await sleep(50)
|
||||
await phoneContext.close()
|
||||
await gmView.context.close()
|
||||
} finally {
|
||||
raw.ws.close()
|
||||
await browser.close()
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user