@jskit-ai/shell-web 0.2.13 → 0.2.14

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/fixtures/adaptive-shell/src/ActionsFormPage.vue +22 -0
  3. package/fixtures/adaptive-shell/src/ActionsPage.vue +74 -0
  4. package/fixtures/adaptive-shell/src/App.vue +1 -0
  5. package/fixtures/adaptive-shell/src/ButtonStatesPage.vue +63 -0
  6. package/fixtures/adaptive-shell/src/ButtonsPage.vue +33 -3
  7. package/fixtures/adaptive-shell/src/ComponentsPage.vue +178 -0
  8. package/fixtures/adaptive-shell/src/FeedbackPage.vue +59 -0
  9. package/fixtures/adaptive-shell/src/ReportsPage.vue +29 -0
  10. package/fixtures/adaptive-shell/src/StatusButton.vue +17 -0
  11. package/fixtures/adaptive-shell/src/TitleClaim.vue +17 -0
  12. package/fixtures/adaptive-shell/src/main.js +131 -5
  13. package/fixtures/production-build/index.html +15 -0
  14. package/fixtures/production-build/package.json +5 -0
  15. package/fixtures/production-build/src/App.vue +27 -0
  16. package/fixtures/production-build/src/componentChunk.css +5 -0
  17. package/fixtures/production-build/src/main.js +10 -0
  18. package/fixtures/production-build/vite.config.mjs +12 -0
  19. package/locales/en.json +1 -0
  20. package/package.json +9 -5
  21. package/patterns/application-shell/PATTERN.md +11 -6
  22. package/patterns/application-shell/example/src/components/menus/SectionTabLinkItem.vue +42 -0
  23. package/patterns/application-shell/example/src/pages/home.vue +1 -1
  24. package/patterns/application-shell/example/src/views/NotFound.vue +1 -1
  25. package/patterns/page-and-placement/PATTERN.md +6 -0
  26. package/patterns/page-and-placement/example/src/pages/home/reports.vue +9 -4
  27. package/patterns/page-and-placement/example/src/placementTopology.js +5 -3
  28. package/src/client/components/ShellErrorHost.vue +20 -1
  29. package/src/client/components/ShellLayout.vue +42 -27
  30. package/src/client/components/ShellNavigationItem.vue +8 -3
  31. package/src/client/components/ShellNavigationScope.vue +1 -1
  32. package/src/client/components/ShellOutlet.vue +12 -1
  33. package/src/client/components/ShellPageAction.vue +107 -28
  34. package/src/client/components/ShellPageActionsTarget.vue +81 -2
  35. package/src/client/components/ShellPrimaryAction.vue +69 -0
  36. package/src/client/components/ShellSectionTabLinkItem.vue +104 -0
  37. package/src/client/components/ShellTabLinkItem.vue +18 -3
  38. package/src/client/components/ShellUpButton.vue +13 -8
  39. package/src/client/composables/useShellAppBar.js +10 -1
  40. package/src/client/composables/useShellPageClose.js +18 -0
  41. package/src/client/index.js +3 -0
  42. package/src/client/navigation/shellNavigationRuntime.js +50 -11
  43. package/src/client/navigation/usePaths.js +13 -0
  44. package/src/client/navigation/useShellNavigation.js +2 -0
  45. package/src/client/support/drawerPresentation.js +23 -6
  46. package/src/client/support/navigationPresentation.js +1 -1
  47. package/src/client/support/pageActions.js +126 -0
  48. package/src/test/adaptiveShellSmoke.js +31 -16
  49. package/test/adaptiveShell.browser.test.js +1019 -334
  50. package/test/drawerPresentation.test.js +20 -2
  51. package/test/linkResolver.test.js +4 -0
  52. package/test/materialBaselines.browser.test.js +142 -27
  53. package/test/packageRouteParent.test.js +41 -0
  54. package/test/pageActions.test.js +84 -0
  55. package/test/productionBuild.browser.test.js +98 -0
  56. package/test/settingsPlacementContract.test.js +11 -4
  57. package/test/shellNavigationRuntime.test.js +181 -0
@@ -4,7 +4,8 @@ import {
4
4
  normalizeDesktopDrawerClosedMode,
5
5
  resolveShellDrawerPresentation,
6
6
  resolveShellDrawerToggleLabel,
7
- shellLayoutHasDrawer
7
+ shellLayoutHasDrawer,
8
+ shellLayoutHasNavigationBar
8
9
  } from "../src/client/support/drawerPresentation.js";
