Allow scrolling past the game board to view the colony
This commit is contained in:
parent
f45b2107ee
commit
914c057f00
4 changed files with 82 additions and 2 deletions
|
|
@ -21,7 +21,7 @@
|
|||
"preview:tutorial": "node tests/tutorial-preview.mjs",
|
||||
"test:locales": "node scripts/check-locales.mjs packages/viewer/src/localization && node --test scripts/localization.test.mjs",
|
||||
"test:locales:browser": "node tests/localization-browser.mjs",
|
||||
"test:scroll": "node tests/mobile-scroll.mjs",
|
||||
"test:scroll": "node tests/mobile-scroll.mjs && node tests/scenic-scroll.mjs",
|
||||
"test:bulk": "node tests/bulk-purchase-browser.mjs",
|
||||
"test:undo": "node tests/undo-browser.mjs"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "outpost-viewer",
|
||||
"version": "0.1.30",
|
||||
"version": "0.1.31",
|
||||
"description": "Browser viewer for the Outpost game on boardgamers.space",
|
||||
"license": "AGPL-3.0",
|
||||
"files": [
|
||||
|
|
|
|||
|
|
@ -59,11 +59,15 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="scenic-overlook" aria-hidden="true"></div>
|
||||
{:else}
|
||||
<div class="loading">Waiting for game state…</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.scenic-overlook {
|
||||
height: 1100px;
|
||||
}
|
||||
.board {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
|
|
|
|||
76
tests/scenic-scroll.mjs
Normal file
76
tests/scenic-scroll.mjs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { chromium } from "playwright";
|
||||
import { initGame } from "../packages/engine/dist/index.js";
|
||||
import { stripSecret } from "../packages/engine/dist/wrapper.js";
|
||||
import { previewServer } from "./tutorial-preview.mjs";
|
||||
|
||||
const server = previewServer();
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
const browser = await chromium.launch({ executablePath: process.env.OUTPOST_CHROMIUM_EXECUTABLE });
|
||||
try {
|
||||
for (const viewport of [
|
||||
{ width: 390, height: 844 },
|
||||
{ width: 1400, height: 950 },
|
||||
]) {
|
||||
for (const embedded of [false, true]) {
|
||||
const page = await browser.newPage({ viewport });
|
||||
const errors = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
const markup =
|
||||
'<!doctype html><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div>';
|
||||
let frame = page;
|
||||
if (embedded) {
|
||||
await page.setContent(
|
||||
"<!doctype html><style>body{margin:0}iframe{display:block;width:100%;border:0}</style><iframe></iframe>"
|
||||
);
|
||||
frame = page.frames()[1];
|
||||
await frame.setContent(markup);
|
||||
} else {
|
||||
await page.setContent(markup);
|
||||
}
|
||||
await frame.addStyleTag({ path: "packages/viewer/dist/outpost-viewer.css" });
|
||||
await frame.addScriptTag({ url: `http://127.0.0.1:${server.address().port}/bundle.js` });
|
||||
const state = initGame(3, {}, "scenic-scroll");
|
||||
await frame.evaluate(
|
||||
(state) => {
|
||||
window.emitter = outpost.launch("#app");
|
||||
emitter.emit("player", { index: 0 });
|
||||
emitter.emit("state", state);
|
||||
},
|
||||
stripSecret(state, 0)
|
||||
);
|
||||
await frame.locator(".scenic-overlook").waitFor();
|
||||
if (embedded) {
|
||||
await frame.evaluate(() => {
|
||||
const resize = () => {
|
||||
window.frameElement.style.height = `${document.body.scrollHeight}px`;
|
||||
};
|
||||
new ResizeObserver(resize).observe(document.body);
|
||||
resize();
|
||||
});
|
||||
}
|
||||
await page.waitForTimeout(200);
|
||||
const initial = await frame.evaluate(() => document.body.scrollHeight);
|
||||
await page.waitForTimeout(200);
|
||||
assert.equal(await frame.evaluate(() => document.body.scrollHeight), initial, "iframe sizing stays stable");
|
||||
assert.ok(initial >= (await frame.locator(".board").evaluate((el) => el.offsetHeight)) + 1100);
|
||||
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
||||
await page.waitForTimeout(100);
|
||||
const board = await frame.locator(".board").boundingBox();
|
||||
const moon = await frame.locator(".moon").boundingBox();
|
||||
assert.ok(board && board.y + board.height < 0, "the entire game UI scrolls out of view");
|
||||
assert.ok(moon && moon.y + moon.height > viewport.height - 2, "the moon stays at the bottom");
|
||||
assert.ok(moon && moon.y < viewport.height - 50, "buildings remain visible on the surface");
|
||||
assert.ok((await frame.locator(".moon .bldg").count()) > 0, "the surface contains game buildings");
|
||||
assert.equal(await frame.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
"Scenic scrolling clears the UI and leaves the moon visible on mobile and desktop, standalone and embedded."
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue