@yuneta/gobj-ui 7.26.41 → 7.26.43

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 (66) hide show
  1. package/README.md +510 -78
  2. package/dist/gobj-ui.cjs.js +1120 -326
  3. package/dist/gobj-ui.es.js +1120 -326
  4. package/package.json +1 -1
  5. package/scripts/validate-locales.mjs +971 -177
  6. package/src/c_g6_nodes_tree.js +3 -2
  7. package/src/c_yui_form.js +261 -154
  8. package/src/c_yui_fsm_graph.js +3 -2
  9. package/src/c_yui_gobj_tree_js.js +3 -2
  10. package/src/c_yui_json_graph.js +3 -2
  11. package/src/c_yui_nav.js +43 -28
  12. package/src/c_yui_node.js +51 -7
  13. package/src/c_yui_schema_editor.css +16 -0
  14. package/src/c_yui_schema_editor.js +110 -20
  15. package/src/c_yui_shell.css +4 -1
  16. package/src/c_yui_shell.js +227 -61
  17. package/src/c_yui_treedb_schema.js +3 -2
  18. package/src/c_yui_window.js +373 -62
  19. package/src/c_yui_window_manager.js +80 -8
  20. package/src/escape_taken.js +58 -0
  21. package/src/form_close_asks_for_edits.wiring.test.js +6 -3
  22. package/src/form_json_editor_names.js +3 -1
  23. package/src/form_json_editor_names.wiring.test.js +8 -4
  24. package/src/form_json_expand.wiring.test.js +6 -3
  25. package/src/form_json_field.wiring.test.js +8 -4
  26. package/src/form_label_i18n.wiring.test.js +10 -5
  27. package/src/form_table_edits_ask.wiring.test.js +18 -8
  28. package/src/form_table_rearm.wiring.test.js +13 -5
  29. package/src/form_table_rows.wiring.test.js +489 -0
  30. package/src/form_table_validator.wiring.test.js +8 -4
  31. package/src/form_template_field.wiring.test.js +6 -3
  32. package/src/g6_canvas_tab_order.css +29 -0
  33. package/src/g6_canvas_tab_order.js +41 -9
  34. package/src/g6_canvas_tab_order.wiring.test.js +107 -1
  35. package/src/g6_long_press_clock.test.js +8 -3
  36. package/src/i18n_key_functions.js +81 -27
  37. package/src/i18n_key_functions.test.js +402 -4
  38. package/src/modal_guard_back.wiring.test.js +188 -0
  39. package/src/named_controls.wiring.test.js +323 -19
  40. package/src/nav_cards_helpers.js +9 -4
  41. package/src/nav_item_badge.wiring.test.js +163 -15
  42. package/src/node_nav_events.wiring.test.js +93 -1
  43. package/src/route_map_model.js +59 -10
  44. package/src/route_map_model.test.js +90 -0
  45. package/src/schema_editor_diagram_click.wiring.test.js +277 -0
  46. package/src/schema_editor_openers.wiring.test.js +283 -0
  47. package/src/shell_dialog_names.wiring.test.js +149 -0
  48. package/src/shell_escape_taken.wiring.test.js +142 -0
  49. package/src/shell_focus_trap.js +30 -2
  50. package/src/shell_focus_trap.test.js +90 -6
  51. package/src/shell_modals.js +113 -22
  52. package/src/shell_route_map.js +15 -3
  53. package/src/shell_section_index.js +3 -1
  54. package/src/table_editor_name.wiring.test.js +10 -5
  55. package/src/treedb_column_title.wiring.test.js +8 -4
  56. package/src/treedb_graph_writes.wiring.test.js +6 -3
  57. package/src/treedb_json_drill.wiring.test.js +6 -3
  58. package/src/uplot_add_serie.test.js +6 -3
  59. package/src/uplot_ink.test.js +8 -4
  60. package/src/window_dialog.wiring.test.js +486 -0
  61. package/src/window_dock_band.wiring.test.js +189 -0
  62. package/src/window_layer.wiring.test.js +114 -0
  63. package/src/window_rect_rounding.wiring.test.js +121 -0
  64. package/src/yui_gclass_view.js +16 -1
  65. package/src/yui_tabulator_i18n.js +31 -1
  66. package/src/yui_tabulator_i18n.test.js +46 -0
@@ -11,6 +11,12 @@
11
11
  * promise, and the modal takes its entry back once the question
12
12
  * is over.
13
13
  *
