@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,151 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { vPending } from "../src/client/directives/vPending.js";
|
|
4
|
+
|
|
5
|
+
// The browser behaviour (focus kept, Enter ignored, a marked field focused) is in pendingAction.browser.test.js; these
|
|
6
|
+
// check the directive's own steps on stand-in elements.
|
|
7
|
+
|
|
8
|
+
function createDocument() {
|
|
9
|
+
return { activeElement: null };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// A field the refusal marked; the directive's selector for a focusable control leaves out a disabled one.
|
|
13
|
+
function createField(document, { visible = true, disabled = false } = {}) {
|
|
14
|
+
const field = {
|
|
15
|
+
matches: () => !disabled,
|
|
16
|
+
querySelector: () => null,
|
|
17
|
+
getClientRects: () => (visible ? [{}] : []),
|
|
18
|
+
focus() {
|
|
19
|
+
document.activeElement = field;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return field;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createButton(document, { form = null, dialog = null } = {}) {
|
|
26
|
+
const attributes = new Map();
|
|
27
|
+
const listeners = [];
|
|
28
|
+
const button = {
|
|
29
|
+
ownerDocument: document,
|
|
30
|
+
form,
|
|
31
|
+
matches: () => true,
|
|
32
|
+
querySelector: () => null,
|
|
33
|
+
closest: () => dialog,
|
|
34
|
+
contains: (other) => other === button,
|
|
35
|
+
setAttribute: (name, value) => attributes.set(name, String(value)),
|
|
36
|
+
removeAttribute: (name) => attributes.delete(name),
|
|
37
|
+
getAttribute: (name) => attributes.get(name) ?? null,
|
|
38
|
+
addEventListener: (type, handler, capture) => listeners.push({ type, handler, capture }),
|
|
39
|
+
removeEventListener: (type, handler, capture) => {
|
|
40
|
+
const index = listeners.findIndex((entry) => entry.type === type && entry.handler === handler && entry.capture === capture);
|
|
41
|
+
if (index >= 0) listeners.splice(index, 1);
|
|
42
|
+
},
|
|
43
|
+
listeners,
|
|
44
|
+
click() {
|
|
45
|
+
const calls = [];
|
|
46
|
+
const event = {
|
|
47
|
+
currentTarget: button,
|
|
48
|
+
preventDefault: () => calls.push("preventDefault"),
|
|
49
|
+
stopImmediatePropagation: () => calls.push("stopImmediatePropagation")
|
|
50
|
+
};
|
|
51
|
+
for (const { handler } of listeners.filter((entry) => entry.type === "click")) handler(event);
|
|
52
|
+
return calls;
|
|
53
|
+
},
|
|
54
|
+
focus() {
|
|
55
|
+
document.activeElement = button;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return button;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function scope(fields) {
|
|
62
|
+
return { querySelectorAll: () => fields };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const settled = () => new Promise((resolve) => setTimeout(resolve, 5));
|
|
66
|
+
|
|
67
|
+
test("a pending button reads as unavailable and cancels its activation until it settles", () => {
|
|
68
|
+
const document = createDocument();
|
|
69
|
+
const button = createButton(document);
|
|
70
|
+
vPending.mounted(button, { value: false });
|
|
71
|
+
assert.deepEqual(button.listeners.map(({ type, capture }) => [type, capture]), [["click", true]]);
|
|
72
|
+
assert.equal(button.getAttribute("aria-disabled"), null);
|
|
73
|
+
assert.deepEqual(button.click(), [], "an idle button's click goes through");
|
|
74
|
+
|
|
75
|
+
vPending.updated(button, { value: true, oldValue: false });
|
|
76
|
+
assert.equal(button.getAttribute("aria-disabled"), "true");
|
|
77
|
+
assert.deepEqual(button.click(), ["preventDefault", "stopImmediatePropagation"]);
|
|
78
|
+
|
|
79
|
+
vPending.updated(button, { value: false, oldValue: true });
|
|
80
|
+
assert.equal(button.getAttribute("aria-disabled"), null);
|
|
81
|
+
assert.deepEqual(button.click(), []);
|
|
82
|
+
|
|
83
|
+
vPending.beforeUnmount(button);
|
|
84
|
+
assert.equal(button.listeners.length, 0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("settling with focus on the button focuses the first visible, enabled field the refusal marked in its form", async () => {
|
|
88
|
+
const document = createDocument();
|
|
89
|
+
const hidden = createField(document, { visible: false });
|
|
90
|
+
const disabled = createField(document, { disabled: true });
|
|
91
|
+
const email = createField(document);
|
|
92
|
+
const button = createButton(document, { form: scope([hidden, disabled, email]) });
|
|
93
|
+
vPending.mounted(button, { value: true });
|
|
94
|
+
button.focus();
|
|
95
|
+
vPending.updated(button, { value: false, oldValue: true });
|
|
96
|
+
assert.equal(document.activeElement, button, "focus moves only once the refusal's errors have drawn");
|
|
97
|
+
await settled();
|
|
98
|
+
assert.equal(document.activeElement, email);
|
|
99
|
+
vPending.beforeUnmount(button);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("outside a form the button's dialog, then the page, holds the marked fields", async () => {
|
|
103
|
+
const document = createDocument();
|
|
104
|
+
const inDialog = createField(document);
|
|
105
|
+
const dialogButton = createButton(document, { dialog: scope([inDialog]) });
|
|
106
|
+
vPending.mounted(dialogButton, { value: true });
|
|
107
|
+
dialogButton.focus();
|
|
108
|
+
vPending.updated(dialogButton, { value: false, oldValue: true });
|
|
109
|
+
await settled();
|
|
110
|
+
assert.equal(document.activeElement, inDialog);
|
|
111
|
+
vPending.beforeUnmount(dialogButton);
|
|
112
|
+
|
|
113
|
+
const onPage = createField(document);
|
|
114
|
+
Object.assign(document, scope([onPage]));
|
|
115
|
+
const barButton = createButton(document);
|
|
116
|
+
vPending.mounted(barButton, { value: true });
|
|
117
|
+
barButton.focus();
|
|
118
|
+
vPending.updated(barButton, { value: false, oldValue: true });
|
|
119
|
+
await settled();
|
|
120
|
+
assert.equal(document.activeElement, onPage);
|
|
121
|
+
vPending.beforeUnmount(barButton);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("focus stays where it is when nothing is marked, when it left the button, or when the button goes", async () => {
|
|
125
|
+
const document = createDocument();
|
|
126
|
+
const accepted = createButton(document, { form: scope([]) });
|
|
127
|
+
vPending.mounted(accepted, { value: true });
|
|
128
|
+
accepted.focus();
|
|
129
|
+
vPending.updated(accepted, { value: false, oldValue: true });
|
|
130
|
+
await settled();
|
|
131
|
+
assert.equal(document.activeElement, accepted);
|
|
132
|
+
vPending.beforeUnmount(accepted);
|
|
133
|
+
|
|
134
|
+
const marked = createField(document);
|
|
135
|
+
const left = createButton(document, { form: scope([marked]) });
|
|
136
|
+
const elsewhere = createField(document);
|
|
137
|
+
vPending.mounted(left, { value: true });
|
|
138
|
+
elsewhere.focus();
|
|
139
|
+
vPending.updated(left, { value: false, oldValue: true });
|
|
140
|
+
await settled();
|
|
141
|
+
assert.equal(document.activeElement, elsewhere);
|
|
142
|
+
vPending.beforeUnmount(left);
|
|
143
|
+
|
|
144
|
+
const gone = createButton(document, { form: scope([marked]) });
|
|
145
|
+
vPending.mounted(gone, { value: true });
|
|
146
|
+
gone.focus();
|
|
147
|
+
vPending.updated(gone, { value: false, oldValue: true });
|
|
148
|
+
vPending.beforeUnmount(gone);
|
|
149
|
+
await settled();
|
|
150
|
+
assert.equal(document.activeElement, gone);
|
|
151
|
+
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath, URL } from "node:url";
|
|
2
|
-
import { defineConfig } from "vite";
|
|
3
|
-
import { resolveSideEffectsMode, withSideEffectsMeta } from "@jskit-ai/kernel/shared/support/sideEffects";
|
|
4
|
-
|
|
5
|
-
// The page names the server's SIDE_EFFECTS as a JSKIT server or development server names it.
|
|
6
|
-
const sideEffectsPage = {
|
|
7
|
-
name: "fixture-side-effects-page",
|
|
8
|
-
transformIndexHtml: (html) => withSideEffectsMeta(html, resolveSideEffectsMode(process.env))
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default defineConfig({
|
|
12
|
-
root: fileURLToPath(new URL(".", import.meta.url)),
|
|
13
|
-
plugins: [sideEffectsPage],
|
|
14
|
-
server: {
|
|
15
|
-
host: "127.0.0.1"
|
|
16
|
-
}
|
|
17
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SIDE_EFFECTS_SIMULATE,
|
|
3
|
-
pageSideEffectsMode
|
|
4
|
-
} from "@jskit-ai/kernel/shared/support/sideEffects";
|
|
5
|
-
import { pageDocument } from "../browser.js";
|
|
6
|
-
import { useJskitText } from "../i18n.js";
|
|
7
|
-
|
|
8
|
-
const { t } = useJskitText();
|
|
9
|
-
|
|
10
|
-
const TEST_COPY_BANNER_ID = "jskit-test-copy-banner";
|
|
11
|
-
|
|
12
|
-
// A small tab hanging from the top edge, above everything, that never takes a click or a tap: it marks the page
|
|
13
|
-
// without covering a control the person needs. Amber with near-black text reads the same in light and dark themes.
|
|
14
|
-
const TEST_COPY_BANNER_STYLE = Object.freeze({
|
|
15
|
-
position: "fixed",
|
|
16
|
-
top: "env(safe-area-inset-top, 0px)",
|
|
17
|
-
left: "50%",
|
|
18
|
-
transform: "translateX(-50%)",
|
|
19
|
-
zIndex: "2147483000",
|
|
20
|
-
pointerEvents: "none",
|
|
21
|
-
userSelect: "none",
|
|
22
|
-
padding: "2px 12px 3px",
|
|
23
|
-
borderRadius: "0 0 8px 8px",
|
|
24
|
-
background: "#ffb300",
|
|
25
|
-
color: "#1f1300",
|
|
26
|
-
font: "600 12px/16px system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif",
|
|
27
|
-
letterSpacing: "0.02em",
|
|
28
|
-
whiteSpace: "nowrap",
|
|
29
|
-
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.3)"
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
function removeNothing() {}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Shows the "Test copy" banner when the page says its server simulates side effects (SIDE_EFFECTS is not `live`),
|
|
36
|
-
* so everyone using a test copy knows no real email, message or payment goes out. It needs no application code: the
|
|
37
|
-
* shell adds it to the page's body, outside the application's own layout. A live page, or a page that names no
|
|
38
|
-
* setting, gets none. Returns the function that removes it.
|
|
39
|
-
* @param {object} [options]
|
|
40
|
-
* @param {Document | null} [options.documentObject]
|
|
41
|
-
* @param {"live" | "simulate" | ""} [options.mode] The page's setting; read from its meta tag when omitted.
|
|
42
|
-
* @returns {() => void}
|
|
43
|
-
*/
|
|
44
|
-
function installTestCopyBanner({ documentObject = pageDocument(), mode = pageSideEffectsMode(documentObject) } = {}) {
|
|
45
|
-
if (mode !== SIDE_EFFECTS_SIMULATE || !documentObject?.body || documentObject.getElementById(TEST_COPY_BANNER_ID)) {
|
|
46
|
-
return removeNothing;
|
|
47
|
-
}
|
|
48
|
-
const banner = documentObject.createElement("div");
|
|
49
|
-
banner.id = TEST_COPY_BANNER_ID;
|
|
50
|
-
banner.setAttribute("data-testid", TEST_COPY_BANNER_ID);
|
|
51
|
-
// A note read by its visible text, with the full sentence as its description. A label would make it a labelled
|
|
52
|
-
// element, which a browser test's field lookup such as `getByLabel("Email")` would also find.
|
|
53
|
-
banner.setAttribute("role", "note");
|
|
54
|
-
banner.setAttribute("aria-description", t("jskit.shell.sideEffects.testCopyDescription"));
|
|
55
|
-
banner.textContent = t("jskit.shell.sideEffects.testCopy");
|
|
56
|
-
// Through the style object, not a style attribute, so a strict content policy without inline styles allows it.
|
|
57
|
-
Object.assign(banner.style, TEST_COPY_BANNER_STYLE);
|
|
58
|
-
documentObject.body.append(banner);
|
|
59
|
-
return () => banner.remove();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The shell's banner runtime: `install()` shows the banner as the shell boots, `dispose()` removes it as it shuts
|
|
64
|
-
* down.
|
|
65
|
-
* @param {Parameters<typeof installTestCopyBanner>[0]} [options]
|
|
66
|
-
*/
|
|
67
|
-
function createTestCopyBannerRuntime(options) {
|
|
68
|
-
let remove = removeNothing;
|
|
69
|
-
|
|
70
|
-
function install() {
|
|
71
|
-
remove();
|
|
72
|
-
remove = installTestCopyBanner(options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function dispose() {
|
|
76
|
-
remove();
|
|
77
|
-
remove = removeNothing;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return Object.freeze({
|
|
81
|
-
install,
|
|
82
|
-
dispose
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { TEST_COPY_BANNER_ID, createTestCopyBannerRuntime, installTestCopyBanner };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
3
|
-
import { createTestCopyBannerRuntime, installTestCopyBanner } from "../src/client/sideEffects/testCopyBanner.js";
|
|
4
|
-
|
|
5
|
-
// The part of a document the banner uses: a body to append to, elements, and lookup by id.
|
|
6
|
-
function fakeDocument(sideEffects) {
|
|
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: () => (sideEffects === undefined ? null : { getAttribute: () => sideEffects })
|
|
22
|
-
};
|
|
23
|
-
return documentObject;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
test("a simulating page gets one Test copy banner that takes no clicks", () => {
|
|
27
|
-
const documentObject = fakeDocument("simulate");
|
|
28
|
-
const remove = installTestCopyBanner({ documentObject });
|
|
29
|
-
assert.equal(documentObject.appended.length, 1);
|
|
30
|
-
const [banner] = documentObject.appended;
|
|
31
|
-
assert.equal(banner.textContent, "Test copy");
|
|
32
|
-
assert.equal(banner.attributes.role, "note");
|
|
33
|
-
assert.equal(banner.attributes["aria-description"], "Test copy: emails, messages and payments are simulated, not sent.");
|
|
34
|
-
// No label, so a field lookup by label (Playwright's getByLabel reads aria-label and aria-labelledby) never finds it.
|
|
35
|
-
assert.equal("aria-label" in banner.attributes, false);
|
|
36
|
-
assert.equal("aria-labelledby" in banner.attributes, false);
|
|
37
|
-
assert.equal(banner.attributes["data-testid"], "jskit-test-copy-banner");
|
|
38
|
-
assert.equal(banner.style.pointerEvents, "none");
|
|
39
|
-
assert.equal(banner.style.position, "fixed");
|
|
40
|
-
installTestCopyBanner({ documentObject });
|
|
41
|
-
assert.equal(documentObject.appended.length, 1, "never two");
|
|
42
|
-
remove();
|
|
43
|
-
assert.equal(documentObject.appended.length, 0);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("a live page, a page that names no setting and no document get no banner", () => {
|
|
47
|
-
for (const sideEffects of ["live", undefined]) {
|
|
48
|
-
const documentObject = fakeDocument(sideEffects);
|
|
49
|
-
installTestCopyBanner({ documentObject });
|
|
50
|
-
assert.equal(documentObject.appended.length, 0, String(sideEffects));
|
|
51
|
-
}
|
|
52
|
-
assert.doesNotThrow(() => installTestCopyBanner({ documentObject: null })());
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("the shell's banner runtime shows the banner on install and removes it on dispose", () => {
|
|
56
|
-
const documentObject = fakeDocument("simulate");
|
|
57
|
-
const runtime = createTestCopyBannerRuntime({ documentObject });
|
|
58
|
-
runtime.install();
|
|
59
|
-
runtime.install();
|
|
60
|
-
assert.equal(documentObject.appended.length, 1);
|
|
61
|
-
runtime.dispose();
|
|
62
|
-
assert.equal(documentObject.appended.length, 0);
|
|
63
|
-
runtime.dispose();
|
|
64
|
-
});
|