@webship-js/adminlte-steps 0.0.0-stage → 2.0.0

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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +348 -2
  3. package/demo-site/.ddev/config.yaml +10 -0
  4. package/demo-site/3.2/cards.html +89 -0
  5. package/demo-site/3.2/chat.html +84 -0
  6. package/demo-site/3.2/components.html +79 -0
  7. package/demo-site/3.2/css/demo.css +7 -0
  8. package/demo-site/3.2/index.html +93 -0
  9. package/demo-site/3.2/no-sidebar.html +2 -0
  10. package/demo-site/3.2/settings.html +74 -0
  11. package/demo-site/3.2/vendor/admin-lte-3.2.0/LICENSE +20 -0
  12. package/demo-site/3.2/vendor/admin-lte-3.2.0/css/adminlte.min.css +12 -0
  13. package/demo-site/3.2/vendor/admin-lte-3.2.0/js/adminlte.min.js +7 -0
  14. package/demo-site/3.2/vendor/bootstrap-4.6.2/LICENSE +22 -0
  15. package/demo-site/3.2/vendor/bootstrap-4.6.2/js/bootstrap.bundle.min.js +7 -0
  16. package/demo-site/3.2/vendor/jquery-3.6.4/LICENSE.txt +20 -0
  17. package/demo-site/3.2/vendor/jquery-3.6.4/jquery.min.js +2 -0
  18. package/demo-site/cards.html +98 -0
  19. package/demo-site/chat.html +93 -0
  20. package/demo-site/components.html +88 -0
  21. package/demo-site/css/adminlte-no-banner.min.css +1 -0
  22. package/demo-site/css/demo.css +5 -0
  23. package/demo-site/index.html +102 -0
  24. package/demo-site/no-banner.html +101 -0
  25. package/demo-site/no-sidebar.html +2 -0
  26. package/demo-site/settings.html +83 -0
  27. package/demo-site/vendor/admin-lte-4.10.4/LICENSE +20 -0
  28. package/demo-site/vendor/admin-lte-4.10.4/css/adminlte.min.css +7 -0
  29. package/demo-site/vendor/admin-lte-4.10.4/js/adminlte.min.js +7 -0
  30. package/demo-site/vendor/bootstrap-5.3.9/LICENSE +21 -0
  31. package/demo-site/vendor/bootstrap-5.3.9/js/bootstrap.bundle.min.js +7 -0
  32. package/package.json +70 -4
  33. package/tests/features/README.md +20 -0
  34. package/tests/features/bootstrap-inside.feature +22 -0
  35. package/tests/features/cards.feature +34 -0
  36. package/tests/features/chat.feature +13 -0
  37. package/tests/features/menu.feature +24 -0
  38. package/tests/features/page.feature +37 -0
  39. package/tests/features/sidebar.feature +24 -0
  40. package/tests/step-definitions/README.md +1 -0
  41. package/tests/step-definitions/adminlte-cards.steps.js +211 -0
  42. package/tests/step-definitions/adminlte-helpers.js +385 -0
  43. package/tests/step-definitions/adminlte-layout.steps.js +231 -0
  44. package/tests/step-definitions/adminlte-menu.steps.js +98 -0