14
+ * And what the promise SETTLES with is the answer (REV-CLOUD V24.5,
15
+ * Info): `true` closes the modal; anything else -- what a question
16
+ * that closed the modal itself on "yes" settles with, `false`, a
17
+ * rejection -- is the veto it was. Up to 7.26.41 any promise was a
18
+ * veto, so an `async () => true` left a modal nobody could close.
19
+ *
14
20
  * Copyright (c) 2026, ArtGins.
15
21
  * All Rights Reserved.
16
22
  ***********************************************************************/
@@ -27,6 +33,7 @@ const {
27
33
  const {register_c_yui_shell} = await import("./c_yui_shell.js");
28
34
  const {
29
35
  yui_shell_show_modal,
36
+ yui_shell_confirm_yesno,
30
37
  yui_shell_confirm_yesnocancel,
31
38
  } = await import("./shell_modals.js");
32
39
 
@@ -191,3 +198,184 @@ describe("a modal whose guard asks before it closes", () => {
191
198
  expect(errors()).toEqual([]);
192
199
  });
193
200
  });
201
+
202
+ describe("what the guard's promise settles with is the answer", () => {
203
+ /* A shell, and a sheet over it guarded by `guard`; `closes` counts
204
+ * its on_close. */
205
+ function open_sheet(guard)
206
+ {
207
+ seq++;
208
+ const app = gobj_create(`papp${seq}`, "C_TEST_GUARD_HOST", {}, yuno);
209
+ gobj_start(app);
210
+ const shell = gobj_create(`pshell${seq}`, "C_YUI_SHELL",
211
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
212
+ gobj_start(shell);
213
+ logged.length = 0;
214
+
215
+ const counts = {closes: 0, asked: 0};
216
+ const handle = yui_shell_show_modal(shell, "the sheet", {
217
+ dialog: true,
218
+ logical_class: "TEST_SHEET",
219
+ title: "settings",
220
+ before_close: function() {
221
+ counts.asked++;
222
+ return guard(() => handle);
223
+ },
224
+ on_close: function() {
225
+ counts.closes++;
226
+ }
227
+ });
228
+ return {shell, handle, counts};
229
+ }
230
+
231
+ function warnings()
232
+ {
233
+ return logged.filter((l) => l.level === "warning").map((l) => l.msg);
234
+ }
235
+
236
+ test("an async guard that settles with true closes it: by Back, and by its back arrow", async () => {
237
+ const back = open_sheet(async () => true);
238
+ press_back(back.shell);
239
+ expect(sheets()).toBe(1); // the answer is not in yet
240
+ await settle();
241
+ expect(sheets()).toBe(0);
242
+ expect(back.counts.closes).toBe(1);
243
+ expect(back.shell.priv.overlay_stack).toEqual([]);
244
+
245
+ const arrow = open_sheet(async () => true);
246
+ document.querySelector(".TEST_SHEET .yui-dialog-back").click();
247
+ await settle();
248
+ expect(sheets()).toBe(0);
249
+ expect(arrow.counts.closes).toBe(1);
250
+ expect(arrow.shell.priv.overlay_stack).toEqual([]);
251
+ expect(errors()).toEqual([]);
252
+ });
253
+
254
+ test("anything else it settles with is a veto, and Back gets its entry back", async () => {
255
+ for(const answer of [false, undefined, "yes", 1]) {
256
+ const {shell, handle, counts} = open_sheet(async () => answer);
257
+ press_back(shell);
258
+ await settle();
259
+ expect(sheets()).toBe(1);
260
+ expect(counts.closes).toBe(0);
261
+ expect(shell.priv.overlay_stack.length).toBe(1);
262
+
263
+ /* And the next Back asks again: the entry is there. */
264
+ press_back(shell);
265
+ expect(counts.asked).toBe(2);
266
+ await settle();
267
+ handle.close();
268
+ expect(sheets()).toBe(0);
269
+ }
270
+ expect(errors()).toEqual([]);
271
+ });
272
+
273
+ /* An `async` guard that ends in `return;` settles with undefined:
274
+ * a veto, as for every promise, and with no question on the screen
275
+ * the reader is left with a modal that does not close. Said, so
276
+ * the developer learns it from the log and not from the reader. */
277
+ test("an async guard that settles with undefined and asked nothing is a veto, said", async () => {
278
+ const {shell, handle, counts} = open_sheet(async () => {
279
+ return;
280
+ });
281
+ document.querySelector(".TEST_SHEET .yui-dialog-x").click();
282
+ await settle();
283
+ expect(sheets()).toBe(1);
284
+ expect(counts.closes).toBe(0);
285
+ expect(warnings().some((m) => m.includes("before_close") &&
286
+ m.includes("undefined") &&
287
+ m.includes("asked nothing"))).toBe(true);
288
+
289
+ handle.close();
290
+ expect(sheets()).toBe(0);
291
+ expect(shell.priv.overlay_stack).toEqual([]);
292
+ expect(errors()).toEqual([]);
293
+ });
294
+
295
+ /* The README's guard: a question, and a `.then()` that returns
296
+ * nothing -- it closes the modal itself on "yes". On "no" the
297
+ * undefined is the veto it means, and nothing is said. */
298
+ test("a guard that asked and settles with undefined on \"no\" is a veto, said nothing", async () => {
299
+ let shell_of = null;
300
+ const {shell, handle, counts} = open_sheet((handle_of) => {
301
+ return yui_shell_confirm_yesnocancel(shell_of, "all changes will be lost", {
302
+ yes_label: "yes", no_label: "no", cancel_label: "cancel"
303
+ }).then((answer) => {
304
+ if(answer === "yes") {
305
+ handle_of().close();
306
+ }
307
+ });
308
+ });
309
+ shell_of = shell;
310
+ document.querySelector(".TEST_SHEET .yui-dialog-x").click();
311
+ await settle();
312
+ expect(questions()).toBe(1);
313
+ document.querySelector('.CONFIRM [data-modal-button-value="no"]').click();
314
+ await settle();
315
+ await settle();
316
+ expect(questions()).toBe(0);
317
+ expect(sheets()).toBe(1);
318
+ expect(counts.closes).toBe(0);
319
+ expect(warnings()).toEqual([]);
320
+
321
+ handle.close();
322
+ expect(sheets()).toBe(0);
323
+ expect(errors()).toEqual([]);
324
+ });
325
+
326
+ test("a promise that rejects is a veto, said, and Back gets its entry back", async () => {
327
+ const {shell, handle, counts} = open_sheet(() => Promise.reject(new Error("no answer")));
328
+ press_back(shell);
329
+ await settle();
330
+ expect(sheets()).toBe(1);
331
+ expect(counts.closes).toBe(0);
332
+ expect(shell.priv.overlay_stack.length).toBe(1);
333
+ expect(warnings().some((m) => m.includes("before_close") && m.includes("no answer"))).toBe(true);
334
+
335
+ handle.close();
336
+ expect(sheets()).toBe(0);
337
+ });
338
+
339
+ /* The idiom the README shows: hand back the yes/no question as it
340
+ * is -- it settles with true on "yes". */
341
+ test("an async guard that answers yui_shell_confirm_yesno(): \"yes\" closes, \"no\" keeps it up", async () => {
342
+ for(const [button, stays] of [["no", 1], ["yes", 0]]) {
343
+ let shell_of = null;
344
+ const {shell, handle, counts} = open_sheet(async () => {
345
+ return yui_shell_confirm_yesno(shell_of, "all changes will be lost", {
346
+ yes_label: "yes", no_label: "no"
347
+ });
348
+ });
349
+ shell_of = shell;
350
+ press_back(shell);
351
+ await settle();
352
+ expect(questions()).toBe(1);
353
+ document.querySelector(`.CONFIRM [data-modal-button-value="${button}"]`).click();
354
+ await settle();
355
+ await settle();
356
+ expect(questions()).toBe(0);
357
+ expect(sheets()).toBe(stays);
358
+ expect(counts.closes).toBe(stays ? 0 : 1);
359
+ if(stays) {
360
+ expect(shell.priv.overlay_stack.length).toBe(1);
361
+ handle.close();
362
+ }
363
+ }
364
+ expect(errors()).toEqual([]);
365
+ });
366
+
367
+ test("a guard that closed the modal itself and then settles with true: closed once", async () => {
368
+ const {shell, counts} = open_sheet((handle_of) => {
369
+ return Promise.resolve().then(() => {
370
+ handle_of().close();
371
+ return true;
372
+ });
373
+ });
374
+ press_back(shell);
375
+ await settle();
376
+ expect(sheets()).toBe(0);
377
+ expect(counts.closes).toBe(1);
378
+ expect(shell.priv.overlay_stack).toEqual([]);
379
+ expect(errors()).toEqual([]);
380
+ });
381
+ });
@@ -18,7 +18,11 @@
18
18
  * named by all its content, "close" included): two sibling
