@jskit-ai/shell-web 0.2.51 → 0.2.52
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 +1 -0
- package/fixtures/adaptive-shell/src/NotesPage.vue +7 -2
- package/fixtures/adaptive-shell/src/main.js +10 -0
- package/package.json +4 -4
- package/patterns/application-shell/example/src/components/menus/TabLinkItem.vue +5 -0
- package/src/client/components/ShellMenuLinkItem.vue +5 -0
- package/src/client/components/ShellTabLinkItem.vue +11 -4
- package/src/client/composables/useShellNavigationLink.js +8 -0
- package/src/client/types.js +2 -0
- package/src/test/adaptiveShellSmoke.js +81 -0
- package/test/adaptiveShell.browser.test.js +57 -0
- package/test/colorContrast.browser.test.js +148 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **Breaking for apps' smoke checks:** a navigation bar destination takes `shortLabel`, the label a phone's bar shows (each destination there has about 68px); menus, the rail and the drawer keep `label`. A bar label wider than its slot now ends in an ellipsis inside it: the label could be 88px (5.5rem) wide in a 68px slot, so the centred button cut both its ends (mobilynet's "Metal servers" read "etal server"). The ellipsis is a fallback, not a pass: `runAdaptiveShellSmoke` and `runAdaptiveShellSmokeCase` now fail on any bar label that is cut or ends in an ellipsis, naming it, and `expectWholeNavigationBarLabels(bottomNavigation, expect)` (`@jskit-ai/shell-web/test/adaptiveShellSmoke`) runs the same check on any page. **An app whose bar labels run long must give those placements a `shortLabel` when it takes this JSKIT**, or its adaptive shell smoke fails. An app's own tab link wrapper that lists its props passes `shortLabel` on, as the application-shell pattern's `TabLinkItem` now does.
|
|
5
6
|
- A UI kit, `@jskit-ai/shell-web/client/ui`, through which an application gives JSKIT's views its own design system's button, dialog frame and text classes: `provideShellUi(vueApp, { Button, Dialog, text })`, once before it mounts, and `useShellUi()` in a view, which returns them. `Button` takes `emphasis` (`high`, `medium`, `subtle`, `low`), `tone` (`accent`, `neutral`, `danger`), `size` (`default`, `large`), `type`, `disabled`, `pending`, `block`, `href` and `icon`, with its label in the default slot; `Dialog` takes `open` and `title`, emits `close`, and has a default slot for its body and an `actions` slot; `text` maps the text roles `title`, `heading`, `subheading`, `strong`, `lead`, `body` and `caption` to class names. A kit is partial: the roles and text roles it leaves out are Material 3's, `ShellUiButton` (a Vuetify button: flat, tonal, outlined and text, in primary, secondary and error) and `ShellUiDialog` (a 440 px `v-dialog` named by its title), and Material's type scale (`MATERIAL_TEXT`); an unknown role or text role, a role that is not a component and a class that is not a string throw. It exports Vue components, so shell-web's `optimizeDeps.exclude` names `@jskit-ai/shell-web/client/ui` and a dependency scan leaves it source, as it leaves `@jskit-ai/shell-web/client`.
|
|
6
7
|
- `ShellErrorHost`'s banners no longer cover the page below a top app bar. They floated there over the top of the content, fixed and up to 1,120 px wide, and reserved no room, so on every page with an app bar a request recovery banner hid the content's first lines and took their clicks (Playwright: `.shell-error-host__banner` intercepts pointer events). They are now a top Vuetify layout item (`v-layout-item`) of their own measured height, placed after the app bar and the navigation, so `v-main` starts the content below them as it starts it below the app bar, and gives the room back when they close; content scrolled under them passes under them as under the app bar. On a surface without an app bar (sign-in) they still join the page flow above the content and publish `--shell-error-banners-inline-height`, as before. They keep their z-index (2600) and their look. An app that draws its own layout around `v-main` gets the same room, since Vuetify's layout reserves it.
|
|
7
8
|
- The environment banner of a staging page that real people use (its server has `STAGING_REACHES_REAL_PEOPLE=true`, so the page carries the kernel's `jskit-staging-reaches-real-people` tag) reads "Staging · real people", described as "Staging that real people use: email and text messages reach the people they are for, other messages are logged and payments use the sandbox.", in place of the test-copy wording; `installAppEnvironmentBanner` takes `reachesRealPeople`, read from the page when omitted. New message keys: `jskit.shell.appEnvironment.stagingRealPeople` and `stagingRealPeopleDescription`. Every other page's banner is unchanged.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
-
import { RouterLink } from "vue-router";
|
|
3
|
+
import { RouterLink, useRoute } from "vue-router";
|
|
4
4
|
import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
|
|
5
5
|
import ShellPrimaryAction from "../../../src/client/components/ShellPrimaryAction.vue";
|
|
6
6
|
|
|
@@ -10,8 +10,10 @@ import ShellPrimaryAction from "../../../src/client/components/ShellPrimaryActio
|
|
|
10
10
|
// while the dialog is open), "Remove access" (a second dialog over the first) and "Open contacts" (a link that leaves
|
|
11
11
|
// the page with the dialog open). "Note details" opens a dialog from its activator; "Report a problem" opens the
|
|
12
12
|
// shell's own error dialog. The note's "Archive note" and the dialog's "Remove access" each have a tooltip and open a
|
|
13
|
-
// dialog. Presses of the note's Edit and the dialogs' actions are counted.
|
|
13
|
+
// dialog. Presses of the note's Edit and the dialogs' actions are counted. `?unreadable=1` adds a line of text no one can
|
|
14
|
+
// read (#f2f2f2 on #f9f9ff, 1.07:1), which an accessibility check must fail.
|
|
14
15
|
const errorRuntime = useShellWebErrorRuntime();
|
|
16
|
+
const unreadable = useRoute().query.unreadable === "1";
|
|
15
17
|
const invite = ref(false);
|
|
16
18
|
const removeAccess = ref(false);
|
|
17
19
|
const archive = ref(false);
|
|
@@ -75,6 +77,9 @@ function reportProblem() {
|
|
|
75
77
|
<v-btn variant="text" data-testid="fixture-report-problem" @click="reportProblem">Report a problem</v-btn>
|
|
76
78
|
</div>
|
|
77
79
|
<p data-testid="fixture-notes-presses">{{ presses.join(",") }}</p>
|
|
80
|
+
<p v-if="unreadable" data-testid="fixture-unreadable" style="background: #f9f9ff; color: #f2f2f2;">
|
|
81
|
+
This line is unreadable on purpose.
|
|
82
|
+
</p>
|
|
78
83
|
|
|
79
84
|
<v-dialog v-model="invite" max-width="480" height="600" aria-label="Invite someone">
|
|
80
85
|
<v-card title="Invite someone" data-testid="fixture-invite-dialog">
|
|
@@ -211,6 +211,16 @@ const placements = [
|
|
|
211
211
|
}
|
|
212
212
|
];
|
|
213
213
|
|
|
214
|
+
// `?barLabel=short` names Suppliers "Supplier directory", too wide for a phone's navigation bar, with "Suppliers" as its
|
|
215
|
+
// label there; `?barLabel=long` gives it the long label alone.
|
|
216
|
+
const barLabel = new URLSearchParams(window.location.search).get("barLabel");
|
|
217
|
+
if (barLabel === "short" || barLabel === "long") {
|
|
218
|
+
Object.assign(placements.find(({ id }) => id === "fixture.home.suppliers").props, {
|
|
219
|
+
label: "Supplier directory",
|
|
220
|
+
...(barLabel === "short" ? { shortLabel: "Suppliers" } : {})
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
214
224
|
// `?topRight=3` gives the top app bar three items of its own, as an app's tools, status and avatar; the status draws a
|
|
215
225
|
// surface of its own on the page too.
|
|
216
226
|
const statusPlacements = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/shell-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"./locales/en.json": "./locales/en.json"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@jskit-ai/architecture-inspector": "0.1.
|
|
51
|
+
"@jskit-ai/architecture-inspector": "0.1.34"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@jskit-ai/material-web": "0.1.
|
|
54
|
+
"@jskit-ai/material-web": "0.1.11",
|
|
55
55
|
"@vue/compiler-sfc": "3.5.44"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@jskit-ai/kernel": "0.2.
|
|
58
|
+
"@jskit-ai/kernel": "0.2.35",
|
|
59
59
|
"pinia": "^4.0.3",
|
|
60
60
|
"vue": "^3.5.44",
|
|
61
61
|
"vue-router": "^5.3.1",
|
|
@@ -12,6 +12,11 @@ const props = defineProps({
|
|
|
12
12
|
type: [String, Object],
|
|
13
13
|
default: ""
|
|
14
14
|
},
|
|
15
|
+
// The navigation bar's shorter label for the same destination: a menu shows the whole label.
|
|
16
|
+
shortLabel: {
|
|
17
|
+
type: [String, Object],
|
|
18
|
+
default: ""
|
|
19
|
+
},
|
|
15
20
|
to: {
|
|
16
21
|
type: String,
|
|
17
22
|
default: ""
|
|
@@ -17,7 +17,8 @@ import ShellSectionTabLinkItem from "./ShellSectionTabLinkItem.vue";
|
|
|
17
17
|
|
|
18
18
|
// A Material 3 navigation bar destination: its icon and its label below, which @jskit-ai/material-web's material.css
|
|
19
19
|
// draws as it draws every v-bottom-navigation's buttons (the icon in its 64x32 indicator); the active one's icon is
|
|
20
|
-
// the filled one.
|
|
20
|
+
// the filled one. The label is the destination's shortLabel, else its label: a phone gives each destination about 68px,
|
|
21
|
+
// and a label wider than its slot ends in an ellipsis there, never cut at both ends by the centred button. It is one only in ShellLayout's navigation bar; placed anywhere else (a page's section tabs), it is
|
|
21
22
|
// a section tab, ShellSectionTabLinkItem, which a page.section-nav names itself. In the bar it is a text button, so
|
|
22
23
|
// no app's filled-button defaults fill it.
|
|
23
24
|
const props = defineProps(shellNavigationLinkProps);
|
|
@@ -25,7 +26,7 @@ const props = defineProps(shellNavigationLinkProps);
|
|
|
25
26
|
const presentation = inject(SHELL_NAVIGATION_PRESENTATION_KEY, NO_SHELL_NAVIGATION_PRESENTATION);
|
|
26
27
|
const inNavigationBar = computed(() => presentation.value === "bar");
|
|
27
28
|
const { t } = useJskitText();
|
|
28
|
-
const {
|
|
29
|
+
const { resolvedShortLabel, resolvedTarget, resolvedIcon } = useShellNavigationLink(props);
|
|
29
30
|
/** @type {{ aliases?: Record<string, unknown> }} */
|
|
30
31
|
const iconOptions = inject(VUETIFY_ICONS_KEY, NO_VUETIFY_ICONS);
|
|
31
32
|
const link = useLink({ to: computed(() => (resolvedTarget.value.sameOrigin && resolvedTarget.value.href) || "/") });
|
|
@@ -54,7 +55,7 @@ const displayIcon = computed(() =>
|
|
|
54
55
|
stacked
|
|
55
56
|
>
|
|
56
57
|
<v-icon v-if="displayIcon" :icon="displayIcon" />
|
|
57
|
-
<span class="tab-link-item__label">{{
|
|
58
|
+
<span class="tab-link-item__label">{{ resolvedShortLabel || t("jskit.shell.layout.tab") }}</span>
|
|
58
59
|
</v-btn>
|
|
59
60
|
</template>
|
|
60
61
|
|
|
@@ -66,8 +67,14 @@ const displayIcon = computed(() =>
|
|
|
66
67
|
padding-inline: 0;
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
/* The button's content, which clips, is the slot's width; the label is at most that, so its ellipsis shows. */
|
|
71
|
+
.tab-link-item :deep(.v-btn__content) {
|
|
72
|
+
max-width: 100%;
|
|
73
|
+
min-width: 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
.tab-link-item__label {
|
|
70
|
-
max-width:
|
|
77
|
+
max-width: 100%;
|
|
71
78
|
overflow: hidden;
|
|
72
79
|
text-overflow: ellipsis;
|
|
73
80
|
white-space: nowrap;
|
|
@@ -14,6 +14,12 @@ const shellNavigationLinkProps = Object.freeze({
|
|
|
14
14
|
type: [String, Object],
|
|
15
15
|
default: ""
|
|
16
16
|
},
|
|
17
|
+
// The label in the navigation bar, where a phone gives each destination about 68px; as `label`, and `label` when
|
|
18
|
+
// empty. Menus, the rail and the drawer show `label`.
|
|
19
|
+
shortLabel: {
|
|
20
|
+
type: [String, Object],
|
|
21
|
+
default: ""
|
|
22
|
+
},
|
|
17
23
|
to: {
|
|
18
24
|
type: String,
|
|
19
25
|
default: ""
|
|
@@ -53,6 +59,7 @@ function useShellNavigationLink(props) {
|
|
|
53
59
|
const { context: placementContext } = useWebPlacementContext();
|
|
54
60
|
const { text } = useJskitText();
|
|
55
61
|
const resolvedLabel = computed(() => text(props.label));
|
|
62
|
+
const resolvedShortLabel = computed(() => text(props.shortLabel) || resolvedLabel.value);
|
|
56
63
|
|
|
57
64
|
const resolvedTo = computed(() => {
|
|
58
65
|
const currentSurfaceId = resolveSurfaceIdFromPlacementPathname(placementContext.value, route.path);
|
|
@@ -81,6 +88,7 @@ function useShellNavigationLink(props) {
|
|
|
81
88
|
|
|
82
89
|
return {
|
|
83
90
|
resolvedLabel,
|
|
91
|
+
resolvedShortLabel,
|
|
84
92
|
resolvedTarget,
|
|
85
93
|
resolvedIcon
|
|
86
94
|
};
|
package/src/client/types.js
CHANGED
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
* The props of a surface-aware menu or tab link.
|
|
29
29
|
* @typedef {object} ShellNavigationLinkProps
|
|
30
30
|
* @property {string | { key: string, fallback?: string }} label A message key, `{ key, fallback }` or plain text.
|
|
31
|
+
* @property {string | { key: string, fallback?: string }} [shortLabel] The label in the navigation bar, as `label`;
|
|
32
|
+
* `label` when empty. A phone's bar gives each destination about 68px, and a label wider than that ends in an ellipsis.
|
|
31
33
|
* @property {string} to
|
|
32
34
|
* @property {string} icon
|
|
33
35
|
* @property {string} surface
|
|
@@ -210,6 +210,85 @@ async function expectContentAwareDrawerFit(drawer, expect) {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
// A phone's navigation bar gives each destination about 68px. Lists each label it does not show whole: one that ends in
|
|
214
|
+
// an ellipsis, and one cut by its destination or by anything in it that clips (a centred label wider than its slot loses
|
|
215
|
+
// both ends: mobilynet's "Metal servers" read "etal server"). Badges, icons and visually hidden text are not labels.
|
|
216
|
+
function readNavigationBarLabelProblems(bottomNavigation) {
|
|
217
|
+
return bottomNavigation.evaluate((bar) => {
|
|
218
|
+
const problems = [];
|
|
219
|
+
const fix = "give its destination a shortLabel that fits";
|
|
220
|
+
const visuallyHidden = (element, destination) => {
|
|
221
|
+
for (let current = element; current && current !== destination; current = current.parentElement) {
|
|
222
|
+
const box = current.getBoundingClientRect();
|
|
223
|
+
const style = window.getComputedStyle(current);
|
|
224
|
+
if (box.width <= 1 || box.height <= 1 || style.visibility === "hidden" || style.clipPath.startsWith("inset(50%")) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
};
|
|
230
|
+
for (const destination of bar.querySelectorAll(".v-btn")) {
|
|
231
|
+
const texts = document.createTreeWalker(destination, NodeFilter.SHOW_TEXT, {
|
|
232
|
+
acceptNode: (node) => node.textContent.trim() && !node.parentElement.closest(".v-icon, .v-badge__badge") &&
|
|
233
|
+
!visuallyHidden(node.parentElement, destination)
|
|
234
|
+
? NodeFilter.FILTER_ACCEPT
|
|
235
|
+
: NodeFilter.FILTER_REJECT
|
|
236
|
+
});
|
|
237
|
+
for (let node = texts.nextNode(); node; node = texts.nextNode()) {
|
|
238
|
+
const label = node.textContent.trim();
|
|
239
|
+
const range = document.createRange();
|
|
240
|
+
range.selectNodeContents(node);
|
|
241
|
+
const text = range.getBoundingClientRect();
|
|
242
|
+
range.detach?.();
|
|
243
|
+
if (text.width === 0) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// The element that ends the text in an ellipsis, if one does: the text shows to its edges.
|
|
247
|
+
let shortenedBy = null;
|
|
248
|
+
for (let element = node.parentElement; element && destination.contains(element); element = element.parentElement) {
|
|
249
|
+
if (window.getComputedStyle(element).textOverflow === "ellipsis" && element.scrollWidth > element.clientWidth) {
|
|
250
|
+
shortenedBy = element;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const shown = shortenedBy ? shortenedBy.getBoundingClientRect() : text;
|
|
255
|
+
let cut = false;
|
|
256
|
+
for (let element = shortenedBy ? shortenedBy.parentElement : node.parentElement;
|
|
257
|
+
element && destination.contains(element);
|
|
258
|
+
element = element.parentElement) {
|
|
259
|
+
if (element !== destination && window.getComputedStyle(element).overflowX === "visible") {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const box = element.getBoundingClientRect();
|
|
263
|
+
cut ||= shown.left < box.left - 0.5 || shown.right > box.right + 0.5;
|
|
264
|
+
}
|
|
265
|
+
const size = `${Math.round(text.width)}px of text in a ${Math.round(destination.getBoundingClientRect().width)}px destination`;
|
|
266
|
+
if (cut) {
|
|
267
|
+
problems.push(`"${label}" is cut in the navigation bar (${size}): ${fix}.`);
|
|
268
|
+
} else if (shortenedBy) {
|
|
269
|
+
problems.push(`"${label}" ends in an ellipsis in the navigation bar (${size}): ${fix}.`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return problems;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Every navigation bar label shows whole, once the fonts settle; otherwise fails naming each label and the fix.
|
|
278
|
+
async function expectWholeNavigationBarLabels(bottomNavigation, expect) {
|
|
279
|
+
let problems = [];
|
|
280
|
+
try {
|
|
281
|
+
await expect.poll(async () => {
|
|
282
|
+
problems = await readNavigationBarLabelProblems(bottomNavigation);
|
|
283
|
+
return problems.length;
|
|
284
|
+
}).toBe(0);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
throw new Error(`The navigation bar must show each destination's label whole:\n- ${problems.join("\n- ")}`, {
|
|
287
|
+
cause: error
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
213
292
|
async function readNavigationIconCenters(drawer, expect) {
|
|
214
293
|
const icons = drawer.locator("a.shell-menu-link-item[href] .v-icon");
|
|
215
294
|
await icons.first().waitFor({ state: "visible" });
|
|
@@ -424,6 +503,7 @@ async function runAdaptiveShellSmokeCase({
|
|
|
424
503
|
for (const height of navButtonHeights) {
|
|
425
504
|
expect(height).toBeGreaterThanOrEqual(48);
|
|
426
505
|
}
|
|
506
|
+
await expectWholeNavigationBarLabels(bottomNavigation, expect);
|
|
427
507
|
|
|
428
508
|
await pullToRefresh(page, expect);
|
|
429
509
|
await expect.poll(() => bootstrapRequests).toBeGreaterThan(bootstrapRequestsBeforePull);
|
|
@@ -488,6 +568,7 @@ function runAdaptiveShellSmoke({
|
|
|
488
568
|
export {
|
|
489
569
|
DEFAULT_VIEWPORTS,
|
|
490
570
|
expectNavigationBesideAppBar,
|
|
571
|
+
expectWholeNavigationBarLabels,
|
|
491
572
|
isRequestedOrDescendantLocation,
|
|
492
573
|
runAdaptiveShellSmoke,
|
|
493
574
|
runAdaptiveShellSmokeCase
|
|
@@ -322,6 +322,63 @@ test("the shared smoke case passes a phone shell whose destinations are all in t
|
|
|
322
322
|
await page.close();
|
|
323
323
|
});
|
|
324
324
|
|
|
325
|
+
// A phone's navigation bar gives each destination about 68px. mobilynet's "Metal servers" showed there as "etal server" on
|
|
326
|
+
// every console page: the label ran wider than its slot and the centred button cut both its ends. A destination's
|
|
327
|
+
// shortLabel is its label in the bar; a longer label ends in an ellipsis inside its slot; and the shared smoke case,
|
|
328
|
+
// which apps' own checks run, refuses a bar label that is cut or ends in an ellipsis, naming it and the fix.
|
|
329
|
+
test("a navigation bar destination shows its shortLabel, a longer label ends in an ellipsis inside its slot, and the shared smoke case refuses a cut or shortened one", {
|
|
330
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
331
|
+
timeout: 120_000
|
|
332
|
+
}, async (t) => {
|
|
333
|
+
const { vite, browser } = await startFixture(t);
|
|
334
|
+
const compact = DEFAULT_VIEWPORTS.find(({ name }) => name === "compact");
|
|
335
|
+
const expanded = DEFAULT_VIEWPORTS.find(({ name }) => name === "expanded");
|
|
336
|
+
const page = await browser.newPage({ baseURL: vite.baseURL });
|
|
337
|
+
const bar = page.getByTestId("jskit-shell-bottom-nav");
|
|
338
|
+
const fixWords = /give its destination a shortLabel/u;
|
|
339
|
+
|
|
340
|
+
// The short label is the bar's; the shared smoke case passes; the drawer of a wider window shows the whole label.
|
|
341
|
+
await runAdaptiveShellSmokeCase({ page, expect, smokePath: "/home?barLabel=short", viewport: compact });
|
|
342
|
+
await expect(bar.getByRole("link", { name: "Suppliers", exact: true })).toBeVisible();
|
|
343
|
+
await expect(bar.getByText("Supplier directory")).toHaveCount(0);
|
|
344
|
+
await page.setViewportSize({ width: expanded.width, height: expanded.height });
|
|
345
|
+
await expect(page.getByTestId("jskit-shell-drawer").getByRole("link", { name: "Supplier directory", exact: true })).toBeVisible();
|
|
346
|
+
|
|
347
|
+
// The long label alone ends in an ellipsis inside its own slot, and the shared smoke case names it.
|
|
348
|
+
await page.setViewportSize({ width: compact.width, height: compact.height });
|
|
349
|
+
await page.goto("/home?barLabel=long");
|
|
350
|
+
const longLabel = bar.getByRole("link", { name: "Supplier directory", exact: true }).locator(".tab-link-item__label");
|
|
351
|
+
await expect(longLabel).toBeVisible();
|
|
352
|
+
assert.deepEqual(await longLabel.evaluate((label) => {
|
|
353
|
+
const slot = label.closest(".v-btn").getBoundingClientRect();
|
|
354
|
+
const box = label.getBoundingClientRect();
|
|
355
|
+
return {
|
|
356
|
+
insideItsSlot: box.left >= slot.left - 0.5 && box.right <= slot.right + 0.5,
|
|
357
|
+
endsInEllipsis: window.getComputedStyle(label).textOverflow === "ellipsis" && label.scrollWidth > label.clientWidth
|
|
358
|
+
};
|
|
359
|
+
}), { insideItsSlot: true, endsInEllipsis: true });
|
|
360
|
+
await assert.rejects(
|
|
361
|
+
runAdaptiveShellSmokeCase({ page, expect, smokePath: "/home?barLabel=long", viewport: compact }),
|
|
362
|
+
(error) => /"Supplier directory" ends in an ellipsis in the navigation bar/u.test(error.message) && fixWords.test(error.message)
|
|
363
|
+
);
|
|
364
|
+
await page.close();
|
|
365
|
+
|
|
366
|
+
// A label the bar cuts without an ellipsis, as before: the shared smoke case names it too.
|
|
367
|
+
const cutPage = await browser.newPage({ baseURL: vite.baseURL });
|
|
368
|
+
await cutPage.addInitScript(() => {
|
|
369
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
370
|
+
const style = document.createElement("style");
|
|
371
|
+
style.textContent = ".tab-link-item__label { max-width: 5.5rem !important; text-overflow: clip !important; }";
|
|
372
|
+
document.head.append(style);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
await assert.rejects(
|
|
376
|
+
runAdaptiveShellSmokeCase({ page: cutPage, expect, smokePath: "/home?barLabel=long", viewport: compact }),
|
|
377
|
+
(error) => /"Supplier directory" is cut in the navigation bar/u.test(error.message) && fixWords.test(error.message)
|
|
378
|
+
);
|
|
379
|
+
await cutPage.close();
|
|
380
|
+
});
|
|
381
|
+
|
|
325
382
|
// Material 3 runs the rail and the standard drawer the window's full height beside the top app bar: their menu control
|
|
326
383
|
// shares the page title's row, the destinations start right below it, and an inner page keeps its Up arrow in the bar.
|
|
327
384
|
// A phone keeps its navigation bar and its modal drawer, opened from the app bar over everything.
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { expect } from "@playwright/test";
|
|
8
|
+
import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
9
|
+
|
|
10
|
+
// axe judges the contrast of every text on a shell page. Two things hid every text from it (color-contrast
|
|
11
|
+
// "incomplete", bgOverlap), so even text no one can read passed:
|
|
12
|
+
// - a closed menu that stays mounted, as ShellLayout's overflow menu does to keep the app bar's own items mounted on a
|
|
13
|
+
// phone, kept Vuetify's overlay root over the whole page: an absolute layer the size of the window at z-index 2000;
|
|
14
|
+
// - Vuetify draws a button's, chip's, list item's, card's and avatar's state layer and underlay over its label.
|
|
15
|
+
// material.css takes a closed overlay's root away once its content has gone, and draws the state layers under the
|
|
16
|
+
// content, as Material 3 orders them.
|
|
17
|
+
const SKIP = process.env.JSKIT_SHELL_WEB_BROWSER_INTEGRATION === "1"
|
|
18
|
+
? false
|
|
19
|
+
: "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1 to check axe judges the contrast of a shell page's text";
|
|
20
|
+
const FIXTURE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../fixtures/adaptive-shell");
|
|
21
|
+
const AXE_PATH = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
|
|
22
|
+
const open = sharedBrowserFixture({ fixtureRoot: FIXTURE_ROOT, configFile: "vite.config.mjs" });
|
|
23
|
+
const UNREADABLE = "p[data-testid=\"fixture-unreadable\"]";
|
|
24
|
+
|
|
25
|
+
// What axe may leave unjudged or fail on these pages, each for its reason; anything else fails the test.
|
|
26
|
+
// - emptyValue: an empty field has no text to judge.
|
|
27
|
+
// - shortTextContent: a label of one or two characters (an icon's ligature, a count) is too short for axe to judge.
|
|
28
|
+
// - field outline: an outlined field's text (its value, or its floating label in the outline's notch) lies under the
|
|
29
|
+
// field's own outline, which Vuetify draws as boxes over the field, transparent but for their borders, so the text
|
|
30
|
+
// shows on the field's background (axe-core 4.11 also reports an empty input under its resting label so).
|
|
31
|
+
// - disabled chip: a disabled chip's label is Material 3's disabled colour (on-surface at 38%), which WCAG 1.4.3
|
|
32
|
+
// exempts as part of an inactive control; Vuetify marks the chip disabled only with a `disabled` attribute on a
|
|
33
|
+
// span, which axe does not read as disabled.
|
|
34
|
+
async function contrastResults(page) {
|
|
35
|
+
if (!(await page.evaluate(() => Boolean(globalThis.axe)))) {
|
|
36
|
+
await page.addScriptTag({ path: AXE_PATH });
|
|
37
|
+
}
|
|
38
|
+
return page.evaluate(async () => {
|
|
39
|
+
const results = await globalThis.axe.run(document, { runOnly: { type: "rule", values: ["color-contrast"] } });
|
|
40
|
+
const name = (element) => `${element.tagName.toLowerCase()}${[...element.classList].slice(0, 2).map((c) => `.${c}`).join("")}`;
|
|
41
|
+
const nodes = (outcome) => outcome.flatMap((rule) => rule.nodes).map((node) => ({
|
|
42
|
+
node,
|
|
43
|
+
element: document.querySelector(node.target[0]),
|
|
44
|
+
reason: node.any.map((check) => check.data?.messageKey || check.message).join("|")
|
|
45
|
+
}));
|
|
46
|
+
globalThis.axe.setup(document);
|
|
47
|
+
try {
|
|
48
|
+
const incomplete = nodes(results.incomplete).filter(({ element, reason }) => {
|
|
49
|
+
if (reason === "emptyValue" || reason === "shortTextContent") {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const over = (globalThis.axe.commons.dom.getTextElementStack(element)[0] || [])[0];
|
|
53
|
+
const field = element.closest(".v-field");
|
|
54
|
+
return !(reason === "bgOverlap" && field && over && field.contains(over) &&
|
|
55
|
+
over.closest(".v-field__outline, .v-field-label"));
|
|
56
|
+
}).map(({ node, element, reason }) => {
|
|
57
|
+
const stack = globalThis.axe.commons.dom.getTextElementStack(element)[0] || [];
|
|
58
|
+
const over = stack.indexOf(element) > 0 ? ` under ${name(stack[0])}` : "";
|
|
59
|
+
return `${reason}: ${node.target.join(" ")} "${element.textContent.trim().slice(0, 30)}"${over}`;
|
|
60
|
+
});
|
|
61
|
+
const violations = nodes(results.violations)
|
|
62
|
+
.filter(({ element }) => !element.closest(".v-chip--disabled"))
|
|
63
|
+
.map(({ node }) => `${node.target.join(" ")} ${JSON.stringify(node.any.map((check) => check.data?.contrastRatio))}`);
|
|
64
|
+
return { violations, incomplete };
|
|
65
|
+
} finally {
|
|
66
|
+
globalThis.axe.teardown();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function expectJudged(page, where, violations) {
|
|
72
|
+
const results = await contrastResults(page);
|
|
73
|
+
assert.deepEqual(results.violations.map((violation) => violation.split(" [")[0]), violations,
|
|
74
|
+
`${where}: axe's color-contrast failures (${JSON.stringify(results.violations)})`);
|
|
75
|
+
assert.deepEqual(results.incomplete, [], `${where}: every text axe could not judge, with the element over it`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
test("axe judges every text on a shell page: unreadable text fails, and no closed menu or state layer covers a label", {
|
|
79
|
+
skip: SKIP,
|
|
80
|
+
timeout: 120_000
|
|
81
|
+
}, async (t) => {
|
|
82
|
+
const { vite, browser } = await open(t);
|
|
83
|
+
|
|
84
|
+
// A phone with the app bar's own items: ShellLayout mounts its overflow menu for them (closed, as all three fit);
|
|
85
|
+
// text buttons, a card and the FAB.
|
|
86
|
+
const phone = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 }, reducedMotion: "reduce" });
|
|
87
|
+
t.after(() => phone.close());
|
|
88
|
+
await phone.goto("/home/notes?topRight=3&unreadable=1");
|
|
89
|
+
await expect(phone.getByTestId("fixture-unreadable")).toBeVisible();
|
|
90
|
+
await expect(phone.getByTestId("jskit-shell-page-actions-overflow-items")).toBeAttached();
|
|
91
|
+
await expectJudged(phone, "notes at 390 with the overflow menu closed", [UNREADABLE]);
|
|
92
|
+
|
|
93
|
+
// Segmented buttons, filter chips, an active list item and fields; buttons and chips in every variant and state, an
|
|
94
|
+
// avatar and a pagination; cards in each variant; an outlined field with a value.
|
|
95
|
+
for (const route of ["/home/components?topRight=3", "/home/button-states", "/home/buttons", "/home/feedback"]) {
|
|
96
|
+
await phone.goto(route);
|
|
97
|
+
await expect(phone.getByTestId("jskit-shell-page-title")).toBeVisible();
|
|
98
|
+
await expectJudged(phone, `${route} at 390`, []);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const desktop = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 900 }, reducedMotion: "reduce" });
|
|
102
|
+
t.after(() => desktop.close());
|
|
103
|
+
await desktop.goto("/home/notes?unreadable=1");
|
|
104
|
+
await expect(desktop.getByTestId("fixture-unreadable")).toBeVisible();
|
|
105
|
+
await expectJudged(desktop, "notes at 1280", [UNREADABLE]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("a menu mounted while closed covers nothing, and still opens and closes with its animation", {
|
|
109
|
+
skip: SKIP,
|
|
110
|
+
timeout: 60_000
|
|
111
|
+
}, async (t) => {
|
|
112
|
+
const { vite, browser } = await open(t);
|
|
113
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
|
|
114
|
+
t.after(() => page.close());
|
|
115
|
+
await page.goto("/home/actions?topRight=3&title=Actions");
|
|
116
|
+
const items = page.getByTestId("jskit-shell-page-actions-overflow-items");
|
|
117
|
+
await expect(items).toBeAttached();
|
|
118
|
+
const root = () => items.evaluate((element) => getComputedStyle(element.closest(".v-overlay")).display);
|
|
119
|
+
assert.equal(await root(), "none", "the closed menu's overlay is not drawn");
|
|
120
|
+
|
|
121
|
+
await page.getByTestId("jskit-shell-page-actions-overflow").click();
|
|
122
|
+
await expect(page.getByRole("menu")).toBeVisible();
|
|
123
|
+
assert.notEqual(await root(), "none", "the open menu's overlay is drawn");
|
|
124
|
+
await items.evaluate((element) => Promise.all(element.closest(".v-overlay__content").getAnimations().map((animation) => animation.finished)));
|
|
125
|
+
|
|
126
|
+
// Frame by frame from Escape until the overlay is gone: its content animates out while the overlay is still drawn.
|
|
127
|
+
const frames = items.evaluate(async (element) => {
|
|
128
|
+
const content = element.closest(".v-overlay__content");
|
|
129
|
+
const overlay = content.parentElement;
|
|
130
|
+
const seen = [];
|
|
131
|
+
const started = performance.now();
|
|
132
|
+
while (performance.now() - started < 3000) {
|
|
133
|
+
const animating = content.getAnimations().some((animation) => animation.playState === "running");
|
|
134
|
+
seen.push({ overlay: getComputedStyle(overlay).display, content: content.style.display || "shown", animating });
|
|
135
|
+
if (seen.at(-1).overlay === "none") {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
139
|
+
}
|
|
140
|
+
return seen;
|
|
141
|
+
});
|
|
142
|
+
await page.keyboard.press("Escape");
|
|
143
|
+
const seen = await frames;
|
|
144
|
+
assert.ok(seen.some((frame) => frame.overlay !== "none" && frame.content === "shown" && frame.animating),
|
|
145
|
+
`the menu animates out while its overlay is drawn: ${JSON.stringify(seen.filter((_, index) => index % 4 === 0))}`);
|
|
146
|
+
assert.equal(seen.at(-1).overlay, "none", "once closed, the menu's overlay is gone again");
|
|
147
|
+
await expect(items).toBeAttached();
|
|
148
|
+
});
|