76 lines
3.2 KiB
JavaScript
76 lines
3.2 KiB
JavaScript
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));
|
|
}
|