19
19
  * buttons now, each named;
20
20
  * - the ✕ of an option of a Tom Select ("Remove", in English,
21
- * title only, out of the keyboard's reach).
21
+ * title only, out of the keyboard's reach);
22
+ * - an item of C_YUI_NAV without a `name`, in every layout: its
23
+ * raw id was its aria-label, with no key and no title
24
+ * (REV-CLOUD V24.5.4). Its id is its KEY now, or its
25
+ * `aria_label` when it declares one.
22
26
  *
23
27
  * The real gclasses on a document double; G6 and Tom Select as
24
28
  * doubles (what is checked is built before either draws).
@@ -33,9 +37,12 @@ install_dom_double();
33
37
 
34
38
  if(typeof globalThis.ResizeObserver === "undefined") {
35
39
  globalThis.ResizeObserver = class {
36
- observe() {}
37
- unobserve() {}
38
- disconnect() {}
40
+ observe() {
41
+ }
42
+ unobserve() {
43
+ }
44
+ disconnect() {
45
+ }
39
46
  };
40
47
  }
41
48
 
@@ -55,7 +62,8 @@ vi.mock("@antv/g6", async (importOriginal) => {
55
62
  draw() {
56
63
  return Promise.resolve();
57
64
  }
58
- on() {}
65
+ on() {
66
+ }
59
67
  getZoom() {
60
68
  return 1;
61
69
  }
@@ -77,7 +85,8 @@ vi.mock("@antv/g6", async (importOriginal) => {
77
85
  getOptions() {
78
86
  return {behaviors: []};
79
87
  }
80
- destroy() {}
88
+ destroy() {
89
+ }
81
90
  }
82
91
  return {...real, Graph: FakeGraph};
83
92
  });
@@ -105,7 +114,8 @@ vi.mock("tabulator-tables", () => {
105
114
  off(ev) {
106
115
  delete this.externalEvents.events[ev];
107
116
  }
108
- destroy() {}
117
+ destroy() {
118
+ }
109
119
  }
110
120
  return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
111
121
  });
@@ -119,16 +129,23 @@ vi.mock("tom-select", () => ({
119
129
  this.settings = settings;
120
130
  selects.push(this);
121
131
  }
122
- on() {}
123
- disable() {}
124
- enable() {}
132
+ on() {
133
+ }
134
+ disable() {
135
+ }
136
+ enable() {
137
+ }
125
138
  getValue() {
126
139
  return [];
127
140
  }
128
- clear() {}
129
- setValue() {}
130
- addOption() {}
131
- destroy() {}
141
+ clear() {
142
+ }
143
+ setValue() {
144
+ }
145
+ addOption() {
146
+ }
147
+ destroy() {
148
+ }
132
149
  }
133
150
  }));
