@jskit-ai/shell-web 0.2.37 → 0.2.38
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/{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 +3 -3
- package/src/client/appEnvironment/appEnvironmentBanner.js +89 -0
- package/src/client/providers/ShellWebClientProvider.js +6 -6
- package/test/{testCopyBanner.browser.test.js → appEnvironmentBanner.browser.test.js} +27 -13
- package/test/appEnvironmentBanner.test.js +71 -0
- package/test/provider.test.js +2 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **Breaking:** the shell's banner names the page's environment from the `jskit-app-environment` meta tag: "Development", "Test" or "Staging", and none in production. It replaces the "Test copy" banner; its id and test id are `jskit-app-environment-banner`, and the shell runtime's key is `appEnvironmentBanner`. It is still a note that never takes a click, with the environment's sentence as its description and no label.
|
|
5
6
|
- The navigation rail and the standard drawer run the window's full height beside the top app bar, as Material 3 draws them: their menu control sits in the page title's row and the first destination starts right below it. The app bar spanned the window's width and the rail or drawer started under it, adding a 56dp row of its own for the menu control, so the control sat under the title and the destinations started two rows down. They now come before the app bar in the layout (`order` -1, and -2 for the modal drawer, which still opens from the window's edge over the rail and the app bar), and their header is the app bar's 64dp. An inner page keeps its Up arrow in the app bar beside them. Compact windows are unchanged (navigation bar, modal drawer). `runAdaptiveShellSmokeCase` checks it on medium and expanded windows, and `expectNavigationBesideAppBar(navigation, expect)` is exported for a test of its own.
|
|
6
7
|
- On a compact window (under 600 px), a message that shows while a dialog, a bottom sheet or a temporary navigation drawer is open sits at the top of the window, clear of the actions it reports on; it keeps that place until it closes. Elsewhere and on wider windows messages stay at the bottom start.
|
|
7
8
|
- A message showing over a dialog no longer takes Escape and the browser's Back from it: the snackbar stays out of Vuetify's overlay stack (`_disable-global-stack`), as Vuetify's tooltips do, so Escape and Back close the dialog under it. This uses a private Vuetify prop until Vuetify leaves snackbars off the stack itself (reported as https://github.com/vuetifyjs/vuetify/issues/23392).
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>JSKIT
|
|
6
|
+
<title>JSKIT environment banner</title>
|
|
7
7
|
</head>
|
|
8
8
|
<body>
|
|
9
9
|
<button id="under-banner" type="button">Pressed 0 times</button>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAppEnvironmentBannerRuntime } from "../../../src/client/appEnvironment/appEnvironmentBanner.js";
|
|
2
2
|
|
|
3
3
|
// A control stretched across the top of the page, where the banner hangs, counts the presses that reach it.
|
|
4
4
|
const button = document.getElementById("under-banner");
|
|
@@ -9,5 +9,5 @@ button.addEventListener("click", () => {
|
|
|
9
9
|
button.textContent = `Pressed ${presses} times`;
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
createAppEnvironmentBannerRuntime().install();
|
|
13
13
|
document.documentElement.dataset.ready = "true";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fileURLToPath, URL } from "node:url";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
import { appEnvironment, withAppEnvironmentMeta } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
4
|
+
|
|
5
|
+
// The page names the server's APP_ENV as a JSKIT server or development server names it.
|
|
6
|
+
const appEnvironmentPage = {
|
|
7
|
+
name: "fixture-app-environment-page",
|
|
8
|
+
transformIndexHtml: (html) => withAppEnvironmentMeta(html, appEnvironment(process.env))
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
root: fileURLToPath(new URL(".", import.meta.url)),
|
|
13
|
+
plugins: [appEnvironmentPage],
|
|
14
|
+
server: {
|
|
15
|
+
host: "127.0.0.1"
|
|
16
|
+
}
|
|
17
|
+
});
|
package/locales/en.json
CHANGED
|
@@ -46,9 +46,13 @@
|
|
|
46
46
|
"thisAppUpdated": "This app was updated. Reload to get the latest version.",
|
|
47
47
|
"unreachable": "{label} could not reach the server or network. Check the connection and try again."
|
|
48
48
|
},
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
49
|
+
"appEnvironment": {
|
|
50
|
+
"development": "Development",
|
|
51
|
+
"developmentDescription": "Development: emails and messages are logged, not sent; payments use the sandbox.",
|
|
52
|
+
"test": "Test",
|
|
53
|
+
"testDescription": "Test: emails and messages are logged, not sent; payments use the sandbox.",
|
|
54
|
+
"staging": "Staging",
|
|
55
|
+
"stagingDescription": "Staging: email and text messages reach only the staging test addresses, other messages are logged and payments use the sandbox."
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
}
|
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.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"./locales/en.json": "./locales/en.json"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@jskit-ai/architecture-inspector": "0.1.
|
|
49
|
+
"@jskit-ai/architecture-inspector": "0.1.25"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@jskit-ai/material-web": "0.1.8",
|
|
53
53
|
"@vue/compiler-sfc": "3.5.44"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@jskit-ai/kernel": "0.2.
|
|
56
|
+
"@jskit-ai/kernel": "0.2.27",
|
|
57
57
|
"pinia": "^4.0.3",
|
|
58
58
|
"vue": "^3.5.44",
|
|
59
59
|
"vue-router": "^5.3.1",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { pageAppEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
2
|
+
import { pageDocument } from "../browser.js";
|
|
3
|
+
import { useJskitText } from "../i18n.js";
|
|
4
|
+
|
|
5
|
+
const { t } = useJskitText();
|
|
6
|
+
|
|
7
|
+
const APP_ENVIRONMENT_BANNER_ID = "jskit-app-environment-banner";
|
|
8
|
+
// Every environment but production names itself on the page.
|
|
9
|
+
const BANNERED_ENVIRONMENTS = Object.freeze(["development", "test", "staging"]);
|
|
10
|
+
// Each bannered environment's label and description: `<prefix><environment>` and `<prefix><environment>Description`.
|
|
11
|
+
const BANNER_TEXT_PREFIX = "jskit.shell.appEnvironment.";
|
|
12
|
+
|
|
13
|
+
// A small tab hanging from the top edge, above everything, that never takes a click or a tap: it marks the page
|
|
14
|
+
// without covering a control the person needs. Amber with near-black text reads the same in light and dark themes.
|
|
15
|
+
const APP_ENVIRONMENT_BANNER_STYLE = Object.freeze({
|
|
16
|
+
position: "fixed",
|
|
17
|
+
top: "env(safe-area-inset-top, 0px)",
|
|
18
|
+
left: "50%",
|
|
19
|
+
transform: "translateX(-50%)",
|
|
20
|
+
zIndex: "2147483000",
|
|
21
|
+
pointerEvents: "none",
|
|
22
|
+
userSelect: "none",
|
|
23
|
+
padding: "2px 12px 3px",
|
|
24
|
+
borderRadius: "0 0 8px 8px",
|
|
25
|
+
background: "#ffb300",
|
|
26
|
+
color: "#1f1300",
|
|
27
|
+
font: "600 12px/16px system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif",
|
|
28
|
+
letterSpacing: "0.02em",
|
|
29
|
+
whiteSpace: "nowrap",
|
|
30
|
+
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.3)"
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function removeNothing() {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shows the page's environment, "Development", "Test" or "Staging", from the page's APP_ENV meta tag, so everyone
|
|
37
|
+
* using a copy that is not production knows what it sends. It needs no application code: the shell adds it to the
|
|
38
|
+
* page's body, outside the application's own layout. A production page, or a page that names no environment, gets
|
|
39
|
+
* none. Returns the function that removes it.
|
|
40
|
+
* @param {object} [options]
|
|
41
|
+
* @param {Document | null} [options.documentObject]
|
|
42
|
+
* @param {"development" | "test" | "staging" | "production" | ""} [options.environment] The page's environment; read
|
|
43
|
+
* from its meta tag when omitted.
|
|
44
|
+
* @returns {() => void}
|
|
45
|
+
*/
|
|
46
|
+
function installAppEnvironmentBanner({ documentObject = pageDocument(), environment = pageAppEnvironment(documentObject) } = {}) {
|
|
47
|
+
if (!BANNERED_ENVIRONMENTS.includes(environment) || !documentObject?.body ||
|
|
48
|
+
documentObject.getElementById(APP_ENVIRONMENT_BANNER_ID)) {
|
|
49
|
+
return removeNothing;
|
|
50
|
+
}
|
|
51
|
+
const banner = documentObject.createElement("div");
|
|
52
|
+
banner.id = APP_ENVIRONMENT_BANNER_ID;
|
|
53
|
+
banner.setAttribute("data-testid", APP_ENVIRONMENT_BANNER_ID);
|
|
54
|
+
// A note read by its visible text, with the full sentence as its description. A label would make it a labelled
|
|
55
|
+
// element, which a browser test's field lookup such as `getByLabel("Email")` would also find.
|
|
56
|
+
banner.setAttribute("role", "note");
|
|
57
|
+
banner.setAttribute("aria-description", t(`${BANNER_TEXT_PREFIX}${environment}Description`));
|
|
58
|
+
banner.textContent = t(`${BANNER_TEXT_PREFIX}${environment}`);
|
|
59
|
+
// Through the style object, not a style attribute, so a strict content policy without inline styles allows it.
|
|
60
|
+
Object.assign(banner.style, APP_ENVIRONMENT_BANNER_STYLE);
|
|
61
|
+
documentObject.body.append(banner);
|
|
62
|
+
return () => banner.remove();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The shell's banner runtime: `install()` shows the banner as the shell boots, `dispose()` removes it as it shuts
|
|
67
|
+
* down.
|
|
68
|
+
* @param {Parameters<typeof installAppEnvironmentBanner>[0]} [options]
|
|
69
|
+
*/
|
|
70
|
+
function createAppEnvironmentBannerRuntime(options) {
|
|
71
|
+
let remove = removeNothing;
|
|
72
|
+
|
|
73
|
+
function install() {
|
|
74
|
+
remove();
|
|
75
|
+
remove = installAppEnvironmentBanner(options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function dispose() {
|
|
79
|
+
remove();
|
|
80
|
+
remove = removeNothing;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
install,
|
|
85
|
+
dispose
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { APP_ENVIRONMENT_BANNER_ID, createAppEnvironmentBannerRuntime, installAppEnvironmentBanner };
|
|
@@ -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();
|
|
@@ -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
|
+
});
|
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 }
|
|
@@ -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
|
-
});
|