Files
Homelab-manager/server/test/mobile.test.ts
T
bobbanandClaude Sonnet 5.5 5750350565 Mobile pass: a top bar that stays put, a menu that scrolls, room for notches
On phones the top bar is now sticky and compact with a 44 px menu button, an
open menu scrolls by itself with finger-sized rows, the page asks for the whole
screen (viewport-fit=cover) and keeps toasts, drawers and the bar clear of the
notch and home bar, text is slightly larger on small screens, toasts and
drawers use the full width, and presses do not wait for a second tap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 22:18:59 +01:00

61 lines
3.5 KiB
TypeScript

/**
* What the phone layout depends on, read from the page and its style sheet: the page asks for the whole screen (so the notch and the home bar can be left clear), the top bar stays put and has a
* menu button that can be hit, an open menu scrolls by itself, and the rows in it are finger-sized.
*
* Run with: npm test --workspace server
*/
import { test, describe } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const web = (...p: string[]) => readFileSync(new URL(`../../web/${p.join("/")}`, import.meta.url), "utf8");
const html = web("index.html");
const css = web("src", "styles.css");
/** The body of the first rule block that starts with `selector` inside the narrowest "phone" media query we wrote last. */
const phoneBlock = css.slice(css.lastIndexOf("@media (max-width: 991.98px) {\n .navbar-vertical {"));
describe("the page asks for the whole screen and the app leaves room", () => {
test("viewport-fit=cover, and a status bar that sits over the app (which keeps clear of it)", () => {
assert.match(html, /<meta name="viewport" content="[^"]*viewport-fit=cover/);
assert.match(html, /apple-mobile-web-app-status-bar-style" content="black-translucent"/);
});
test("the top bar, the toasts and the drawers keep clear of the notch and the home bar", () => {
for (const rule of [/padding-top: env\(safe-area-inset-top\)/, /padding-bottom: env\(safe-area-inset-bottom\)/, /bottom: calc\(1rem \+ env\(safe-area-inset-bottom\)\)/, /padding-left: env\(safe-area-inset-left\)/]) assert.match(css, rule);
});
});
describe("the top bar and the menu on a phone", () => {
test("the bar stays at the top of the screen (the menu was out of reach after scrolling) and sits above the page", () => {
assert.ok(phoneBlock.startsWith("@media (max-width: 991.98px)"), "the phone block is there");
assert.match(phoneBlock, /\.navbar-vertical \{\s*position: sticky;\s*top: 0;\s*z-index: 1030;/);
});
test("the menu button is at least 44 px, and the rows in the menu are finger-sized", () => {
assert.match(phoneBlock, /\.navbar-toggler \{[^}]*width: 2\.75rem;\s*height: 2\.75rem;/);
assert.match(phoneBlock, /\.nav-link,\s*\.navbar-vertical \.dropdown-item \{\s*min-height: 2\.75rem;/);
assert.match(phoneBlock, /\.fav-star \{\s*width: 2\.5rem;\s*height: 2\.5rem;/);
});
test("an open menu is as tall as the screen at most and scrolls by itself without passing the scroll on to the page", () => {
assert.match(phoneBlock, /\.navbar-collapse\.show[^{]*\{[^}]*max-height: calc\(100dvh - 4\.5rem - env\(safe-area-inset-top\)\);[^}]*overflow-y: auto;[^}]*overscroll-behavior: contain;/);
});
});
describe("small screens and touch", () => {
test("a little larger text on a small screen, toasts across the width, drawers the full width", () => {
assert.match(css, /@media \(max-width: 575\.98px\) \{\s*\/\*[^*]*\*\/\s*body \{\s*--tblr-body-font-size: 0\.9375rem;/);
assert.match(css, /\.toast-stack \{\s*left: calc\(1rem \+ env\(safe-area-inset-left\)\);\s*width: auto;/);
assert.match(css, /\.detail-drawer \{\s*width: 100vw;/);
});
test("what is pressed does not wait for a second tap", () => {
assert.match(css, /a,\s*button,\s*summary,\s*label,\s*select,\s*\[role="button"\],\s*\[role="tab"\] \{\s*touch-action: manipulation;/);
});
test("the small buttons and fields keep their finger size", () => {
assert.match(css, /\.btn\.btn-sm:not\(\.btn-link\):not\(\.btn-icon\),\s*\.form-select-sm,\s*\.form-control-sm \{\s*min-height: 2\.5rem;/);
});
});