134
151
 
@@ -136,9 +153,9 @@ const {
136
153
  SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr,
137
154
  gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_pure_child, gobj_create_service,
138
155
  gobj_start, gobj_read_attr, gobj_send_event, gobj_change_state, gobj_current_state,
139
- gobj_is_destroying, set_log_callback, register_c_timer,
156
+ gobj_is_destroying, set_log_callback, register_c_timer, refresh_language,
140
157
  } = await import("@yuneta/gobj-js");
141
- const {register_c_yui_shell} = await import("./c_yui_shell.js");
158
+ const {register_c_yui_shell, yui_shell_navigate} = await import("./c_yui_shell.js");
142
159
  const {register_c_yui_nav} = await import("./c_yui_nav.js");
143
160
  const {register_c_yui_window} = await import("./c_yui_window.js");
144
161
  const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
@@ -215,6 +232,11 @@ beforeEach(() => {
215
232
  selects.length = 0;
216
233
  });
217
234
 
235
+ function errors()
236
+ {
237
+ return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
238
+ }
239
+
218
240
  /* title and aria-label, both, and the key of each when it is `key`. */
219
241
  function expect_named($el, key)
220
242
  {
@@ -327,6 +349,79 @@ describe("a link of the site map", () => {
327
349
  expect($here.getAttribute("aria-current")).toBe("page");
328
350
  expect($link.getAttribute("aria-current")).toBe(null);
329
351
  });
352
+
353
+ /* One rule names an item everywhere (REV-CLOUD V24.5.4): up to
354
+ * 7.26.41 a row was labelled `name || wordmark || id || route`, so an
355
+ * entry that declares only an `aria_label` read its id in the map, the
356
+ * language button "ES/EN", a menu's id and a route were asked of the
357
+ * locales as keys. */
358
+ test("a row says the name its control says; a menu's id is data; a route is no name", () => {
359
+ const view = {stage: "main", gclass: "C_TEST_NAMED_VIEW", kw: {}};
360
+ const shell = gobj_create(`rshell${++seq}`, "C_YUI_SHELL", {
361
+ config: {
362
+ shell: {
363
+ zones: {top: {host: "toolbar"}, left: {host: "menu.primary"},
364
+ center: {host: "stage.main"}},
365
+ stages: {main: {zone: "center", default_route: "/home"}},
366
+ routes: {"/orphan": view}
367
+ },
368
+ toolbar: {zone: "top", items: [
369
+ {id: "lang", icon: "yi-language", name: "ES/EN", aria_label: "toggle language",
370
+ action: {type: "navigate", route: "/lang"}}
371
+ ]},
372
+ menu: {
373
+ primary: {items: [
374
+ {id: "home", name: "home", route: "/home", target: view},
375
+ {id: "x9", aria_label: "active alarms", icon: "yi-eye", route: "/x9",
376
+ target: view}
377
+ ]},
378
+ quick: {render: {overlay: "drawer"}, items: [
379
+ {id: "q1", name: "first", route: "/q1", target: view}
380
+ ]}
381
+ }
382
+ },
383
+ use_hash: false
384
+ }, yuno);
385
+ gobj_start(shell);
386
+ logged.length = 0;
387
+
388
+ /* A map an earlier test left open is closed by the first call. */
389
+ let win = yui_shell_show_route_map(shell);
390
+ if(!win) {
391
+ win = yui_shell_show_route_map(shell);
392
+ }
393
+ const $body = gobj_read_attr(win, "$container");
394
+
395
+ /* The row of a menu entry, and the entry in the nav: one name. */
396
+ const $x9 = $body.querySelector('.ROUTEMAP_LINK[href="#/x9"]');
397
+ expect($x9.getAttribute("aria-label")).toBe("active alarms");
398
+ expect($x9.getAttribute("data-i18n-aria-label")).toBe("active alarms");
399
+ expect($x9.querySelector(".ROUTEMAP_NAME").getAttribute("data-i18n")).toBe("active alarms");
400
+ const $entry = gobj_read_attr(shell, "$container").querySelector('a[data-item-id="x9"]');
401
+ expect($entry.getAttribute("data-i18n-aria-label")).toBe("active alarms");
402
+
403
+ /* A toolbar button: as the toolbar names it. */
404
+ const $lang = $body.querySelector('.ROUTEMAP_LINK[href="#/lang"]');
405
+ expect($lang.getAttribute("data-i18n-aria-label")).toBe("toggle language");
406
+
407
+ /* Another menu is a group named by its id, drawn as data. */
408
+ const $quick = Array.from($body.querySelectorAll(".ROUTEMAP_STRUCT .ROUTEMAP_NAME"))
409
+ .find(($n) => $n.textContent === "quick");
410
+ expect(!!$quick).toBe(true);
411
+ expect($quick.getAttribute("data-i18n")).toBe(null);
412
+
413
+ /* A route of the route table that no item names: its route in
414
+ * its column, and no name of its own. */
415
+ const $orphan = $body.querySelector('.ROUTEMAP_LINK[href="#/orphan"]');
416
+ expect(!!$orphan).toBe(true);
417
+ expect($orphan.querySelector(".ROUTEMAP_NAME")).toBe(null);
418
+ expect($orphan.getAttribute("aria-label")).toBe("/orphan"); // data, as its title
419
+ expect($orphan.getAttribute("data-i18n-aria-label")).toBe(null);
420
+ expect($orphan.querySelector(".ROUTEMAP_ROUTE").textContent).toBe("/orphan");
421
+
422
+ yui_shell_show_route_map(shell); // closes it
423
+ expect(errors()).toEqual([]);
424
+ });
330
425
  });