9
10
 
10
11
  test("wide closed navigation defaults to a visible Material navigation rail", () => {
@@ -68,9 +69,17 @@ test("open navigation renders as a full drawer and labels its toggle responsivel
68
69
  );
69
70
  });
70
71
 
71
- test("a surface has a drawer with menu destinations or its own menu, and for its identity only beside navigation", () => {
72
+ test("a surface has a drawer for menu destinations of two or more in all, or its own menu, and for its identity beside navigation", () => {
72
73
  assert.equal(shellLayoutHasDrawer({ menuCount: 3 }), true);
74
+ assert.equal(shellLayoutHasDrawer({ menuCount: 2 }), true);
73
75
  assert.equal(shellLayoutHasDrawer({ menuSlot: true }), true);
76
+ // Home alone is nowhere to go: no drawer, rail or menu control.
77
+ assert.equal(shellLayoutHasDrawer({ menuCount: 1 }), false);
78
+ assert.equal(shellLayoutHasDrawer({ bottomNavigationCount: 1 }), false);
79
+ // A phone's one drawer destination (Settings) beside the bar's (Home) keeps its drawer.
80
+ assert.equal(shellLayoutHasDrawer({ menuCount: 1, bottomNavigationCount: 1 }), true);
81
+ // The workspace switcher keeps the drawer beside Home.
82
+ assert.equal(shellLayoutHasDrawer({ identityCount: 1, menuCount: 1 }), true);
74
83
  // A phone whose destinations are all in the navigation bar keeps the drawer for its workspace switcher.
75
84
  assert.equal(shellLayoutHasDrawer({ identityCount: 1, bottomNavigationCount: 3 }), true);
76
85
  // An empty drawer is not drawn, nor is one holding only the identity on a surface without navigation.
@@ -78,3 +87,12 @@ test("a surface has a drawer with menu destinations or its own menu, and for its
78
87
  assert.equal(shellLayoutHasDrawer({ identityCount: 1 }), false);
79
88
  assert.equal(shellLayoutHasDrawer(), false);
80
89
  });
90
+
91
+ test("a compact window shows the navigation bar for its destinations of two or more in all", () => {
92
+ assert.equal(shellLayoutHasNavigationBar({ bottomNavigationCount: 3 }), true);
93
+ assert.equal(shellLayoutHasNavigationBar({ bottomNavigationCount: 2 }), true);
94
+ assert.equal(shellLayoutHasNavigationBar({ bottomNavigationCount: 1 }), false);
95
+ assert.equal(shellLayoutHasNavigationBar({ bottomNavigationCount: 1, menuCount: 1 }), true);
96
+ assert.equal(shellLayoutHasNavigationBar({ menuCount: 3 }), false);
97
+ assert.equal(shellLayoutHasNavigationBar(), false);
98
+ });
@@ -180,4 +180,8 @@ test("usePaths().page() fills a declared parent's params from the current route"
180
180
  assert.equal(paths.page("/books/:bookId"), "/console/books/7");
181
181
  assert.equal(paths.page("/books/:bookId", { params: { bookId: "8" } }), "/console/books/8");
182
182
  assert.throws(() => paths.page("/authors/:authorId"), /Missing required route params/u);
183
+ // A global route belongs to no surface: its app path, its params filled the same way.
184
+ assert.equal(paths.page("/auth/login", { scope: "global" }), "/auth/login");
185
+ assert.equal(paths.page("/shared/:bookId", { scope: "global" }), "/shared/7");
186
+ assert.throws(() => paths.page("/shared/:authorId", { scope: "global" }), /Missing required route params/u);
183
187
  });
@@ -37,7 +37,17 @@ const SHELL_PROBES = Object.freeze([
37
37
  { name: "scrim", selector: ".v-navigation-drawer__scrim" },
38
38
  { name: "content", selector: ".shell-layout__content" },
39
39
  { name: "listItem", selector: ".v-main .v-list-item" },
40
- { name: "listPane", selector: "[data-testid=jskit-shell-list-detail] .shell-list-detail__list", width: true }
40
+ { name: "listPane", selector: "[data-testid=jskit-shell-list-detail] .shell-list-detail__list", width: true },
41
+ // A page's section tabs (page.section-nav), Material 3 primary tabs, and the navigation bar's item placed in a page.
42
+ { name: "sectionTabs", selector: "[data-testid=fixture-section-tabs]", width: true },
43
+ { name: "sectionTab", selector: "[data-testid=fixture-section-tabs] .section-tab-link-item:not(.section-tab-link-item--active)" },
44
+ { name: "sectionTabActive", selector: "[data-testid=fixture-section-tabs] .section-tab-link-item--active" },
45
+ {
46
+ name: "sectionTabIndicator",
47
+ selector: "[data-testid=fixture-section-tabs] .section-tab-link-item--active .section-tab-link-item__indicator",
48
+ width: true
49
+ },
50
+ { name: "barItemInPage", selector: "[data-testid=fixture-bar-items-in-page] .section-tab-link-item--active" }
41
51
  ]);
42
52
 
43
53
  const SCREENS = Object.freeze([
@@ -45,48 +55,153 @@ const SCREENS = Object.freeze([
45
55
  { name: "list", path: "/home/contacts" },
46
56
  { name: "record", path: "/home/contacts/ada" },
47
57
  { name: "list-detail", path: "/home/settings/general" },
58
+ { name: "section-tabs", path: "/home/reports/overview" },
48
59
  { name: "drawer-open", path: "/home", openDrawer: true }
49
60
  ]);
50
61
 
51
62
  test("shell-web keeps its Material 3 baselines in light and dark at every window size", {
52
63
  skip: RUN_BROWSER_TEST ? false : "set JSKIT_MATERIAL_BASELINES=1 to check the Material 3 baselines",
53
64
  timeout: 300_000
65
+ }, async (t) => {
66
+ // Stopped in after hooks, which run when the test fails or times out too (a body's `finally` doesn't after a
67
+ // timeout, and the server and browser would keep the test file's process alive).
68
+ const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
69
+ t.after(() => stopProcess(vite));
70
+ const browser = await chromium.launch(createChromiumLaunchOptions());
71
+ t.after(() => browser.close());
72
+ for (const viewport of DEFAULT_VIEWPORTS) {
73
+ for (const theme of ["light", "dark"]) {
74
+ const context = await browser.newContext({
75
+ baseURL: vite.baseURL,
76
+ colorScheme: theme,
77
+ locale: "en-US",
78
+ reducedMotion: "reduce",
79
+ viewport: { width: viewport.width, height: viewport.height }
80
+ });
81
+ try {
82
+ const page = await context.newPage();
83
+ for (const screen of SCREENS) {
84
+ // The expanded window already shows its drawer.
85
+ if (screen.openDrawer && viewport.name === "expanded") {
86
+ continue;
87
+ }
88
+ await page.goto(`${screen.path}?theme=${theme}`);
89
+ await expect(page.getByTestId("jskit-shell-page-title")).toBeVisible();
90
+ if (screen.openDrawer) {
91
+ await page.getByTestId("jskit-shell-nav-toggle").click();
92
+ await expect(page.locator("[data-testid=jskit-shell-drawer].v-navigation-drawer--active")).toBeVisible();
93
+ }
94
+ await expectMaterialBaseline(page, {
95
+ directory: BASELINE_DIRECTORY,
96
+ name: `shell-${screen.name}-${viewport.width}-${theme}`,
97
+ probes: SHELL_PROBES
98
+ });
99
+ }
100
+ } finally {
101
+ await context.close();
102
+ }
103
+ }
104
+ }
105
+ });
106
+
107
+ // Buttons and pressable chips with their state layers, which Material 3 draws inside the control's shape: by variant
108
+ // at rest, selected and disabled, with a pagination's selected page; then a tonal button hovered, focused and
109
+ // pressed, at rest and selected, a selected tonal icon toggle hovered, a tonal chip hovered, and a profile menu's
110
+ // avatar trigger pressed and open, with its name and as an icon button.
111
+ const STATE_PROBES = Object.freeze([
112
+ { name: "tonal", selector: "[data-testid=state-tonal-rest]" },
113
+ { name: "tonalUnderlay", selector: "[data-testid=state-tonal-rest] > .v-btn__underlay" },
114
+ { name: "tonalOverlay", selector: "[data-testid=state-tonal-rest] > .v-btn__overlay" },
115
+ // Only while it is pressed: its ripple keeps the pill's corners.
116
+ { name: "tonalRipple", selector: "[data-testid=state-tonal-rest] > .v-ripple__container" },
117
+ { name: "selectedOverlay", selector: "[data-testid=state-tonal-active] > .v-btn__overlay" },
118
+ { name: "disabled", selector: "[data-testid=state-flat-disabled]" },
119
+ { name: "disabledOverlay", selector: "[data-testid=state-flat-disabled] > .v-btn__overlay" },
120
+ { name: "iconUnderlay", selector: "[data-testid=state-icon-rest] > .v-btn__underlay" },
121
+ { name: "iconSelectedOverlay", selector: "[data-testid=state-icon-active] > .v-btn__overlay" },
122
+ {
123
+ name: "paginationSelectedOverlay",
124
+ selector: "[data-testid=state-pagination] .v-pagination__item--is-active > .v-btn > .v-btn__overlay"
125
+ },
126
+ { name: "chipUnderlay", selector: "[data-testid=state-chip-tonal] > .v-chip__underlay" },
127
+ { name: "chipOverlay", selector: "[data-testid=state-chip-tonal] > .v-chip__overlay" },
128
+ { name: "blockDisabledOverlay", selector: "[data-testid=state-block-disabled] > .v-btn__overlay" },
129
+ { name: "profileOverlay", selector: "[data-testid=state-profile] > .v-btn__overlay" },
130
+ { name: "profileIconOverlay", selector: "[data-testid=state-profile-icon] > .v-btn__overlay" }
131
+ ]);
132
+
133
+ const STATE_TARGETS = Object.freeze([
134
+ { name: "tonal", testId: "state-tonal-rest", states: ["hover", "focus", "pressed"] },
135
+ { name: "selected", testId: "state-tonal-active", states: ["hover", "focus", "pressed"] },
136
+ { name: "icon-selected", testId: "state-icon-active", states: ["hover"] },
137
+ { name: "chip", testId: "state-chip-tonal", states: ["hover"] },
138
+ { name: "profile", testId: "state-profile", states: ["pressed", "open"] },
139
+ { name: "profile-icon", testId: "state-profile-icon", states: ["pressed", "open"] }
140
+ ]);
141
+
142
+ test("buttons and chips keep every state layer inside their shape, in light and dark", {
143
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_MATERIAL_BASELINES=1 to check the Material 3 baselines",
144
+ timeout: 180_000
54
145
  }, async () => {
55
146
  const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
56
147
  let browser = null;
57
148
  try {
58
149
  browser = await chromium.launch(createChromiumLaunchOptions());
59
- for (const viewport of DEFAULT_VIEWPORTS) {
60
- for (const theme of ["light", "dark"]) {
61
- const context = await browser.newContext({
62
- baseURL: vite.baseURL,
63
- colorScheme: theme,
64
- locale: "en-US",
65
- reducedMotion: "reduce",
66
- viewport: { width: viewport.width, height: viewport.height }
150
+ for (const theme of ["light", "dark"]) {
151
+ const context = await browser.newContext({
152
+ baseURL: vite.baseURL,
153
+ colorScheme: theme,
154
+ locale: "en-US",
155
+ reducedMotion: "reduce",
156
+ viewport: { width: 390, height: 844 }
157
+ });
158
+ try {
159
+ const page = await context.newPage();
160
+ await page.goto(`/home/button-states?theme=${theme}`);
161
+ await expect(page.getByTestId("jskit-shell-page-title")).toHaveText("Button states");
162
+ const baseline = (name) => expectMaterialBaseline(page, {
163
+ directory: BASELINE_DIRECTORY,
164
+ name: `buttons-${name}-${theme}`,
165
+ probes: STATE_PROBES
67
166
  });
68
- try {
69
- const page = await context.newPage();
70
- for (const screen of SCREENS) {
71
- // The expanded window already shows its drawer.
72
- if (screen.openDrawer && viewport.name === "expanded") {
73
- continue;
167
+ await baseline("rest");
168
+ for (const target of STATE_TARGETS) {
169
+ const control = page.getByTestId(target.testId);
170
+ for (const state of target.states) {
171
+ if (state === "hover") {
172
+ await control.hover();
173
+ } else if (state === "focus") {
174
+ // A key press first, so the focus shows as keyboard focus.
175
+ await page.keyboard.press("Shift");
176
+ await control.focus();
177
+ } else if (state === "open") {
178
+ await control.click();
179
+ await expect(control).toHaveAttribute("aria-expanded", "true");
180
+ } else {
181
+ await control.hover();
182
+ await page.mouse.down();
183
+ }
184
+ await baseline(`${target.name}-${state}`);
185
+ if (state === "pressed") {
186
+ await page.mouse.up();
74
187
  }
75
- await page.goto(`${screen.path}?theme=${theme}`);
76
- await expect(page.getByTestId("jskit-shell-page-title")).toBeVisible();
77
- if (screen.openDrawer) {
78
- await page.getByTestId("jskit-shell-nav-toggle").click();
79
- await expect(page.locator("[data-testid=jskit-shell-drawer].v-navigation-drawer--active")).toBeVisible();
188
+ // Releasing a menu's trigger opens its menu; neither stays open for the next state. Escape closes the top
189
+ // overlay, which can be the trigger's tooltip, so it is pressed until the menu has closed too.
190
+ if (await control.getAttribute("aria-expanded") === "true") {
191
+ await page.mouse.move(1, 300);
192
+ await expect(async () => {
193
+ await page.keyboard.press("Escape");
194
+ await expect(control).toHaveAttribute("aria-expanded", "false", { timeout: 1000 });
195
+ }).toPass({ timeout: 10_000 });
80
196
  }
81
- await expectMaterialBaseline(page, {
82
- directory: BASELINE_DIRECTORY,
83
- name: `shell-${screen.name}-${viewport.width}-${theme}`,
84
- probes: SHELL_PROBES
85
- });
197
+ await control.blur();
198
+ await page.mouse.move(1, 300);
199
+ // A released press leaves its ripple fading out for a moment; the next state starts once it has gone.
200
+ await expect(page.locator(".v-ripple__container")).toHaveCount(0);
86
201
  }
87
- } finally {
88
- await context.close();
89
202
  }
203
+ } finally {
204
+ await context.close();
90
205
  }
91
206
  }
92
207
  } finally {
@@ -0,0 +1,41 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { bootClientModules } from "@jskit-ai/kernel/client/moduleBootstrap";
4
+ import { createSurfaceRuntime } from "@jskit-ai/kernel/shared/surface/runtime";
5
+ import { silentLogger } from "@jskit-ai/kernel/shared/support/silentLogger";
6
+ import { resolvePageParent } from "../src/client/navigation/shellNavigationRuntime.js";
7
+
8
+ // A package's page (package.json jskit.metadata.ui.routes) is one record at the top level, so the shell's Up reads the
9
+ // parent it declares; one that declares none is top-level, with no Up.
10
+ test("Up reads the parent a package's surface route declares", async () => {
11
+ const routes = [];
12
+ await bootClientModules({
13
+ clientModules: [
14
+ {
15
+ packageId: "@example/manage",
16
+ packageMetadataUiRoutes: [
17
+ { id: "manage", path: "/app/manage", scope: "surface", surface: "app", componentKey: "page" },
18
+ { id: "manage.view", path: "/app/manage/:view", scope: "surface", surface: "app", componentKey: "page", meta: { jskit: { parent: "/manage" } } },
19
+ { id: "account", path: "/account", scope: "global", componentKey: "page", meta: { jskit: { parent: { surface: "app", path: "/" } } } }
20
+ ],
21
+ module: { routeComponents: { page: {} } }
22
+ }
23
+ ],
24
+ router: { addRoute: (route) => routes.push(route), getRoutes: () => [...routes] },
25
+ surfaceRuntime: createSurfaceRuntime({
26
+ allMode: "all",
27
+ surfaces: { app: { id: "app", pagesRoot: "app", enabled: true } },
28
+ defaultSurfaceId: "app"
29
+ }),
30
+ surfaceMode: "all",
31
+ logger: silentLogger
32
+ });
33
+
34
+ const parentOf = (path) => {
35
+ const parent = resolvePageParent([routes.find((route) => route.path === path)]);
36
+ return parent && { surface: parent.surface, path: parent.path };
37
+ };
38
+ assert.equal(parentOf("/app/manage"), null);
39
+ assert.deepEqual(parentOf("/app/manage/:view"), { surface: "", path: "/manage" });
40
+ assert.deepEqual(parentOf("/account"), { surface: "app", path: "/" });
41
+ });
@@ -0,0 +1,84 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import test from "node:test";
4
+ import { compileScript, compileTemplate, parse } from "@vue/compiler-sfc";
5
+ import { computed, ref } from "vue";
6
+ import { createShellPageActionsRegistry } from "../src/client/support/pageActions.js";
7
+
8
+ function action(label, { primary = false, overflow = false } = {}) {
9
+ return { id: label, state: computed(() => ({ label, primary, overflow })), attrs: {}, activate() {}, anchor: null };
10
+ }
11
+
12
+ function menuLabels(registry) {
13
+ return registry.menuEntries.value.map((entry) => entry.state.value.label);
14
+ }
15
+
16
+ test("a compact top app bar keeps only the primary action, and wider bars every action", () => {
17
+ const isCompact = ref(true);
18
+ const registry = createShellPageActionsRegistry({ isCompact });
19
+ const releases = ["Edit", "Share"].map((label) => registry.register(action(label)).release);
20
+ assert.deepEqual(menuLabels(registry), ["Edit", "Share"], "a compact bar keeps its place for the account avatar");
21
+ assert.equal(registry.hasPrimary.value, false);
22
+
23
+ const save = registry.register(action("Save", { primary: true }));
24
+ assert.deepEqual(menuLabels(registry), ["Edit", "Share"], "the primary action takes the place");
25
+ assert.equal(registry.hasPrimary.value, true);
26
+
27
+ isCompact.value = false;
28
+ assert.deepEqual(menuLabels(registry), [], "wider windows show every action");
29
+ assert.equal(registry.hasPrimary.value, true);
30
+
31
+ save.release();
32
+ releases.forEach((release) => release());
33
+ assert.deepEqual(menuLabels(registry), []);
34
+ assert.equal(registry.hasPrimary.value, false);
35
+ });
36
+
37
+ test("overflow actions go to the menu at every width, in bar order, and an overflow primary action takes no place", () => {
38
+ const isCompact = ref(false);
39
+ const registry = createShellPageActionsRegistry({ isCompact });
40
+ const edit = action("Edit");
41
+ const duplicate = action("Duplicate", { overflow: true });
42
+ registry.register(edit);
43
+ registry.register(duplicate);
44
+ registry.register(action("Delete"));
45
+ assert.deepEqual(menuLabels(registry), ["Duplicate"]);
46
+ assert.equal(registry.inMenu(duplicate), true);
47
+ assert.equal(registry.inMenu(edit), false);
48
+
49
+ registry.register(action("Publish", { primary: true, overflow: true }));
50
+ assert.equal(registry.hasPrimary.value, false);
51
+ isCompact.value = true;
52
+ assert.deepEqual(menuLabels(registry), ["Edit", "Duplicate", "Delete", "Publish"]);
53
+ });
54
+
55
+ test("ShellPageAction forwards its attributes to the button in each form and registers with the bar", async () => {
56
+ const filename = new URL("../src/client/components/ShellPageAction.vue", import.meta.url);
57
+ const source = await readFile(filename, "utf8");
58
+ assert.match(source, /defineOptions\(\{ inheritAttrs: false \}\)/u);
59
+ assert.match(source, /v-bind="mergeProps\(attrs, tooltipProps\)"/u);
60
+ assert.match(source, /v-else\s+v-bind="attrs"/u);
61
+ for (const prop of ["color", "download", "replace", "overflow"]) {
62
+ assert.match(source, new RegExp(`\\n ${prop}: \\{`, "u"), `${prop} is a prop`);
63
+ }
64
+ for (const file of ["ShellPageAction.vue", "ShellPageActionsTarget.vue", "ShellPrimaryAction.vue"]) {
65
+ const componentPath = new URL(`../src/client/components/${file}`, import.meta.url);
66
+ const { descriptor, errors } = parse(await readFile(componentPath, "utf8"), { filename: componentPath.pathname });
67
+ assert.deepEqual(errors, [], file);
68
+ const script = compileScript(descriptor, { id: file });
69
+ const compiled = compileTemplate({
70
+ id: file,
71
+ filename: componentPath.pathname,
72
+ source: descriptor.template.content,
73
+ compilerOptions: { bindingMetadata: script.bindings }
74
+ });
75
+ assert.deepEqual(compiled.errors, [], file);
76
+ }
77
+ const target = await readFile(new URL("../src/client/components/ShellPageActionsTarget.vue", import.meta.url), "utf8");
78
+ assert.match(target, /<v-list v-if="!slots\.menu" role="menu"/u);
79
+ assert.match(target, /v-bind="itemProps\(entry\)"\s+role="menuitem"/u);
80
+ assert.match(target, /mergeProps\(entry\.attrs, \{/u);
81
+ const primary = await readFile(new URL("../src/client/components/ShellPrimaryAction.vue", import.meta.url), "utf8");
82
+ assert.match(primary, /<v-fab\s+v-if="isCompact \|\| isMedium"[\s\S]*\bapp\b[\s\S]*\bextended\b/u);
83
+ assert.match(primary, /<ShellPageActions v-else>\s*<ShellPageAction[\s\S]*\bprimary\b/u);
84
+ });
@@ -0,0 +1,98 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFile } from "node:child_process";
3
+ import { mkdtemp, rm } from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import process from "node:process";
7
+ import test from "node:test";
8
+ import { fileURLToPath } from "node:url";
9
+ import { promisify } from "node:util";
10
+ import { chromium } from "@playwright/test";
11
+ import {
12
+ createChromiumLaunchOptions,
13
+ reservePort,
14
+ startCapturedProcess,
15
+ startViteFixture,
16
+ stopProcess
17
+ } from "../../../tooling/testUtils/browserFixture.mjs";
18
+
19
+ const execFileAsync = promisify(execFile);
20
+ const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
21
+ const FIXTURE_ROOT = path.resolve(TEST_DIRECTORY, "../fixtures/production-build");
22
+ const VITE_CLI = path.resolve(TEST_DIRECTORY, "../../../node_modules/vite/bin/vite.js");
23
+ const RUN_BROWSER_TEST = process.env.JSKIT_SHELL_WEB_BROWSER_INTEGRATION === "1";
24
+ // The controls Vuetify's reset (button, input, select, textarea { font: inherit }) would restyle if it came after
25
+ // Vuetify's component styles.
26
+ const CONTROLS = Object.freeze({
27
+ button: "[data-testid=button-control]",
28
+ link: "[data-testid=link-control]",
29
+ input: "[data-testid=input-control] input",
30
+ textarea: "[data-testid=textarea-control] textarea",
31
+ select: "[data-testid=select-control] input:not([type=hidden])"
32
+ });
33
+
34
+ // Buttons whose state layer (Vuetify's overlay and underlay) must take the button's own shape, round or full.
35
+ const STATE_LAYERS = Object.freeze({
36
+ iconButton: "[data-testid=icon-control]",
37
+ avatarButton: "[data-testid=avatar-control]",
38
+ disabledButton: "[data-testid=disabled-control]"
39
+ });
40
+
41
+ async function readControls(page) {
42
+ await page.locator(CONTROLS.select).waitFor({ state: "attached" });
43
+ return page.evaluate(({ controls, stateLayers }) => {
44
+ const type = Object.entries(controls).map(([name, selector]) => {
45
+ const style = window.getComputedStyle(document.querySelector(selector));
46
+ const { fontFamily, fontSize, fontWeight, letterSpacing, lineHeight } = style;
47
+ return [name, { fontFamily, fontSize, fontWeight, letterSpacing, lineHeight }];
48
+ });
49
+ const shapes = Object.entries(stateLayers).map(([name, selector]) => {
50
+ const button = document.querySelector(selector);
51
+ const radius = (node) => window.getComputedStyle(node).borderTopLeftRadius;
52
+ return [name, {
53
+ button: radius(button),
54
+ overlay: radius(button.querySelector(".v-btn__overlay")),
55
+ underlay: radius(button.querySelector(".v-btn__underlay"))
56
+ }];
57
+ });
58
+ return Object.fromEntries([...type, ...shapes]);
59
+ }, { controls: CONTROLS, stateLayers: STATE_LAYERS });
60
+ }
61
+
62
+ // A production build links its shared component chunks' stylesheets before the entry's (the fixture's page links one
63
+ // such stylesheet first), which named vuetify-components before vuetify-core: every <button> v-btn lost
64
+ // label-large. The page JSKIT's Vite plugin builds names Vuetify's layer order first.
65
+ test("a production build styles buttons and fields as development does, with label-large on every button", {
66
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
67
+ timeout: 180_000
68
+ }, async (t) => {
69
+ const outDir = await mkdtemp(path.join(os.tmpdir(), "shell-web-production-build-"));
70
+ t.after(() => rm(outDir, { recursive: true, force: true }));
71
+ const config = path.join(FIXTURE_ROOT, "vite.config.mjs");
72
+ await execFileAsync(process.execPath, [VITE_CLI, "build", "--config", config, "--outDir", outDir, "--emptyOutDir", "--logLevel", "warn"], {
73
+ cwd: FIXTURE_ROOT
74
+ });
75
+ const port = await reservePort();
76
+ const preview = startCapturedProcess(process.execPath, [
77
+ VITE_CLI, "preview", "--config", config, "--outDir", outDir, "--port", String(port), "--strictPort"
78
+ ], { cwd: FIXTURE_ROOT });
79
+ // Stopped in after hooks, which run when the test fails or times out too (a body's `finally` doesn't after a timeout).
80
+ t.after(() => stopProcess(preview));
81
+ await preview.waitFor(new RegExp(`http://127\\.0\\.0\\.1:${port}/`, "u"));
82
+ const dev = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
83
+ t.after(() => stopProcess(dev));
84
+ const browser = await chromium.launch(createChromiumLaunchOptions());
85
+ t.after(() => browser.close());
86
+ const page = await browser.newPage();
87
+ await page.goto(`http://127.0.0.1:${port}/`);
88
+ const built = await readControls(page);
89
+ assert.deepEqual([built.button.fontSize, built.button.fontWeight], ["14px", "500"], "a <button> v-btn is label-large");
90
+ assert.deepEqual(built.link, built.button, "an <a> v-btn and a <button> one look alike");
91
+ for (const name of Object.keys(STATE_LAYERS)) {
92
+ const { button, overlay, underlay } = built[name];
93
+ assert.notEqual(button, "0px", `${name} has its shape`);
94
+ assert.deepEqual({ overlay, underlay }, { overlay: button, underlay: button }, `${name}'s state layer takes its shape`);
95
+ }
96
+ await page.goto(dev.baseURL);
97
+ assert.deepEqual(built, await readControls(page), "every control styles as in development");
98
+ });
@@ -80,10 +80,14 @@ test("shell-web shell layout registers navigation at the app layout level", asyn
80
80
  );
81
81
 
82
82
  // ShellLayout's bar is made of the pieces a layout with its own top app bar uses: one owner, no copy.
83
- assert.match(layoutSource, /useShellAppBar\(\);/u);
83
+ assert.match(layoutSource, /const \{ pageActions \} = useShellAppBar\(\);/u);
84
84
  assert.match(layoutSource, /<ShellUpButton v-if="canGoUp" class="shell-layout__leading" \/>/u);
85
85
  assert.match(layoutSource, /<ShellPageTitle :title="fallbackTitle" \/>/u);
86
- assert.match(layoutSource, /<ShellPageActionsTarget \/>/u);
86
+ assert.match(
87
+ layoutSource,
88
+ /<ShellPageActionsTarget>\s*<template v-if="topRightInMenu > 0" #menu>\s*<ShellOutlet target="shell-layout:top-right" :end="topRightInMenu" \/>/u
89
+ );
90
+ assert.match(layoutSource, /<ShellOutlet target="shell-layout:top-right" :start="topRightInMenu" \/>/u);
87
91
  assert.doesNotMatch(layoutSource, /\$arrowBack|PAGE_TITLE_ID|SHELL_PAGE_ACTIONS_ID|attachShell/u);
88
92
 
89
93
  assert.doesNotMatch(source, /<v-layout\b/);
@@ -94,12 +98,15 @@ test("shell-web shell layout registers navigation at the app layout level", asyn
94
98
  assert.match(source, /data-testid="jskit-shell-app-bar"/);
95
99
  assert.match(source, /:height="64"/u);
96
100
  assert.match(source, /:color="scrolled \? 'surface-container' : 'surface'"/u);
97
- assert.match(barPieces, /data-testid="jskit-shell-back"[\s\S]*:aria-label="t\('jskit\.shell\.actions\.back'\)"/u);
101
+ assert.match(barPieces, /data-testid="jskit-shell-back"[\s\S]*:aria-label="label"/u);
102
+ assert.match(barPieces, /: t\("jskit\.shell\.actions\.back"\)\)\);/u);
98
103
  assert.match(barPieces, /:id="PAGE_TITLE_ID"/u);
99
104
  assert.match(barPieces, /:id="SHELL_PAGE_ACTIONS_ID"/u);
100
105
  assert.match(barPieces, /provide\(SHELL_PAGE_ACTIONS_TARGET_KEY, `#\$\{SHELL_PAGE_ACTIONS_ID\}`\)/u);
101
106
  assert.match(barPieces, /release = navigationRuntime\.attachShell\(\);/u);
102
- assert.match(source, /shell-layout__surface-label/);
107
+ // The drawer's menu control stands alone, its tooltip its label; nothing beside it reads as its label.
108
+ assert.doesNotMatch(source, /shell-layout__surface-label/);
109
+ assert.match(source, /data-testid="jskit-shell-nav-toggle"[\s\S]*?<v-tooltip activator="parent" location="end" :text="drawerToggleLabel" \/>/u);
103
110
  assert.doesNotMatch(source, /shell-layout__surface-chip/);
104
111
  assert.doesNotMatch(source, /<v-chip[^>]*resolvedSurfaceLabel/);
105
112
  assert.match(source, /<v-bottom-navigation[\s\S]*target="shell-layout:primary-bottom-nav"/);