@jskit-ai/shell-web 0.2.56 → 0.2.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,8 +62,10 @@ function contrastRatio(foreground, background) {
62
62
  return (lighter + 0.05) / (darker + 0.05);
63
63
  }
64
64
 
65
- // The computed colour of a theme role, read from a probe painted with it.
65
+ // The computed colour of a theme role, read from a probe painted with it once the app has mounted: the fixture,
66
+ // like an app, mounts after its boot request, so its page can load first.
66
67
  async function readRoleColor(page, role) {
68
+ await page.locator(".v-application").waitFor({ state: "attached" });
67
69
  return page.evaluate((name) => {
68
70
  const probe = document.createElement("div");
69
71
  probe.style.background = `rgb(var(--v-theme-${name}))`;
@@ -74,6 +76,20 @@ async function readRoleColor(page, role) {
74
76
  }, role);
75
77
  }
76
78
 
79
+ // Holds the fixture's boot request, the one its main.js awaits before it mounts, until the returned function is
80
+ // called: the page has loaded and the app is not there yet, as an app's page loads before its bootstrap answers.
81
+ async function holdFixtureBoot(page) {
82
+ let release;
83
+ const released = new Promise((resolve) => {
84
+ release = resolve;
85
+ });
86
+ await page.route("**/api/fixture/boot", async (route) => {
87
+ await released;
88
+ await route.continue().catch(() => undefined);
89
+ });
90
+ return release;
91
+ }
92
+
77
93
  function symbolPath(alias) {
78
94
  return materialSymbols[alias].slice("svg:".length);
79
95
  }
@@ -1429,6 +1445,160 @@ test("page actions carry their attributes in every form, collapse into the overf
1429
1445
  }
1430
1446
  });
1431
1447
 
