ui5-playwright-gherkin-sandbox 0.1.0 → 0.1.2
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/README.md +8 -6
- package/app/products.feature +5 -4
- package/package.json +10 -12
- package/src/index.js +126 -33
- package/src/styles.js +26 -12
package/README.md
CHANGED
|
@@ -13,16 +13,15 @@ Components.
|
|
|
13
13
|
## Use it
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
npm install ui5-playwright-gherkin-sandbox
|
|
16
|
+
npm install ui5-playwright-gherkin-sandbox
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
|
-
import "@ui5/webcomponents/dist/Assets.js"; // themes; optional
|
|
21
20
|
import { mount } from "ui5-playwright-gherkin-sandbox";
|
|
22
21
|
|
|
23
22
|
const sandbox = await mount(document.querySelector("#sandbox"), {
|
|
24
23
|
base: "app/", // where the app and the feature are, relative to the page
|
|
25
|
-
app: "index.html", // the
|
|
24
|
+
app: "index.html", // the OpenUI5/SAPUI5 app's page, same-origin
|
|
26
25
|
feature: "products.feature", // the sample feature in the editor
|
|
27
26
|
sites: { Products: "index.html" } // for Given I open the site "Products" (as ui5Sites)
|
|
28
27
|
});
|
|
@@ -30,8 +29,11 @@ sandbox.run(); sandbox.stop();
|
|
|
30
29
|
```
|
|
31
30
|
|
|
32
31
|
Bundle it for browsers with the `browser` export condition (Rolldown, Vite, ...), so
|
|
33
|
-
ui5-playwright-gherkin's `#expect` resolves to the browser one.
|
|
34
|
-
|
|
32
|
+
ui5-playwright-gherkin's `#expect` resolves to the browser one.
|
|
33
|
+
|
|
34
|
+
- **The app under test** is any OpenUI5 or SAPUI5 app. The sandbox's own panel (editor, buttons,
|
|
35
|
+
results) is drawn with UI5 Web Components, which come with the package; a page that uses them too
|
|
36
|
+
shares one copy (npm installs one when the versions fit), since each custom element exists once.
|
|
35
37
|
|
|
36
38
|
- **The app** must be served from the same origin as the page: the steps reach into its frame.
|
|
37
39
|
- **Styles** come with `mount()` (adopted style sheets, no `<style>` element or file to link), and
|
|
@@ -64,7 +66,7 @@ npm install
|
|
|
64
66
|
npm run build:app # the demo app into .app-dist/ (slow, once)
|
|
65
67
|
npm run build # the live demo into dist/
|
|
66
68
|
npm run serve # http://localhost:4174/ui5-playwright-gherkin-sandbox/
|
|
67
|
-
npm test # dist/ in Chromium, WebKit and on a phone (Playwright)
|
|
69
|
+
npm test # dist/ in Chromium, WebKit and on a phone (Playwright); CI runs Chromium only
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
The demo page (`demo/`) is the same sandbox with a page around it. `.github/workflows/pages.yml`
|
package/app/products.feature
CHANGED
|
@@ -5,16 +5,17 @@ Feature: Products
|
|
|
5
5
|
Background:
|
|
6
6
|
Given I open the site "Products"
|
|
7
7
|
|
|
8
|
-
Scenario:
|
|
8
|
+
Scenario: An added product is in the table, as entered
|
|
9
9
|
When I press the button "Add"
|
|
10
10
|
And I write "Tablet" into "Name" at the "dialog"
|
|
11
11
|
And I select "Tablets" in "Category" at the "dialog"
|
|
12
12
|
And I write "399" into "Price" at the "dialog"
|
|
13
13
|
And I press "Save" at the "dialog"
|
|
14
|
-
|
|
14
|
+
And I write "Tablet" into "Search"
|
|
15
|
+
Then I should see 1 row
|
|
15
16
|
And I should see rows
|
|
16
|
-
| Name | Category | Price | $highlight |
|
|
17
|
-
| Tablet | Tablets | 399 | Success |
|
|
17
|
+
| Name | Category | Price | Status | $highlight |
|
|
18
|
+
| Tablet | Tablets | 399 | In stock | Success |
|
|
18
19
|
|
|
19
20
|
Scenario: The name is required
|
|
20
21
|
When I press the button "Add"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui5-playwright-gherkin-sandbox",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Try ui5-playwright-gherkin in the browser: a sandbox with an editor, a step builder, a recorder and live results, running the steps against an OpenUI5 app",
|
|
5
5
|
"homepage": "https://bkrrrr.github.io/ui5-playwright-gherkin-sandbox/",
|
|
6
6
|
"repository": {
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
],
|
|
43
43
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"
|
|
46
|
-
"ui5-
|
|
45
|
+
"@ui5/webcomponents": "^2.29.0",
|
|
46
|
+
"@ui5/webcomponents-icons": "^2.29.0",
|
|
47
|
+
"sandbox-playwright-gherkin": "^0.1.1",
|
|
48
|
+
"ui5-playwright-gherkin": "^0.3.1"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
|
-
"@ui5/cli": ">=4"
|
|
50
|
-
"@ui5/webcomponents": "^2.28.1",
|
|
51
|
-
"@ui5/webcomponents-icons": "^2.28.1"
|
|
51
|
+
"@ui5/cli": ">=4"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@ui5/cli": {
|
|
@@ -57,12 +57,10 @@
|
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@fontsource/lato": "5.3.0",
|
|
60
|
-
"@playwright/test": "1.
|
|
61
|
-
"@ui5/cli": "4.0
|
|
62
|
-
"@ui5/webcomponents": "2.
|
|
63
|
-
"
|
|
64
|
-
"@ui5/webcomponents-icons": "2.28.1",
|
|
65
|
-
"rolldown": "1.3.2"
|
|
60
|
+
"@playwright/test": "1.65.2",
|
|
61
|
+
"@ui5/cli": "4.1.0",
|
|
62
|
+
"@ui5/webcomponents-base": "2.29.0",
|
|
63
|
+
"rolldown": "1.3.4"
|
|
66
64
|
},
|
|
67
65
|
"engines": {
|
|
68
66
|
"node": ">=20.11"
|
package/src/index.js
CHANGED
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
// frame. UI5 Web Components for the UI. The steps and their catalog (steps.json) are
|
|
4
4
|
// ui5-playwright-gherkin's; they run on sandbox-playwright-gherkin's runner and Playwright-like driver.
|
|
5
5
|
//
|
|
6
|
+
// The app under test is any UI5 app (OpenUI5, SAPUI5) in the frame. UI5 Web Components only draw
|
|
7
|
+
// this panel: they come with the package, and a page that uses them too shares one copy.
|
|
8
|
+
//
|
|
6
9
|
// Typed step definitions are not offered: they would need `new Function`, which a strict Content
|
|
7
10
|
// Security Policy forbids. Everything here works under `script-src 'self'`.
|
|
8
11
|
|
|
12
|
+
// themes (light, dark, high contrast) and translations of the panel, each fetched when first needed
|
|
13
|
+
import "@ui5/webcomponents/dist/Assets.js";
|
|
9
14
|
import "@ui5/webcomponents/dist/Button.js";
|
|
10
15
|
import "@ui5/webcomponents/dist/SegmentedButton.js";
|
|
11
16
|
import "@ui5/webcomponents/dist/SegmentedButtonItem.js";
|
|
@@ -45,7 +50,7 @@ import { createPage } from "sandbox-playwright-gherkin/dom";
|
|
|
45
50
|
import { defineSteps } from "ui5-playwright-gherkin/steps/index";
|
|
46
51
|
import { Ui5Page } from "ui5-playwright-gherkin/page";
|
|
47
52
|
import catalog from "ui5-playwright-gherkin/steps.json";
|
|
48
|
-
import { describe as describeElement, toSteps } from "ui5-playwright-gherkin/record";
|
|
53
|
+
import { countCheck, describe as describeElement, toSteps } from "ui5-playwright-gherkin/record";
|
|
49
54
|
import { adoptStyles } from "./styles.js";
|
|
50
55
|
|
|
51
56
|
/** "Given I use a phone" ...: the sizes the ui5 fixture uses in Playwright. */
|
|
@@ -60,8 +65,8 @@ const TEXT = {
|
|
|
60
65
|
restore: "Restore sample", clearRecording: "Clear recording", stop: "Stop", run: "Run",
|
|
61
66
|
showExample: "Example", showRecording: "My recording", showWhich: "Feature to show", recordingFeature: "My recording",
|
|
62
67
|
cannotNameHover: "No step can name this", recordingEmpty: "Nothing recorded yet. Press Record and use the app.",
|
|
63
|
-
feature: "
|
|
64
|
-
featureHint: "Ctrl/⌘ + Enter runs. Every step is verb · target · location;
|
|
68
|
+
feature: "Feature", steps: "Help", results: "Run", featureLabel: "Feature file",
|
|
69
|
+
featureHint: "Ctrl/⌘ + Enter runs. Every step is verb · target · location; Add a step below writes them for you, Help lists them all.",
|
|
65
70
|
stepsHint: "ui5-playwright-gherkin's sentences: every verb works with every target and location. Click an example to add it at the cursor.",
|
|
66
71
|
builder: "Add a step", builderVerb: "Do", builderValue: "Value", builderKind: "Control", builderText: "Text or label",
|
|
67
72
|
builderWhere: "Where", builderRow: "Row with text", builderAdd: "Add step", anyKind: "anything with this text",
|
|
@@ -103,9 +108,10 @@ const BUILDER_VERBS = [
|
|
|
103
108
|
{ label: "expect that … is (state)", value: "state", make: (t, l, v) => `Then I expect that ${t}${l} is "${v}"` },
|
|
104
109
|
{ label: "the value of … is", value: true, make: (t, l, v) => `Then the value of ${t}${l} is "${v}"` }
|
|
105
110
|
];
|
|
106
|
-
//
|
|
111
|
+
// Kinds (<kind>: button, row ...), the common ones first; steps.json before 0.3.0 called them "words"
|
|
112
|
+
const CATALOG_KINDS = catalog.kinds ?? catalog.words;
|
|
107
113
|
const COMMON = ["button", "row", "input", "select", "text", "title", "tab", "link", "checkbox", "dialog", "searchfield"];
|
|
108
|
-
const KINDS = [...COMMON, ...Object.keys(
|
|
114
|
+
const KINDS = [...COMMON, ...Object.keys(CATALOG_KINDS).filter((w) => !COMMON.includes(w)).sort()];
|
|
109
115
|
|
|
110
116
|
/** The step reference, from ui5-playwright-gherkin's catalog. Examples insert themselves. */
|
|
111
117
|
function reference() {
|
|
@@ -118,7 +124,7 @@ function reference() {
|
|
|
118
124
|
<h3>More steps</h3><dl>${catalog.fixed.map((f) => `<dt><code>${esc(f.step)}</code></dt>${f.does ? `<dd>${esc(f.does)}</dd>` : ""}`).join("")}</dl>
|
|
119
125
|
<h3>Areas</h3><p>${code(catalog.areas)}</p>
|
|
120
126
|
<h3>States</h3><p>${code(catalog.states)}</p>
|
|
121
|
-
<h3>
|
|
127
|
+
<h3>Kinds</h3><p>${code(Object.keys(CATALOG_KINDS))}</p>`;
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
/**
|
|
@@ -150,18 +156,25 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
150
156
|
<ui5-segmented-button-item data-ms="900">${TEXT.slow}</ui5-segmented-button-item>
|
|
151
157
|
</ui5-segmented-button>
|
|
152
158
|
<span class="sbx-spacer"></span>
|
|
153
|
-
<ui5-button class="sbx-record" icon="record" design="Transparent" disabled>${TEXT.record}</ui5-button>
|
|
154
|
-
<ui5-button class="sbx-restore" design="Transparent" icon="reset">${TEXT.restore}</ui5-button>
|
|
155
159
|
<ui5-button class="sbx-stop" icon="stop" disabled>${TEXT.stop}</ui5-button>
|
|
156
160
|
<ui5-button class="sbx-run" design="Emphasized" icon="media-play" disabled>${TEXT.run}</ui5-button>
|
|
157
161
|
</div>
|
|
158
162
|
<ui5-message-strip class="sbx-recording" design="Information" hide-close-button hidden>${TEXT.recording}</ui5-message-strip>
|
|
159
163
|
<ui5-tabcontainer class="sbx-tabs" content-background-design="Transparent" header-background-design="Transparent">
|
|
164
|
+
<ui5-tab text="${TEXT.steps}" data-tab="help">
|
|
165
|
+
<p class="sbx-hint">${esc(TEXT.stepsHint)}</p>
|
|
166
|
+
<div class="pg-reference">${reference()}</div>
|
|
167
|
+
</ui5-tab>
|
|
160
168
|
<ui5-tab text="${TEXT.feature}" data-tab="feature" selected>
|
|
161
|
-
<
|
|
162
|
-
<ui5-segmented-button-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
<div class="sbx-doc">
|
|
170
|
+
<ui5-segmented-button class="sbx-which" accessible-name="${TEXT.showWhich}">
|
|
171
|
+
<ui5-segmented-button-item data-doc="example" selected>${TEXT.showExample}</ui5-segmented-button-item>
|
|
172
|
+
<ui5-segmented-button-item data-doc="recording">${TEXT.showRecording}</ui5-segmented-button-item>
|
|
173
|
+
</ui5-segmented-button>
|
|
174
|
+
<span class="sbx-spacer"></span>
|
|
175
|
+
<ui5-button class="sbx-record" icon="record" disabled>${TEXT.record}</ui5-button>
|
|
176
|
+
<ui5-button class="sbx-restore" design="Transparent" icon="reset">${TEXT.restore}</ui5-button>
|
|
177
|
+
</div>
|
|
165
178
|
<ui5-textarea class="sbx-code" rows="12" accessible-name="${TEXT.featureLabel}" accessible-description="${esc(TEXT.featureHint)}"></ui5-textarea>
|
|
166
179
|
<ui5-message-strip class="sbx-perr" design="Negative" hide-close-button hidden></ui5-message-strip>
|
|
167
180
|
<p class="sbx-hint">${esc(TEXT.featureHint)}</p>
|
|
@@ -176,10 +189,6 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
176
189
|
<div class="pg-out"><code class="pg-preview"></code><ui5-button class="pg-add" icon="add">${TEXT.builderAdd}</ui5-button></div>
|
|
177
190
|
</fieldset>
|
|
178
191
|
</ui5-tab>
|
|
179
|
-
<ui5-tab text="${TEXT.steps}" data-tab="steps">
|
|
180
|
-
<p class="sbx-hint">${esc(TEXT.stepsHint)}</p>
|
|
181
|
-
<div class="pg-reference">${reference()}</div>
|
|
182
|
-
</ui5-tab>
|
|
183
192
|
<ui5-tab text="${TEXT.results}" data-tab="results">
|
|
184
193
|
<ui5-message-strip class="sbx-summary" hide-close-button hidden></ui5-message-strip>
|
|
185
194
|
<ui5-list class="sbx-results" no-data-text="${TEXT.noRun}"></ui5-list>
|
|
@@ -209,13 +218,32 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
209
218
|
const show = (name) => {
|
|
210
219
|
docs[shown] = code.value;
|
|
211
220
|
shown = name;
|
|
212
|
-
|
|
221
|
+
setCode(docs[name]);
|
|
213
222
|
code.placeholder = name === "recording" ? TEXT.recordingEmpty : "";
|
|
214
223
|
restoreButton.textContent = name === "recording" ? TEXT.clearRecording : TEXT.restore;
|
|
215
224
|
for (const item of $(".sbx-which").querySelectorAll("ui5-segmented-button-item")) item.selected = item.dataset.doc === name;
|
|
216
225
|
$(".sbx-perr").hidden = true;
|
|
217
226
|
};
|
|
218
|
-
code.value = sample;
|
|
227
|
+
code.value = sample; // fitted when the size observer below starts
|
|
228
|
+
// The editor grows with its text, wrapped lines included (UI5's own growing counts only line
|
|
229
|
+
// breaks): its height is the text's, at least 12 rows. So the page has the only scrollbar.
|
|
230
|
+
const fitEditor = () => {
|
|
231
|
+
const area = code.shadowRoot?.querySelector("textarea");
|
|
232
|
+
if (!area) return;
|
|
233
|
+
code.style.height = ""; // back to 12 rows, then as tall as the text
|
|
234
|
+
if (area.scrollHeight > area.clientHeight) code.style.height = `${area.scrollHeight + code.offsetHeight - area.clientHeight}px`;
|
|
235
|
+
};
|
|
236
|
+
function setCode(value) {
|
|
237
|
+
code.value = value;
|
|
238
|
+
requestAnimationFrame(fitEditor); // after the component has the new text
|
|
239
|
+
}
|
|
240
|
+
code.addEventListener("input", fitEditor);
|
|
241
|
+
let editorWidth = 0;
|
|
242
|
+
new ResizeObserver(([entry]) => {
|
|
243
|
+
if (Math.round(entry.contentRect.width) === editorWidth) return; // only a new width wraps differently
|
|
244
|
+
editorWidth = Math.round(entry.contentRect.width);
|
|
245
|
+
fitEditor();
|
|
246
|
+
}).observe(code);
|
|
219
247
|
const tab = (name) => { for (const [key, t] of Object.entries(tabs)) t.selected = key === name; };
|
|
220
248
|
$("ui5-segmented-button").addEventListener("selection-change", (e) => { delay = Number(e.detail.selectedItems[0]?.dataset.ms ?? 350); });
|
|
221
249
|
$(".sbx-which").addEventListener("selection-change", (e) => {
|
|
@@ -223,7 +251,7 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
223
251
|
if (name && name !== shown) show(name);
|
|
224
252
|
});
|
|
225
253
|
restoreButton.addEventListener("click", () => {
|
|
226
|
-
|
|
254
|
+
setCode(shown === "recording" ? "" : sample);
|
|
227
255
|
$(".sbx-perr").hidden = true;
|
|
228
256
|
});
|
|
229
257
|
stopButton.addEventListener("click", () => controller?.abort(new Error("Stopped")));
|
|
@@ -235,9 +263,22 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
235
263
|
}
|
|
236
264
|
});
|
|
237
265
|
|
|
238
|
-
// The box over the app: where the step acts, green when
|
|
266
|
+
// The box over the app: where the step acts (accent colour), green when a check passed. It fades
|
|
267
|
+
// shortly after the step, so it never stays over the app (after a run, a recorded click, a hover).
|
|
268
|
+
let fade = 0;
|
|
269
|
+
const hideBox = () => {
|
|
270
|
+
clearTimeout(fade);
|
|
271
|
+
box.classList.remove("sbx-fading");
|
|
272
|
+
box.hidden = true;
|
|
273
|
+
};
|
|
239
274
|
const highlight = ({ element: target, label, passed }) => {
|
|
240
275
|
if (!delay || !target.isConnected) return;
|
|
276
|
+
clearTimeout(fade);
|
|
277
|
+
box.classList.remove("sbx-fading");
|
|
278
|
+
fade = setTimeout(() => {
|
|
279
|
+
box.classList.add("sbx-fading");
|
|
280
|
+
fade = setTimeout(hideBox, 400);
|
|
281
|
+
}, Math.max(delay, 300) + 600);
|
|
241
282
|
const r = target.getBoundingClientRect();
|
|
242
283
|
Object.assign(box.style, {
|
|
243
284
|
left: `${frame.offsetLeft + r.left - 4}px`, top: `${frame.offsetTop + r.top - 4}px`,
|
|
@@ -259,14 +300,14 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
259
300
|
label.style.top = below ? "calc(100% + 2px)" : "";
|
|
260
301
|
};
|
|
261
302
|
frame.addEventListener("load", () => {
|
|
262
|
-
|
|
303
|
+
hideBox();
|
|
263
304
|
// a new page in the app (a link, a reload): keep recording there
|
|
264
305
|
if (rec && frame.contentDocument && frame.contentDocument !== rec.doc) {
|
|
265
306
|
rec.off();
|
|
266
307
|
rec.doc = frame.contentDocument;
|
|
267
308
|
rec.off = attach(rec.doc);
|
|
268
309
|
}
|
|
269
|
-
frame.contentWindow?.addEventListener("scroll",
|
|
310
|
+
frame.contentWindow?.addEventListener("scroll", hideBox, { passive: true });
|
|
270
311
|
});
|
|
271
312
|
const newPage = (signal) => createPage({
|
|
272
313
|
frame, baseURL: appUrl, timeout: 10_000, signal,
|
|
@@ -298,7 +339,7 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
298
339
|
const toast = (text) => { const t = $(".sbx-toast"); t.textContent = text; t.open = true; };
|
|
299
340
|
const render = () => {
|
|
300
341
|
const lines = toSteps(rec.interactions).map((line) => ` ${line}`);
|
|
301
|
-
|
|
342
|
+
setCode(`${rec.before}\n Scenario: ${rec.scenarioName}\n${lines.join("\n")}${lines.length ? "\n" : ""}`);
|
|
302
343
|
previews = new WeakMap(); // the page changed: names may too
|
|
303
344
|
};
|
|
304
345
|
// While a click is named and done, the recorder is busy: shown on the playground
|
|
@@ -389,7 +430,9 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
389
430
|
const onCheck = async (el, x, y) => {
|
|
390
431
|
await flushTyping();
|
|
391
432
|
const seen = await name(el);
|
|
392
|
-
|
|
433
|
+
// in or at a table (a row, its title "Products (2)"): how many rows it says it has
|
|
434
|
+
const count = await countCheck(rec.ui5, locatorFor(el)).catch(() => null);
|
|
435
|
+
if (!seen && !count) {
|
|
393
436
|
toast(TEXT.cannotName);
|
|
394
437
|
return;
|
|
395
438
|
}
|
|
@@ -401,13 +444,14 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
401
444
|
control.getAttribute("aria-invalid") === "true" && "Error",
|
|
402
445
|
control.getAttribute("aria-expanded") === "true" && "expanded"
|
|
403
446
|
].filter(Boolean);
|
|
404
|
-
const steps = [`Then I should see ${seen.text}`];
|
|
447
|
+
const steps = seen ? [`Then I should see ${seen.text}`] : [];
|
|
405
448
|
const input = el.matches(EDITABLE) ? el : null;
|
|
406
449
|
if (input) {
|
|
407
450
|
const field = await name(input, { input: true });
|
|
408
451
|
if (field) steps.push(`Then the value of ${field.text} is "${input.value.replace(/["\\]/g, "\\$&")}"`);
|
|
409
452
|
}
|
|
410
|
-
steps.push(...states.map((state) => `Then I expect that ${seen.text} is "${state}"`));
|
|
453
|
+
if (seen) steps.push(...states.map((state) => `Then I expect that ${seen.text} is "${state}"`));
|
|
454
|
+
if (count) steps.push(count);
|
|
411
455
|
checks.replaceChildren(...steps.map((step) => {
|
|
412
456
|
const item = document.createElement("ui5-menu-item");
|
|
413
457
|
item.text = step.replace(/^Then /, "");
|
|
@@ -510,7 +554,7 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
510
554
|
let hovered = null;
|
|
511
555
|
let hoverTimer = 0;
|
|
512
556
|
const label = (text) => {
|
|
513
|
-
box.dataset.passed = text ? "yes" : "
|
|
557
|
+
box.dataset.passed = text ? "yes" : "unnamed";
|
|
514
558
|
box.firstChild.textContent = text ?? TEXT.cannotNameHover;
|
|
515
559
|
placeLabel();
|
|
516
560
|
};
|
|
@@ -528,6 +572,8 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
528
572
|
label(previews.get(control));
|
|
529
573
|
return;
|
|
530
574
|
}
|
|
575
|
+
clearTimeout(fade); // a hover box stays while hovered
|
|
576
|
+
box.classList.remove("sbx-fading");
|
|
531
577
|
box.dataset.passed = "yes";
|
|
532
578
|
box.firstChild.textContent = "…";
|
|
533
579
|
placeLabel();
|
|
@@ -556,6 +602,13 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
556
602
|
doc.addEventListener("keydown", onKey, true);
|
|
557
603
|
doc.addEventListener("contextmenu", onMenu, true);
|
|
558
604
|
doc.addEventListener("mouseover", onHover, true);
|
|
605
|
+
// the mouse leaves the app: no box stays behind
|
|
606
|
+
const onLeave = (e) => {
|
|
607
|
+
if (e.relatedTarget) return;
|
|
608
|
+
hovered = null;
|
|
609
|
+
hideBox();
|
|
610
|
+
};
|
|
611
|
+
doc.addEventListener("mouseout", onLeave, true);
|
|
559
612
|
return () => {
|
|
560
613
|
for (const type of types) doc.removeEventListener(type, hold, true);
|
|
561
614
|
onTouchCancel();
|
|
@@ -571,6 +624,7 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
571
624
|
doc.removeEventListener("keydown", onKey, true);
|
|
572
625
|
doc.removeEventListener("contextmenu", onMenu, true);
|
|
573
626
|
doc.removeEventListener("mouseover", onHover, true);
|
|
627
|
+
doc.removeEventListener("mouseout", onLeave, true);
|
|
574
628
|
};
|
|
575
629
|
};
|
|
576
630
|
|
|
@@ -602,7 +656,7 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
602
656
|
await flushTyping().catch(() => {}); // a field still being typed into
|
|
603
657
|
current.off();
|
|
604
658
|
rec = null;
|
|
605
|
-
|
|
659
|
+
hideBox();
|
|
606
660
|
recordButton.textContent = TEXT.record;
|
|
607
661
|
recordButton.icon = "record";
|
|
608
662
|
recordStatus.hidden = true;
|
|
@@ -626,7 +680,7 @@ export async function mount(element, { base, app, feature, sites = {} }) {
|
|
|
626
680
|
const lastKeyword = stepLines.map((l) => l.trim().split(/\s/)[0]).filter((k) => !["And", "But"].includes(k)).at(-1);
|
|
627
681
|
const [keyword, ...rest] = line.split(" ");
|
|
628
682
|
const text = `${indent || " "}${keyword === lastKeyword ? "And" : keyword} ${rest.join(" ")}`;
|
|
629
|
-
|
|
683
|
+
setCode(`${value.slice(0, lineEnd)}\n${text}${value.slice(lineEnd)}`);
|
|
630
684
|
const end = lineEnd + 1 + text.length;
|
|
631
685
|
requestAnimationFrame(() => { textarea()?.focus(); textarea()?.setSelectionRange(end, end); });
|
|
632
686
|
tab("feature");
|
|
@@ -736,8 +790,45 @@ ${result.snippet ? `<pre class="sbx-snippet">${esc(result.snippet)}</pre><ui5-bu
|
|
|
736
790
|
tab("feature");
|
|
737
791
|
};
|
|
738
792
|
|
|
793
|
+
// Scrolling along a run: it starts with the app at the top (below a sticky page header, the
|
|
794
|
+
// sandbox's scroll-margin-top), then the page glides so the running step stays at about the
|
|
795
|
+
// same height on screen, never above that start. Wide screens only; stacked, the app stays put.
|
|
796
|
+
const sbx = $(".sbx");
|
|
797
|
+
const topOfApp = () => sbx.getBoundingClientRect().top + scrollY - parseFloat(getComputedStyle(sbx).scrollMarginTop || "0");
|
|
798
|
+
// One gentle animation that each new step only retargets: a part of the way per frame, at most
|
|
799
|
+
// 48px. Scrolling by the user (wheel, touch, keys) lets go; "reduce motion" jumps instead.
|
|
800
|
+
let target = 0;
|
|
801
|
+
let gliding = 0;
|
|
802
|
+
const towards = () => {
|
|
803
|
+
const end = Math.min(target, document.documentElement.scrollHeight - innerHeight); // as far as the page goes
|
|
804
|
+
const rest = end - scrollY;
|
|
805
|
+
const from = scrollY;
|
|
806
|
+
if (Math.abs(rest) >= 1) scrollTo(0, scrollY + Math.sign(rest) * Math.min(48, Math.max(1, Math.abs(rest) * 0.12)));
|
|
807
|
+
gliding = Math.abs(rest) >= 1 && scrollY !== from ? requestAnimationFrame(towards) : 0; // there, or stuck
|
|
808
|
+
};
|
|
809
|
+
const letGo = () => {
|
|
810
|
+
cancelAnimationFrame(gliding);
|
|
811
|
+
gliding = 0;
|
|
812
|
+
};
|
|
813
|
+
for (const type of ["wheel", "touchstart", "keydown"]) addEventListener(type, letGo, { passive: true });
|
|
814
|
+
const glide = (y) => {
|
|
815
|
+
target = Math.max(0, Math.round(y));
|
|
816
|
+
if (matchMedia("(prefers-reduced-motion: reduce)").matches) scrollTo(0, target);
|
|
817
|
+
else if (!gliding) gliding = requestAnimationFrame(towards);
|
|
818
|
+
};
|
|
819
|
+
// The app floats only down to the sandbox's bottom edge: past the point where it meets it, its
|
|
820
|
+
// top would be cut off. So the page goes no further; the last steps sit lower on the screen.
|
|
821
|
+
const appBox = $(".sbx-browser");
|
|
822
|
+
const lastWholeApp = () => sbx.getBoundingClientRect().bottom + scrollY - parseFloat(getComputedStyle(sbx).scrollMarginTop || "0") - appBox.offsetHeight;
|
|
823
|
+
const follow = (li) => {
|
|
824
|
+
if (!matchMedia("(min-width: 60rem)").matches) return;
|
|
825
|
+
const wanted = li.getBoundingClientRect().top + scrollY - innerHeight * 0.55;
|
|
826
|
+
glide(Math.max(topOfApp(), Math.min(wanted, lastWholeApp())));
|
|
827
|
+
};
|
|
828
|
+
|
|
739
829
|
async function run() {
|
|
740
830
|
if (controller || runButton.disabled || rec) return;
|
|
831
|
+
glide(topOfApp());
|
|
741
832
|
const registry = createRegistry();
|
|
742
833
|
defineSteps(registry.group("ui5-playwright-gherkin"));
|
|
743
834
|
controller = new AbortController();
|
|
@@ -746,7 +837,7 @@ ${result.snippet ? `<pre class="sbx-snippet">${esc(result.snippet)}</pre><ui5-bu
|
|
|
746
837
|
stopButton.disabled = false;
|
|
747
838
|
$(".sbx-perr").hidden = true;
|
|
748
839
|
summary.hidden = true;
|
|
749
|
-
tabs.results.
|
|
840
|
+
tabs.results.text = TEXT.results;
|
|
750
841
|
const rows = new Map(); // step id -> li
|
|
751
842
|
|
|
752
843
|
const execution = runFeatures([{ uri: "sandbox.feature", source: code.value }], {
|
|
@@ -781,7 +872,9 @@ ${result.snippet ? `<pre class="sbx-snippet">${esc(result.snippet)}</pre><ui5-bu
|
|
|
781
872
|
tab("results");
|
|
782
873
|
});
|
|
783
874
|
execution.on("step-started", ({ step }) => {
|
|
784
|
-
|
|
875
|
+
const li = rows.get(step.id);
|
|
876
|
+
paint(li, "running");
|
|
877
|
+
follow(li);
|
|
785
878
|
now.hidden = false;
|
|
786
879
|
now.textContent = `${step.keyword.trim()} ${step.text}`;
|
|
787
880
|
});
|
|
@@ -798,12 +891,12 @@ ${result.snippet ? `<pre class="sbx-snippet">${esc(result.snippet)}</pre><ui5-bu
|
|
|
798
891
|
summary.design = bad ? "Negative" : "Positive";
|
|
799
892
|
summary.textContent = `${parts.join(" · ")} · ${plural(result.steps.total, "step")} in ${(result.duration / 1000).toFixed(1)} s${result.stopped ? " (stopped)" : ""}`;
|
|
800
893
|
summary.hidden = false;
|
|
801
|
-
tabs.results.
|
|
894
|
+
tabs.results.text = bad ? `${TEXT.results} · ${bad} not passed` : `${TEXT.results} ✓`;
|
|
802
895
|
}
|
|
803
896
|
return result;
|
|
804
897
|
} finally {
|
|
805
898
|
now.hidden = true;
|
|
806
|
-
|
|
899
|
+
hideBox();
|
|
807
900
|
controller = null;
|
|
808
901
|
runButton.disabled = false;
|
|
809
902
|
stopButton.disabled = true;
|
package/src/styles.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// --sbx-accent-text the current step, examples --sbx-tint-strong an example on hover
|
|
10
10
|
// --sbx-font text --sbx-radius corners of the app and fields
|
|
11
11
|
// --sbx-mono code --sbx-ease the highlight box's motion
|
|
12
|
+
// --sbx-accent the box where a step acts --sbx-sticky-top where the app floats, below a sticky header (1rem)
|
|
13
|
+
// --sbx-app-height the app's height on wide screens (default: the window's, up to 42rem)
|
|
12
14
|
//
|
|
13
15
|
// The selectors are plain classes (.sbx-…, .pg-…), after the page's own style sheets: a page rule
|
|
14
16
|
// with a more specific selector wins.
|
|
@@ -23,14 +25,22 @@ const tint = "var(--sbx-tint, color-mix(in srgb, var(--sapBrandColor, #0a6ed1) 1
|
|
|
23
25
|
const tintStrong = "var(--sbx-tint-strong, color-mix(in srgb, var(--sapBrandColor, #0a6ed1) 17%, transparent))";
|
|
24
26
|
const radius = "var(--sbx-radius, var(--sapElement_BorderCornerRadius, .75rem))";
|
|
25
27
|
const ease = "var(--sbx-ease, cubic-bezier(.2, .8, .2, 1))";
|
|
28
|
+
const accent = "var(--sbx-accent, var(--sapBrandColor, #0a6ed1))";
|
|
26
29
|
const negative = "var(--sapNegativeColor, #e00)";
|
|
27
30
|
const positive = "var(--sapPositiveColor, #2b7c2b)";
|
|
28
31
|
|
|
29
32
|
export const css = `
|
|
30
|
-
/* the app on the left, the panel on the right
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.sbx
|
|
33
|
+
/* the app on the left, the panel on the right. The panel grows with its content and the page
|
|
34
|
+
scrolls; the app keeps one size and floats along (sticky), so it never jumps. Stacked on narrow
|
|
35
|
+
screens. */
|
|
36
|
+
.sbx { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1rem; align-items: start;
|
|
37
|
+
scroll-margin-top: var(--sbx-sticky-top, 1rem);
|
|
38
|
+
/* at least the window below the header: a run can always bring the app to the top, and the page
|
|
39
|
+
does not shrink when the editor gives way to the (still empty) results */
|
|
40
|
+
min-height: calc(100vh - var(--sbx-sticky-top, 1rem)); }
|
|
41
|
+
@media (max-width: 60rem) { .sbx { grid-template-columns: 1fr; min-height: 0; } .sbx .sbx-browser { position: relative; top: auto; height: 28rem; } }
|
|
42
|
+
.sbx-browser { position: sticky; top: var(--sbx-sticky-top, 1rem); z-index: 1;
|
|
43
|
+
height: var(--sbx-app-height, min(42rem, calc(100vh - var(--sbx-sticky-top, 1rem) - 1.5rem))); display: flex; flex-direction: column; min-height: 0; overflow: hidden;
|
|
34
44
|
border-radius: ${radius}; border: 1px solid ${line}; background: var(--sapBackgroundColorDefault, #fff); }
|
|
35
45
|
.sbx-chrome { display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; font-size: .8125rem; color: ${muted};
|
|
36
46
|
border-bottom: 1px solid ${line}; background: ${surface}; }
|
|
@@ -40,19 +50,23 @@ export const css = `
|
|
|
40
50
|
.sbx-now { margin-left: auto; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: ${accentText}; }
|
|
41
51
|
.sbx-viewport { position: relative; flex: 1; min-height: 0; }
|
|
42
52
|
.sbx-viewport iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
|
|
43
|
-
.sbx-box { position: absolute; pointer-events: none; border: 2px solid ${
|
|
44
|
-
background: color-mix(in srgb, ${
|
|
53
|
+
.sbx-box { position: absolute; pointer-events: none; border: 2px solid ${accent}; border-radius: .375rem;
|
|
54
|
+
background: color-mix(in srgb, ${accent} 12%, transparent); transition: all .15s ${ease}, opacity .4s ${ease}; }
|
|
55
|
+
.sbx-box.sbx-fading { opacity: 0; }
|
|
45
56
|
.sbx-box[data-passed="yes"] { border-color: ${positive}; background: color-mix(in srgb, ${positive} 12%, transparent); }
|
|
46
57
|
.sbx-box span { position: absolute; left: -2px; bottom: 100%; margin-bottom: 2px; padding: .1rem .4rem; border-radius: .25rem;
|
|
47
|
-
font-size: .75rem; color: #fff; background: ${
|
|
58
|
+
font-size: .75rem; color: #fff; background: ${accent}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
48
59
|
.sbx-box[data-passed="yes"] span { background: ${positive}; }
|
|
49
|
-
.sbx-
|
|
50
|
-
.sbx-
|
|
60
|
+
.sbx-box[data-passed="unnamed"] { border-color: ${negative}; background: color-mix(in srgb, ${negative} 12%, transparent); }
|
|
61
|
+
.sbx-box[data-passed="unnamed"] span { background: ${negative}; }
|
|
62
|
+
.sbx-panel { display: flex; flex-direction: column; min-width: 0; }
|
|
51
63
|
.sbx-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .25rem; }
|
|
52
64
|
.sbx-spacer { flex: 1; }
|
|
53
|
-
.sbx-
|
|
54
|
-
|
|
55
|
-
.sbx-
|
|
65
|
+
.sbx-doc { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .5rem; }
|
|
66
|
+
/* a step scrolled to stays clear of a sticky page header */
|
|
67
|
+
.sbx-results ui5-li-custom { scroll-margin-top: calc(var(--sbx-sticky-top, 1rem) + 1rem); scroll-margin-bottom: 1.5rem; }
|
|
68
|
+
/* the editor grows with its text: its measuring copy must use the same (monospace) font */
|
|
69
|
+
.sbx-code { width: 100%; font-family: ${mono}; --sapFontFamily: ${mono}; }
|
|
56
70
|
.sbx-hint { margin: .5rem .25rem; color: ${muted}; font-size: .8125rem; }
|
|
57
71
|
.sbx-row { display: flex; align-items: flex-start; gap: .625rem; padding: .375rem 0; width: 100%; }
|
|
58
72
|
.sbx-row ui5-icon { flex: none; margin-top: .2rem; }
|