331
426
 
332
427
  describe("the links of a nav", () => {
@@ -344,15 +439,224 @@ describe("the links of a nav", () => {
344
439
  {id: "i", icon: "yi-eye", route: "/i"}
345
440
  ]);
346
441
  expect_named($c.querySelector('a[data-item-id="b"]'), "devices");
347
- const $icon_only = $c.querySelector('a[data-item-id="i"]');
348
- expect($icon_only.getAttribute("aria-label")).toBe("i"); // its id: no key
349
- expect($icon_only.getAttribute("data-i18n-aria-label")).toBe(null);
442
+ /* Its id, AS A KEY (REV-CLOUD V24.5.4): up to 7.26.41 the raw
443
+ * id was its aria-label, with no key and no title. */
444
+ expect_named($c.querySelector('a[data-item-id="i"]'), "i");
445
+ });
446
+
447
+ /* The same in every layout that draws an item (REV-CLOUD V24.5.4:
448
+ * c_yui_nav.js item_li, item_iconbar, the tabs, and the cards of
449
+ * nav_cards_helpers.js). */
450
+ for(const layout of ["vertical", "icon-bar", "tabs", "cards", "breadcrumb"]) {
451
+ test(`an item without a \`name\` (${layout}): named by its id as a key, or by its \`aria_label\``, () => {
452
+ const $c = nav({layout: layout, show_label: false}, [
453
+ {id: "alarms", icon: "yi-eye", route: "/alarms"},
454
+ {id: "x7", icon: "yi-eye", route: "/x7", aria_label: "active alarms"}
455
+ ]);
456
+ expect_named($c.querySelector('a[data-item-id="alarms"]'), "alarms");
457
+ expect_named($c.querySelector('a[data-item-id="x7"]'), "active alarms");
458
+ expect(errors()).toEqual([]);
459
+ });
460
+ }
461
+
462
+ test("an accordion head without a `name`: named by its id as a key, or by its `aria_label`", () => {
463
+ const $c = nav({layout: "accordion"}, [
464
+ {id: "alarms", submenu: {items: [{id: "open", name: "open", route: "/alarms/open"}]}},
465
+ {id: "s2", aria_label: "settings", submenu: {items: []}}
466
+ ]);
467
+ expect_named($c.querySelector('button[data-item-id="alarms"]'), "alarms");
468
+ expect_named($c.querySelector('button[data-item-id="s2"]'), "settings");
469
+ expect(errors()).toEqual([]);
470
+ });
471
+
472
+ test("a nameless item changes language with the page, by its key", async () => {
473
+ const i18next = (await import("i18next")).default;
474
+ i18next.addResourceBundle("es", "translation", {"alarms": "alarmas"}, true, true);
475
+ const $c = nav({layout: "vertical", show_label: false}, [
476
+ {id: "alarms", icon: "yi-eye", route: "/alarms"}
477
+ ]);
478
+ refresh_language($c, i18next.getFixedT("es"));
479
+ const $a = $c.querySelector('a[data-item-id="alarms"]');
480
+ expect($a.getAttribute("aria-label")).toBe("alarmas");
481
+ expect($a.getAttribute("title")).toBe("alarmas");
350
482
  });
