181 lines
7.8 KiB
JavaScript
181 lines
7.8 KiB
JavaScript
// 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()
|
|
}
|
|
})
|
|
})
|