@jskit-ai/shell-web 0.2.9 → 0.2.11
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.
- package/CHANGELOG.md +9 -0
- package/fixtures/adaptive-shell/src/App.vue +2 -0
- package/fixtures/adaptive-shell/src/RecordListPage.vue +22 -0
- package/fixtures/adaptive-shell/src/RecordPage.vue +30 -0
- package/fixtures/adaptive-shell/src/ScreenPage.vue +7 -3
- package/fixtures/adaptive-shell/src/SettingsPage.vue +24 -0
- package/fixtures/adaptive-shell/src/main.js +60 -55
- package/fixtures/adaptive-shell/src/records.js +13 -0
- package/fixtures/adaptive-shell/src/theme/index.js +3 -0
- package/locales/en.json +1 -0
- package/package.json +17 -5
- package/patterns/application-shell/PATTERN.md +3 -1
- package/patterns/application-shell/example/expected-existing/src/pages/home/index.vue +5 -18
- package/patterns/application-shell/example/expected-existing/src/views/NotFound.vue +14 -0
- package/patterns/application-shell/example/src/pages/home/index.vue +21 -57
- package/patterns/application-shell/example/src/pages/home/settings/general/index.vue +24 -19
- package/patterns/application-shell/example/src/pages/home/settings.vue +27 -84
- package/patterns/application-shell/example/src/views/NotFound.vue +15 -0
- package/patterns/page-and-placement/example/src/components/SyncStatusElement.vue +2 -2
- package/patterns/page-and-placement/example/src/pages/home/reports/activity.vue +1 -1
- package/patterns/page-and-placement/example/src/pages/home/reports/overview.vue +1 -1
- package/patterns/page-and-placement/example/src/pages/home/reports.vue +6 -3
- package/patterns/page-and-placement/example/src/placement.js +1 -1
- package/src/client/components/ShellErrorHost.vue +13 -15
- package/src/client/components/ShellLayout.vue +388 -186
- package/src/client/components/ShellListDetail.vue +77 -0
- package/src/client/components/ShellMenuLinkItem.vue +10 -24
- package/src/client/components/ShellNavigationItem.vue +175 -0
- package/src/client/components/ShellNavigationScope.vue +18 -0
- package/src/client/components/ShellOutlet.vue +1 -1
- package/src/client/components/ShellOutletMenuWidget.vue +2 -2
- package/src/client/components/ShellPageAction.vue +91 -0
- package/src/client/components/ShellPageActions.vue +32 -0
- package/src/client/components/ShellSurfaceAwareMenuLinkItem.vue +10 -24
- package/src/client/components/ShellTabLinkItem.vue +77 -3
- package/src/client/composables/useShellDrawer.js +28 -18
- package/src/client/composables/useShellPageTitle.js +15 -0
- package/src/client/composables/useShellRouteTransition.js +1 -1
- package/src/client/composables/useShellWindowSizeClass.js +21 -0
- package/src/client/error/presentation.js +3 -5
- package/src/client/index.js +7 -0
- package/src/client/lib/menuIcons.js +21 -65
- package/src/client/navigation/documentNavigation.js +38 -0
- package/src/client/navigation/shellNavigationRuntime.js +480 -0
- package/src/client/navigation/useShellNavigation.js +94 -0
- package/src/client/providers/ShellWebClientProvider.js +11 -0
- package/src/client/support/drawerPresentation.js +9 -4
- package/src/client/support/drawerWidth.js +18 -1
- package/src/client/support/navigationPresentation.js +40 -0
- package/src/client/support/shellLayoutClass.js +6 -25
- package/src/client/support/windowSizeClass.js +29 -0
- package/src/test/adaptiveShellSmoke.js +43 -16
- package/src/test/shellNavigation.js +32 -0
- package/test/adaptiveShell.browser.test.js +207 -111
- package/test/clientUpdate.test.js +6 -1
- package/test/drawerPresentation.test.js +7 -7
- package/test/errorPresentation.test.js +4 -5
- package/test/materialBaselines.browser.test.js +96 -0
- package/test/menuIcons.test.js +14 -22
- package/test/outletMenuWidgetContract.test.js +2 -3
- package/test/playwrightContract.test.js +3 -1
- package/test/provider.test.js +9 -1
- package/test/settingsPlacementContract.test.js +33 -28
- package/test/shellGestureSupport.test.js +21 -9
- package/test/translation.test.js +2 -2
- package/test/useShellDrawer.test.js +20 -5
- package/test/useShellRouteTransition.test.js +3 -3
- package/patterns/application-shell/example/src/pages/home/settings/index.vue +0 -7
- package/src/client/components/ShellNavigationTooltip.vue +0 -39
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** How navigation items inside it present: "rail", "drawer" or, outside the shell's navigation, "list". */
|
|
2
|
+
const SHELL_NAVIGATION_PRESENTATION_KEY = "jskit.shell-web.navigation.presentation";
|
|
3
|
+
/** Navigation items outside the shell's drawer and rail, such as a settings section's own menu, present as a list. */
|
|
4
|
+
const NO_SHELL_NAVIGATION_PRESENTATION = Object.freeze({ value: "list" });
|
|
5
|
+
|
|
6
|
+
/** The page actions slot in the shell's app bar, which ShellPageActions renders into. */
|
|
7
|
+
const SHELL_PAGE_ACTIONS_TARGET_KEY = "jskit.shell-web.layout.page-actions-target";
|
|
8
|
+
const SHELL_PAGE_ACTIONS_ID = "jskit-shell-page-actions";
|
|
9
|
+
/** A page outside a ShellLayout has no app bar, so its page actions render in place. */
|
|
10
|
+
const NO_SHELL_PAGE_ACTIONS_TARGET = "";
|
|
11
|
+
|
|
12
|
+
/** Vuetify's icon options, which hold the theme's aliases (Vuetify provides them under this global symbol). */
|
|
13
|
+
const VUETIFY_ICONS_KEY = Symbol.for("vuetify:icons");
|
|
14
|
+
const NO_VUETIFY_ICONS = Object.freeze({ aliases: Object.freeze({}) });
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The filled form of a navigation icon alias for the active destination: Material 3 shows the active destination's
|
|
18
|
+
* icon filled. `$home` becomes `$homeFilled` when the theme defines it; any other icon stays as it is.
|
|
19
|
+
* @param {string} icon
|
|
20
|
+
* @param {Record<string, unknown> | undefined} aliases The Vuetify icon aliases.
|
|
21
|
+
*/
|
|
22
|
+
function filledIconAlias(icon, aliases) {
|
|
23
|
+
const name = String(icon || "");
|
|
24
|
+
if (!name.startsWith("$") || !aliases) {
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
const filled = `${name.slice(1)}Filled`;
|
|
28
|
+
return Object.hasOwn(aliases, filled) ? `$${filled}` : name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
NO_SHELL_NAVIGATION_PRESENTATION,
|
|
33
|
+
NO_SHELL_PAGE_ACTIONS_TARGET,
|
|
34
|
+
NO_VUETIFY_ICONS,
|
|
35
|
+
SHELL_NAVIGATION_PRESENTATION_KEY,
|
|
36
|
+
SHELL_PAGE_ACTIONS_ID,
|
|
37
|
+
SHELL_PAGE_ACTIONS_TARGET_KEY,
|
|
38
|
+
VUETIFY_ICONS_KEY,
|
|
39
|
+
filledIconAlias
|
|
40
|
+
};
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import { pageViewportWidth } from "../browser.js";
|
|
2
|
+
import { resolveWindowSizeClass } from "./windowSizeClass.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function resolveShellLayoutClass(displayName = "", viewportWidth = pageViewportWidth()) {
|
|
9
|
-
const name = String(displayName || "").trim().toLowerCase();
|
|
10
|
-
if (name === "xs" || name === "sm") {
|
|
11
|
-
return "compact";
|
|
12
|
-
}
|
|
13
|
-
if (name === "md") {
|
|
14
|
-
return "medium";
|
|
15
|
-
}
|
|
16
|
-
if (name === "lg" || name === "xl" || name === "xxl") {
|
|
17
|
-
return "expanded";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const width = Number(viewportWidth) || 0;
|
|
21
|
-
if (width > 0 && width < COMPACT_MAX_WIDTH) {
|
|
22
|
-
return "compact";
|
|
23
|
-
}
|
|
24
|
-
if (width > 0 && width < MEDIUM_MAX_WIDTH) {
|
|
25
|
-
return "medium";
|
|
26
|
-
}
|
|
27
|
-
return "expanded";
|
|
4
|
+
// The layout class placement variants are keyed by (compact, medium, expanded): the window size class, with large
|
|
5
|
+
// placed like expanded.
|
|
6
|
+
function resolveShellLayoutClass(viewportWidth = pageViewportWidth()) {
|
|
7
|
+
const sizeClass = resolveWindowSizeClass(viewportWidth);
|
|
8
|
+
return sizeClass === "large" ? "expanded" : sizeClass;
|
|
28
9
|
}
|
|
29
10
|
|
|
30
11
|
export { resolveShellLayoutClass };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Material 3 window size classes by window width in dp: compact below 600, medium below 840, expanded below 1200 and
|
|
2
|
+
// large from 1200 (extra-large folds into large).
|
|
3
|
+
const MEDIUM_MIN_WIDTH = 600;
|
|
4
|
+
const EXPANDED_MIN_WIDTH = 840;
|
|
5
|
+
const LARGE_MIN_WIDTH = 1200;
|
|
6
|
+
const WINDOW_SIZE_CLASSES = Object.freeze(["compact", "medium", "expanded", "large"]);
|
|
7
|
+
|
|
8
|
+
/** @param {number} width */
|
|
9
|
+
function resolveWindowSizeClass(width) {
|
|
10
|
+
const value = Number(width) || 0;
|
|
11
|
+
if (value < MEDIUM_MIN_WIDTH) {
|
|
12
|
+
return "compact";
|
|
13
|
+
}
|
|
14
|
+
if (value < EXPANDED_MIN_WIDTH) {
|
|
15
|
+
return "medium";
|
|
16
|
+
}
|
|
17
|
+
if (value < LARGE_MIN_WIDTH) {
|
|
18
|
+
return "expanded";
|
|
19
|
+
}
|
|
20
|
+
return "large";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
EXPANDED_MIN_WIDTH,
|
|
25
|
+
LARGE_MIN_WIDTH,
|
|
26
|
+
MEDIUM_MIN_WIDTH,
|
|
27
|
+
WINDOW_SIZE_CLASSES,
|
|
28
|
+
resolveWindowSizeClass
|
|
29
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const DEFAULT_SMOKE_PATH = String(process.env.JSKIT_PLAYWRIGHT_SMOKE_PATH || "/home");
|
|
2
2
|
const DEFAULT_VIEWPORTS = Object.freeze([
|
|
3
3
|
Object.freeze({ name: "compact", width: 390, height: 844 }),
|
|
4
|
-
Object.freeze({ name: "medium", width:
|
|
4
|
+
Object.freeze({ name: "medium", width: 768, height: 1024 }),
|
|
5
5
|
Object.freeze({ name: "expanded", width: 1280, height: 900 })
|
|
6
6
|
]);
|
|
7
7
|
|
|
@@ -171,17 +171,30 @@ async function expectContentAwareDrawerFit(drawer, expect) {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
async function readNavigationIconCenters(drawer) {
|
|
174
|
+
async function readNavigationIconCenters(drawer, expect) {
|
|
175
175
|
const icons = drawer.locator("a.shell-menu-link-item[href] .v-icon");
|
|
176
176
|
await icons.first().waitFor({ state: "visible" });
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
// A modal drawer slides in: measure its icons once two reads, each a couple of frames later, agree.
|
|
178
|
+
const readCenters = () => icons.evaluateAll(async (elements) => {
|
|
179
|
+
await new Promise((resolve) => window.requestAnimationFrame(() => window.requestAnimationFrame(resolve)));
|
|
180
|
+
const centers = [];
|
|
181
|
+
for (const element of elements) {
|
|
182
|
+
const box = element.getBoundingClientRect();
|
|
183
|
+
if (!box.width) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
centers.push(box.x + box.width / 2);
|
|
183
187
|
}
|
|
184
|
-
centers
|
|
188
|
+
return centers;
|
|
189
|
+
});
|
|
190
|
+
let centers = await readCenters();
|
|
191
|
+
await expect.poll(async () => {
|
|
192
|
+
const previous = centers;
|
|
193
|
+
centers = await readCenters();
|
|
194
|
+
return JSON.stringify(centers) === JSON.stringify(previous);
|
|
195
|
+
}, { message: "Shell navigation icons did not come to rest." }).toBe(true);
|
|
196
|
+
if (!centers) {
|
|
197
|
+
throw new Error("Shell navigation exposed an unmeasurable icon.");
|
|
185
198
|
}
|
|
186
199
|
return centers;
|
|
187
200
|
}
|
|
@@ -211,7 +224,7 @@ async function expectCentredRailNavigation(page, drawer, expect, expandedIconCen
|
|
|
211
224
|
expect(linkBox).not.toBeNull();
|
|
212
225
|
expect(linkBox.width).toBeGreaterThanOrEqual(48);
|
|
213
226
|
expect(linkBox.height).toBeGreaterThanOrEqual(48);
|
|
214
|
-
const railIconCenters = await readNavigationIconCenters(drawer);
|
|
227
|
+
const railIconCenters = await readNavigationIconCenters(drawer, expect);
|
|
215
228
|
expect(railIconCenters.length).toBe(expandedIconCenters.length);
|
|
216
229
|
for (let index = 0; index < railIconCenters.length; index += 1) {
|
|
217
230
|
expect(Math.abs(
|
|
@@ -291,12 +304,10 @@ async function runAdaptiveShellSmokeCase({
|
|
|
291
304
|
await expect(page.getByTestId("jskit-shell-bottom-nav")).toBeVisible();
|
|
292
305
|
await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
|
|
293
306
|
|
|
307
|
+
// The modal drawer opens over the app bar, as Material 3 draws it; tapping the scrim beside it closes it.
|
|
294
308
|
await openCompactDrawer(page, expect);
|
|
295
|
-
await toggle.
|
|
296
|
-
await
|
|
297
|
-
|
|
298
|
-
await openCompactDrawer(page, expect);
|
|
299
|
-
await page.getByRole("button", { name: "Close navigation menu" }).click();
|
|
309
|
+
await expect(toggle).toHaveAttribute("aria-label", "Close navigation menu");
|
|
310
|
+
await page.mouse.click(viewport.width - 8, Math.round(viewport.height / 2));
|
|
300
311
|
await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
|
|
301
312
|
|
|
302
313
|
await openCompactDrawer(page, expect);
|
|
@@ -314,6 +325,22 @@ async function runAdaptiveShellSmokeCase({
|
|
|
314
325
|
|
|
315
326
|
await pullToRefresh(page, expect);
|
|
316
327
|
await expect.poll(() => bootstrapRequests).toBeGreaterThan(bootstrapRequestsBeforePull);
|
|
328
|
+
} else if (layoutClass === "medium") {
|
|
329
|
+
// Medium windows keep a navigation rail and open the drawer over the page from the rail's menu control.
|
|
330
|
+
const rail = page.getByTestId("jskit-shell-rail");
|
|
331
|
+
await expect(rail).toBeVisible();
|
|
332
|
+
await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
|
|
333
|
+
await expectDrawerWidth(rail, expect, await readConfiguredWidth(drawer, "data-rail-width"));
|
|
334
|
+
await toggle.click();
|
|
335
|
+
await expect(drawer).toHaveAttribute("data-presentation", "modal");
|
|
336
|
+
await expectElementVisibility(page, expect, "jskit-shell-drawer", true);
|
|
337
|
+
await expectDrawerWidth(drawer, expect, await readConfiguredWidth(drawer, "data-drawer-width"));
|
|
338
|
+
const drawerIconCenters = await readNavigationIconCenters(drawer, expect);
|
|
339
|
+
await page.keyboard.press("Escape");
|
|
340
|
+
await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
|
|
341
|
+
await expect(toggle).toBeFocused();
|
|
342
|
+
await expectCentredRailNavigation(page, rail, expect, drawerIconCenters);
|
|
343
|
+
await expectNoHorizontalOverflow(page, expect);
|
|
317
344
|
} else {
|
|
318
345
|
await expect(drawer).toBeVisible();
|
|
319
346
|
if (await drawer.getAttribute("data-presentation") === "rail") {
|
|
@@ -322,7 +349,7 @@ async function runAdaptiveShellSmokeCase({
|
|
|
322
349
|
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
323
350
|
await expectDrawerWidth(drawer, expect, await readConfiguredWidth(drawer, "data-drawer-width"));
|
|
324
351
|
await expectContentAwareDrawerFit(drawer, expect);
|
|
325
|
-
const expandedIconCenters = await readNavigationIconCenters(drawer);
|
|
352
|
+
const expandedIconCenters = await readNavigationIconCenters(drawer, expect);
|
|
326
353
|
await page.keyboard.press("Escape");
|
|
327
354
|
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
328
355
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Playwright helpers for the shell's app bar: its Up arrow and page title.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The shell's Up arrow, the leading button of an inner page's app bar.
|
|
5
|
+
* @param {import("@playwright/test").Page} page
|
|
6
|
+
*/
|
|
7
|
+
function shellBackButton(page) {
|
|
8
|
+
return page.getByTestId("jskit-shell-back");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The app bar's page title.
|
|
13
|
+
* @param {import("@playwright/test").Page} page
|
|
14
|
+
*/
|
|
15
|
+
function shellPageTitle(page) {
|
|
16
|
+
return page.getByTestId("jskit-shell-page-title");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Presses the shell's Up arrow and waits for the URL to change. It waits for the arrow first, so a navigation that
|
|
21
|
+
* is still opening the page has finished before the starting URL is read.
|
|
22
|
+
* @param {import("@playwright/test").Page} page
|
|
23
|
+
*/
|
|
24
|
+
async function pressShellBack(page) {
|
|
25
|
+
const button = shellBackButton(page);
|
|
26
|
+
await button.waitFor();
|
|
27
|
+
const before = page.url();
|
|
28
|
+
await button.click();
|
|
29
|
+
await page.waitForURL((url) => url.href !== before);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { pressShellBack, shellBackButton, shellPageTitle };
|
|
@@ -9,10 +9,12 @@ import {
|
|
|
9
9
|
startViteFixture,
|
|
10
10
|
stopProcess
|
|
11
11
|
} from "../../../tooling/testUtils/browserFixture.mjs";
|
|
12
|
+
import { materialSymbols } from "@jskit-ai/material-web/client/symbols";
|
|
12
13
|
import {
|
|
13
14
|
DEFAULT_VIEWPORTS,
|
|
14
15
|
runAdaptiveShellSmokeCase
|
|
15
16
|
} from "../src/test/adaptiveShellSmoke.js";
|
|
17
|
+
import { pressShellBack, shellBackButton, shellPageTitle } from "../src/test/shellNavigation.js";
|
|
16
18
|
|
|
17
19
|
const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
18
20
|
const FIXTURE_ROOT = path.resolve(TEST_DIRECTORY, "../fixtures/adaptive-shell");
|
|
@@ -48,81 +50,66 @@ function contrastRatio(foreground, background) {
|
|
|
48
50
|
return (lighter + 0.05) / (darker + 0.05);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const colors = await tooltip.evaluate((element) => {
|
|
62
|
-
const style = window.getComputedStyle(element);
|
|
63
|
-
return {
|
|
64
|
-
background: style.backgroundColor,
|
|
65
|
-
color: style.color,
|
|
66
|
-
opacity: Number(style.opacity)
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
const background = parseRgb(colors.background);
|
|
70
|
-
const foreground = parseRgb(colors.color);
|
|
71
|
-
assert.equal(colors.opacity, 1);
|
|
72
|
-
assert.equal(background.alpha, 1);
|
|
73
|
-
assert.ok(
|
|
74
|
-
contrastRatio(foreground, background) >= 4.5,
|
|
75
|
-
`${linkName} tooltip contrast was ${contrastRatio(foreground, background).toFixed(2)}:1.`
|
|
76
|
-
);
|
|
77
|
-
await page.keyboard.press("Escape");
|
|
53
|
+
// The computed colour of a theme role, read from a probe painted with it.
|
|
54
|
+
async function readRoleColor(page, role) {
|
|
55
|
+
return page.evaluate((name) => {
|
|
56
|
+
const probe = document.createElement("div");
|
|
57
|
+
probe.style.background = `rgb(var(--v-theme-${name}))`;
|
|
58
|
+
document.querySelector(".v-application").append(probe);
|
|
59
|
+
const color = window.getComputedStyle(probe).backgroundColor;
|
|
60
|
+
probe.remove();
|
|
61
|
+
return color;
|
|
62
|
+
}, role);
|
|
78
63
|
}
|
|
79
64
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const countVisibleTooltips = () => Array.from(
|
|
84
|
-
document.querySelectorAll(".shell-navigation-tooltip")
|
|
85
|
-
).filter((element) => {
|
|
86
|
-
const style = window.getComputedStyle(element);
|
|
87
|
-
const rect = element.getBoundingClientRect();
|
|
88
|
-
return (
|
|
89
|
-
style.display !== "none" &&
|
|
90
|
-
style.visibility !== "hidden" &&
|
|
91
|
-
Number(style.opacity) > 0 &&
|
|
92
|
-
rect.width > 0 &&
|
|
93
|
-
rect.height > 0
|
|
94
|
-
);
|
|
95
|
-
}).length;
|
|
96
|
-
|
|
97
|
-
const samples = [];
|
|
98
|
-
let activeLink = null;
|
|
99
|
-
for (const link of links) {
|
|
100
|
-
activeLink?.dispatchEvent(new MouseEvent("mouseleave"));
|
|
101
|
-
link.dispatchEvent(new MouseEvent("mouseenter"));
|
|
102
|
-
activeLink = link;
|
|
103
|
-
await pause(24);
|
|
104
|
-
samples.push(countVisibleTooltips());
|
|
105
|
-
}
|
|
106
|
-
activeLink?.dispatchEvent(new MouseEvent("mouseleave"));
|
|
107
|
-
await pause(100);
|
|
65
|
+
function symbolPath(alias) {
|
|
66
|
+
return materialSymbols[alias].slice("svg:".length);
|
|
67
|
+
}
|
|
108
68
|
|
|
69
|
+
// Material 3 chrome: a 64dp surface app bar and a surface drawer without dividers, the active destination on a
|
|
70
|
+
// secondary-container pill with its icon filled, and inactive labels readable on the drawer.
|
|
71
|
+
async function assertMaterialChrome(page, activeLabel, activeIcon) {
|
|
72
|
+
const drawer = page.getByTestId("jskit-shell-drawer");
|
|
73
|
+
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
74
|
+
const surface = await readRoleColor(page, "surface");
|
|
75
|
+
const secondaryContainer = await readRoleColor(page, "secondary-container");
|
|
76
|
+
const chrome = await page.evaluate((label) => {
|
|
77
|
+
const style = (element) => window.getComputedStyle(element);
|
|
78
|
+
const appBar = document.querySelector("[data-testid='jskit-shell-app-bar']");
|
|
79
|
+
const drawerElement = document.querySelector("[data-testid='jskit-shell-drawer']");
|
|
80
|
+
const items = Array.from(drawerElement.querySelectorAll("a.shell-menu-link-item"));
|
|
81
|
+
const active = items.find((item) => item.textContent.trim() === label);
|
|
82
|
+
const inactive = items.find((item) => item !== active);
|
|
109
83
|
return {
|
|
110
|
-
|
|
111
|
-
|
|
84
|
+
appBarHeight: appBar.getBoundingClientRect().height,
|
|
85
|
+
appBarBackground: style(appBar).backgroundColor,
|
|
86
|
+
appBarBorders: [style(appBar).borderBottomWidth, style(appBar).borderTopWidth],
|
|
87
|
+
drawerBackground: style(drawerElement).backgroundColor,
|
|
88
|
+
drawerBorder: style(drawerElement).borderRightWidth,
|
|
89
|
+
activeBackground: style(active).backgroundColor,
|
|
90
|
+
activeHeight: active.getBoundingClientRect().height,
|
|
91
|
+
activeRadius: Number.parseFloat(style(active).borderTopLeftRadius),
|
|
92
|
+
activeIconPath: active.querySelector(".v-icon svg path")?.getAttribute("d") || "",
|
|
93
|
+
inactiveColor: style(inactive.querySelector(".v-list-item-title")).color
|
|
112
94
|
};
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
assert.equal(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
);
|
|
120
|
-
assert.equal(
|
|
95
|
+
}, activeLabel);
|
|
96
|
+
assert.equal(chrome.appBarHeight, 64);
|
|
97
|
+
assert.equal(chrome.appBarBackground, surface);
|
|
98
|
+
assert.deepEqual(chrome.appBarBorders, ["0px", "0px"]);
|
|
99
|
+
assert.equal(chrome.drawerBackground, surface);
|
|
100
|
+
assert.equal(chrome.drawerBorder, "0px");
|
|
101
|
+
assert.equal(chrome.activeBackground, secondaryContainer);
|
|
102
|
+
assert.equal(chrome.activeHeight, 56);
|
|
103
|
+
assert.ok(chrome.activeRadius >= 28, `The active destination's corner radius was ${chrome.activeRadius}px.`);
|
|
104
|
+
assert.equal(chrome.activeIconPath, symbolPath(activeIcon));
|
|
105
|
+
const ratio = contrastRatio(parseRgb(chrome.inactiveColor), parseRgb(chrome.drawerBackground));
|
|
106
|
+
assert.ok(ratio >= 4.5, `Inactive navigation labels had ${ratio.toFixed(2)}:1 contrast.`);
|
|
121
107
|
}
|
|
122
108
|
|
|
123
109
|
async function assertDrawerFit(page) {
|
|
124
110
|
const drawer = page.getByTestId("jskit-shell-drawer");
|
|
125
111
|
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
112
|
+
await expect(drawer).toHaveAttribute("data-drawer-width-mode", "content");
|
|
126
113
|
assert.equal(
|
|
127
114
|
await drawer.locator(".v-list-subheader").count(),
|
|
128
115
|
0,
|
|
@@ -193,10 +180,11 @@ async function assertRailKeyboardAndSelection(page) {
|
|
|
193
180
|
}).toBeLessThanOrEqual(1);
|
|
194
181
|
|
|
195
182
|
const activeLink = page.getByRole("link", { name: "Bookings", exact: true });
|
|
196
|
-
const activeBackground = await activeLink.locator(".
|
|
183
|
+
const activeBackground = await activeLink.locator(".shell-menu-link-item__indicator").evaluate(
|
|
197
184
|
(element) => window.getComputedStyle(element).backgroundColor
|
|
198
185
|
);
|
|
199
|
-
assert.
|
|
186
|
+
assert.equal(activeBackground, await readRoleColor(page, "secondary-container"));
|
|
187
|
+
await expect(activeLink.locator(".shell-menu-link-item__rail-label")).toHaveText("Bookings");
|
|
200
188
|
|
|
201
189
|
const contacts = page.getByRole("link", { name: "Contacts", exact: true });
|
|
202
190
|
await contacts.focus();
|
|
@@ -231,49 +219,45 @@ test("shell-web adaptive navigation passes package-owned browser contracts", {
|
|
|
231
219
|
const page = await context.newPage();
|
|
232
220
|
await runAdaptiveShellSmokeCase({ page, expect, viewport });
|
|
233
221
|
if (viewport.name !== "compact") {
|
|
234
|
-
await expect(page).toHaveURL(/\/home\/settings
|
|
222
|
+
await expect(page).toHaveURL(/\/home\/settings$/u);
|
|
235
223
|
}
|
|
236
224
|
await page.close();
|
|
237
225
|
}
|
|
238
226
|
|
|
239
|
-
for (const pathAndTheme of [
|
|
240
|
-
"/home?theme=light",
|
|
241
|
-
"/home?theme=dark",
|
|
242
|
-
"/w/acme/admin/bookings?theme=light",
|
|
243
|
-
"/w/acme/admin/bookings?theme=dark"
|
|
227
|
+
for (const [pathAndTheme, activeLabel, activeIcon] of [
|
|
228
|
+
["/home?theme=light", "Home", "homeFilled"],
|
|
229
|
+
["/home?theme=dark", "Home", "homeFilled"],
|
|
230
|
+
["/w/acme/admin/bookings?theme=light", "Bookings", "adminPanelSettingsFilled"],
|
|
231
|
+
["/w/acme/admin/bookings?theme=dark", "Bookings", "adminPanelSettingsFilled"]
|
|
244
232
|
]) {
|
|
245
233
|
const page = await context.newPage();
|
|
246
234
|
await page.setViewportSize({ width: 1280, height: 900 });
|
|
247
235
|
await page.goto(pathAndTheme);
|
|
248
236
|
await expect(page.getByTestId("jskit-shell-drawer")).toBeVisible();
|
|
249
|
-
await
|
|
250
|
-
await assertRapidTooltipTraversal(page);
|
|
251
|
-
await assertTooltipContrast(page, "Bookings", "focus");
|
|
252
|
-
await assertTooltipContrast(page, "Help and support", "hover");
|
|
237
|
+
await assertMaterialChrome(page, activeLabel, activeIcon);
|
|
253
238
|
await page.close();
|
|
254
239
|
}
|
|
255
240
|
|
|
256
|
-
const
|
|
257
|
-
await
|
|
258
|
-
await
|
|
259
|
-
await expect(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
);
|
|
263
|
-
await
|
|
264
|
-
await mediumTooltipPage.close();
|
|
241
|
+
const mediumPage = await context.newPage();
|
|
242
|
+
await mediumPage.setViewportSize({ width: 768, height: 1024 });
|
|
243
|
+
await mediumPage.goto("/w/acme/admin/bookings?theme=light");
|
|
244
|
+
await expect(mediumPage.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-layout", "medium");
|
|
245
|
+
const railLabels = mediumPage.getByTestId("jskit-shell-rail").locator(".shell-menu-link-item__rail-label");
|
|
246
|
+
await expect(railLabels.first()).toBeVisible();
|
|
247
|
+
assert.ok(await railLabels.count() >= 5, "The navigation rail labels each destination.");
|
|
248
|
+
await mediumPage.close();
|
|
265
249
|
|
|
266
250
|
const railPage = await context.newPage();
|
|
267
251
|
await railPage.setViewportSize({ width: 1280, height: 900 });
|
|
268
252
|
await railPage.goto("/w/acme/admin/bookings?theme=light");
|
|
269
|
-
await
|
|
253
|
+
await expect(railPage.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-drawer-width", "360");
|
|
270
254
|
await assertRailKeyboardAndSelection(railPage);
|
|
271
255
|
await railPage.close();
|
|
272
256
|
|
|
273
257
|
const configuredPage = await context.newPage();
|
|
274
258
|
await configuredPage.setViewportSize({ width: 1280, height: 900 });
|
|
275
259
|
await configuredPage.goto(
|
|
276
|
-
"/w/acme/admin/bookings?theme=light&railWidth=64&navigationItemSpacing=8"
|
|
260
|
+
"/w/acme/admin/bookings?theme=light&railWidth=64&navigationItemSpacing=8&drawerWidth=content"
|
|
277
261
|
);
|
|
278
262
|
const configuredDrawer = configuredPage.getByTestId("jskit-shell-drawer");
|
|
279
263
|
await expect(configuredDrawer).toHaveAttribute("data-navigation-item-spacing", "8");
|
|
@@ -440,7 +424,7 @@ test("shell-web error banners never cover content and keep a readable close butt
|
|
|
440
424
|
}
|
|
441
425
|
});
|
|
442
426
|
|
|
443
|
-
test("shell-web
|
|
427
|
+
test("shell-web's app bar fills with surface-container once the page scrolls under it", {
|
|
444
428
|
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
445
429
|
timeout: 90_000
|
|
446
430
|
}, async () => {
|
|
@@ -448,31 +432,143 @@ test("shell-web chrome borders and surfaces follow app-supplied tokens", {
|
|
|
448
432
|
let browser;
|
|
449
433
|
try {
|
|
450
434
|
browser = await chromium.launch(createChromiumLaunchOptions());
|
|
451
|
-
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width:
|
|
452
|
-
await page.goto("/home?theme=light");
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
assert.deepEqual(defaults.appBar.slice(0, 4), ["0px", "0px", "1px", "0px"]);
|
|
465
|
-
assert.deepEqual(defaults.drawer.slice(0, 4), ["0px", "1px", "0px", "0px"]);
|
|
466
|
-
|
|
467
|
-
await page.addStyleTag({
|
|
468
|
-
content: ":root { --shell-chrome-border-width: 0; --shell-app-bar-background: rgb(1, 2, 3); --shell-navigation-background: rgb(4, 5, 6); }"
|
|
469
|
-
});
|
|
470
|
-
const restyled = await read();
|
|
471
|
-
assert.deepEqual(restyled.appBar, ["0px", "0px", "0px", "0px", "rgb(1, 2, 3)"]);
|
|
472
|
-
assert.deepEqual(restyled.drawer, ["0px", "0px", "0px", "0px", "rgb(4, 5, 6)"]);
|
|
435
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
|
|
436
|
+
await page.goto("/home/contacts?theme=light");
|
|
437
|
+
const appBar = page.getByTestId("jskit-shell-app-bar");
|
|
438
|
+
const background = () => appBar.evaluate((element) => window.getComputedStyle(element).backgroundColor);
|
|
439
|
+
await expect.poll(background).toBe(await readRoleColor(page, "surface"));
|
|
440
|
+
const bar = page.getByTestId("jskit-shell-bottom-nav");
|
|
441
|
+
assert.equal(
|
|
442
|
+
await bar.evaluate((element) => window.getComputedStyle(element).backgroundColor),
|
|
443
|
+
await readRoleColor(page, "surface-container")
|
|
444
|
+
);
|
|
445
|
+
assert.equal(Math.round((await bar.boundingBox()).height), 80);
|
|
446
|
+
await page.evaluate(() => window.scrollTo(0, 400));
|
|
447
|
+
await expect.poll(background).toBe(await readRoleColor(page, "surface-container"));
|
|
473
448
|
await page.close();
|
|
474
449
|
} finally {
|
|
475
450
|
await browser?.close();
|
|
476
451
|
await stopProcess(vite);
|
|
477
452
|
}
|
|
478
453
|
});
|
|
454
|
+
|
|
455
|
+
async function openMainDestination(page, label) {
|
|
456
|
+
await page.getByRole("link", { name: label, exact: true }).filter({ visible: true }).first().click();
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
test("shell-web Up follows the tab's trail, falls back to the parent and returns to where the person was", {
|
|
460
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
461
|
+
timeout: 180_000
|
|
462
|
+
}, async () => {
|
|
463
|
+
const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
|
|
464
|
+
let browser;
|
|
465
|
+
try {
|
|
466
|
+
browser = await chromium.launch(createChromiumLaunchOptions());
|
|
467
|
+
for (const viewport of DEFAULT_VIEWPORTS) {
|
|
468
|
+
const context = await browser.newContext({
|
|
469
|
+
baseURL: vite.baseURL,
|
|
470
|
+
viewport: { width: viewport.width, height: viewport.height }
|
|
471
|
+
});
|
|
472
|
+
const page = await context.newPage();
|
|
473
|
+
const at = `${viewport.width}px`;
|
|
474
|
+
|
|
475
|
+
// Main-menu pages have no arrow.
|
|
476
|
+
for (const path of ["/home", "/home/contacts", "/home/suppliers", "/home/bookings", "/home/settings"]) {
|
|
477
|
+
await page.goto(path);
|
|
478
|
+
await expect(shellPageTitle(page)).toBeVisible();
|
|
479
|
+
await expect(shellBackButton(page), `${at} ${path}`).toHaveCount(0);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// contact -> supplier -> Up = contact -> Up = the Contacts list.
|
|
483
|
+
await page.goto("/home/contacts");
|
|
484
|
+
await page.getByRole("link", { name: "Ada Lovelace", exact: true }).click();
|
|
485
|
+
await expect(page).toHaveURL(/\/home\/contacts\/ada$/u);
|
|
486
|
+
await expect(shellPageTitle(page)).toHaveText("Ada Lovelace");
|
|
487
|
+
await expect(shellBackButton(page)).toHaveAccessibleName("Back");
|
|
488
|
+
await page.getByRole("link", { name: "Supplier", exact: true }).click();
|
|
489
|
+
await expect(page).toHaveURL(/\/home\/suppliers\/acme$/u);
|
|
490
|
+
// A refresh keeps the trail.
|
|
491
|
+
await page.reload();
|
|
492
|
+
await expect(shellPageTitle(page)).toHaveText("Acme Supplies");
|
|
493
|
+
await pressShellBack(page);
|
|
494
|
+
await expect(page).toHaveURL(/\/home\/contacts\/ada$/u);
|
|
495
|
+
// The browser's Back and Forward move the trail with them.
|
|
496
|
+
await page.goBack();
|
|
497
|
+
await expect(page).toHaveURL(/\/home\/suppliers\/acme$/u);
|
|
498
|
+
await page.goForward();
|
|
499
|
+
await expect(page).toHaveURL(/\/home\/contacts\/ada$/u);
|
|
500
|
+
await pressShellBack(page);
|
|
501
|
+
await expect(page).toHaveURL(/\/home\/contacts$/u);
|
|
502
|
+
await expect(shellBackButton(page)).toHaveCount(0);
|
|
503
|
+
|
|
504
|
+
// The trail is a stack of visits: contact -> supplier -> the same contact -> Up = supplier.
|
|
505
|
+
await page.getByRole("link", { name: "Ada Lovelace", exact: true }).click();
|
|
506
|
+
await page.getByRole("link", { name: "Supplier", exact: true }).click();
|
|
507
|
+
await page.getByRole("link", { name: "Contact", exact: true }).click();
|
|
508
|
+
await expect(page).toHaveURL(/\/home\/contacts\/ada$/u);
|
|
509
|
+
await pressShellBack(page);
|
|
510
|
+
await expect(page).toHaveURL(/\/home\/suppliers\/acme$/u);
|
|
511
|
+
|
|
512
|
+
// A main destination starts a fresh trail.
|
|
513
|
+
await openMainDestination(page, "Suppliers");
|
|
514
|
+
await expect(page).toHaveURL(/\/home\/suppliers$/u);
|
|
515
|
+
await page.getByRole("link", { name: "Acme Supplies", exact: true }).click();
|
|
516
|
+
await expect(page).toHaveURL(/\/home\/suppliers\/acme$/u);
|
|
517
|
+
await pressShellBack(page);
|
|
518
|
+
await expect(page).toHaveURL(/\/home\/suppliers$/u);
|
|
519
|
+
|
|
520
|
+
// Up to a page that is no longer available goes to the current page's parent instead.
|
|
521
|
+
await page.goto("/home/contacts/ada");
|
|
522
|
+
await page.getByRole("link", { name: "Supplier", exact: true }).click();
|
|
523
|
+
await page.evaluate(() => {
|
|
524
|
+
window.__fixtureBlockedRecords = ["ada"];
|
|
525
|
+
});
|
|
526
|
+
await pressShellBack(page);
|
|
527
|
+
await expect(page).toHaveURL(/\/home\/suppliers$/u);
|
|
528
|
+
await page.evaluate(() => {
|
|
529
|
+
window.__fixtureBlockedRecords = [];
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// Up returns to the list where it was scrolled, with focus on the record it opened.
|
|
533
|
+
await page.goto("/home/contacts");
|
|
534
|
+
const deepLink = page.getByRole("link", { name: "Contact 35", exact: true });
|
|
535
|
+
await deepLink.scrollIntoViewIfNeeded();
|
|
536
|
+
const scrollBefore = await page.evaluate(() => window.scrollY);
|
|
537
|
+
assert.ok(scrollBefore > 200, `${at}: the contacts list did not scroll.`);
|
|
538
|
+
await deepLink.click();
|
|
539
|
+
await expect(page).toHaveURL(/\/home\/contacts\/contact-35$/u);
|
|
540
|
+
await pressShellBack(page);
|
|
541
|
+
await expect(page).toHaveURL(/\/home\/contacts$/u);
|
|
542
|
+
await expect.poll(() => page.evaluate(() => window.scrollY)).toBeGreaterThan(scrollBefore - 3);
|
|
543
|
+
assert.ok(Math.abs(await page.evaluate(() => window.scrollY) - scrollBefore) <= 2, `${at}: scroll was not restored.`);
|
|
544
|
+
await expect(page.getByRole("link", { name: "Contact 35", exact: true })).toBeFocused();
|
|
545
|
+
|
|
546
|
+
// A pasted supplier link goes Up to the Suppliers list.
|
|
547
|
+
const pasted = await context.newPage();
|
|
548
|
+
await pasted.goto("/home/suppliers/acme");
|
|
549
|
+
await pressShellBack(pasted);
|
|
550
|
+
await expect(pasted).toHaveURL(/\/home\/suppliers$/u);
|
|
551
|
+
await expect(shellPageTitle(pasted)).toHaveText("Suppliers");
|
|
552
|
+
await pasted.close();
|
|
553
|
+
|
|
554
|
+
// List-detail: beside the visible list, General has no arrow; alone, it has one back to the list.
|
|
555
|
+
await page.goto("/home/settings");
|
|
556
|
+
await page.getByRole("link", { name: "General", exact: true }).click();
|
|
557
|
+
await expect(page).toHaveURL(/\/home\/settings\/general$/u);
|
|
558
|
+
if (viewport.name === "expanded") {
|
|
559
|
+
await expect(shellBackButton(page)).toHaveCount(0);
|
|
560
|
+
await expect(page.getByRole("link", { name: "General", exact: true })).toBeVisible();
|
|
561
|
+
} else {
|
|
562
|
+
await pressShellBack(page);
|
|
563
|
+
await expect(page).toHaveURL(/\/home\/settings$/u);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// No page carries a worded back control.
|
|
567
|
+
await expect(page.getByText(/Back to /u)).toHaveCount(0);
|
|
568
|
+
await context.close();
|
|
569
|
+
}
|
|
570
|
+
} finally {
|
|
571
|
+
await browser?.close();
|
|
572
|
+
await stopProcess(vite);
|
|
573
|
+
}
|
|
574
|
+
});
|