@@ -0,0 +1,231 @@
1
+ 'use strict';
2
+
3
+ // The frame of a dashboard: the sidebar and its toggle, full screen, the color mode (AdminLTE 4) and the theme's
4
+ // style sheet. AdminLTE's script moves the sidebar (a 0.3 second slide); the steps wait for its end state and the end
5
+ // of the slide.
6
+
7
+ const { When, Then } = require('@cucumber/cucumber');
8
+ const h = require('./adminlte-helpers');
9
+
10
+ function describeSidebar(s) {
11
+ return `it is ${s.expanded ? 'expanded' : 'collapsed'} (${s.width} pixels wide at ${s.left} pixels from the left, in a window ${s.windowWidth} pixels wide; the page's classes "${s.classes}")`;
12
+ }
13
+
14
+ async function sidebarTo(world, want) {
15
+ return h.poll(world, (lib, a) => { const s = lib.sidebarState(); return { done: !s.missing && s.expanded === a.want && !s.moving, state: s }; }, { want }, h.budget(world));
16
+ }
17
+
18
+ /**
19
+ * Collapse or expand the sidebar with its toggle (the button of the top bar that AdminLTE's push menu answers to) and
20
+ * wait until it has slid to the end. On a narrow screen, where the open sidebar covers its toggle, it is collapsed
21
+ * the way a person does: with a click beside it, on the overlay over the page. On both versions a person sees the same: expanded, the sidebar at its full width
22
+ * with the labels of its menu; collapsed, the sidebar out of the window (AdminLTE 4, and 3.2 on a narrow screen) or
23
+ * reduced to its strip of icons (3.2 on a wide screen). A sidebar already in that state is left as it is.
24
+ *
25
+ * Example #1: When I collapse the sidebar
26
+ * Example #2: When I expand the sidebar
27
+ * Example #3: When we collapse the sidebar
28
+ * Example #4: When we expand the sidebar
29
+ * Example #5: And I expand the sidebar
30
+ */
31
+ When(/^(?:I |we )?(collapse|expand) the sidebar$/, async function (action) {
32
+ const want = action === 'expand';
33
+ const first = await h.poll(this, (lib) => { const s = lib.sidebarState(); return { done: !s.missing && !s.moving, state: s }; }, null, h.budget(this));
34
+ const s = first.state || {};
35
+ if (s.missing) {
36
+ throw h.failure(this.page, `Could not ${action} the sidebar: the page has none.`, { hint: 'the sidebar of AdminLTE is an <aside class="app-sidebar"> (4) or <aside class="main-sidebar"> (3.2).' });
37
+ }
38
+ if (s.expanded === want) return;
39
+ if (!s.toggle) {
40
+ throw h.failure(this.page, `Could not ${action} the sidebar: no visible toggle opens and closes it.`, { hint: 'the toggle is a link or a button with data-lte-toggle="sidebar" (4) or data-widget="pushmenu" (3.2), in the top bar.' });
41
+ }
42
+ // On a narrow screen the open sidebar covers its own toggle: a person closes it with a click beside it, on the
43
+ // overlay AdminLTE puts over the page.
44
+ const beside = !want && !s.toggleReachable ? await h.call(this, 'besideSidebar') : null;
45
+ if (beside) await this.page.mouse.click(beside.x, beside.y);
46
+ else await h.clickRef(this, s.toggle, 'the toggle of the sidebar');
47
+ const result = await sidebarTo(this, want);
48
+ if (result.done) return;
49
+ throw h.failure(this.page, `Expected the sidebar to be ${want ? 'expanded' : 'collapsed'} after its toggle was clicked, but ${describeSidebar(result.state || {})}.`, {
50
+ hint: 'check that the page loads AdminLTE\'s script ("adminlte.min.js") after Bootstrap\'s (and jQuery\'s, on 3.2).',
51
+ });
52
+ });
53
+
54
+ /**
55
+ * The sidebar is expanded (drawn at its full width inside the window, the labels of its menu shown) or collapsed (out
56
+ * of the window, or reduced to 3.2's strip of icons), and has stopped moving. The same on both versions; a narrow
57
+ * window starts with the sidebar collapsed.
58
+ *
59
+ * Example #1: Then the sidebar should be expanded
60
+ * Example #2: Then the sidebar should be collapsed
61
+ * Example #3: And the sidebar should be collapsed
62
+ * Example #4: But the sidebar should be expanded
63
+ * Example #5: Then the sidebar should be collapsed
64
+ */
65
+ Then(/^the sidebar should be (expanded|collapsed)$/, async function (wanted) {
66
+ const result = await sidebarTo(this, wanted === 'expanded');
67
+ if (result.done) return;
68
+ const s = result.state || {};
69
+ if (s.missing) throw h.failure(this.page, `Expected the sidebar to be ${wanted}, but the page has none.`, { hint: 'the sidebar of AdminLTE is an <aside class="app-sidebar"> (4) or <aside class="main-sidebar"> (3.2).' });
70
+ throw h.failure(this.page, `Expected the sidebar to be ${wanted}, but ${describeSidebar(s)}.`, {
71
+ hint: wanted === 'expanded' ? 'expand it first: When I expand the sidebar' : 'collapse it first: When I collapse the sidebar',
72
+ });
73
+ });
74
+
75
+ /**
76
+ * Enter or leave full screen with the page's own toggle (the button of the top bar AdminLTE's full screen plugin
77
+ * answers to), and wait until the browser is (or is no longer) in full screen. The same on both versions.
78
+ *
79
+ * Example #1: When I enter full screen
80
+ * Example #2: When I leave full screen
81
+ * Example #3: When we enter full screen
82
+ * Example #4: When we leave full screen
83
+ * Example #5: And I leave full screen
84
+ */
85
+ When(/^(?:I |we )?(enter|leave) full screen$/, async function (action) {
86
+ const want = action === 'enter';
87
+ const s = await h.call(this, 'fullscreenState');
88
+ if (s.on === want) return;
89
+ if (!s.toggle) {
90
+ throw h.failure(this.page, `Could not ${action} full screen: the page has no visible full screen toggle.`, { hint: 'the toggle is a link or a button with data-lte-toggle="fullscreen" (4) or data-widget="fullscreen" (3.2).' });
91
+ }
92
+ await h.clickRef(this, s.toggle, 'the full screen toggle');
93
+ const result = await h.poll(this, (lib, a) => { const t = lib.fullscreenState(); return { done: t.on === a.want, state: t }; }, { want }, h.budget(this));
94
+ if (result.done) return;
95
+ throw h.failure(this.page, `Expected the page to be ${want ? '' : 'no longer '}in full screen after its toggle was clicked, but it is ${result.state.on ? '' : 'not '}in full screen.`, {
96
+ hint: 'a browser enters full screen only on a click of the page (a user gesture), and only where full screen is allowed (not in a frame without allowfullscreen).',
97
+ });
98
+ });
99
+
100
+ /**
101
+ * The page is in full screen (with "not": it is not), waiting for the browser to get there.
102
+ *
103
+ * Example #1: Then the page should be in full screen
104
+ * Example #2: Then the page should not be in full screen
105
+ * Example #3: And the page should be in full screen
106
+ * Example #4: And the page should not be in full screen
107
+ * Example #5: But the page should not be in full screen
108
+ */
109
+ Then(/^the page should( not)? be in full screen$/, async function (not) {
110
+ const result = await h.poll(this, (lib, a) => { const t = lib.fullscreenState(); return { done: t.on === !a.not, state: t }; }, { not: !!not }, h.budget(this));
111
+ if (result.done) return;
112
+ throw h.failure(this.page, `Expected the page ${not ? 'not ' : ''}to be in full screen, but it is ${result.state.on ? '' : 'not '}in full screen.`, {
113
+ hint: not ? 'leave it first: When I leave full screen' : 'enter it first: When I enter full screen',
114
+ });
115
+ });
116
+
117
+ /**
118
+ * AdminLTE 4 only (3.2 has no color mode switcher, and the step fails there with a hint, never passes quietly).
119
+ * Switch the color mode with the page's own switcher: the button whose label (or value) is the mode, "Light", "Dark"
120
+ * or "Auto", opened from its drop-down menu first when it is hidden there; then wait until the mode is applied (its
121
+ * button pressed, and for light or dark, the page drawn in it: data-bs-theme on the page) and the page's colours
122
+ * have finished moving to it (they change with a transition).
123
+ *
124
+ * Example #1: When I switch the dashboard's color mode to "Dark"
125
+ * Example #2: When I switch the dashboard's color mode to "Light"
126
+ * Example #3: When I switch the dashboard's color mode to "Auto"
127
+ * Example #4: When we switch the dashboard's color mode to "dark"
128
+ * Example #5: And I switch the dashboard's color mode to "Light"
129
+ */
130
+ When(/^(?:I |we )?switch the dashboard's color mode to "([^"]*)"$/, async function (mode) {
131
+ const buttons = await h.call(this, 'colorButtons');
132
+ if (!buttons.length) {
133
+ throw h.failure(this.page, `Could not switch the dashboard's color mode to "${mode}": the page has no color mode switcher.`, {
134
+ hint: 'the switcher is AdminLTE 4\'s (buttons with data-bs-theme-value, since 4.1); AdminLTE 3.2 has none, so leave this step out of a 3.2 site\'s scenarios (tag them, as the demo\'s @lte4).',
135
+ });
136
+ }
137
+ const hit = await h.call(this, 'pick', buttons, mode);
138
+ if (!hit) {
139
+ throw h.failure(this.page, `Could not switch the dashboard's color mode to "${mode}": the switcher has no such mode.`, { found: `its modes: ${h.listed(buttons.map((b) => b.names[0]))}`, hint: 'a mode is named by the label of its button (or its data-bs-theme-value).' });
140
+ }
141
+ const visible = await h.locatorOf(this, hit.ref).isVisible();
142
+ if (!visible) {
143
+ const toggle = await h.call(this, 'dropdownToggleOf', hit.ref);
144
+ if (toggle) await h.clickRef(this, toggle, 'the color mode menu');
145
+ }
146
+ await h.clickRef(this, hit.ref, `the color mode "${mode}"`);
147
+ const result = await h.poll(this, (lib, a) => {
148
+ const s = lib.colorState();
149
+ const b = s.buttons.find((x) => x.value === a.value);
150
+ const applied = a.value === 'auto' ? true : s.theme === a.value;
151
+ return { done: !!b && b.pressed && applied && s.settled, state: s };
152
+ }, { value: hit.value }, h.budget(this));
153
+ if (result.done) return;
154
+ throw h.failure(this.page, `Expected the color mode "${mode}" to be applied after its button was clicked, but the page is drawn in "${result.state.theme || 'its default'}".`, {
155
+ found: `the modes: ${result.state.buttons.map((b) => `${b.name}${b.pressed ? ' (chosen)' : ''}`).join(', ')}`,
156
+ hint: 'AdminLTE 4\'s color mode module applies the mode as data-bs-theme on <html>; a page that opted out (data-lte-color-mode="off") handles it itself.',
157
+ });
158
+ });
159
+
160
+ /**
161
+ * AdminLTE 4 only (3.2 has no color modes: the step fails there with a hint). The page is drawn in a color mode,
162
+ * "light" or "dark" (data-bs-theme on the page, as AdminLTE 4's color mode module resolves it, "auto" included).
163
+ *
164
+ * Example #1: Then the dashboard's color mode should be "dark"
165
+ * Example #2: Then the dashboard's color mode should be "light"
166
+ * Example #3: And the dashboard's color mode should be "dark"
167
+ * Example #4: Then the dashboard's color mode should be "Dark"
168
+ * Example #5: But the dashboard's color mode should be "light"
169
+ */
170
+ Then(/^the dashboard's color mode should be "([^"]*)"$/, async function (mode) {
171
+ const want = h.norm(mode).toLowerCase();
172
+ const result = await h.poll(this, (lib, a) => { const s = lib.colorState(); return { done: s.theme === a.want && s.settled, state: s, buttons: s.buttons.length }; }, { want }, h.budget(this));
173
+ if (result.done) return;
174
+ const s = result.state || {};
175
+ throw h.failure(this.page, `Expected the dashboard's color mode to be "${want}", but the page is drawn in "${s.theme || 'no mode (no data-bs-theme on the page)'}".`, {
176
+ hint: result.buttons ? `switch it first: When I switch the dashboard's color mode to "${mode}"` : 'the page has no color mode switcher: color modes are AdminLTE 4\'s (3.2 has none), so leave this step out of a 3.2 site\'s scenarios.',
177
+ });
178
+ });
179
+
180
+ // The banner AdminLTE's build puts at the top of its style sheet: `/*! * AdminLTE v4.10.4 ...`.
181
+ const BANNER = /\/\*![\s*]*AdminLTE\s+v(\d+\.\d+\.\d+[\w.-]*)/i;
182
+
183
+ /**
184
+ * The page loads AdminLTE's style sheet, read from the address of each `<link rel="stylesheet">` the page has (the
185
+ * file the browser loads): the one whose banner names AdminLTE. With a version ("4", "4.10" or "4.10.4"), the
186
+ * banner's version starts with it. Fails with a hint when the page loads a style sheet that looks like AdminLTE's
187
+ * (its address says "adminlte") but whose banner a build stripped, since the version cannot be read then.
188
+ *
189
+ * Example #1: Then the page should use the dashboard theme
190
+ * Example #2: Then the page should use the dashboard theme at version "4"
191
+ * Example #3: Then the page should use the dashboard theme at version "4.10.4"
192
+ * Example #4: Then the page should use the dashboard theme at version "3.2"
193
+ * Example #5: And the page should use the dashboard theme at version "3.2.0"
194
+ */
195
+ Then(/^the page should use the dashboard theme(?: at version "([^"]*)")?$/, async function (version) {
196
+ const hrefs = await h.call(this, 'styleSheets');
197
+ const read = [];
198
+ for (const href of hrefs) {
199
+ let head = '';
200
+ let status = 0;
201
+ try {
202
+ const response = await this.page.request.get(href, { timeout: h.budget(this) });
203
+ status = response.status();
204
+ head = status < 400 ? (await response.text()).slice(0, 2000) : '';
205
+ } catch (e) {
206
+ status = -1;
207
+ }
208
+ const m = head.match(BANNER);
209
+ read.push({ href, status, version: m ? m[1] : '', looksLike: /admin-?lte/i.test(href) });
210
+ }
211
+ const found = `the style sheets of the page: ${read.map((r) => `${r.href} (${r.version ? `AdminLTE v${r.version}` : r.status > 0 && r.status < 400 ? 'no AdminLTE banner' : `not loaded: ${r.status === -1 ? 'no answer' : `HTTP ${r.status}`}`})`).join('; ') || '(none)'}`;
212
+ const lte = read.filter((r) => r.version);
213
+ if (!lte.length) {
214
+ const stripped = read.find((r) => r.looksLike && r.status > 0 && r.status < 400);
215
+ throw h.failure(this.page, stripped
216
+ ? `Expected the page to use AdminLTE's style sheet${version ? ` at version "${version}"` : ''}, but the banner of ${stripped.href} was stripped, so its version cannot be read.`
217
+ : `Expected the page to use AdminLTE's style sheet${version ? ` at version "${version}"` : ''}, but none of its style sheets carries AdminLTE's banner.`, {
218
+ found,
219
+ hint: stripped
220
+ ? 'AdminLTE\'s own build begins its style sheet with "/*! AdminLTE v<version> ..."; a build that strips comments (or bundles AdminLTE into another file) loses it: keep the /*! comments in the build.'
221
+ : 'a page loads AdminLTE with <link rel="stylesheet" href=".../adminlte.min.css">.',
222
+ });
223
+ }
224
+ if (!version) return;
225
+ const want = String(version).replace(/^v/i, '');
226
+ if (lte.some((r) => r.version === want || r.version.startsWith(`${want}.`))) return;
227
+ throw h.failure(this.page, `Expected the page to use AdminLTE's style sheet at version "${version}", but it uses ${h.listed(lte.map((r) => r.version))}.`, {
228
+ found,
229
+ hint: 'the version is the one in the banner of the style sheet the page loads; "4.10" matches 4.10.4.',
230
+ });
231
+ });
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ // The tree menu of a dashboard's sidebar: items with a submenu that slides open and shut (AdminLTE's treeview), and
4
+ // the item of the current page, active. AdminLTE 4 slides the submenu in its inline style and sets aria-expanded on
5
+ // the item's link; 3.2 slides it with jQuery and sets no ARIA. The steps wait for what a person sees on both (the
6
+ // submenu shown or hidden, at rest) and check aria-expanded where the page sets it.
7
+
8
+ const { When, Then } = require('@cucumber/cucumber');
9
+ const h = require('./adminlte-helpers');
10
+
11
+ const HINT = 'a menu item is an item of the sidebar\'s tree menu (data-lte-toggle="treeview" on 4, data-widget="treeview" on 3.2), named by its label.';
12
+
13
+ async function item(world, name) {
14
+ return h.resolve(world, 'menuItems', name, 'sidebar menu item', HINT);
15
+ }
16
+
17
+ function describe(s) {
18
+ return `${s.subShown ? 'its submenu is shown' : 'its submenu is hidden'} (classes "${s.classes}"${s.aria ? `, aria-expanded "${s.aria}"` : ''})`;
19
+ }
20
+
21
+ async function toState(world, ref, want) {
22
+ return h.poll(world, (lib, a) => { const s = lib.menuItemState(a.ref); return { done: s.hasSub && s.subShown === a.want && s.open === a.want && s.ariaAgrees && !s.moving, state: s }; }, { ref, want }, h.budget(world));
23
+ }
24
+
25
+ /**
26
+ * Expand or collapse an item of the sidebar's tree menu, named by its label, with a click on it, and wait until its
27
+ * submenu has slid open (shown, the item marked open) or shut (hidden), and stopped. The same on both versions; on
28
+ * AdminLTE 4 the item's link also says aria-expanded "true" or "false", and the step waits for it. An item already in
29
+ * that state is left as it is; an item without a submenu fails, saying so.
30
+ *
31
+ * Example #1: When I expand the "Reports" sidebar menu item
32
+ * Example #2: When I collapse the "Reports" sidebar menu item
33
+ * Example #3: When I expand the "Settings" sidebar menu item
34
+ * Example #4: When we collapse the "Settings" sidebar menu item
35
+ * Example #5: When I expand the "reports" sidebar menu item
36
+ */
37
+ When(/^(?:I |we )?(expand|collapse) the "([^"]*)" sidebar menu item$/, async function (action, name) {
38
+ const want = action === 'expand';
39
+ const ref = await item(this, name);
40
+ const first = await h.poll(this, (lib, a) => { const s = lib.menuItemState(a.ref); return { done: !s.moving, state: s }; }, { ref }, h.budget(this));
41
+ const s = first.state || {};
42
+ if (!s.hasSub) {
43
+ throw h.failure(this.page, `Could not ${action} the "${name}" sidebar menu item: it has no submenu.`, { hint: 'only an item with a nested <ul class="nav-treeview"> opens and closes; an item without one is a link (check it with: Then the "..." sidebar menu item should be active).' });
44
+ }
45
+ if (s.subShown === want && s.open === want) return;
46
+ if (!s.drawn) {
47
+ throw h.failure(this.page, `Could not ${action} the "${name}" sidebar menu item: it is not shown (the sidebar is collapsed?).`, { hint: 'expand the sidebar first: When I expand the sidebar' });
48
+ }
49
+ await h.clickRef(this, s.link, `the "${name}" sidebar menu item`);
50
+ const result = await toState(this, ref, want);
51
+ if (result.done) return;
52
+ throw h.failure(this.page, `Expected the "${name}" sidebar menu item to be ${want ? 'expanded' : 'collapsed'} after it was clicked, but ${describe(result.state || {})}.`, {
53
+ hint: (result.state || {}).subShown === want ? 'the submenu moved but the item\'s aria-expanded did not follow.' : 'check that the page loads AdminLTE\'s script and that the menu carries data-lte-toggle="treeview" (4) or data-widget="treeview" (3.2).',
54
+ });
55
+ });
56
+
57
+ /**
58
+ * An item of the sidebar's tree menu is expanded (its submenu shown) or collapsed (its submenu hidden), at rest. The
59
+ * same on both versions; on AdminLTE 4, whose links carry aria-expanded, it must agree with what is drawn (3.2 sets no
60
+ * ARIA there, and only what is drawn decides).
61
+ *
62
+ * Example #1: Then the "Reports" sidebar menu item should be expanded
63
+ * Example #2: Then the "Reports" sidebar menu item should be collapsed
64
+ * Example #3: Then the "Settings" sidebar menu item should be collapsed
65
+ * Example #4: And the "Settings" sidebar menu item should be expanded
66
+ * Example #5: But the "Reports" sidebar menu item should be collapsed
67
+ */
68
+ Then(/^the "([^"]*)" sidebar menu item should be (expanded|collapsed)$/, async function (name, wanted) {
69
+ const ref = await item(this, name);
70
+ const result = await toState(this, ref, wanted === 'expanded');
71
+ if (result.done) return;
72
+ const s = result.state || {};
73
+ if (!s.hasSub) throw h.failure(this.page, `Expected the "${name}" sidebar menu item to be ${wanted}, but it has no submenu.`, { hint: 'only an item with a nested <ul class="nav-treeview"> opens and closes.' });
74
+ throw h.failure(this.page, `Expected the "${name}" sidebar menu item to be ${wanted}, but ${describe(s)}.`, {
75
+ hint: !s.ariaAgrees ? 'the item\'s aria-expanded disagrees with what is drawn.' : `${wanted === 'expanded' ? 'expand' : 'collapse'} it first: When I ${wanted === 'expanded' ? 'expand' : 'collapse'} the "${name}" sidebar menu item`,
76
+ });
77
+ });
78
+
79
+ /**
80
+ * An item of the sidebar's tree menu is active (its link has the class active: the page it leads to, or the item
81
+ * whose submenu holds it), or with "not" is not. The same on both versions.
82
+ *
83
+ * Example #1: Then the "Cards" sidebar menu item should be active
84
+ * Example #2: Then the "Dashboard" sidebar menu item should not be active
85
+ * Example #3: Then the "Reports" sidebar menu item should be active
86
+ * Example #4: And the "Dashboard" sidebar menu item should be active
87
+ * Example #5: But the "Components" sidebar menu item should not be active
88
+ */
89
+ Then(/^the "([^"]*)" sidebar menu item should( not)? be active$/, async function (name, not) {
90
+ const ref = await item(this, name);
91
+ const result = await h.poll(this, (lib, a) => { const s = lib.menuItemState(a.ref); return { done: s.active === !a.not, state: s }; }, { ref, not: !!not }, h.budget(this));
92
+ if (result.done) return;
93
+ const active = await h.poll(this, (lib) => ({ done: true, names: lib.menuItems().filter((i) => lib.menuItemState(i.ref).active).map((i) => i.names[0]) }), null, 100);
94
+ throw h.failure(this.page, `Expected the "${name}" sidebar menu item ${not ? 'not ' : ''}to be active, but it is ${result.state.active ? '' : 'not '}active.`, {
95
+ found: `the active menu items: ${h.listed(active.names)}`,
96
+ hint: 'the page marks its own item active with the class active on the item\'s link (and the item whose submenu holds it).',
97
+ });
98
+ });