351
483
 
352
484
  test("a card: a title without a tooltip", () => {
353
485
  const $c = nav({layout: "cards"}, [{id: "c", name: "reports", icon: "yi-eye", route: "/c"}]);
354
486
  expect_named($c.querySelector('a[data-item-id="c"]'), "reports");
355
487
  });
488
+
489
+ /* The navigation a parent entry opens -- its tab strip, its
490
+ * section-index landing -- is named by that entry, by the same
491
+ * rule. Up to 7.26.41 a tab strip took `name || ""` (a parent with
492
+ * only an `aria_label` gave a navigation named "navigation"), and a
493
+ * landing `name || id`. */
494
+ test("the navigation an entry opens is named by the entry's name: `name`, else `aria_label`, else id", () => {
495
+ const view = {stage: "main", gclass: "C_TEST_NAMED_VIEW", kw: {}};
496
+ const shell = gobj_create(`sshell${++seq}`, "C_YUI_SHELL", {
497
+ config: {
498
+ shell: {
499
+ zones: {left: {host: "menu.primary"}, "top-sub": {host: "menu.secondary"},
500
+ center: {host: "stage.main"}},
501
+ stages: {main: {zone: "center", default_route: "/home"}}
502
+ },
503
+ menu: {primary: {items: [
504
+ {id: "home", name: "home", route: "/home", target: view},
505
+ {id: "dev", aria_label: "device settings", icon: "yi-cog", route: "/dev",
506
+ submenu: {render: {"top-sub": "tabs"}, items: [
507
+ {id: "a", name: "a", route: "/dev/a", target: view}
508
+ ]}},
509
+ {id: "rep", aria_label: "reports", icon: "yi-table", route: "/rep",
510
+ submenu: {index: true, items: [
511
+ {id: "d", name: "daily", route: "/rep/d", target: view}
512
+ ]}}
513
+ ]}}
514
+ },
515
+ use_hash: false
516
+ }, yuno);
517
+ gobj_start(shell);
518
+ const $root = gobj_read_attr(shell, "$container");
519
+
520
+ const $tabs = $root.querySelector('[data-zone="top-sub"] [role="navigation"]');
521
+ expect(!!$tabs).toBe(true);
522
+ expect($tabs.getAttribute("aria-label")).toBe("device settings");
523
+ expect($tabs.getAttribute("data-i18n-aria-label")).toBe("device settings");
524
+
525
+ yui_shell_navigate(shell, "/rep");
526
+ const $landing = $root.querySelector('[data-zone="center"] [role="navigation"]');
527
+ expect(!!$landing).toBe(true);
528
+ expect($landing.getAttribute("aria-label")).toBe("reports");
529
+ expect($landing.getAttribute("data-i18n-aria-label")).toBe("reports");
530
+ expect(errors()).toEqual([]);
531
+ });
532
+ });
533
+
534
+ describe("the items of the toolbar: what the nav got (REV-CLOUD V24.5.4)", () => {
535
+ /* A shell whose toolbar is `items`, on the page. */
536
+ function toolbar_shell(items)
537
+ {
538
+ const shell = gobj_create(`tshell${++seq}`, "C_YUI_SHELL", {
539
+ config: {
540
+ shell: {
541
+ zones: {top: {host: "toolbar"}, center: {host: "stage.main"}},
542
+ stages: {main: {zone: "center", default_route: "/home"}}
543
+ },
544
+ toolbar: {zone: "top", items: items},
545
+ menu: {primary: {items: [
546
+ {id: "home", name: "home", route: "/home",
547
+ target: {stage: "main", gclass: "C_TEST_NAMED_VIEW", kw: {}}}
548
+ ]}}
549
+ },
550
+ use_hash: false
551
+ }, yuno);
552
+ gobj_start(shell);
553
+ return shell;
554
+ }
555
+
556
+ function item_of(shell, id)
557
+ {
558
+ return gobj_read_attr(shell, "$container").querySelector(`[data-toolbar-item-id="${id}"]`);
559
+ }
560
+
561
+ test("an action item with no `aria_label` nor `name`: named by its id, as a key, with a title", () => {
562
+ const shell = toolbar_shell([
563
+ {id: "help", icon: "yi-circle-question", action: {type: "event", event: "EV_HELP"}},
564
+ /* The toolbar's own order is kept: its explicit `aria_label`
565
+ * names it, over a visible `name` that is a symbol. */
566
+ {id: "lang", icon: "yi-language", name: "ES/EN", aria_label: "toggle language",
567
+ action: {type: "event", event: "EV_LANG"}}
568
+ ]);
569
+ /* Up to 7.26.41: its raw id, with no key and no title. */
570
+ expect_named(item_of(shell, "help"), "help");
571
+ expect_named(item_of(shell, "lang"), "toggle language");
572
+ expect(errors()).toEqual([]);
573
+ });
574
+
575
+ test("a row of a toolbar menu with neither: named by its id as a key; the menu as its trigger", () => {
576
+ const shell = toolbar_shell([
577
+ {id: "user", type: "avatar", action: {type: "dropdown", items: [
578
+ {id: "logout", icon: "yi-xmark", action: {type: "event", event: "EV_LOGOUT"}},
579
+ {id: "prefs", name: "preferences", action: {type: "event", event: "EV_PREFS"}}
580
+ ]}}
581
+ ]);
582
+ /* An avatar that says nothing is the library's "user menu" from
583
+ * the start: up to 7.26.41 it showed its raw id until a pass of
584
+ * translation replaced it with that key. */
585
+ const $avatar = item_of(shell, "user");
586
+ expect_named($avatar, "user menu");
587
+
588
+ $avatar.click();
589
+ const $panel = document.querySelector('[data-toolbar-dropdown-for="user"]');
590
+ expect(!!$panel).toBe(true);
591
+ expect($panel.getAttribute("aria-label")).toBe("user menu");
592
+ expect($panel.getAttribute("data-i18n-aria-label")).toBe("user menu");
593
+ expect_named($panel.querySelector('[data-dropdown-item-id="logout"]'), "logout");
594
+ expect_named($panel.querySelector('[data-dropdown-item-id="prefs"]'), "preferences");
595
+ $avatar.click(); // the trigger closes its menu
596
+ expect(document.querySelector('[data-toolbar-dropdown-for="user"]')).toBe(null);
597
+ expect(errors()).toEqual([]);
598
+ });
599
+
600
+ test("a menu named by its trigger's id says its trigger's key", () => {
601
+ const shell = toolbar_shell([
602
+ {id: "more", icon: "yi-ellipsis", action: {type: "dropdown", items: [
603
+ {id: "about", name: "about", action: {type: "event", event: "EV_ABOUT"}}
604
+ ]}}
605
+ ]);
606
+ const $more = item_of(shell, "more");
607
+ expect_named($more, "more");
608
+ $more.click();
609
+ const $panel = document.querySelector('[data-toolbar-dropdown-for="more"]');
610
+ expect($panel.getAttribute("aria-label")).toBe("more");
611
+ expect($panel.getAttribute("data-i18n-aria-label")).toBe("more");
612
+ $more.click();
613
+ expect(errors()).toEqual([]);
614
+ });
615
+
616
+ test("the menu a right-click opens is named as its trigger, as the left-click one is", () => {
617
+ const shell = toolbar_shell([
618
+ {id: "conn", type: "connection", aria_label: "server link",
619
+ context_action: {type: "dropdown", items: [
620
+ {id: "logs", icon: "yi-list", action: {type: "event", event: "EV_LOGS"}}
621
+ ]}},
622
+ {id: "tools", icon: "yi-gear", name: "tools key", action: {type: "event", event: "EV_TOOLS"},
623
+ context_action: {type: "dropdown", items: [
624
+ {id: "about", name: "about", action: {type: "event", event: "EV_ABOUT"}}
625
+ ]}}
626
+ ]);
627
+ const right_click = ($el) => $el.dispatchEvent({type: "contextmenu", preventDefault() {}});
628
+ /* Up to 7.26.42 it was named by the raw id: the right-click handed
629
+ * the shell `{id, action}`, which dropped the trigger's names */
630
+ right_click(item_of(shell, "conn"));
631
+ let $panel = document.querySelector('[data-toolbar-dropdown-for="conn"]');
632
+ expect($panel.getAttribute("aria-label")).toBe("server link");
633
+ expect($panel.getAttribute("data-i18n-aria-label")).toBe("server link");
634
+ expect_named($panel.querySelector('[data-dropdown-item-id="logs"]'), "logs");
635
+ right_click(item_of(shell, "conn"));
636
+ right_click(item_of(shell, "tools"));
637
+ $panel = document.querySelector('[data-toolbar-dropdown-for="tools"]');
638
+ expect($panel.getAttribute("aria-label")).toBe("tools key");
639
+ right_click(item_of(shell, "tools"));
640
+ expect(errors()).toEqual([]);
641
+ });
642
+
643
+ test("a connection dot with neither: the library's own key, from the start", () => {
644
+ const shell = toolbar_shell([{id: "conn", type: "connection"}]);
645
+ expect_named(item_of(shell, "conn"), "backend connection");
646
+ expect(errors()).toEqual([]);
647
+ });
648
+
649
+ test("a nameless toolbar item changes language with the page, by its key", async () => {
650
+ const i18next = (await import("i18next")).default;
651
+ i18next.addResourceBundle("es", "translation", {"help": "ayuda"}, true, true);
652
+ const shell = toolbar_shell([
653
+ {id: "help", icon: "yi-circle-question", action: {type: "event", event: "EV_HELP"}}
654
+ ]);
655
+ refresh_language(gobj_read_attr(shell, "$container"), i18next.getFixedT("es"));
656
+ const $help = item_of(shell, "help");
657
+ expect($help.getAttribute("aria-label")).toBe("ayuda");
658
+ expect($help.getAttribute("title")).toBe("ayuda");
659
+ });
356
660
  });
