@jskit-ai/shell-web 0.2.37 → 0.2.39
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 +3 -0
- package/fixtures/adaptive-shell/src/PendingActionsPage.vue +51 -0
- package/fixtures/adaptive-shell/src/PendingDialogPage.vue +57 -0
- package/fixtures/adaptive-shell/src/main.js +4 -0
- package/fixtures/{test-copy-banner → app-environment-banner}/index.html +1 -1
- package/fixtures/{test-copy-banner → app-environment-banner}/src/main.js +2 -2
- package/fixtures/app-environment-banner/vite.config.mjs +17 -0
- package/locales/en.json +7 -3
- package/package.json +6 -4
- package/src/client/appEnvironment/appEnvironmentBanner.js +89 -0
- package/src/client/components/ShellLayout.vue +2 -1
- package/src/client/components/ShellNavigationItem.vue +55 -26
- package/src/client/components/ShellPageAction.vue +18 -3
- package/src/client/components/ShellPageActionsTarget.vue +1 -1
- package/src/client/components/ShellPrimaryAction.vue +13 -2
- package/src/client/directives/vPending.js +111 -0
- package/src/client/index.js +1 -0
- package/src/client/providers/ShellWebClientProvider.js +6 -6
- package/src/client/support/navigationPresentation.js +8 -0
- package/src/client/support/pageActions.js +1 -0
- package/test/adaptiveShell.browser.test.js +95 -0
- package/test/{testCopyBanner.browser.test.js → appEnvironmentBanner.browser.test.js} +27 -13
- package/test/appEnvironmentBanner.test.js +71 -0
- package/test/pendingAction.browser.test.js +182 -0
- package/test/provider.test.js +2 -2
- package/test/vPending.test.js +151 -0
- package/fixtures/test-copy-banner/vite.config.mjs +0 -17
- package/src/client/sideEffects/testCopyBanner.js +0 -86
- package/test/testCopyBanner.test.js +0 -64
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// `v-pending="running"`: a command button that keeps keyboard focus while its action runs. A focused button that
|
|
2
|
+
// becomes `disabled` loses focus (Chromium moves it to the page body), so a keyboard or screen-reader user who pressed
|
|
3
|
+
// Save, Send or "Load more" lands back at the top of the page. While `running` is true the button stays enabled and
|
|
4
|
+
// focusable instead: it reads as unavailable (`aria-disabled="true"`) and ignores activation, so a second click, Enter
|
|
5
|
+
// or Space, or a form's implicit submission through it, does nothing until the action settles. When it settles with
|
|
6
|
+
// focus still on the button, focus moves to the first field the action's refusal marked (a Vuetify field showing an
|
|
7
|
+
// error, or a control with `aria-invalid="true"`): in the button's form, else its dialog, else the page. Without one,
|
|
8
|
+
// focus stays on the button.
|
|
9
|
+
//
|
|
10
|
+
// Put it on the button (`v-btn`, `button`), or on a component that wraps one (`v-fab`, or a live action's `v-checkbox`
|
|
11
|
+
// or `v-switch`): the control is the element itself when it is a button, a link, a checkbox or a radio, or else the
|
|
12
|
+
// first one inside it. Use it in place of `:disabled` for the pending state; `disabled` stays for an action that cannot
|
|
13
|
+
// run at all. Give the button a pending label ("Saving…").
|
|
14
|
+
|
|
15
|
+
const CONTROL =
|
|
16
|
+
"button, a[href], input[type='submit'], input[type='button'], input[type='checkbox'], input[type='radio'], [role='button']";
|
|
17
|
+
const MARKED_FIELD = ".v-input--error, [aria-invalid='true']";
|
|
18
|
+
// A control that can take focus. A marked radio group may start with a disabled choice (the current one), and a select
|
|
19
|
+
// keeps its value in a hidden input, so the first enabled, visible control is the one focused.
|
|
20
|
+
const FOCUSABLE =
|
|
21
|
+
"input:not([type='hidden'], :disabled), textarea:not(:disabled), select:not(:disabled), button:not(:disabled), " +
|
|
22
|
+
"[tabindex]:not([tabindex='-1'])";
|
|
23
|
+
const DIALOG = ".v-overlay__content, [role='dialog'], [role='alertdialog'], dialog";
|
|
24
|
+
const STATE = Symbol("jskit.shell-web.pending");
|
|
25
|
+
|
|
26
|
+
/** @param {Element} element */
|
|
27
|
+
function controlOf(element) {
|
|
28
|
+
return element.matches(CONTROL) ? element : element.querySelector(CONTROL) || element;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Capturing on the button (or its wrapper), so its own click handlers, a router link's navigation and a submit
|
|
33
|
+
* button's form submission never see the activation.
|
|
34
|
+
* @param {Event} event
|
|
35
|
+
*/
|
|
36
|
+
function ignoreWhilePending(event) {
|
|
37
|
+
if (event.currentTarget[STATE]?.pending) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
event.stopImmediatePropagation();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @param {Element} control */
|
|
44
|
+
function firstMarkedField(control) {
|
|
45
|
+
const scope = control.form || control.closest(DIALOG) || control.ownerDocument;
|
|
46
|
+
for (const marked of scope.querySelectorAll(MARKED_FIELD)) {
|
|
47
|
+
const field = marked.matches(FOCUSABLE) ? marked : marked.querySelector(FOCUSABLE);
|
|
48
|
+
if (field && field.getClientRects().length > 0) {
|
|
49
|
+
return field;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {Element} element
|
|
57
|
+
* @param {boolean} pending
|
|
58
|
+
*/
|
|
59
|
+
function mark(element, pending) {
|
|
60
|
+
const state = element[STATE];
|
|
61
|
+
const control = controlOf(element);
|
|
62
|
+
state.pending = pending;
|
|
63
|
+
if (pending) {
|
|
64
|
+
control.setAttribute("aria-disabled", "true");
|
|
65
|
+
state.marked = control;
|
|
66
|
+
} else if (state.marked) {
|
|
67
|
+
state.marked.removeAttribute("aria-disabled");
|
|
68
|
+
state.marked = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The action settled with focus on its button: once the refusal's field errors have drawn, the first marked field
|
|
74
|
+
* takes focus. A later move of focus by the person, or the button going away, leaves focus alone.
|
|
75
|
+
* @param {Element} element
|
|
76
|
+
*/
|
|
77
|
+
function settle(element) {
|
|
78
|
+
const state = element[STATE];
|
|
79
|
+
clearTimeout(state.settling);
|
|
80
|
+
state.settling = setTimeout(() => {
|
|
81
|
+
state.settling = 0;
|
|
82
|
+
if (state.pending || !element.contains(element.ownerDocument.activeElement)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
firstMarkedField(controlOf(element))?.focus();
|
|
86
|
+
}, 0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @type {import("vue").ObjectDirective<HTMLElement, boolean | undefined>} */
|
|
90
|
+
const vPending = {
|
|
91
|
+
mounted(element, binding) {
|
|
92
|
+
element[STATE] = { pending: false, marked: null, settling: 0 };
|
|
93
|
+
element.addEventListener("click", ignoreWhilePending, true);
|
|
94
|
+
mark(element, Boolean(binding.value));
|
|
95
|
+
},
|
|
96
|
+
updated(element, binding) {
|
|
97
|
+
const pending = Boolean(binding.value);
|
|
98
|
+
const wasPending = element[STATE].pending;
|
|
99
|
+
mark(element, pending);
|
|
100
|
+
if (wasPending && !pending && element.contains(element.ownerDocument.activeElement)) {
|
|
101
|
+
settle(element);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
beforeUnmount(element) {
|
|
105
|
+
clearTimeout(element[STATE]?.settling);
|
|
106
|
+
element.removeEventListener("click", ignoreWhilePending, true);
|
|
107
|
+
delete element[STATE];
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { vPending };
|
package/src/client/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export { useShellLayoutState } from "./composables/useShellLayoutState.js";
|
|
|
23
23
|
export { useShellPageTitle } from "./composables/useShellPageTitle.js";
|
|
24
24
|
export { useShellPageClose } from "./composables/useShellPageClose.js";
|
|
25
25
|
export { useShellWindowSizeClass } from "./composables/useShellWindowSizeClass.js";
|
|
26
|
+
export { vPending } from "./directives/vPending.js";
|
|
26
27
|
export { useShellNavigation } from "./navigation/useShellNavigation.js";
|
|
27
28
|
export { leaveApp, reloadAppPage } from "./navigation/documentNavigation.js";
|
|
28
29
|
export { useShellLayoutStore } from "./stores/useShellLayoutStore.js";
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "../asyncModuleRecovery/inject.js";
|
|
11
11
|
import { createShellAsyncModuleRecoveryRuntime } from "../asyncModuleRecovery/runtime.js";
|
|
12
12
|
import { createShellClientUpdateRuntime } from "../clientUpdate/runtime.js";
|
|
13
|
-
import {
|
|
13
|
+
import { createAppEnvironmentBannerRuntime } from "../appEnvironment/appEnvironmentBanner.js";
|
|
14
14
|
import {
|
|
15
15
|
SHELL_REQUEST_RECOVERY_RUNTIME_KEY
|
|
16
16
|
} from "../requestRecovery/inject.js";
|
|
@@ -337,7 +337,7 @@ const ShellWebClientProvider = defineProvider({
|
|
|
337
337
|
logger
|
|
338
338
|
});
|
|
339
339
|
const navigationRuntime = createShellNavigationRuntime({ router });
|
|
340
|
-
const
|
|
340
|
+
const appEnvironmentBannerRuntime = createAppEnvironmentBannerRuntime();
|
|
341
341
|
|
|
342
342
|
return {
|
|
343
343
|
shell: Object.freeze({
|
|
@@ -351,7 +351,7 @@ const ShellWebClientProvider = defineProvider({
|
|
|
351
351
|
placement: placementRuntime,
|
|
352
352
|
refresh: refreshRuntime,
|
|
353
353
|
requestRecovery: requestRecoveryRuntime,
|
|
354
|
-
|
|
354
|
+
appEnvironmentBanner: appEnvironmentBannerRuntime
|
|
355
355
|
})
|
|
356
356
|
};
|
|
357
357
|
},
|
|
@@ -370,8 +370,8 @@ const ShellWebClientProvider = defineProvider({
|
|
|
370
370
|
asyncModuleRecoveryRuntime.install();
|
|
371
371
|
// Before the router's first navigation, so the trail starts with the page the tab opened on.
|
|
372
372
|
navigationRuntime.install();
|
|
373
|
-
//
|
|
374
|
-
outputs.shell.
|
|
373
|
+
// Development, test and staging pages say so from the first frame, whatever the application's layout.
|
|
374
|
+
outputs.shell.appEnvironmentBanner.install();
|
|
375
375
|
|
|
376
376
|
const appModules = importAppModules();
|
|
377
377
|
const placementTopology = await loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime, appModules.placementTopology);
|
|
@@ -413,7 +413,7 @@ const ShellWebClientProvider = defineProvider({
|
|
|
413
413
|
installRouterErrorBridge(router, errorRuntime, logger);
|
|
414
414
|
},
|
|
415
415
|
shutdown(_dependencies, { outputs }) {
|
|
416
|
-
outputs.shell.
|
|
416
|
+
outputs.shell.appEnvironmentBanner.dispose();
|
|
417
417
|
outputs.shell.navigation.dispose();
|
|
418
418
|
outputs.shell.clientUpdate.dispose();
|
|
419
419
|
outputs.shell.requestRecovery.dispose();
|
|
@@ -12,6 +12,12 @@ const NO_SHELL_PAGE_ACTIONS_TARGET = "";
|
|
|
12
12
|
/** Vuetify's icon options, which hold the theme's aliases (Vuetify provides them under this global symbol). */
|
|
13
13
|
const VUETIFY_ICONS_KEY = Symbol.for("vuetify:icons");
|
|
14
14
|
const NO_VUETIFY_ICONS = Object.freeze({ aliases: Object.freeze({}) });
|
|
15
|
+
/**
|
|
16
|
+
* The list a Vuetify v-list provides to what it holds (under this global symbol); in one, Vuetify gives a link item
|
|
17
|
+
* the role "link". Outside a list, as in the navigation bar, there is none.
|
|
18
|
+
*/
|
|
19
|
+
const VUETIFY_LIST_KEY = Symbol.for("vuetify:list");
|
|
20
|
+
const NO_VUETIFY_LIST = null;
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* The filled form of a navigation icon alias for the active destination: Material 3 shows the active destination's
|
|
@@ -32,9 +38,11 @@ export {
|
|
|
32
38
|
NO_SHELL_NAVIGATION_PRESENTATION,
|
|
33
39
|
NO_SHELL_PAGE_ACTIONS_TARGET,
|
|
34
40
|
NO_VUETIFY_ICONS,
|
|
41
|
+
NO_VUETIFY_LIST,
|
|
35
42
|
SHELL_NAVIGATION_PRESENTATION_KEY,
|
|
36
43
|
SHELL_PAGE_ACTIONS_ID,
|
|
37
44
|
SHELL_PAGE_ACTIONS_TARGET_KEY,
|
|
38
45
|
VUETIFY_ICONS_KEY,
|
|
46
|
+
VUETIFY_LIST_KEY,
|
|
39
47
|
filledIconAlias
|
|
40
48
|
};
|
|
@@ -375,6 +375,101 @@ test("the rail and the drawer run the window's full height beside the top app ba
|
|
|
375
375
|
await page.close();
|
|
376
376
|
});
|
|
377
377
|
|
|
378
|
+
// What a navigation list holds as assistive technology sees it, as axe reads it: the roles of its children, where a
|
|
379
|
+
// child with no role of its own (a div) or a presentational one hands its children to the list; and for each
|
|
380
|
+
// destination, the links in its list item and where it sits in the list.
|
|
381
|
+
function readNavigationList(list) {
|
|
382
|
+
return list.evaluate((element) => {
|
|
383
|
+
const implicitRole = (node) => ({ A: node.hasAttribute("href") ? "link" : "", HR: "separator", LI: "listitem" })[node.tagName] || "";
|
|
384
|
+
const owned = [];
|
|
385
|
+
const own = (node) => {
|
|
386
|
+
const role = node.getAttribute("role") || implicitRole(node);
|
|
387
|
+
if (!role || role === "presentation" || role === "none") {
|
|
388
|
+
for (const child of node.children) own(child);
|
|
389
|
+
} else {
|
|
390
|
+
owned.push(role);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
for (const child of element.children) own(child);
|
|
394
|
+
const top = element.getBoundingClientRect().top;
|
|
395
|
+
return {
|
|
396
|
+
role: element.getAttribute("role"),
|
|
397
|
+
owned,
|
|
398
|
+
destinations: [...element.querySelectorAll(".v-list-item")].map((item) => ({
|
|
399
|
+
links: [...(item.closest("[role=listitem]")?.querySelectorAll("[role=link]") || [])].map((link) => link.textContent.trim()),
|
|
400
|
+
top: Math.round(item.getBoundingClientRect().top - top),
|
|
401
|
+
height: Math.round(item.getBoundingClientRect().height)
|
|
402
|
+
})),
|
|
403
|
+
dividers: [...element.querySelectorAll("hr")].map((hr) => ({
|
|
404
|
+
role: hr.getAttribute("role"),
|
|
405
|
+
orientation: hr.getAttribute("aria-orientation")
|
|
406
|
+
}))
|
|
407
|
+
};
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// axe's aria-required-children (WCAG 1.3.1 Info and Relationships): a list holds only list items. Vuetify makes a
|
|
412
|
+
// navigation item in a v-list the link itself and the drawer's divider an hr, a separator, so the drawer's and the
|
|
413
|
+
// rail's lists held links and a separator. Each destination is a list item holding its link, the divider is
|
|
414
|
+
// presentational, and the destinations sit where they did: 4dp apart in the drawer and the rail, the divider 8dp from
|
|
415
|
+
// each group. The navigation bar is no list, so its destinations are not list items.
|
|
416
|
+
test("the drawer's, the rail's and a section's navigation lists hold only list items, each with its link: WCAG 1.3.1 (axe aria-required-children)", {
|
|
417
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
418
|
+
timeout: 120_000
|
|
419
|
+
}, async (t) => {
|
|
420
|
+
const { vite, browser } = await startFixture(t);
|
|
421
|
+
const home = ["Home", "Settings", "Contacts", "Suppliers", "Bookings", "Help and support"];
|
|
422
|
+
const drawerList = "[data-testid=jskit-shell-drawer] .shell-layout__drawer-list";
|
|
423
|
+
// Each destination's top in its list, as drawn before the list items: in the drawer 4dp apart, Help and support
|
|
424
|
+
// past the 1dp divider 8dp from each group; in the rail 4dp apart; in a phone's drawer after the hidden divider;
|
|
425
|
+
// in a settings section's list under its 8dp padding.
|
|
426
|
+
const drawerTops = [0, 60, 120, 180, 240, 313];
|
|
427
|
+
const railTops = [0, 60, 120, 180, 240, 300];
|
|
428
|
+
const cases = [
|
|
429
|
+
{ at: "expanded drawer", width: 1280, height: 900, path: "/home", list: drawerList, labels: home, tops: drawerTops, dividers: 1 },
|
|
430
|
+
{ at: "expanded rail", width: 1280, height: 900, path: "/home", toggle: true, list: drawerList, labels: home, tops: railTops, dividers: 1 },
|
|
431
|
+
{
|
|
432
|
+
at: "medium rail",
|
|
433
|
+
width: 768,
|
|
434
|
+
height: 1024,
|
|
435
|
+
path: "/home",
|
|
436
|
+
list: "[data-testid=jskit-shell-rail] .shell-layout__rail-list",
|
|
437
|
+
labels: home,
|
|
438
|
+
tops: railTops,
|
|
439
|
+
dividers: 0
|
|
440
|
+
},
|
|
441
|
+
{ at: "medium drawer", width: 768, height: 1024, path: "/home", toggle: true, list: drawerList, labels: home, tops: drawerTops, dividers: 1 },
|
|
442
|
+
{ at: "compact drawer", width: 390, height: 844, path: "/home", toggle: true, list: drawerList, labels: ["Help and support"], tops: [4], dividers: 1 },
|
|
443
|
+
{ at: "settings section", width: 1280, height: 900, path: "/home/settings", list: ".v-main .v-list--nav", labels: ["General"], tops: [8], dividers: 0 }
|
|
444
|
+
];
|
|
445
|
+
for (const { at, width, height, path: pagePath, toggle, list, labels, tops, dividers } of cases) {
|
|
446
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width, height }, reducedMotion: "reduce" });
|
|
447
|
+
await page.goto(pagePath);
|
|
448
|
+
if (toggle) await page.locator("[data-testid=jskit-shell-nav-toggle]:visible").first().click();
|
|
449
|
+
const navigation = page.locator(list);
|
|
450
|
+
await expect(navigation.locator(".v-list-item").first(), at).toBeVisible();
|
|
451
|
+
// The drawer settles from opening or collapsing before the destinations are read.
|
|
452
|
+
await expect.poll(async () => (await readNavigationList(navigation)).destinations.map(({ top }) => top), { message: at })
|
|
453
|
+
.toEqual(tops);
|
|
454
|
+
const read = await readNavigationList(navigation);
|
|
455
|
+
assert.equal(read.role, "list", `${at}: a list`);
|
|
456
|
+
assert.deepEqual(read.owned, labels.map(() => "listitem"), `${at}: what the list holds`);
|
|
457
|
+
assert.deepEqual(read.destinations.map(({ links }) => links), labels.map((label) => [label]), `${at}: each list item's link`);
|
|
458
|
+
assert.ok(read.destinations.every((destination) => destination.height >= 56), `${at}: 56dp destinations`);
|
|
459
|
+
assert.deepEqual(read.dividers, Array.from({ length: dividers }, () => ({ role: "presentation", orientation: null })), `${at}: the divider`);
|
|
460
|
+
for (const label of labels) {
|
|
461
|
+
const item = navigation.getByRole("listitem").filter({ has: page.getByRole("link", { name: label, exact: true }) });
|
|
462
|
+
await expect(item, `${at}: ${label}`).toHaveCount(1);
|
|
463
|
+
}
|
|
464
|
+
if (width < 600) {
|
|
465
|
+
const bar = page.getByTestId("jskit-shell-bottom-nav");
|
|
466
|
+
await expect(bar.getByRole("link").first(), `${at}: the navigation bar`).toBeVisible();
|
|
467
|
+
await expect(bar.locator("[role=list], [role=listitem]"), `${at}: no list in the navigation bar`).toHaveCount(0);
|
|
468
|
+
}
|
|
469
|
+
await page.close();
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
378
473
|
test("shell-web preserves the active form across responsive changes", {
|
|
379
474
|
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
380
475
|
timeout: 90_000
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "../../../tooling/testUtils/browserFixture.mjs";
|
|
12
12
|
|
|
13
13
|
const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
const FIXTURE_ROOT = path.resolve(TEST_DIRECTORY, "../fixtures/
|
|
14
|
+
const FIXTURE_ROOT = path.resolve(TEST_DIRECTORY, "../fixtures/app-environment-banner");
|
|
15
15
|
const RUN_BROWSER_TEST = process.env.JSKIT_SHELL_WEB_BROWSER_INTEGRATION === "1";
|
|
16
16
|
const VIEWPORTS = Object.freeze([
|
|
17
17
|
{ name: "compact", width: 360, height: 740 },
|
|
@@ -43,10 +43,10 @@ async function startFixture(t, env) {
|
|
|
43
43
|
return { vite, browser };
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
test("a
|
|
46
|
+
test("a development page shows the Development banner at every width, in light and dark, without taking a click", {
|
|
47
47
|
skip: !RUN_BROWSER_TEST
|
|
48
48
|
}, async (t) => {
|
|
49
|
-
const { vite, browser } = await startFixture(t, {
|
|
49
|
+
const { vite, browser } = await startFixture(t, { APP_ENV: "development" });
|
|
50
50
|
for (const colorScheme of ["light", "dark"]) {
|
|
51
51
|
for (const viewport of VIEWPORTS) {
|
|
52
52
|
const context = await browser.newContext({ viewport, colorScheme });
|
|
@@ -55,10 +55,10 @@ test("a simulating page shows the Test copy banner at every width, in light and
|
|
|
55
55
|
await page.goto(vite.baseURL);
|
|
56
56
|
await page.waitForSelector("html[data-ready=true]");
|
|
57
57
|
const label = `${colorScheme} ${viewport.name}`;
|
|
58
|
-
const banner = page.getByTestId("jskit-
|
|
59
|
-
assert.equal(await banner.textContent(), "
|
|
60
|
-
assert.equal(await page.getByRole("note").textContent(), "
|
|
61
|
-
assert.equal(await banner.getAttribute("aria-description"), "
|
|
58
|
+
const banner = page.getByTestId("jskit-app-environment-banner");
|
|
59
|
+
assert.equal(await banner.textContent(), "Development", label);
|
|
60
|
+
assert.equal(await page.getByRole("note").textContent(), "Development", `${label}: a note`);
|
|
61
|
+
assert.equal(await banner.getAttribute("aria-description"), "Development: emails and messages are logged, not sent; payments use the sandbox.", label);
|
|
62
62
|
// An application's inexact field lookup finds only its Email field, never the banner whose sentence says emails.
|
|
63
63
|
assert.equal(await page.getByLabel("Email").count(), 1, `${label}: one Email match`);
|
|
64
64
|
assert.equal(await page.getByLabel("Email").getAttribute("id"), "email", `${label}: the Email field`);
|
|
@@ -80,10 +80,24 @@ test("a simulating page shows the Test copy banner at every width, in light and
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
test("a
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
test("a test page shows Test and a staging page Staging, at the narrowest width; a production page shows none", {
|
|
84
|
+
skip: !RUN_BROWSER_TEST
|
|
85
|
+
}, async (t) => {
|
|
86
|
+
for (const [APP_ENV, expected] of [["test", "Test"], ["staging", "Staging"], ["production", null]]) {
|
|
87
|
+
await t.test(APP_ENV, async (subtest) => {
|
|
88
|
+
const { vite, browser } = await startFixture(subtest, { APP_ENV });
|
|
89
|
+
const page = await browser.newPage({ viewport: VIEWPORTS[0] });
|
|
90
|
+
await page.goto(vite.baseURL);
|
|
91
|
+
await page.waitForSelector("html[data-ready=true]");
|
|
92
|
+
const banner = page.getByTestId("jskit-app-environment-banner");
|
|
93
|
+
if (expected === null) {
|
|
94
|
+
assert.equal(await banner.count(), 0);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
assert.equal(await banner.textContent(), expected);
|
|
98
|
+
const box = await banner.boundingBox();
|
|
99
|
+
assert.ok(box.width < VIEWPORTS[0].width / 2, `${APP_ENV}: small (${box.width})`);
|
|
100
|
+
assert.equal(await page.getByLabel("Email").count(), 1, `${APP_ENV}: one Email match`);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
89
103
|
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createAppEnvironmentBannerRuntime, installAppEnvironmentBanner } from "../src/client/appEnvironment/appEnvironmentBanner.js";
|
|
4
|
+
|
|
5
|
+
// The part of a document the banner uses: a body to append to, elements, and lookup by id.
|
|
6
|
+
function fakeDocument(environment) {
|
|
7
|
+
const appended = [];
|
|
8
|
+
const documentObject = {
|
|
9
|
+
appended,
|
|
10
|
+
body: {
|
|
11
|
+
append(element) {
|
|
12
|
+
appended.push(element);
|
|
13
|
+
element.remove = () => appended.splice(appended.indexOf(element), 1);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
createElement(tag) {
|
|
17
|
+
const attributes = {};
|
|
18
|
+
return { tag, style: {}, attributes, setAttribute: (name, value) => { attributes[name] = value; } };
|
|
19
|
+
},
|
|
20
|
+
getElementById: (id) => appended.find((element) => element.id === id) || null,
|
|
21
|
+
querySelector: () => (environment === undefined ? null : { getAttribute: () => environment })
|
|
22
|
+
};
|
|
23
|
+
return documentObject;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test("a development, test or staging page gets one banner naming its environment, which takes no clicks", () => {
|
|
27
|
+
for (const [environment, label, description] of [
|
|
28
|
+
["development", "Development", "Development: emails and messages are logged, not sent; payments use the sandbox."],
|
|
29
|
+
["test", "Test", "Test: emails and messages are logged, not sent; payments use the sandbox."],
|
|
30
|
+
["staging", "Staging", "Staging: email and text messages reach only the staging test addresses, other messages are " +
|
|
31
|
+
"logged and payments use the sandbox."]
|
|
32
|
+
]) {
|
|
33
|
+
const documentObject = fakeDocument(environment);
|
|
34
|
+
const remove = installAppEnvironmentBanner({ documentObject });
|
|
35
|
+
assert.equal(documentObject.appended.length, 1, environment);
|
|
36
|
+
const [banner] = documentObject.appended;
|
|
37
|
+
assert.equal(banner.textContent, label);
|
|
38
|
+
assert.equal(banner.attributes.role, "note");
|
|
39
|
+
assert.equal(banner.attributes["aria-description"], description);
|
|
40
|
+
// No label, so a field lookup by label (Playwright's getByLabel reads aria-label and aria-labelledby) never finds it.
|
|
41
|
+
assert.equal("aria-label" in banner.attributes, false);
|
|
42
|
+
assert.equal("aria-labelledby" in banner.attributes, false);
|
|
43
|
+
assert.equal(banner.attributes["data-testid"], "jskit-app-environment-banner");
|
|
44
|
+
assert.equal(banner.style.pointerEvents, "none");
|
|
45
|
+
assert.equal(banner.style.position, "fixed");
|
|
46
|
+
installAppEnvironmentBanner({ documentObject });
|
|
47
|
+
assert.equal(documentObject.appended.length, 1, "never two");
|
|
48
|
+
remove();
|
|
49
|
+
assert.equal(documentObject.appended.length, 0);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("a production page, a page that names no environment and no document get no banner", () => {
|
|
54
|
+
for (const environment of ["production", "", "live", undefined]) {
|
|
55
|
+
const documentObject = fakeDocument(environment);
|
|
56
|
+
installAppEnvironmentBanner({ documentObject });
|
|
57
|
+
assert.equal(documentObject.appended.length, 0, String(environment));
|
|
58
|
+
}
|
|
59
|
+
assert.doesNotThrow(() => installAppEnvironmentBanner({ documentObject: null })());
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("the shell's banner runtime shows the banner on install and removes it on dispose", () => {
|
|
63
|
+
const documentObject = fakeDocument("development");
|
|
64
|
+
const runtime = createAppEnvironmentBannerRuntime({ documentObject });
|
|
65
|
+
runtime.install();
|
|
66
|
+
runtime.install();
|
|
67
|
+
assert.equal(documentObject.appended.length, 1);
|
|
68
|
+
runtime.dispose();
|
|
69
|
+
assert.equal(documentObject.appended.length, 0);
|
|
70
|
+
runtime.dispose();
|
|
71
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { expect } from "@playwright/test";
|
|
7
|
+
import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
8
|
+
|
|
9
|
+
// A command button keeps keyboard focus while its action runs: ShellPageAction and ShellPrimaryAction with `pending`
|
|
10
|
+
// or `loading`, and any button with v-pending, read as unavailable, ignore a second activation and never hand focus to
|
|
11
|
+
// the page body, which is where a focused button that becomes `disabled` sends it in Chromium. Each test reaches the
|
|
12
|
+
// button with Tab, presses Enter, holds the action, then settles it.
|
|
13
|
+
const SKIP = process.env.JSKIT_SHELL_WEB_BROWSER_INTEGRATION === "1"
|
|
14
|
+
? false
|
|
15
|
+
: "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1 to check that pending actions keep keyboard focus";
|
|
16
|
+
const FIXTURE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../fixtures/adaptive-shell");
|
|
17
|
+
const open = sharedBrowserFixture({ fixtureRoot: FIXTURE_ROOT, configFile: "vite.config.mjs" });
|
|
18
|
+
const COMPACT = Object.freeze({ width: 390, height: 844 });
|
|
19
|
+
const EXPANDED = Object.freeze({ width: 1280, height: 900 });
|
|
20
|
+
|
|
21
|
+
async function openPage(t, viewport, url) {
|
|
22
|
+
const { vite, browser } = await open(t);
|
|
23
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport, reducedMotion: "reduce" });
|
|
24
|
+
await page.goto(url);
|
|
25
|
+
return page;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Records, at every frame until read, each time focus is on the page body (or nowhere).
|
|
29
|
+
async function watchFocus(page) {
|
|
30
|
+
await page.evaluate(() => {
|
|
31
|
+
const lost = [];
|
|
32
|
+
let watching = true;
|
|
33
|
+
const sample = () => {
|
|
34
|
+
const active = document.activeElement;
|
|
35
|
+
if (!active || active === document.body || active === document.documentElement) {
|
|
36
|
+
lost.push(performance.now());
|
|
37
|
+
}
|
|
38
|
+
if (watching) {
|
|
39
|
+
requestAnimationFrame(sample);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
requestAnimationFrame(sample);
|
|
43
|
+
globalThis.jskitPendingFocusWatch = () => {
|
|
44
|
+
watching = false;
|
|
45
|
+
return lost.length;
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
return () => page.evaluate(() => globalThis.jskitPendingFocusWatch());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// The button inside `locator` when it wraps one (a FAB), else the element itself.
|
|
52
|
+
function buttonOf(locator) {
|
|
53
|
+
return locator.locator("xpath=self::button | self::a | .//button | .//a").first();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Presses Tab until `locator` has focus, as a keyboard user reaches it.
|
|
57
|
+
async function tabTo(page, locator, { max = 80 } = {}) {
|
|
58
|
+
await locator.waitFor({ state: "visible", timeout: 10_000 });
|
|
59
|
+
for (let presses = 0; presses <= max; presses += 1) {
|
|
60
|
+
if (await locator.evaluate((element) => element === document.activeElement)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
await page.keyboard.press("Tab");
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Tab never reached ${locator}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const presses = (page) => page.getByTestId("fixture-pending-presses");
|
|
69
|
+
|
|
70
|
+
// Tab to the action's button, press Enter, and check it while it runs: focused, unavailable, a second Enter ignored;
|
|
71
|
+
// then settle it and check focus stayed on it throughout.
|
|
72
|
+
async function checkPendingAction(page, { testId, name, running, idle }) {
|
|
73
|
+
const button = buttonOf(page.getByTestId(testId));
|
|
74
|
+
await tabTo(page, button);
|
|
75
|
+
const framesOnBody = await watchFocus(page);
|
|
76
|
+
await page.keyboard.press("Enter");
|
|
77
|
+
await expect(presses(page)).toContainText(`${name}=1`);
|
|
78
|
+
if (running) {
|
|
79
|
+
await expect(button).toContainText(running);
|
|
80
|
+
}
|
|
81
|
+
await expect(button).toBeFocused();
|
|
82
|
+
await expect(button).toHaveAttribute("aria-disabled", "true");
|
|
83
|
+
await expect(button).not.toHaveAttribute("disabled");
|
|
84
|
+
await page.keyboard.press("Enter");
|
|
85
|
+
await page.keyboard.press(" ");
|
|
86
|
+
await page.waitForTimeout(200);
|
|
87
|
+
await expect(presses(page)).toContainText(`${name}=1`);
|
|
88
|
+
await expect(button).toBeFocused();
|
|
89
|
+
|
|
90
|
+
await page.evaluate((action) => globalThis.settleFixtureAction(action), name);
|
|
91
|
+
if (idle) {
|
|
92
|
+
await expect(button).toContainText(idle);
|
|
93
|
+
}
|
|
94
|
+
await expect(button).not.toHaveAttribute("aria-disabled", "true");
|
|
95
|
+
await expect(button).toBeFocused();
|
|
96
|
+
assert.equal(await framesOnBody(), 0, `focus fell to the page body while ${name} was pending`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
test("page actions keep focus while they run: `pending`, and the primary one with `loading`", {
|
|
100
|
+
skip: SKIP,
|
|
101
|
+
timeout: 120_000
|
|
102
|
+
}, async (t) => {
|
|
103
|
+
const page = await openPage(t, EXPANDED, "/home/pending");
|
|
104
|
+
await expect(page.getByTestId("fixture-pending-sync")).toBeVisible();
|
|
105
|
+
await checkPendingAction(page, { testId: "fixture-pending-sync", name: "sync", running: "Syncing…", idle: "Sync" });
|
|
106
|
+
await checkPendingAction(page, { testId: "fixture-pending-save", name: "save" });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("the screen's primary action keeps focus while it runs, as a FAB and as the bar's primary action", {
|
|
110
|
+
skip: SKIP,
|
|
111
|
+
timeout: 120_000
|
|
112
|
+
}, async (t) => {
|
|
113
|
+
for (const viewport of [COMPACT, EXPANDED]) {
|
|
114
|
+
const page = await openPage(t, viewport, "/home/pending");
|
|
115
|
+
await expect(page.getByTestId("fixture-pending-send")).toBeVisible();
|
|
116
|
+
await checkPendingAction(page, { testId: "fixture-pending-send", name: "send", running: "Sending…", idle: "Send" });
|
|
117
|
+
await page.close();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("a dialog's v-pending action keeps focus, ignores a second press and focuses the field a refusal marks", {
|
|
122
|
+
skip: SKIP,
|
|
123
|
+
timeout: 120_000
|
|
124
|
+
}, async (t) => {
|
|
125
|
+
const page = await openPage(t, EXPANDED, "/home/pending-dialog");
|
|
126
|
+
await tabTo(page, page.getByTestId("fixture-open-invite"));
|
|
127
|
+
await page.keyboard.press("Enter");
|
|
128
|
+
const dialog = page.getByRole("dialog");
|
|
129
|
+
await expect(dialog).toBeVisible();
|
|
130
|
+
const send = page.getByTestId("fixture-send-invite");
|
|
131
|
+
await tabTo(page, send, { max: 8 });
|
|
132
|
+
const framesOnBody = await watchFocus(page);
|
|
133
|
+
await page.keyboard.press("Enter");
|
|
134
|
+
await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
|
|
135
|
+
await expect(send).toHaveText("Sending…");
|
|
136
|
+
await expect(send).toBeFocused();
|
|
137
|
+
await expect(send).toHaveAttribute("aria-disabled", "true");
|
|
138
|
+
await page.keyboard.press("Enter");
|
|
139
|
+
await page.waitForTimeout(200);
|
|
140
|
+
await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
|
|
141
|
+
|
|
142
|
+
await page.evaluate(() => globalThis.settleFixtureInvite("Already invited."));
|
|
143
|
+
await expect(dialog.getByText("Already invited.")).toBeVisible();
|
|
144
|
+
await expect(dialog.getByRole("textbox", { name: "Email" })).toBeFocused();
|
|
145
|
+
assert.equal(await framesOnBody(), 0, "focus fell to the page body while Send invite was pending");
|
|
146
|
+
|
|
147
|
+
// Accepted, focus stays on the button.
|
|
148
|
+
await tabTo(page, send, { max: 8 });
|
|
149
|
+
await page.keyboard.press("Enter");
|
|
150
|
+
await expect(page.getByTestId("fixture-invite-presses")).toHaveText("2");
|
|
151
|
+
await page.evaluate(() => globalThis.settleFixtureInvite());
|
|
152
|
+
await expect(send).toHaveText("Send invite");
|
|
153
|
+
await page.waitForTimeout(100);
|
|
154
|
+
await expect(send).toBeFocused();
|
|
155
|
+
|
|
156
|
+
// A refusal that marks a radio group whose first choice is disabled focuses its first enabled choice.
|
|
157
|
+
await page.keyboard.press("Enter");
|
|
158
|
+
await expect(page.getByTestId("fixture-invite-presses")).toHaveText("3");
|
|
159
|
+
await page.evaluate(() => globalThis.settleFixtureInvite("Choose a larger plan.", "plan"));
|
|
160
|
+
await expect(dialog.getByText("Choose a larger plan.")).toBeVisible();
|
|
161
|
+
await expect(dialog.getByRole("radio", { name: "Larger plan" })).toBeFocused();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("a form's implicit submission does nothing while its v-pending submit button runs", {
|
|
165
|
+
skip: SKIP,
|
|
166
|
+
timeout: 120_000
|
|
167
|
+
}, async (t) => {
|
|
168
|
+
const page = await openPage(t, EXPANDED, "/home/pending-dialog");
|
|
169
|
+
await page.getByTestId("fixture-open-invite").click();
|
|
170
|
+
const name = page.getByRole("dialog").getByRole("textbox", { name: "Name" });
|
|
171
|
+
await name.fill("Ada");
|
|
172
|
+
await name.press("Enter");
|
|
173
|
+
await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
|
|
174
|
+
await expect(page.getByTestId("fixture-send-invite")).toHaveText("Sending…");
|
|
175
|
+
await name.press("Enter");
|
|
176
|
+
await page.waitForTimeout(200);
|
|
177
|
+
await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
|
|
178
|
+
await page.evaluate(() => globalThis.settleFixtureInvite());
|
|
179
|
+
await expect(page.getByTestId("fixture-send-invite")).toHaveText("Send invite");
|
|
180
|
+
// Focus was never on the button, so the settled action leaves it in the field.
|
|
181
|
+
await expect(name).toBeFocused();
|
|
182
|
+
});
|
package/test/provider.test.js
CHANGED
|
@@ -147,6 +147,7 @@ test("shell capability owns placement, navigation, bootstrap, refresh, errors, a
|
|
|
147
147
|
|
|
148
148
|
assert.equal(fixture.runtime.diagnostics().lifecycleState, "started");
|
|
149
149
|
assert.deepEqual(Object.keys(fixture.shell).sort(), [
|
|
150
|
+
"appEnvironmentBanner",
|
|
150
151
|
"asyncModuleRecovery",
|
|
151
152
|
"bootstrap",
|
|
152
153
|
"bootstrapHandlers",
|
|
@@ -156,8 +157,7 @@ test("shell capability owns placement, navigation, bootstrap, refresh, errors, a
|
|
|
156
157
|
"navigation",
|
|
157
158
|
"placement",
|
|
158
159
|
"refresh",
|
|
159
|
-
"requestRecovery"
|
|
160
|
-
"testCopyBanner"
|
|
160
|
+
"requestRecovery"
|
|
161
161
|
]);
|
|
162
162
|
assert.deepEqual(fixture.shell.placement.getContext().surfaceAccess, {
|
|
163
163
|
app: { allowed: true }
|