1448
+ // The long actions page's labelled actions, in bar order, and the two its overflow menu holds after them.
1449
+ const LONG_ACTIONS = Object.freeze([
1450
+ "fixture-long-action-size",
1451
+ "fixture-long-action-restart",
1452
+ "fixture-long-action-restore",
1453
+ "fixture-long-action-tags"
1454
+ ]);
1455
+ const LONG_MENU_ONLY = Object.freeze(["fixture-long-action-delete", "fixture-long-action-tooling"]);
1456
+ // A title as wide as two of the long actions page's actions at 1280 px: an expanded bar folds some of them, not all.
1457
+ const LONG_TITLE = "Nightly backups for the billing database";
1458
+
1459
+ // The top app bar as drawn, ShellLayout's or a layout's own: whether the row that holds the page actions overflows,
1460
+ // which long actions it shows, each item a person must reach (More actions and the bar's own items, by their names)
1461
+ // that lies outside the window or under something else at its centre, whether the title is clipped, the room left
1462
+ // beside the title's text in its box, and each shown action's width with its margins.
1463
+ function readLongActionsBar(page) {
1464
+ return page.evaluate(() => {
1465
+ const row = document.querySelector(".shell-page-actions-target").parentElement;
1466
+ const title = document.getElementById("jskit-shell-page-title");
1467
+ const titleBox = [...row.children].find((child) => child.contains(title));
1468
+ const more = row.querySelector("[data-testid=jskit-shell-page-actions-overflow]");
1469
+ const reachable = (element) => {
1470
+ const box = element.getBoundingClientRect();
1471
+ const hit = document.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2);
1472
+ return box.left >= 0 && box.right <= window.innerWidth && Boolean(hit && element.contains(hit));
1473
+ };
1474
+ const style = window.getComputedStyle(titleBox);
1475
+ const text = document.createRange();
1476
+ text.selectNodeContents(title);
1477
+ const actions = [...row.querySelectorAll("[data-testid^=fixture-long-action]")];
1478
+ return {
1479
+ overflows: row.scrollWidth > row.clientWidth,
1480
+ inBar: actions.map((element) => element.dataset.testid),
1481
+ unreachable: [
1482
+ more ? null : "More actions (not drawn)",
1483
+ ...[more, ...row.querySelectorAll("[data-testid=fixture-status], [data-testid=fixture-workspace-control]")]
1484
+ .filter((element) => element && !reachable(element))
1485
+ .map((element) => element.getAttribute("aria-label") || element.textContent.trim())
1486
+ ].filter(Boolean),
1487
+ titleClipped: title.scrollWidth > title.clientWidth + 1,
1488
+ slack: titleBox.clientWidth - Number.parseFloat(style.paddingInlineStart) -
1489
+ Number.parseFloat(style.paddingInlineEnd) - text.getBoundingClientRect().width,
1490
+ widths: Object.fromEntries(actions.map((element) => {
1491
+ const margins = window.getComputedStyle(element);
1492
+ return [element.dataset.testid, element.getBoundingClientRect().width +
1493
+ Number.parseFloat(margins.marginInlineStart) + Number.parseFloat(margins.marginInlineEnd)];
1494
+ }))
1495
+ };
1496
+ });
1497
+ }
1498
+
1499
+ // The long actions page's More actions menu, opened and closed again: its items' data-testids, in order.
1500
+ async function readLongActionsMenu(page) {
1501
+ await page.getByTestId("jskit-shell-page-actions-overflow").click();
1502
+ const menu = page.getByRole("menu");
1503
+ await expect(menu).toBeVisible();
1504
+ const items = await menu.getByRole("menuitem").evaluateAll((elements) => elements.map((element) => element.dataset.testid));
1505
+ await page.keyboard.press("Escape");
1506
+ await expect(menu).toBeHidden();
1507
+ return items;
1508
+ }
1509
+
1510
+ // What a bar that folds its actions by width shows: nothing past the bar, every item a person must reach on screen and
1511
+ // on top, the title whole; the first actions in bar order inline and the rest in More actions before the menu's own,
1512
+ // as few folded as leave the title whole, so the room left beside the title is less than the first folded action
1513
+ // needs, give or take the pixel the bar rounds the title up to. Returns the folded actions.
1514
+ async function foldedByWidth(page, { bar, widths, at }) {
1515
+ assert.deepEqual({ overflows: bar.overflows, unreachable: bar.unreachable, titleClipped: bar.titleClipped }, {
1516
+ overflows: false,
1517
+ unreachable: [],
1518
+ titleClipped: false
1519
+ }, at);
1520
+ const folded = LONG_ACTIONS.slice(bar.inBar.length);
1521
+ assert.deepEqual(bar.inBar, LONG_ACTIONS.slice(0, bar.inBar.length), `${at}: the bar keeps the first actions`);
1522
+ assert.deepEqual(await readLongActionsMenu(page), [...folded, ...LONG_MENU_ONLY], `${at}: More actions holds the rest, in bar order`);
1523
+ if (folded.length > 0) {
1524
+ assert.ok(bar.slack < widths[folded[0]] + 1, `${at}: ${folded[0]} (${widths[folded[0]]}px) folded with ${bar.slack}px left`);
1525
+ }
1526
+ return folded;
1527
+ }
1528
+
1529
+ // A long action in the bar, not its item in More actions, which a menu that keeps its content mounted has too.
1530
+ function barAction(page, testId) {
1531
+ return page.locator(".shell-page-actions-target").getByTestId(testId);
1532
+ }
1533
+
1534
+ // The long actions page at `path`, opened at 1280 px for each action's width in a bar that shows them all, then the
1535
+ // same page at 768 px: it folds some actions and keeps others, and a folded one runs from the menu; at 1280 px again
1536
+ // every action is back in the bar, and at 768 px the same ones fold again.
1537
+ async function checkMediumFold(browser, t, { baseURL, path }) {
1538
+ const wide = await browser.newPage({ baseURL, viewport: { width: 1280, height: 900 } });
1539
+ t.after(() => wide.close());
1540
+ await wide.goto(path);
1541
+ await expect(barAction(wide, "fixture-long-action-tags")).toBeVisible();
1542
+ const { widths, inBar } = await readLongActionsBar(wide);
1543
+ assert.deepEqual(inBar, LONG_ACTIONS, `${path} at 1280px shows every action`);
1544
+
1545
+ const page = await browser.newPage({ baseURL, viewport: { width: 768, height: 1024 } });
1546
+ t.after(() => page.close());
1547
+ await page.goto(path);
1548
+ await expect(page.getByTestId("jskit-shell-page-title")).toHaveText("Hosted service");
1549
+ await expect(barAction(page, "fixture-long-action-size")).toBeVisible();
1550
+ const bar = await readLongActionsBar(page);
1551
+ const folded = await foldedByWidth(page, { bar, widths, at: `${path} at 768px` });
1552
+ assert.ok(folded.length > 0 && bar.inBar.length > 0, `${path} at 768px: some actions fold and some stay (${bar.inBar.join(", ")})`);
1553
+
1554
+ await page.getByTestId("jskit-shell-page-actions-overflow").click();
1555
+ await page.getByRole("menu").getByTestId(folded[0]).click();
1556
+ await expect(page.getByTestId("fixture-action-log")).toHaveText(folded[0].replace("fixture-long-action-", ""));
1557
+
1558
+ await page.setViewportSize({ width: 1280, height: 900 });
1559
+ await expect(barAction(page, "fixture-long-action-tags")).toBeVisible();
1560
+ assert.deepEqual(await foldedByWidth(page, { bar: await readLongActionsBar(page), widths, at: `${path} widened to 1280px` }), []);
1561
+ await page.setViewportSize({ width: 768, height: 1024 });
1562
+ await expect(barAction(page, folded[0])).toHaveCount(0);
1563
+ assert.deepEqual(await foldedByWidth(page, { bar: await readLongActionsBar(page), widths, at: `${path} at 768px again` }), folded);
1564
+ }
1565
+
1566
+ test("a medium window's bar folds the page actions it has no room for into More actions, and More actions and the bar's own items stay on screen and reachable", {
1567
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1568
+ timeout: 90_000
1569
+ }, async (t) => {
1570
+ const { vite, browser } = await startFixture(t);
1571
+ await checkMediumFold(browser, t, { baseURL: vite.baseURL, path: "/home/long-actions?topRight=3" });
1572
+ });
1573
+
1574
+ test("a layout's own top app bar folds the page actions it has no room for the same way, and keeps its own controls on screen", {
1575
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1576
+ timeout: 90_000
1577
+ }, async (t) => {
1578
+ const { vite, browser } = await startFixture(t);
1579
+ await checkMediumFold(browser, t, { baseURL: vite.baseURL, path: "/home/studio-actions" });
1580
+ });
1581
+
1582
+ test("an expanded window's bar keeps every page action that fits beside the title, and a long title folds only those that don't", {
1583
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1584
+ timeout: 90_000
1585
+ }, async (t) => {
1586
+ const { vite, browser } = await startFixture(t);
1587
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 900 } });
1588
+ t.after(() => page.close());
1589
+
1590
+ await page.goto("/home/long-actions?topRight=3");
1591
+ await expect(barAction(page, "fixture-long-action-tags")).toBeVisible();
1592
+ const ordinary = await readLongActionsBar(page);
1593
+ assert.deepEqual(await foldedByWidth(page, { bar: ordinary, widths: ordinary.widths, at: "1280px" }), []);
1594
+
1595
+ await page.goto(`/home/long-actions?topRight=3&title=${encodeURIComponent(LONG_TITLE)}`);
1596
+ await expect(page.getByTestId("jskit-shell-page-title")).toHaveText(LONG_TITLE);
1597
+ const long = await readLongActionsBar(page);
1598
+ const folded = await foldedByWidth(page, { bar: long, widths: ordinary.widths, at: "1280px, a long title" });
1599
+ assert.ok(folded.length > 0 && long.inBar.length > 0, `1280px, a long title: some actions fold and some stay (${long.inBar.join(", ")})`);
1600
+ });
1601
+
1432
1602
  test("a nested component's title gives the page's own title back, and Save returns to the list with its query", {
1433
1603
  skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1434
1604
  timeout: 90_000
@@ -1738,11 +1908,19 @@ test("an app's colours win over the navigation bar's, and a denser bar, a badge
1738
1908
  }, async (t) => {
1739
1909
  const { vite, browser } = await startFixture(t);
1740
1910
  const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
1911
+ const releaseBoot = await holdFixtureBoot(page);
1741
1912
  await page.goto("/home/components");
1913
+ // The page has loaded and the app waits on its boot request, so the colours are read from an app that mounts
1914
+ // only after the reads begin.
1915
+ assert.equal(await page.locator(".v-application").count(), 0);
1742
1916
  const roles = {};
1743
- for (const role of ["primary", "on-primary", "secondary-container", "on-surface-variant"]) {
1744
- roles[role] = await readRoleColor(page, role);
1745
- }
1917
+ const reading = (async () => {
1918
+ for (const role of ["primary", "on-primary", "secondary-container", "on-surface-variant"]) {
1919
+ roles[role] = await readRoleColor(page, role);
1920
+ }
1921
+ })();
1922
+ releaseBoot();
1923
+ await reading;
1746
1924
  const transparent = "rgba(0, 0, 0, 0)";
1747
1925
  const read = (testId) => page.getByTestId(testId).evaluate((button) => {
1748
1926
  const style = (node) => window.getComputedStyle(node);
@@ -0,0 +1,424 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
6
+ import { expect } from "@playwright/test";
7
+ import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
8
+
9
+ // A page's navigation can depend on context an application loads after the page opens, such as the permissions of a
10
+ // session of its own (mobilynet's console merges its staff permissions once its console session arrives). ShellLayout
11
+ // drew the drawer, the rail, the navigation bar and the app bar's menu control only when they arrived, so what a person
12
+ // was reaching for moved under the pointer as the page opened: mobilynet's Builds tab jumped from about x=69 to x=430
13
+ // in the middle of a click, and the click landed in the drawer. The fixture's console page (App.vue) loads its
14
+ // session's permissions after it opens; each case holds that response, so they arrive late on purpose, records where
15
+ // each target is first seen, lets the response go, clicks at once where the target was first seen, and checks that
16
+ // nothing moved once seen and that the click reached the target.
17
+ const SKIP = process.env.JSKIT_SHELL_WEB_BROWSER_INTEGRATION === "1"
18
+ ? false
19
+ : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1 to check the shell's navigation never moves the page under a person's pointer";
20
+ const FIXTURE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../fixtures/adaptive-shell");
21
+ const open = sharedBrowserFixture({ fixtureRoot: FIXTURE_ROOT, configFile: "vite.config.mjs" });
22
+ const EXPANDED = Object.freeze({ width: 1280, height: 900 });
23
+ const MEDIUM = Object.freeze({ width: 768, height: 1024 });
24
+ const COMPACT = Object.freeze({ width: 390, height: 844 });
25
+ const ALL_PERMISSIONS = Object.freeze(["builds.read", "machines.read", "alerts.read"]);
26
+ // The files of Roboto Flex, the typeface material.css gives the page (font-display: swap): the drawer fits its labels
27
+ // in it.
28
+ const ROBOTO_FLEX_FILES = "**/roboto-flex-*.woff2";
29
+ // How long the font cases hold Roboto Flex: as a slow connection would.
30
+ const SLOW_FONT_MS = 3_000;
31
+ const TARGETS = Object.freeze({
32
+ builds: "[data-testid='fixture-console-builds']",
33
+ newBuild: "[data-testid='fixture-console-new-build'] .v-btn",
34
+ title: "[data-testid='jskit-shell-page-title']",
35
+ validate: "button[type='submit']"
36
+ });
37
+
38
+ // Runs in the page before the app: at every frame, where each target is (rounded to the pixel) while a person can see
39
+ // it, its first such place (with when, by the page's clock) and its latest; and what each click landed on. A click on anything but a target stops
40
+ // there, so a missed click changes nothing on the page.
41
+ function watchPlaces(targets) {
42
+ const first = {};
43
+ const last = {};
44
+ const hits = [];
45
+ function placeOf(element) {
46
+ if (!element?.checkVisibility({ opacityProperty: true, visibilityProperty: true })) {
47
+ return null;
48
+ }
49
+ const box = element.getBoundingClientRect();
50
+ if (box.width <= 0 || box.height <= 0) {
51
+ return null;
52
+ }
53
+ return { x: Math.round(box.x), y: Math.round(box.y), width: Math.round(box.width), height: Math.round(box.height) };
54
+ }
55
+ function sample() {
56
+ for (const [name, selector] of Object.entries(targets)) {
57
+ const place = placeOf(document.querySelector(selector));
58
+ if (place) {
59
+ first[name] ??= { ...place, at: performance.now() };
60
+ last[name] = place;
61
+ }
62
+ }
63
+ requestAnimationFrame(sample);
64
+ }
65
+ requestAnimationFrame(sample);
66
+ window.addEventListener("click", (event) => {
67
+ const element = event.target instanceof Element ? event.target : null;
68
+ const target = Object.keys(targets).find((name) => element?.closest(targets[name]));
69
+ if (target) {
70
+ hits.push(target);
71
+ return;
72
+ }
73
+ const part = element?.closest("[data-testid]")?.getAttribute("data-testid") || element?.tagName || "nothing";
74
+ const control = element?.closest("a, button")?.textContent.trim();
75
+ hits.push(control ? `${part} (${control})` : part);
76
+ event.preventDefault();
77
+ event.stopImmediatePropagation();
78
+ }, true);
79
+ globalThis.__shellPlaces = { first, last, hits };
80
+ }
81
+
82
+ async function frames(page, count) {
83
+ await page.evaluate((remaining) => new Promise((resolve) => {
84
+ const step = () => (--remaining <= 0 ? resolve() : requestAnimationFrame(step));
85
+ requestAnimationFrame(step);
86
+ }), count);
87
+ }
88
+
89
+ const places = (page) => page.evaluate(() => globalThis.__shellPlaces);
90
+
91
+ // Opens `url` with the console session's response held until `release()`, which answers it with `permissions` once the
92
+ // page's fonts are in, as they usually are by then: so these cases are about the session, and the font cases below about
93
+ // the font.
94
+ async function openHeld(t, { viewport, url = "/console/builds", targets, permissions = ALL_PERMISSIONS }) {
95
+ const { vite, browser } = await open(t);
96
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport });
97
+ await page.addInitScript(watchPlaces, Object.fromEntries(targets.map((name) => [name, TARGETS[name]])));
98
+ let release = () => {};
99
+ const held = new Promise((resolve) => {
100
+ release = resolve;
101
+ });
102
+ let asked = () => {};
103
+ const sessionAsked = new Promise((resolve) => {
104
+ asked = resolve;
105
+ });
106
+ await page.route("**/api/fixture/console-session", async (route) => {
107
+ asked();
108
+ await held;
109
+ await route.fulfill({ json: { permissions } });
110
+ });
111
+ await page.goto(url);
112
+ await sessionAsked;
113
+ await expect(page.getByTestId("fixture-console-builds")).toBeAttached();
114
+ // The page as it is drawn while the session is held, for a few frames.
115
+ await frames(page, 5);
116
+ return {
117
+ page,
118
+ async release() {
119
+ await page.evaluate(() => document.fonts.ready.then(() => true));
120
+ release();
121
+ }
122
+ };
123
+ }
124
+
125
+ // Opens /home at the expanded size, its drawer fitted to its labels, with Roboto Flex held until `releaseFonts()`
126
+ // (`fonts: "held"`) or failed at once (`fonts: "failed"`); either way the page never gets it.
127
+ async function openHome(t, { fonts, targets }) {
128
+ const { vite, browser } = await open(t);
129
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport: EXPANDED });
130
+ await page.addInitScript(watchPlaces, Object.fromEntries(targets.map((name) => [name, TARGETS[name]])));
131
+ let releaseFonts = () => {};
132
+ const held = new Promise((resolve) => {
133
+ releaseFonts = resolve;
134
+ });
135
+ let asked = () => {};
136
+ const fontAsked = new Promise((resolve) => {
137
+ asked = resolve;
138
+ });
139
+ await page.route(ROBOTO_FLEX_FILES, async (route) => {
140
+ asked(Date.now());
141
+ if (fonts === "held") {
142
+ await held;
143
+ }
144
+ await route.abort().catch(() => {});
145
+ });
146
+ // Not waiting for the load event, which a held font may hold too.
147
+ await page.goto("/home", { waitUntil: "domcontentloaded" });
148
+ const fontAskedAt = await fontAsked;
149
+ await expect(page.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-drawer-width-mode", "content");
150
+ return { page, fontAskedAt, releaseFonts };
151
+ }
152
+
153
+ // Clicks at once at the middle of where `name` was first seen, as a person who aimed at it then does; `timeout` is how
154
+ // long it may take to show.
155
+ async function clickWhereFirstSeen(page, name, { timeout } = {}) {
156
+ await expect.poll(async () => Boolean((await places(page)).first[name]), {
157
+ message: `${name} never showed`,
158
+ timeout
159
+ }).toBe(true);
160
+ const place = (await places(page)).first[name];
161
+ const point = { x: place.x + place.width / 2, y: place.y + place.height / 2 };
162
+ await page.mouse.click(point.x, point.y);
163
+ return point;
164
+ }
165
+
166
+ // Waits until nothing on the page animates any more (the layout's slide, a ripple), then a few frames.
167
+ async function settle(page) {
168
+ await page.waitForFunction(() => document.getAnimations().every((animation) => animation.playState !== "running"));
169
+ await frames(page, 5);
170
+ }
171
+
172
+ // Each target is where it was first seen, and the click made where `clicked` first showed reached it.
173
+ async function assertNothingMoved(page, { targets, clicked, point }) {
174
+ const { first, last, hits } = await places(page);
175
+ const problems = [];
176
+ for (const name of targets) {
177
+ if (!first[name]) {
178
+ problems.push(`${name} never showed`);
179
+ continue;
180
+ }
181
+ const [from, to] = [first[name], last[name]];
182
+ if (Math.abs(from.x - to.x) > 1 || Math.abs(from.y - to.y) > 1) {
183
+ problems.push(`${name} moved after it showed, from x=${from.x} y=${from.y} to x=${to.x} y=${to.y}`);
184
+ }
185
+ }
186
+ if (clicked && hits[0] !== clicked) {
187
+ problems.push(
188
+ `the click at x=${Math.round(point.x)} y=${Math.round(point.y)}, where ${clicked} first showed, landed on ` +
189
+ `${hits[0] || "nothing"} instead`
190
+ );
191
+ }
192
+ assert.deepEqual(problems, []);
193
+ }
194
+
195
+ test("expanded window: the drawer a late session brings never moves the content or the title, nor takes their click", {
196
+ skip: SKIP,
197
+ timeout: 90_000
198
+ }, async (t) => {
199
+ const targets = ["builds", "title"];
200
+ const { page, release } = await openHeld(t, { viewport: EXPANDED, targets });
201
+ // Until the session answers, the console has only its Console entry: no drawer, and no destination it may not use.
202
+ await expect(page.getByTestId("jskit-shell-drawer")).toHaveCount(0);
203
+ await expect(page.getByRole("link", { name: "Machines" })).toHaveCount(0);
204
+
205
+ await release();
206
+ await expect(page.getByTestId("jskit-shell-drawer")).toBeAttached();
207
+ const point = await clickWhereFirstSeen(page, "builds");
208
+ await settle(page);
209
+
210
+ await expect(page.getByTestId("jskit-shell-drawer").getByRole("link", { name: "Machines" })).toBeVisible();
211
+ await assertNothingMoved(page, { targets, clicked: "builds", point });
212
+ });
213
+
214
+ test("medium window: the navigation rail a late session brings never moves the content or the title, nor takes their click", {
215
+ skip: SKIP,
216
+ timeout: 90_000
217
+ }, async (t) => {
218
+ const targets = ["builds", "title"];
219
+ const { page, release } = await openHeld(t, { viewport: MEDIUM, targets });
220
+ await expect(page.getByTestId("jskit-shell-rail")).toHaveCount(0);
221
+
222
+ await release();
223
+ await expect(page.getByTestId("jskit-shell-rail")).toBeAttached();
224
+ const point = await clickWhereFirstSeen(page, "builds");
225
+ await settle(page);
226
+
227
+ await expect(page.getByTestId("jskit-shell-rail").getByRole("link", { name: "Machines" })).toBeVisible();
228
+ await assertNothingMoved(page, { targets, clicked: "builds", point });
229
+ });
230
+
231
+ test("compact window: the navigation bar and the app bar's menu control a late session brings never move the FAB, the title or the content, nor take the FAB's click", {
232
+ skip: SKIP,
233
+ timeout: 90_000
234
+ }, async (t) => {
235
+ const targets = ["newBuild", "title", "builds"];
236
+ const { page, release } = await openHeld(t, { viewport: COMPACT, targets });
237
+ await expect(page.getByTestId("jskit-shell-bottom-nav")).toHaveCount(0);
238
+ await expect(page.getByTestId("jskit-shell-nav-toggle")).toHaveCount(0);
239
+
240
+ await release();
241
+ await expect(page.getByTestId("jskit-shell-bottom-nav")).toBeAttached();
242
+ const point = await clickWhereFirstSeen(page, "newBuild");
243
+ await settle(page);
244
+
245
+ await expect(page.getByTestId("jskit-shell-bottom-nav").getByRole("link", { name: "Machines" })).toBeVisible();
246
+ await expect(page.getByTestId("jskit-shell-nav-toggle")).toBeVisible();
247
+ await assertNothingMoved(page, { targets, clicked: "newBuild", point });
248
+ });
249
+
250
+ test("a late session that grants none of the console's destinations leaves the page without navigation, where it showed", {
251
+ skip: SKIP,
252
+ timeout: 90_000
253
+ }, async (t) => {
254
+ const targets = ["builds", "title"];
255
+ const { page, release } = await openHeld(t, { viewport: EXPANDED, targets, permissions: [] });
256
+
257
+ await release();
258
+ const point = await clickWhereFirstSeen(page, "builds");
259
+ await settle(page);
260
+
261
+ await expect(page.getByTestId("jskit-shell-drawer")).toHaveCount(0);
262
+ await expect(page.getByTestId("jskit-shell-nav-toggle")).toHaveCount(0);
263
+ await expect(page.getByRole("link", { name: "Machines" })).toHaveCount(0);
264
+ await assertNothingMoved(page, { targets, clicked: "builds", point });
265
+ });
266
+
267
+ test("the shell's typeface is asked for before the shell mounts, so it is usually in by the time the shell shows", {
268
+ skip: SKIP,
269
+ timeout: 90_000
270
+ }, async (t) => {
271
+ const { vite, browser } = await open(t);
272
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport: EXPANDED });
273
+ const fontRequests = [];
274
+ page.on("request", (request) => {
275
+ if (/roboto-flex-[^/]*\.woff2/u.test(request.url())) {
276
+ fontRequests.push(request);
277
+ }
278
+ });
279
+ await page.goto("/home");
280
+ await expect(page.getByTestId("jskit-shell-drawer")).toBeVisible();
281
+ await page.evaluate(() => document.fonts.ready.then(() => true));
282
+ assert.ok(fontRequests.length > 0, "the page never asked for Roboto Flex");
283
+ const askedAt = Math.min(...await Promise.all(fontRequests.map(async (request) => {
284
+ await request.response();
285
+ return request.timing().startTime;
286
+ })));
287
+ const mount = await page.evaluate(() => ({ ...window.__fixtureMount, at: performance.timeOrigin + window.__fixtureMount.at }));
288
+ t.diagnostic(`Roboto Flex first asked for ${Math.round(askedAt - mount.at)} ms from the shell's mount; its faces then: ${mount.robotoFlex.join(", ")}`);
289
+
290
+ assert.ok(
291
+ mount.robotoFlex.some((status) => status === "loading" || status === "loaded"),
292
+ `no Roboto Flex face was loading as the shell mounted (${mount.robotoFlex.join(", ")})`
293
+ );
294
+ assert.ok(askedAt < mount.at, `Roboto Flex was first asked for ${Math.round(askedAt - mount.at)} ms after the shell mounted`);
295
+ });
296
+
297
+ test("a page whose navigation is ready as it opens shows its content and title where they stay, its drawer fitted", {
298
+ skip: SKIP,
299
+ timeout: 90_000
300
+ }, async (t) => {
301
+ const targets = ["validate", "title"];
302
+ // Roboto Flex is held throughout, so the drawer's fit is what the case checks, whenever the font would come.
303
+ const { page, releaseFonts } = await openHome(t, { fonts: "held", targets });
304
+ try {
305
+ const point = await clickWhereFirstSeen(page, "validate");
306
+ await settle(page);
307
+
308
+ await assertNothingMoved(page, { targets, clicked: "validate", point });
309
+ } finally {
310
+ releaseFonts();
311
+ }
312
+ });
313
+
314
+ test("a page whose typeface is slow shows in the fallback font within the shell's short wait for it, and nothing moves while the font is held", {
315
+ skip: SKIP,
316
+ timeout: 90_000
317
+ }, async (t) => {
318
+ const targets = ["validate", "title"];
319
+ const { page, fontAskedAt, releaseFonts } = await openHome(t, { fonts: "held", targets });
320
+ try {
321
+ // Seen while the font is still held, well within the 3 s a slow connection takes.
322
+ const point = await clickWhereFirstSeen(page, "validate", { timeout: SLOW_FONT_MS - 1_000 });
323
+ const { first } = await places(page);
324
+ const mountedAt = await page.evaluate(() => window.__fixtureMount.at);
325
+ t.diagnostic(`content first seen ${Math.round(first.validate.at - mountedAt)} ms after the shell mounted, Roboto Flex held`);
326
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, fontAskedAt + SLOW_FONT_MS - Date.now())));
327
+ await settle(page);
328
+
329
+ await assertNothingMoved(page, { targets, clicked: "validate", point });
330
+ } finally {
331
+ releaseFonts();
332
+ }
333
+ });
334
+
335
+ test("a page whose typeface fails shows in the fallback font, and nothing moves", {
336
+ skip: SKIP,
337
+ timeout: 90_000
338
+ }, async (t) => {
339
+ const targets = ["validate", "title"];
340
+ const { page } = await openHome(t, { fonts: "failed", targets });
341
+ const point = await clickWhereFirstSeen(page, "validate");
342
+ await settle(page);
343
+
344
+ await assertNothingMoved(page, { targets, clicked: "validate", point });
345
+ });
346
+
347
+ // Runs in the page before the app: the pull-to-refresh indicator and the supporting side panel as the shell first
348
+ // renders in its settle's hold, two parts of the shell that a page shows only later.
349
+ function recordHeldExtras() {
350
+ const observer = new MutationObserver(() => {
351
+ if (!document.querySelector(".shell-layout--waiting")) {
352
+ return;
353
+ }
354
+ const panel = document.querySelector("[data-testid='jskit-shell-supporting-side-panel']");
355
+ globalThis.__heldExtras = {
356
+ pullIndicator: Boolean(document.querySelector("[data-testid='jskit-shell-pull-refresh']")),
357
+ panel: panel ? { inert: panel.inert, left: Math.round(panel.getBoundingClientRect().left), viewport: window.innerWidth } : null
358
+ };
359
+ observer.disconnect();
360
+ });
361
+ observer.observe(document, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
362
+ }
363
+
364
+ async function openSettled(t, viewport) {
365
+ const { vite, browser } = await open(t);
366
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport });
367
+ await page.addInitScript(recordHeldExtras);
368
+ await page.goto("/home");
369
+ await page.waitForFunction(() => document.querySelector("[data-shell-page]") &&
370
+ !document.querySelector(".shell-layout--waiting, .shell-layout--placing"));
371
+ await settle(page);
372
+ return page;
373
+ }
374
+
375
+ // Whether the element with `testId` is shown and on screen: displayed, not transparent, and inside the window.
376
+ const shownOnScreen = (page, testId) => page.getByTestId(testId).evaluate((element) => {
377
+ const box = element.getBoundingClientRect();
378
+ return element.checkVisibility({ opacityProperty: true, visibilityProperty: true }) &&
379
+ box.width > 0 && box.left < window.innerWidth && box.right > 0;
380
+ });
381
+
382
+ test("the supporting side panel, closed and inert as the shell settles, opens over the settled page and its close button takes a click", {
383
+ skip: SKIP,
384
+ timeout: 90_000
385
+ }, async (t) => {
386
+ const page = await openSettled(t, EXPANDED);
387
+ const held = await page.evaluate(() => globalThis.__heldExtras);
388
+ assert.equal(held.panel?.inert, true, `the side panel was not inert as the shell settled: ${JSON.stringify(held)}`);
389
+ assert.ok(held.panel.left >= held.panel.viewport, `the side panel was on screen as the shell settled: ${JSON.stringify(held)}`);
390
+
391
+ await page.evaluate(() => window.__shellFixtureOpenSupportingContent("Build details"));
392
+ await settle(page);
393
+ assert.equal(await shownOnScreen(page, "jskit-shell-supporting-side-panel"), true, "the opened side panel is not shown on screen");
394
+ await expect(page.getByTestId("jskit-shell-supporting-side-panel")).toContainText("Build details");
395
+ const close = page.getByTestId("jskit-shell-supporting-side-panel").getByRole("button", { name: "Close" });
396
+ const box = await close.boundingBox();
397
+ await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
398
+ await settle(page);
399
+ assert.equal(await shownOnScreen(page, "jskit-shell-supporting-side-panel"), false, "the side panel's close button did not close it");
400
+ });
401
+
402
+ test("the pull-to-refresh indicator, absent as the shell settles, shows over the settled page and its pull refreshes it", {
403
+ skip: SKIP,
404
+ timeout: 90_000
405
+ }, async (t) => {
406
+ const page = await openSettled(t, COMPACT);
407
+ const held = await page.evaluate(() => globalThis.__heldExtras);
408
+ assert.equal(held.pullIndicator, false, `the pull-to-refresh indicator was on the page as the shell settled: ${JSON.stringify(held)}`);
409
+ let refreshes = 0;
410
+ page.on("request", (request) => {
411
+ if (request.url().includes("/api/bootstrap?reason=pull-to-refresh")) {
412
+ refreshes += 1;
413
+ }
414
+ });
415
+
416
+ const touch = { pointerId: 41, pointerType: "touch", isPrimary: true, button: 0 };
417
+ await page.dispatchEvent("body", "pointerdown", { ...touch, clientX: 180, clientY: 90 });
418
+ await page.dispatchEvent("body", "pointermove", { ...touch, clientX: 184, clientY: 250 });
419
+ await expect.poll(() => shownOnScreen(page, "jskit-shell-pull-refresh"), {
420
+ message: "the pull-to-refresh indicator is not shown while the page is pulled"
421
+ }).toBe(true);
422
+ await page.dispatchEvent("body", "pointerup", { ...touch, clientX: 184, clientY: 250 });
423
+ await expect.poll(() => refreshes, { message: "the pull did not refresh the page" }).toBeGreaterThan(0);
424
+ });