357
661
 
358
662
  describe("a chip of the dock", () => {
@@ -48,21 +48,26 @@ export function card_descriptor(it, show_label, badge_of)
48
48
  children.push(badge);
49
49
  }
50
50
 
51
+ /* The name of the card: its `name`, else its `aria_label`, else its
52
+ * id -- a KEY in every case, as in the other layouts of the nav. Up
53
+ * to 7.26.41 a card without a `name` was named by its raw id, with
54
+ * no key and no title. */
55
+ let name_key = label || it.aria_label || it.id || "";
51
56
  let a_attrs = {
52
57
  class: "yui-nav-item yui-nav-card",
53
58
  href: it.route ? "#" + it.route : "#",
54
59
  "data-item-id": it.id,
55
60
  "data-route": it.route || "",
56
61
  "data-disabled": it.disabled ? "1" : "0",
57
- "aria-label": label || it.id
62
+ "aria-label": name_key
58
63
  };
59
- if(label) {
60
- a_attrs["data-i18n-aria-label"] = label;
64
+ if(name_key) {
65
+ a_attrs["data-i18n-aria-label"] = name_key;
61
66
  }
62
67
  /* Every control carries a title: the tooltip when one is declared,
63
68
  * else its name -- as the other layouts of the nav do. Up to
64
69
  * 7.26.34 a card without a `tooltip` had none. */
65
- let tip = it.tooltip || it.aria_label || label;
70
+ let tip = it.tooltip || it.aria_label || name_key;
66
71
  if(tip) {
67
72
  a_attrs.title = tip;
68
73
  a_attrs["data-i18n-title"] = tip;