@yuneta/gobj-ui 7.26.41 → 7.26.42
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 +304 -63
- package/dist/gobj-ui.cjs.js +352 -135
- package/dist/gobj-ui.es.js +352 -135
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +644 -142
- package/src/c_g6_nodes_tree.js +3 -2
- package/src/c_yui_fsm_graph.js +3 -2
- package/src/c_yui_gobj_tree_js.js +3 -2
- package/src/c_yui_json_graph.js +3 -2
- package/src/c_yui_nav.js +43 -28
- package/src/c_yui_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +61 -17
- package/src/c_yui_shell.js +199 -59
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window_manager.js +6 -6
- package/src/g6_canvas_tab_order.css +29 -0
- package/src/g6_canvas_tab_order.js +41 -9
- package/src/g6_canvas_tab_order.wiring.test.js +107 -1
- package/src/i18n_key_functions.js +41 -25
- package/src/i18n_key_functions.test.js +178 -2
- package/src/modal_guard_back.wiring.test.js +135 -0
- package/src/named_controls.wiring.test.js +270 -6
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_modals.js +24 -4
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/window_layer.wiring.test.js +114 -0
- package/src/yui_gclass_view.js +16 -1
|
@@ -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).
|
|
@@ -136,9 +140,9 @@ const {
|
|
|
136
140
|
SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr,
|
|
137
141
|
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_pure_child, gobj_create_service,
|
|
138
142
|
gobj_start, gobj_read_attr, gobj_send_event, gobj_change_state, gobj_current_state,
|
|
139
|
-
gobj_is_destroying, set_log_callback, register_c_timer,
|
|
143
|
+
gobj_is_destroying, set_log_callback, register_c_timer, refresh_language,
|
|
140
144
|
} = await import("@yuneta/gobj-js");
|
|
141
|
-
const {register_c_yui_shell} = await import("./c_yui_shell.js");
|
|
145
|
+
const {register_c_yui_shell, yui_shell_navigate} = await import("./c_yui_shell.js");
|
|
142
146
|
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
143
147
|
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
144
148
|
const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
|
|
@@ -215,6 +219,11 @@ beforeEach(() => {
|
|
|
215
219
|
selects.length = 0;
|
|
216
220
|
});
|
|
217
221
|
|
|
222
|
+
function errors()
|
|
223
|
+
{
|
|
224
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
225
|
+
}
|
|
226
|
+
|
|
218
227
|
/* title and aria-label, both, and the key of each when it is `key`. */
|
|
219
228
|
function expect_named($el, key)
|
|
220
229
|
{
|
|
@@ -327,6 +336,79 @@ describe("a link of the site map", () => {
|
|
|
327
336
|
expect($here.getAttribute("aria-current")).toBe("page");
|
|
328
337
|
expect($link.getAttribute("aria-current")).toBe(null);
|
|
329
338
|
});
|
|
339
|
+
|
|
340
|
+
/* One rule names an item everywhere (REV-CLOUD V24.5.4): up to
|
|
341
|
+
* 7.26.41 a row was labelled `name || wordmark || id || route`, so an
|
|
342
|
+
* entry that declares only an `aria_label` read its id in the map, the
|
|
343
|
+
* language button "ES/EN", a menu's id and a route were asked of the
|
|
344
|
+
* locales as keys. */
|
|
345
|
+
test("a row says the name its control says; a menu's id is data; a route is no name", () => {
|
|
346
|
+
const view = {stage: "main", gclass: "C_TEST_NAMED_VIEW", kw: {}};
|
|
347
|
+
const shell = gobj_create(`rshell${++seq}`, "C_YUI_SHELL", {
|
|
348
|
+
config: {
|
|
349
|
+
shell: {
|
|
350
|
+
zones: {top: {host: "toolbar"}, left: {host: "menu.primary"},
|
|
351
|
+
center: {host: "stage.main"}},
|
|
352
|
+
stages: {main: {zone: "center", default_route: "/home"}},
|
|
353
|
+
routes: {"/orphan": view}
|
|
354
|
+
},
|
|
355
|
+
toolbar: {zone: "top", items: [
|
|
356
|
+
{id: "lang", icon: "yi-language", name: "ES/EN", aria_label: "toggle language",
|
|
357
|
+
action: {type: "navigate", route: "/lang"}}
|
|
358
|
+
]},
|
|
359
|
+
menu: {
|
|
360
|
+
primary: {items: [
|
|
361
|
+
{id: "home", name: "home", route: "/home", target: view},
|
|
362
|
+
{id: "x9", aria_label: "active alarms", icon: "yi-eye", route: "/x9",
|
|
363
|
+
target: view}
|
|
364
|
+
]},
|
|
365
|
+
quick: {render: {overlay: "drawer"}, items: [
|
|
366
|
+
{id: "q1", name: "first", route: "/q1", target: view}
|
|
367
|
+
]}
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
use_hash: false
|
|
371
|
+
}, yuno);
|
|
372
|
+
gobj_start(shell);
|
|
373
|
+
logged.length = 0;
|
|
374
|
+
|
|
375
|
+
/* A map an earlier test left open is closed by the first call. */
|
|
376
|
+
let win = yui_shell_show_route_map(shell);
|
|
377
|
+
if(!win) {
|
|
378
|
+
win = yui_shell_show_route_map(shell);
|
|
379
|
+
}
|
|
380
|
+
const $body = gobj_read_attr(win, "$container");
|
|
381
|
+
|
|
382
|
+
/* The row of a menu entry, and the entry in the nav: one name. */
|
|
383
|
+
const $x9 = $body.querySelector('.ROUTEMAP_LINK[href="#/x9"]');
|
|
384
|
+
expect($x9.getAttribute("aria-label")).toBe("active alarms");
|
|
385
|
+
expect($x9.getAttribute("data-i18n-aria-label")).toBe("active alarms");
|
|
386
|
+
expect($x9.querySelector(".ROUTEMAP_NAME").getAttribute("data-i18n")).toBe("active alarms");
|
|
387
|
+
const $entry = gobj_read_attr(shell, "$container").querySelector('a[data-item-id="x9"]');
|
|
388
|
+
expect($entry.getAttribute("data-i18n-aria-label")).toBe("active alarms");
|
|
389
|
+
|
|
390
|
+
/* A toolbar button: as the toolbar names it. */
|
|
391
|
+
const $lang = $body.querySelector('.ROUTEMAP_LINK[href="#/lang"]');
|
|
392
|
+
expect($lang.getAttribute("data-i18n-aria-label")).toBe("toggle language");
|
|
393
|
+
|
|
394
|
+
/* Another menu is a group named by its id, drawn as data. */
|
|
395
|
+
const $quick = Array.from($body.querySelectorAll(".ROUTEMAP_STRUCT .ROUTEMAP_NAME"))
|
|
396
|
+
.find(($n) => $n.textContent === "quick");
|
|
397
|
+
expect(!!$quick).toBe(true);
|
|
398
|
+
expect($quick.getAttribute("data-i18n")).toBe(null);
|
|
399
|
+
|
|
400
|
+
/* A route of the route table that no item names: its route in
|
|
401
|
+
* its column, and no name of its own. */
|
|
402
|
+
const $orphan = $body.querySelector('.ROUTEMAP_LINK[href="#/orphan"]');
|
|
403
|
+
expect(!!$orphan).toBe(true);
|
|
404
|
+
expect($orphan.querySelector(".ROUTEMAP_NAME")).toBe(null);
|
|
405
|
+
expect($orphan.getAttribute("aria-label")).toBe("/orphan"); // data, as its title
|
|
406
|
+
expect($orphan.getAttribute("data-i18n-aria-label")).toBe(null);
|
|
407
|
+
expect($orphan.querySelector(".ROUTEMAP_ROUTE").textContent).toBe("/orphan");
|
|
408
|
+
|
|
409
|
+
yui_shell_show_route_map(shell); // closes it
|
|
410
|
+
expect(errors()).toEqual([]);
|
|
411
|
+
});
|
|
330
412
|
});
|
|
331
413
|
|
|
332
414
|
describe("the links of a nav", () => {
|
|
@@ -344,15 +426,197 @@ describe("the links of a nav", () => {
|
|
|
344
426
|
{id: "i", icon: "yi-eye", route: "/i"}
|
|
345
427
|
]);
|
|
346
428
|
expect_named($c.querySelector('a[data-item-id="b"]'), "devices");
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
429
|
+
/* Its id, AS A KEY (REV-CLOUD V24.5.4): up to 7.26.41 the raw
|
|
430
|
+
* id was its aria-label, with no key and no title. */
|
|
431
|
+
expect_named($c.querySelector('a[data-item-id="i"]'), "i");
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
/* The same in every layout that draws an item (REV-CLOUD V24.5.4:
|
|
435
|
+
* c_yui_nav.js item_li, item_iconbar, the tabs, and the cards of
|
|
436
|
+
* nav_cards_helpers.js). */
|
|
437
|
+
for(const layout of ["vertical", "icon-bar", "tabs", "cards", "breadcrumb"]) {
|
|
438
|
+
test(`an item without a \`name\` (${layout}): named by its id as a key, or by its \`aria_label\``, () => {
|
|
439
|
+
const $c = nav({layout: layout, show_label: false}, [
|
|
440
|
+
{id: "alarms", icon: "yi-eye", route: "/alarms"},
|
|
441
|
+
{id: "x7", icon: "yi-eye", route: "/x7", aria_label: "active alarms"}
|
|
442
|
+
]);
|
|
443
|
+
expect_named($c.querySelector('a[data-item-id="alarms"]'), "alarms");
|
|
444
|
+
expect_named($c.querySelector('a[data-item-id="x7"]'), "active alarms");
|
|
445
|
+
expect(errors()).toEqual([]);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
test("an accordion head without a `name`: named by its id as a key, or by its `aria_label`", () => {
|
|
450
|
+
const $c = nav({layout: "accordion"}, [
|
|
451
|
+
{id: "alarms", submenu: {items: [{id: "open", name: "open", route: "/alarms/open"}]}},
|
|
452
|
+
{id: "s2", aria_label: "settings", submenu: {items: []}}
|
|
453
|
+
]);
|
|
454
|
+
expect_named($c.querySelector('button[data-item-id="alarms"]'), "alarms");
|
|
455
|
+
expect_named($c.querySelector('button[data-item-id="s2"]'), "settings");
|
|
456
|
+
expect(errors()).toEqual([]);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
test("a nameless item changes language with the page, by its key", async () => {
|
|
460
|
+
const i18next = (await import("i18next")).default;
|
|
461
|
+
i18next.addResourceBundle("es", "translation", {"alarms": "alarmas"}, true, true);
|
|
462
|
+
const $c = nav({layout: "vertical", show_label: false}, [
|
|
463
|
+
{id: "alarms", icon: "yi-eye", route: "/alarms"}
|
|
464
|
+
]);
|
|
465
|
+
refresh_language($c, i18next.getFixedT("es"));
|
|
466
|
+
const $a = $c.querySelector('a[data-item-id="alarms"]');
|
|
467
|
+
expect($a.getAttribute("aria-label")).toBe("alarmas");
|
|
468
|
+
expect($a.getAttribute("title")).toBe("alarmas");
|
|
350
469
|
});
|
|
351
470
|
|
|
352
471
|
test("a card: a title without a tooltip", () => {
|
|
353
472
|
const $c = nav({layout: "cards"}, [{id: "c", name: "reports", icon: "yi-eye", route: "/c"}]);
|
|
354
473
|
expect_named($c.querySelector('a[data-item-id="c"]'), "reports");
|
|
355
474
|
});
|
|
475
|
+
|
|
476
|
+
/* The navigation a parent entry opens -- its tab strip, its
|
|
477
|
+
* section-index landing -- is named by that entry, by the same
|
|
478
|
+
* rule. Up to 7.26.41 a tab strip took `name || ""` (a parent with
|
|
479
|
+
* only an `aria_label` gave a navigation named "navigation"), and a
|
|
480
|
+
* landing `name || id`. */
|
|
481
|
+
test("the navigation an entry opens is named by the entry's name: `name`, else `aria_label`, else id", () => {
|
|
482
|
+
const view = {stage: "main", gclass: "C_TEST_NAMED_VIEW", kw: {}};
|
|
483
|
+
const shell = gobj_create(`sshell${++seq}`, "C_YUI_SHELL", {
|
|
484
|
+
config: {
|
|
485
|
+
shell: {
|
|
486
|
+
zones: {left: {host: "menu.primary"}, "top-sub": {host: "menu.secondary"},
|
|
487
|
+
center: {host: "stage.main"}},
|
|
488
|
+
stages: {main: {zone: "center", default_route: "/home"}}
|
|
489
|
+
},
|
|
490
|
+
menu: {primary: {items: [
|
|
491
|
+
{id: "home", name: "home", route: "/home", target: view},
|
|
492
|
+
{id: "dev", aria_label: "device settings", icon: "yi-cog", route: "/dev",
|
|
493
|
+
submenu: {render: {"top-sub": "tabs"}, items: [
|
|
494
|
+
{id: "a", name: "a", route: "/dev/a", target: view}
|
|
495
|
+
]}},
|
|
496
|
+
{id: "rep", aria_label: "reports", icon: "yi-table", route: "/rep",
|
|
497
|
+
submenu: {index: true, items: [
|
|
498
|
+
{id: "d", name: "daily", route: "/rep/d", target: view}
|
|
499
|
+
]}}
|
|
500
|
+
]}}
|
|
501
|
+
},
|
|
502
|
+
use_hash: false
|
|
503
|
+
}, yuno);
|
|
504
|
+
gobj_start(shell);
|
|
505
|
+
const $root = gobj_read_attr(shell, "$container");
|
|
506
|
+
|
|
507
|
+
const $tabs = $root.querySelector('[data-zone="top-sub"] [role="navigation"]');
|
|
508
|
+
expect(!!$tabs).toBe(true);
|
|
509
|
+
expect($tabs.getAttribute("aria-label")).toBe("device settings");
|
|
510
|
+
expect($tabs.getAttribute("data-i18n-aria-label")).toBe("device settings");
|
|
511
|
+
|
|
512
|
+
yui_shell_navigate(shell, "/rep");
|
|
513
|
+
const $landing = $root.querySelector('[data-zone="center"] [role="navigation"]');
|
|
514
|
+
expect(!!$landing).toBe(true);
|
|
515
|
+
expect($landing.getAttribute("aria-label")).toBe("reports");
|
|
516
|
+
expect($landing.getAttribute("data-i18n-aria-label")).toBe("reports");
|
|
517
|
+
expect(errors()).toEqual([]);
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
describe("the items of the toolbar: what the nav got (REV-CLOUD V24.5.4)", () => {
|
|
522
|
+
/* A shell whose toolbar is `items`, on the page. */
|
|
523
|
+
function toolbar_shell(items)
|
|
524
|
+
{
|
|
525
|
+
const shell = gobj_create(`tshell${++seq}`, "C_YUI_SHELL", {
|
|
526
|
+
config: {
|
|
527
|
+
shell: {
|
|
528
|
+
zones: {top: {host: "toolbar"}, center: {host: "stage.main"}},
|
|
529
|
+
stages: {main: {zone: "center", default_route: "/home"}}
|
|
530
|
+
},
|
|
531
|
+
toolbar: {zone: "top", items: items},
|
|
532
|
+
menu: {primary: {items: [
|
|
533
|
+
{id: "home", name: "home", route: "/home",
|
|
534
|
+
target: {stage: "main", gclass: "C_TEST_NAMED_VIEW", kw: {}}}
|
|
535
|
+
]}}
|
|
536
|
+
},
|
|
537
|
+
use_hash: false
|
|
538
|
+
}, yuno);
|
|
539
|
+
gobj_start(shell);
|
|
540
|
+
return shell;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function item_of(shell, id)
|
|
544
|
+
{
|
|
545
|
+
return gobj_read_attr(shell, "$container").querySelector(`[data-toolbar-item-id="${id}"]`);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
test("an action item with no `aria_label` nor `name`: named by its id, as a key, with a title", () => {
|
|
549
|
+
const shell = toolbar_shell([
|
|
550
|
+
{id: "help", icon: "yi-circle-question", action: {type: "event", event: "EV_HELP"}},
|
|
551
|
+
/* The toolbar's own order is kept: its explicit `aria_label`
|
|
552
|
+
* names it, over a visible `name` that is a symbol. */
|
|
553
|
+
{id: "lang", icon: "yi-language", name: "ES/EN", aria_label: "toggle language",
|
|
554
|
+
action: {type: "event", event: "EV_LANG"}}
|
|
555
|
+
]);
|
|
556
|
+
/* Up to 7.26.41: its raw id, with no key and no title. */
|
|
557
|
+
expect_named(item_of(shell, "help"), "help");
|
|
558
|
+
expect_named(item_of(shell, "lang"), "toggle language");
|
|
559
|
+
expect(errors()).toEqual([]);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
test("a row of a toolbar menu with neither: named by its id as a key; the menu as its trigger", () => {
|
|
563
|
+
const shell = toolbar_shell([
|
|
564
|
+
{id: "user", type: "avatar", action: {type: "dropdown", items: [
|
|
565
|
+
{id: "logout", icon: "yi-xmark", action: {type: "event", event: "EV_LOGOUT"}},
|
|
566
|
+
{id: "prefs", name: "preferences", action: {type: "event", event: "EV_PREFS"}}
|
|
567
|
+
]}}
|
|
568
|
+
]);
|
|
569
|
+
/* An avatar that says nothing is the library's "user menu" from
|
|
570
|
+
* the start: up to 7.26.41 it showed its raw id until a pass of
|
|
571
|
+
* translation replaced it with that key. */
|
|
572
|
+
const $avatar = item_of(shell, "user");
|
|
573
|
+
expect_named($avatar, "user menu");
|
|
574
|
+
|
|
575
|
+
$avatar.click();
|
|
576
|
+
const $panel = document.querySelector('[data-toolbar-dropdown-for="user"]');
|
|
577
|
+
expect(!!$panel).toBe(true);
|
|
578
|
+
expect($panel.getAttribute("aria-label")).toBe("user menu");
|
|
579
|
+
expect($panel.getAttribute("data-i18n-aria-label")).toBe("user menu");
|
|
580
|
+
expect_named($panel.querySelector('[data-dropdown-item-id="logout"]'), "logout");
|
|
581
|
+
expect_named($panel.querySelector('[data-dropdown-item-id="prefs"]'), "preferences");
|
|
582
|
+
$avatar.click(); // the trigger closes its menu
|
|
583
|
+
expect(document.querySelector('[data-toolbar-dropdown-for="user"]')).toBe(null);
|
|
584
|
+
expect(errors()).toEqual([]);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
test("a menu named by its trigger's id says its trigger's key", () => {
|
|
588
|
+
const shell = toolbar_shell([
|
|
589
|
+
{id: "more", icon: "yi-ellipsis", action: {type: "dropdown", items: [
|
|
590
|
+
{id: "about", name: "about", action: {type: "event", event: "EV_ABOUT"}}
|
|
591
|
+
]}}
|
|
592
|
+
]);
|
|
593
|
+
const $more = item_of(shell, "more");
|
|
594
|
+
expect_named($more, "more");
|
|
595
|
+
$more.click();
|
|
596
|
+
const $panel = document.querySelector('[data-toolbar-dropdown-for="more"]');
|
|
597
|
+
expect($panel.getAttribute("aria-label")).toBe("more");
|
|
598
|
+
expect($panel.getAttribute("data-i18n-aria-label")).toBe("more");
|
|
599
|
+
$more.click();
|
|
600
|
+
expect(errors()).toEqual([]);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test("a connection dot with neither: the library's own key, from the start", () => {
|
|
604
|
+
const shell = toolbar_shell([{id: "conn", type: "connection"}]);
|
|
605
|
+
expect_named(item_of(shell, "conn"), "backend connection");
|
|
606
|
+
expect(errors()).toEqual([]);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("a nameless toolbar item changes language with the page, by its key", async () => {
|
|
610
|
+
const i18next = (await import("i18next")).default;
|
|
611
|
+
i18next.addResourceBundle("es", "translation", {"help": "ayuda"}, true, true);
|
|
612
|
+
const shell = toolbar_shell([
|
|
613
|
+
{id: "help", icon: "yi-circle-question", action: {type: "event", event: "EV_HELP"}}
|
|
614
|
+
]);
|
|
615
|
+
refresh_language(gobj_read_attr(shell, "$container"), i18next.getFixedT("es"));
|
|
616
|
+
const $help = item_of(shell, "help");
|
|
617
|
+
expect($help.getAttribute("aria-label")).toBe("ayuda");
|
|
618
|
+
expect($help.getAttribute("title")).toBe("ayuda");
|
|
619
|
+
});
|
|
356
620
|
});
|
|
357
621
|
|
|
358
622
|
describe("a chip of the dock", () => {
|
package/src/nav_cards_helpers.js
CHANGED
|
@@ -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":
|
|
62
|
+
"aria-label": name_key
|
|
58
63
|
};
|
|
59
|
-
if(
|
|
60
|
-
a_attrs["data-i18n-aria-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 ||
|
|
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;
|
|
@@ -24,7 +24,7 @@ const {
|
|
|
24
24
|
SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr,
|
|
25
25
|
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop,
|
|
26
26
|
gobj_destroy, gobj_is_running, gobj_read_attr, gobj_send_event,
|
|
27
|
-
set_log_callback,
|
|
27
|
+
gobj_has_event, gobj_posted_events_size, set_log_callback,
|
|
28
28
|
} = await import("@yuneta/gobj-js");
|
|
29
29
|
const {
|
|
30
30
|
register_c_yui_shell,
|
|
@@ -241,6 +241,36 @@ function said(shell)
|
|
|
241
241
|
return root(shell).querySelector(".SHELL_BADGE_STATUS").textContent;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
/* What the live region holds, one entry per change it says: a line
|
|
245
|
+
* each (an element child), or the bare text up to 7.26.41. */
|
|
246
|
+
function said_lines(shell)
|
|
247
|
+
{
|
|
248
|
+
const $status = root(shell).querySelector(".SHELL_BADGE_STATUS");
|
|
249
|
+
if($status.children.length > 0) {
|
|
250
|
+
return Array.from($status.children).map(($line) => $line.textContent);
|
|
251
|
+
}
|
|
252
|
+
return $status.textContent ? [$status.textContent] : [];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* The turn of the loop is over: what was posted in it is delivered
|
|
256
|
+
* (gobj_post_event() drains on setTimeout(0), queued before this). */
|
|
257
|
+
function next_turn()
|
|
258
|
+
{
|
|
259
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* Every write of the region's content, as the texts it held after it. */
|
|
263
|
+
function spy_writes($status)
|
|
264
|
+
{
|
|
265
|
+
const writes = [];
|
|
266
|
+
const real = $status.replaceChildren;
|
|
267
|
+
$status.replaceChildren = function(...nodes) {
|
|
268
|
+
real.apply(this, nodes);
|
|
269
|
+
writes.push(Array.from(this.children).map(($line) => $line.textContent));
|
|
270
|
+
};
|
|
271
|
+
return writes;
|
|
272
|
+
}
|
|
273
|
+
|
|
244
274
|
|
|
245
275
|
describe("a badge declared in app_config.json", () => {
|
|
246
276
|
test("renders: after the label in the rail, on the icon in the icon bar", () => {
|
|
@@ -684,22 +714,11 @@ describe("a reader gets the count with the name of what it counts", () => {
|
|
|
684
714
|
/* "home" has no badge: its first count is a change from nothing */
|
|
685
715
|
yui_shell_set_nav_item_badge(shell, "home", 1);
|
|
686
716
|
expect(said(shell)).toBe("Home, 1");
|
|
717
|
+
await next_turn();
|
|
687
718
|
|
|
688
|
-
const writes =
|
|
689
|
-
const $status = root(shell).querySelector(".SHELL_BADGE_STATUS");
|
|
690
|
-
const real = Object.getOwnPropertyDescriptor(Object.getPrototypeOf($status), "textContent");
|
|
691
|
-
Object.defineProperty($status, "textContent", {
|
|
692
|
-
get() {
|
|
693
|
-
return real.get.call(this);
|
|
694
|
-
},
|
|
695
|
-
set(v) {
|
|
696
|
-
writes.push(v);
|
|
697
|
-
real.set.call(this, v);
|
|
698
|
-
},
|
|
699
|
-
configurable: true
|
|
700
|
-
});
|
|
719
|
+
const writes = spy_writes(root(shell).querySelector(".SHELL_BADGE_STATUS"));
|
|
701
720
|
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
702
|
-
expect(writes).toEqual(["Alarms, 3"]);
|
|
721
|
+
expect(writes).toEqual([["Alarms, 3"]]);
|
|
703
722
|
});
|
|
704
723
|
|
|
705
724
|
test("the same count is no news, a count going away is not either, one coming back is", async () => {
|
|
@@ -714,15 +733,21 @@ describe("a reader gets the count with the name of what it counts", () => {
|
|
|
714
733
|
yui_shell_set_nav_item_badge(shell, "alarms", 2);
|
|
715
734
|
expect(said(shell)).toBe("");
|
|
716
735
|
|
|
736
|
+
/* Each change in a turn of its own, as a feed of counts sends
|
|
737
|
+
* them: what one turn said stays in the region until the next
|
|
738
|
+
* change is said. */
|
|
717
739
|
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
718
740
|
expect(said(shell)).toBe("Alarms, 3");
|
|
719
741
|
const node = $status.firstChild;
|
|
742
|
+
await next_turn();
|
|
720
743
|
|
|
721
744
|
yui_shell_set_nav_item_badge(shell, "alarms", 3, "danger"); // only the tone
|
|
722
745
|
expect($status.firstChild).toBe(node);
|
|
746
|
+
await next_turn();
|
|
723
747
|
|
|
724
748
|
yui_shell_set_nav_item_badge(shell, "alarms", 0);
|
|
725
749
|
expect($status.firstChild).toBe(node); // not said
|
|
750
|
+
await next_turn();
|
|
726
751
|
|
|
727
752
|
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
728
753
|
expect(said(shell)).toBe("Alarms, 3");
|
|
@@ -743,3 +768,126 @@ describe("a reader gets the count with the name of what it counts", () => {
|
|
|
743
768
|
expect(errors()).toEqual([]);
|
|
744
769
|
});
|
|
745
770
|
});
|
|
771
|
+
|
|
772
|
+
describe("REV-CLOUD V24.5.3: every change is said, as it reads", () => {
|
|
773
|
+
async function english(extra)
|
|
774
|
+
{
|
|
775
|
+
const i18next = (await import("i18next")).default;
|
|
776
|
+
i18next.addResourceBundle("en", "translation", Object.assign(
|
|
777
|
+
{"{{name}}, {{n}}": "{{name}}, {{n}}", "alarms": "Alarms", "home": "Home"},
|
|
778
|
+
extra || {}), true, true);
|
|
779
|
+
return i18next.getFixedT("en");
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/* The test-app's "alerts" button does exactly this: the toolbar
|
|
783
|
+
* count and a menu entry's, in the same action. Up to 7.26.41 the
|
|
784
|
+
* second overwrote the first in the region before a reader could
|
|
785
|
+
* hear it, so the control pressed was never said. */
|
|
786
|
+
test("two changes in one turn: both said, in ONE message, a line each", async () => {
|
|
787
|
+
const shell = new_shell();
|
|
788
|
+
yui_shell_set_translator(shell, await english());
|
|
789
|
+
|
|
790
|
+
yui_shell_set_toolbar_item_badge(shell, "bell", 7);
|
|
791
|
+
yui_shell_set_nav_item_badge(shell, "home", 1);
|
|
792
|
+
expect(said_lines(shell)).toEqual(["Alarms, 7", "Home, 1"]);
|
|
793
|
+
|
|
794
|
+
/* The next turn starts a message of its own: what the last one
|
|
795
|
+
* said is not said again. */
|
|
796
|
+
await next_turn();
|
|
797
|
+
yui_shell_set_nav_item_badge(shell, "home", 2);
|
|
798
|
+
expect(said_lines(shell)).toEqual(["Home, 2"]);
|
|
799
|
+
expect(errors()).toEqual([]);
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
test("the same badge twice in one turn says its last count", async () => {
|
|
803
|
+
const shell = new_shell();
|
|
804
|
+
yui_shell_set_translator(shell, await english());
|
|
805
|
+
|
|
806
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
807
|
+
yui_shell_set_toolbar_item_badge(shell, "bell", 6);
|
|
808
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 5);
|
|
809
|
+
expect(said_lines(shell)).toEqual(["Alarms, 5", "Alarms, 6"]);
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
test("a count that goes away in the turn it came is not said: the badge shows nothing", async () => {
|
|
813
|
+
const shell = new_shell();
|
|
814
|
+
yui_shell_set_translator(shell, await english());
|
|
815
|
+
|
|
816
|
+
yui_shell_set_nav_item_badge(shell, "home", 4);
|
|
817
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
818
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 0);
|
|
819
|
+
expect(said_lines(shell)).toEqual(["Home, 4"]);
|
|
820
|
+
|
|
821
|
+
yui_shell_set_nav_item_badge(shell, "home", 0);
|
|
822
|
+
expect(said_lines(shell)).toEqual([]);
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
test("one turn is closed once, though its message was emptied and opened again", async () => {
|
|
826
|
+
const shell = new_shell();
|
|
827
|
+
yui_shell_set_translator(shell, await english());
|
|
828
|
+
|
|
829
|
+
const before = gobj_posted_events_size();
|
|
830
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
831
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 0); // the message is empty again
|
|
832
|
+
yui_shell_set_nav_item_badge(shell, "home", 1);
|
|
833
|
+
expect(gobj_posted_events_size() - before).toBe(1);
|
|
834
|
+
expect(said_lines(shell)).toEqual(["Home, 1"]);
|
|
835
|
+
|
|
836
|
+
await next_turn();
|
|
837
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 4);
|
|
838
|
+
expect(said_lines(shell)).toEqual(["Alarms, 4"]);
|
|
839
|
+
expect(errors()).toEqual([]);
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
test("two controls of one name with one count: said once", async () => {
|
|
843
|
+
const shell = new_shell();
|
|
844
|
+
yui_shell_set_translator(shell, await english());
|
|
845
|
+
|
|
846
|
+
/* The bell is named "alarms" too */
|
|
847
|
+
yui_shell_set_toolbar_item_badge(shell, "bell", 9);
|
|
848
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 9);
|
|
849
|
+
expect(said_lines(shell)).toEqual(["Alarms, 9"]);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
/* i18next escapes an interpolated value for HTML by default, and
|
|
853
|
+
* the message goes to a text node: a reader would have read the
|
|
854
|
+
* entities. */
|
|
855
|
+
test("the message is text, not HTML: a name with an apostrophe or an ampersand reads as written", async () => {
|
|
856
|
+
const shell = new_shell();
|
|
857
|
+
yui_shell_set_translator(shell, await english({"alarms": "Événements d'alarme & co"}));
|
|
858
|
+
|
|
859
|
+
yui_shell_set_nav_item_badge(shell, "alarms", 3);
|
|
860
|
+
expect(said_lines(shell)).toEqual(["Événements d'alarme & co, 3"]);
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
test("the turn is closed through the machine, by an event of the shell", () => {
|
|
864
|
+
const shell = new_shell();
|
|
865
|
+
expect(gobj_has_event(shell, "EV_CLOSE_BADGE_NEWS")).toBe(true);
|
|
866
|
+
/* Nothing to close: a second message is not opened by it. */
|
|
867
|
+
gobj_send_event(shell, "EV_CLOSE_BADGE_NEWS", {}, shell);
|
|
868
|
+
expect(errors()).toEqual([]);
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
/* One rule names an item everywhere: the nav names a menu entry by
|
|
872
|
+
* its `name`, else its `aria_label`, else its id. Up to 7.26.41 the
|
|
873
|
+
* announcement took `name || id`, so an entry that declares only an
|
|
874
|
+
* `aria_label` was said by its id -- one name on the control,
|
|
875
|
+
* another in the region. */
|
|
876
|
+
test("an entry with no `name` is said by the name the nav gives it: its `aria_label`, else its id", async () => {
|
|
877
|
+
const cfg = config();
|
|
878
|
+
cfg.menu.primary.items.push(
|
|
879
|
+
{id: "x9", aria_label: "active alarms", icon: "yi-triangle-exclamation",
|
|
880
|
+
route: "/x9", target: view()},
|
|
881
|
+
{id: "events", icon: "yi-eye", route: "/events", target: view()}
|
|
882
|
+
);
|
|
883
|
+
const shell = new_shell(cfg);
|
|
884
|
+
yui_shell_set_translator(shell, await english({"active alarms": "Active alarms", "events": "Events"}));
|
|
885
|
+
|
|
886
|
+
const $a = zone(shell, "left").querySelector('a[data-item-id="x9"]');
|
|
887
|
+
expect($a.getAttribute("data-i18n-aria-label")).toBe("active alarms");
|
|
888
|
+
yui_shell_set_nav_item_badge(shell, "x9", 3);
|
|
889
|
+
yui_shell_set_nav_item_badge(shell, "events", 5);
|
|
890
|
+
expect(said_lines(shell)).toEqual(["Active alarms, 3", "Events, 5"]);
|
|
891
|
+
expect(errors()).toEqual([]);
|
|
892
|
+
});
|
|
893
|
+
});
|