@yuneta/gobj-ui 7.27.32 → 7.27.34
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 +43 -5
- package/dist/gobj-ui.cjs.js +140 -37
- package/dist/gobj-ui.es.js +140 -37
- package/package.json +2 -1
- package/src/c_yui_form.js +3 -2
- package/src/c_yui_fsm_graph.js +2 -1
- package/src/c_yui_gobj_tree_js.js +65 -15
- package/src/c_yui_json_graph.js +5 -4
- package/src/c_yui_nav.js +5 -11
- package/src/c_yui_schema_editor.js +2 -1
- package/src/c_yui_shell.js +3 -2
- package/src/c_yui_treedb_graph.js +2 -1
- package/src/c_yui_treedb_schema.js +5 -1
- package/src/c_yui_treedb_topic_with_form.js +5 -4
- package/src/c_yui_treedb_topics.js +4 -3
- package/src/g6_patches_first_graph.wiring.test.js +179 -0
- package/src/gobj_tree_remote.wiring.test.js +157 -3
- package/src/selector_from_data.wiring.test.js +296 -0
- package/src/yui_selector.js +79 -0
|
@@ -307,7 +307,7 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
307
307
|
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
308
308
|
expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
|
|
309
309
|
scope: "global", gobj: "C_YUNO^gate", gclass: "C_YUNO",
|
|
310
|
-
levels: ["ev_kw"], set: true
|
|
310
|
+
levels: ["ev_kw"], set: true, set_id: expect.any(Number)
|
|
311
311
|
}}]);
|
|
312
312
|
expect(row_of(view, "machine").$global.disabled).toBe(true);
|
|
313
313
|
|
|
@@ -328,7 +328,8 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
328
328
|
wanted.length = 0;
|
|
329
329
|
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["machine"], set: true}, view);
|
|
330
330
|
expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
|
|
331
|
-
scope: "gclass", gobj: "", gclass: "C_TCP", levels: ["machine"], set: true
|
|
331
|
+
scope: "gclass", gobj: "", gclass: "C_TCP", levels: ["machine"], set: true,
|
|
332
|
+
set_id: expect.any(Number)
|
|
332
333
|
}}]);
|
|
333
334
|
expect(problems()).toEqual([]);
|
|
334
335
|
});
|
|
@@ -344,7 +345,7 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
344
345
|
$gobj.dispatchEvent(fake_event("change"));
|
|
345
346
|
expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
|
|
346
347
|
scope: "gobj", gobj: "C_YUNO^gate`C_TCP^tcp1", gclass: "C_TCP",
|
|
347
|
-
levels: ["machine"], set: true
|
|
348
|
+
levels: ["machine"], set: true, set_id: expect.any(Number)
|
|
348
349
|
}}]);
|
|
349
350
|
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
350
351
|
|
|
@@ -574,3 +575,156 @@ describe("C_YUI_GOBJ_TREE_JS, source local", () => {
|
|
|
574
575
|
expect(problems()).toEqual([]);
|
|
575
576
|
});
|
|
576
577
|
});
|
|
578
|
+
|
|
579
|
+
/* REV-CLOUD V40.2: a read asked BEFORE a set, answered after it, is
|
|
580
|
+
* not the set's answer. A host that says which set an answer follows
|
|
581
|
+
* (`set_id`, echoed from EV_SET_TRACE_LEVEL; null for a plain read)
|
|
582
|
+
* is taken at its word; one that says nothing is matched by gclass,
|
|
583
|
+
* as the tests above do. */
|
|
584
|
+
describe("C_YUI_GOBJ_TREE_JS, source remote: a host that says which set it answers", () => {
|
|
585
|
+
const last_set_id = () => {
|
|
586
|
+
const sets = wanted.filter((w) => w.event === "EV_SET_TRACE_LEVEL");
|
|
587
|
+
return sets.length ? sets[sets.length - 1].kw.set_id : undefined;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
test("every set carries its own number", async () => {
|
|
591
|
+
const view = await mount("remote", host);
|
|
592
|
+
await open_tcp_card(view);
|
|
593
|
+
gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
|
|
594
|
+
const {$gobj} = row_of(view, "machine");
|
|
595
|
+
$gobj.checked = true;
|
|
596
|
+
$gobj.dispatchEvent(fake_event("change"));
|
|
597
|
+
const one = last_set_id();
|
|
598
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: one}), host);
|
|
599
|
+
const again = row_of(view, "machine").$gobj;
|
|
600
|
+
again.checked = true;
|
|
601
|
+
again.dispatchEvent(fake_event("change"));
|
|
602
|
+
const two = last_set_id();
|
|
603
|
+
expect(typeof one).toBe("number");
|
|
604
|
+
expect(typeof two).toBe("number");
|
|
605
|
+
expect(two).not.toBe(one);
|
|
606
|
+
expect(problems()).toEqual([]);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("the card's own read, answered after a tick, leaves the block locked", async () => {
|
|
610
|
+
const view = await mount("remote", host);
|
|
611
|
+
await open_tcp_card(view); /* the card asks: EV_TRACE_INFO_WANTED */
|
|
612
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
613
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
614
|
+
{id: node_id_of(view, "C_YUNO^gate`C_TCP^tcp1"), client_x: 10, client_y: 10}, view);
|
|
615
|
+
|
|
616
|
+
/* ticked before the second read is answered */
|
|
617
|
+
const {$gobj} = row_of(view, "machine");
|
|
618
|
+
$gobj.checked = true;
|
|
619
|
+
$gobj.dispatchEvent(fake_event("change"));
|
|
620
|
+
const set_id = last_set_id();
|
|
621
|
+
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
622
|
+
|
|
623
|
+
/* the read the click asked for: before the set */
|
|
624
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
625
|
+
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
626
|
+
/* a tree a Refresh asked for before the tick */
|
|
627
|
+
gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE, set_id: null}, host);
|
|
628
|
+
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
629
|
+
|
|
630
|
+
/* what the backend says after the set */
|
|
631
|
+
const tree = JSON.parse(JSON.stringify(TREE));
|
|
632
|
+
tree["C_YUNO^gate"].children["C_TCP^tcp1"].gobj_trace_level.push("machine");
|
|
633
|
+
gobj_send_event(view, "EV_LOAD_TREE", {tree: tree, set_id: set_id}, host);
|
|
634
|
+
expect([row_of(view, "machine").$gobj.checked, row_of(view, "machine").$gobj.disabled])
|
|
635
|
+
.toEqual([true, false]);
|
|
636
|
+
expect(problems()).toEqual([]);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("the viewer is unlocked by its set's answer, not by a read asked before it", async () => {
|
|
640
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
641
|
+
/* the card asked for C_TCP again; not answered yet */
|
|
642
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
643
|
+
{id: node_id_of(view, "C_YUNO^gate`C_TCP^tcp1"), client_x: 10, client_y: 10}, view);
|
|
644
|
+
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["traffic"], set: true}, viewer);
|
|
645
|
+
const set_id = last_set_id();
|
|
646
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
647
|
+
|
|
648
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
649
|
+
expect([viewer_box(viewer, "traffic").checked, viewer_box(viewer, "traffic").disabled])
|
|
650
|
+
.toEqual([false, true]);
|
|
651
|
+
expect(view.priv.set_in_flight).not.toBe(null);
|
|
652
|
+
|
|
653
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
654
|
+
{gclass_on: ["connections", "traffic"], set_id: set_id}), host);
|
|
655
|
+
expect([viewer_box(viewer, "traffic").checked, viewer_box(viewer, "traffic").disabled])
|
|
656
|
+
.toEqual([true, false]);
|
|
657
|
+
expect(view.priv.set_in_flight).toBe(null);
|
|
658
|
+
expect(problems()).toEqual([]);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
test("a set of the yuno's scope: the viewer's own read is asked as part of the set", async () => {
|
|
662
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
663
|
+
/* a read of C_TCP asked before the set (the card, opened again) */
|
|
664
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
665
|
+
{id: node_id_of(view, "C_YUNO^gate`C_TCP^tcp1"), client_x: 10, client_y: 10}, view);
|
|
666
|
+
gobj_read_attr(view, "$container").querySelector(".GOBJ_TREE_YUNO_TRACES_BUTTON").click();
|
|
667
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO, {set_id: null}), host);
|
|
668
|
+
wanted.length = 0;
|
|
669
|
+
|
|
670
|
+
const ev_kw = row_of(view, "ev_kw");
|
|
671
|
+
ev_kw.$global.checked = true;
|
|
672
|
+
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
673
|
+
const set_id = last_set_id();
|
|
674
|
+
wanted.length = 0;
|
|
675
|
+
|
|
676
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO,
|
|
677
|
+
{global_on: ["machine", "ev_kw"], set_id: set_id}), host);
|
|
678
|
+
expect(wanted.map((w) => [w.event, w.kw.gclass, w.kw.set_id]))
|
|
679
|
+
.toEqual([["EV_TRACE_INFO_WANTED", "C_TCP", set_id]]);
|
|
680
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
681
|
+
|
|
682
|
+
/* the read asked before the set: not the one the viewer waits for */
|
|
683
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
684
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
685
|
+
|
|
686
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
687
|
+
{global_levels: YUNO_INFO.global_levels,
|
|
688
|
+
gclass_on: ["connections", "ev_kw"], global_on: ["ev_kw"], set_id: set_id}), host);
|
|
689
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
690
|
+
expect(problems()).toEqual([]);
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
/* REV-CLOUD V41.2.1: the host REPLACES the pending read of a gclass
|
|
694
|
+
* with the one of a newer set of that gclass, so the read the
|
|
695
|
+
* viewer waits for (the yuno's, of an older set) never comes. */
|
|
696
|
+
test("a newer set of the gclass the viewer waits for: it waits for the newer one", async () => {
|
|
697
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
698
|
+
gobj_read_attr(view, "$container").querySelector(".GOBJ_TREE_YUNO_TRACES_BUTTON").click();
|
|
699
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO, {set_id: null}), host);
|
|
700
|
+
|
|
701
|
+
/* S1: a set of the yuno's scope; the viewer of C_TCP waits for C_YUNO */
|
|
702
|
+
const ev_kw = row_of(view, "ev_kw");
|
|
703
|
+
ev_kw.$global.checked = true;
|
|
704
|
+
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
705
|
+
const s1 = last_set_id();
|
|
706
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
707
|
+
gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE, set_id: s1}, host);
|
|
708
|
+
|
|
709
|
+
/* S2: a gobj set on the root's card, before the C_YUNO read of S1 */
|
|
710
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
711
|
+
{id: node_id_of(view, "C_YUNO^gate"), client_x: 10, client_y: 10}, view);
|
|
712
|
+
const {$gobj} = row_of(view, "machine");
|
|
713
|
+
$gobj.checked = true;
|
|
714
|
+
$gobj.dispatchEvent(fake_event("change"));
|
|
715
|
+
const s2 = last_set_id();
|
|
716
|
+
expect(s2).not.toBe(s1);
|
|
717
|
+
wanted.length = 0;
|
|
718
|
+
|
|
719
|
+
/* the host sends only the C_YUNO read of S2: S1's was replaced */
|
|
720
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO,
|
|
721
|
+
{global_on: ["machine", "ev_kw"], set_id: s2}), host);
|
|
722
|
+
expect(wanted.map((w) => [w.event, w.kw.gclass, w.kw.set_id]))
|
|
723
|
+
.toEqual([["EV_TRACE_INFO_WANTED", "C_TCP", s2]]);
|
|
724
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
725
|
+
{global_levels: YUNO_INFO.global_levels,
|
|
726
|
+
gclass_on: ["connections", "ev_kw"], global_on: ["ev_kw"], set_id: s2}), host);
|
|
727
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
728
|
+
expect(problems()).toEqual([]);
|
|
729
|
+
});
|
|
730
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/***********************************************************************
|
|
3
|
+
* selector_from_data.wiring.test.js
|
|
4
|
+
*
|
|
5
|
+
* A NAME IS DATA, NOT A SELECTOR (REV-CLOUD V40.3.1).
|
|
6
|
+
*
|
|
7
|
+
* The G6 views gave their canvas mount the id
|
|
8
|
+
* `<prefix><gobj name>` and found it again with
|
|
9
|
+
* `querySelector("#" + id)`. A gobj name may hold any character,
|
|
10
|
+
* and gui_agent names its gobj tree window
|
|
11
|
+
* `<encoded node>~<encoded key>`:
|
|
12
|
+
*
|
|
13
|
+
* - `~` is a CSS combinator: the lookup answered null, so every
|
|
14
|
+
* open logged "no canvas mount" and the canvas never resized;
|
|
15
|
+
* - `%` (a `^` encoded as `%5E`) makes the selector INVALID:
|
|
16
|
+
* querySelector THROWS, out of mt_start and out of the host's
|
|
17
|
+
* action, and leaves an orphan window behind it -- every later
|
|
18
|
+
* open of that card is "service ALREADY registered";
|
|
19
|
+
* - `.` turns the rest of the id into a class.
|
|
20
|
+
*
|
|
21
|
+
* The real gclasses, in jsdom (whose querySelector throws on an
|
|
22
|
+
* invalid selector as a browser does -- asserted first, or the
|
|
23
|
+
* test proves nothing), on a G6 Graph double.
|
|
24
|
+
*
|
|
25
|
+
* Copyright (c) 2026, ArtGins.
|
|
26
|
+
* All Rights Reserved.
|
|
27
|
+
***********************************************************************/
|
|
28
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
29
|
+
|
|
30
|
+
/* What each view watches: the element it handed to observe(). */
|
|
31
|
+
const observed = vi.hoisted(() => []);
|
|
32
|
+
globalThis.ResizeObserver = class {
|
|
33
|
+
observe($el) {
|
|
34
|
+
observed.push($el);
|
|
35
|
+
}
|
|
36
|
+
unobserve() {
|
|
37
|
+
}
|
|
38
|
+
disconnect() {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
vi.mock("@antv/g6", async (importOriginal) => {
|
|
43
|
+
const real = await importOriginal();
|
|
44
|
+
class FakeGraph {
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.options = options;
|
|
47
|
+
return new Proxy(this, {
|
|
48
|
+
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
draw() {
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
on() {
|
|
58
|
+
}
|
|
59
|
+
getZoom() {
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
getPosition() {
|
|
63
|
+
return [0, 0];
|
|
64
|
+
}
|
|
65
|
+
zoomTo() {
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
translateTo() {
|
|
69
|
+
return Promise.resolve();
|
|
70
|
+
}
|
|
71
|
+
getData() {
|
|
72
|
+
return {nodes: [], edges: [], combos: []};
|
|
73
|
+
}
|
|
74
|
+
getNodeData() {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
getEdgeData() {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
getPlugins() {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
getBehaviors() {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
getOptions() {
|
|
87
|
+
return {behaviors: []};
|
|
88
|
+
}
|
|
89
|
+
getCanvas() {
|
|
90
|
+
return {getLayers: () => ({}), getContainer: () => null};
|
|
91
|
+
}
|
|
92
|
+
fitView() {
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
destroy() {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {...real, Graph: FakeGraph};
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
|
|
103
|
+
gobj_create_pure_child, gobj_start, gobj_read_attr, gobj_read_str_attr,
|
|
104
|
+
gobj_find_service, gobj_name, set_log_callback, register_c_timer,
|
|
105
|
+
} = await import("@yuneta/gobj-js");
|
|
106
|
+
const {register_c_yui_gobj_tree_js} = await import("./c_yui_gobj_tree_js.js");
|
|
107
|
+
const {register_c_yui_json_graph} = await import("./c_yui_json_graph.js");
|
|
108
|
+
const {register_c_yui_fsm_graph} = await import("./c_yui_fsm_graph.js");
|
|
109
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
110
|
+
const {open_gobj_tree_view, close_gobj_tree_view} = await import("./yui_gobj_tree_view.js");
|
|
111
|
+
const {css_string, find_by_id} = await import("./yui_selector.js");
|
|
112
|
+
|
|
113
|
+
const logged = [];
|
|
114
|
+
let yuno = null;
|
|
115
|
+
let host = null;
|
|
116
|
+
let seq = 0;
|
|
117
|
+
|
|
118
|
+
/* The names of the review, and the old one with a dot. */
|
|
119
|
+
const NAMES = [
|
|
120
|
+
"local~gate", /* gui_agent 0.29.106: node~key */
|
|
121
|
+
"n~x%5Ey", /* a `^` in the key, encoded */
|
|
122
|
+
"node.a~key.b", /* a dot: a class selector */
|
|
123
|
+
"a b#c:d[e]\"f\\g", /* what clean_name() leaves and what it does not */
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
beforeAll(async () => {
|
|
127
|
+
const i18next = (await import("i18next")).default;
|
|
128
|
+
await i18next.init({lng: "en", resources: {en: {translation: {}}}});
|
|
129
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
130
|
+
set_log_callback((level, msg) => {
|
|
131
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
132
|
+
});
|
|
133
|
+
register_c_timer();
|
|
134
|
+
register_c_yui_gobj_tree_js();
|
|
135
|
+
register_c_yui_json_graph();
|
|
136
|
+
register_c_yui_fsm_graph();
|
|
137
|
+
register_c_yui_window();
|
|
138
|
+
gclass_create("C_TEST_SEL_YUNO", [], [["ST_IDLE", []]], {}, 0,
|
|
139
|
+
[SDATA_END()], {}, 0, 0, 0, 0);
|
|
140
|
+
gclass_create("C_TEST_SEL_HOST",
|
|
141
|
+
[["EV_TREE_WANTED", 0], ["EV_TRACE_INFO_WANTED", 0],
|
|
142
|
+
["EV_SET_TRACE_LEVEL", 0], ["EV_GCLASS_WANTED", 0]],
|
|
143
|
+
[["ST_IDLE", [
|
|
144
|
+
["EV_TREE_WANTED", null, null],
|
|
145
|
+
["EV_TRACE_INFO_WANTED", null, null],
|
|
146
|
+
["EV_SET_TRACE_LEVEL", null, null],
|
|
147
|
+
["EV_GCLASS_WANTED", null, null],
|
|
148
|
+
]]],
|
|
149
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
150
|
+
yuno = gobj_create_yuno("sel_yuno", "C_TEST_SEL_YUNO", {});
|
|
151
|
+
host = gobj_create("host", "C_TEST_SEL_HOST", {}, yuno);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
logged.length = 0;
|
|
156
|
+
observed.length = 0;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
function problems()
|
|
160
|
+
{
|
|
161
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function settle()
|
|
165
|
+
{
|
|
166
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
describe("the environment is a browser for selectors", () => {
|
|
170
|
+
test("jsdom's querySelector throws on an invalid selector, and reads `~` as a combinator", () => {
|
|
171
|
+
const $root = document.createElement("div");
|
|
172
|
+
const $a = document.createElement("div");
|
|
173
|
+
$a.id = "gobj-tree-canvas-gobj-tree-local~gate";
|
|
174
|
+
$root.appendChild($a);
|
|
175
|
+
const $b = document.createElement("div");
|
|
176
|
+
$b.id = "gobj-tree-canvas-gobj-tree-n~x%5Ey";
|
|
177
|
+
$root.appendChild($b);
|
|
178
|
+
|
|
179
|
+
expect($root.querySelector("#" + $a.id)).toBe(null);
|
|
180
|
+
expect(() => $root.querySelector("#" + $b.id)).toThrow(/selector/i);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("yui_selector.js", () => {
|
|
185
|
+
test("find_by_id() finds any id, in a detached tree, and only below the root", () => {
|
|
186
|
+
const $root = document.createElement("div");
|
|
187
|
+
for(const name of NAMES) {
|
|
188
|
+
const $el = document.createElement("div");
|
|
189
|
+
$el.id = "x-" + name;
|
|
190
|
+
const $wrap = document.createElement("section");
|
|
191
|
+
$wrap.appendChild($el);
|
|
192
|
+
$root.appendChild($wrap);
|
|
193
|
+
expect(find_by_id($root, "x-" + name)).toBe($el);
|
|
194
|
+
}
|
|
195
|
+
$root.id = "the-root";
|
|
196
|
+
expect(find_by_id($root, "the-root")).toBe(null);
|
|
197
|
+
expect(find_by_id($root, "x-absent")).toBe(null);
|
|
198
|
+
expect(find_by_id(null, "x")).toBe(null);
|
|
199
|
+
expect(find_by_id($root, "")).toBe(null);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("css_string() quotes any value for an attribute selector", () => {
|
|
203
|
+
const $root = document.createElement("div");
|
|
204
|
+
const values = NAMES.concat(["a\"]b", "back\\slash", "new\nline", "tab\there", "]'\""]);
|
|
205
|
+
for(const v of values) {
|
|
206
|
+
const $el = document.createElement("a");
|
|
207
|
+
$el.setAttribute("data-v", v);
|
|
208
|
+
$root.appendChild($el);
|
|
209
|
+
}
|
|
210
|
+
for(const v of values) {
|
|
211
|
+
const $found = $root.querySelector('[data-v="' + css_string(v) + '"]');
|
|
212
|
+
expect($found, JSON.stringify(v)).toBeTruthy();
|
|
213
|
+
expect($found.getAttribute("data-v")).toBe(v);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("C_YUI_GOBJ_TREE_JS in a window named by data", () => {
|
|
219
|
+
for(const name of NAMES) {
|
|
220
|
+
test(`open_gobj_tree_view(${JSON.stringify(name)}): the canvas is found and watched`, async () => {
|
|
221
|
+
let handle = null;
|
|
222
|
+
expect(() => {
|
|
223
|
+
handle = open_gobj_tree_view(host, {source: "remote", name: name, title: name});
|
|
224
|
+
}).not.toThrow();
|
|
225
|
+
expect(handle).toBeTruthy();
|
|
226
|
+
expect(handle.win).toBeTruthy();
|
|
227
|
+
await settle();
|
|
228
|
+
|
|
229
|
+
const canvas_id = gobj_read_str_attr(handle.tree, "canvas_id");
|
|
230
|
+
const $canvas = document.getElementById(canvas_id);
|
|
231
|
+
expect($canvas).toBeTruthy();
|
|
232
|
+
expect(observed).toContain($canvas);
|
|
233
|
+
expect(problems()).toEqual([]);
|
|
234
|
+
|
|
235
|
+
/* Closed and opened again: nothing was left registered. */
|
|
236
|
+
const win_name = gobj_name(handle.win);
|
|
237
|
+
close_gobj_tree_view(handle);
|
|
238
|
+
expect(gobj_find_service(win_name, false)).toBeFalsy();
|
|
239
|
+
const again = open_gobj_tree_view(host, {source: "remote", name: name, title: name});
|
|
240
|
+
expect(again && again.win).toBeTruthy();
|
|
241
|
+
await settle();
|
|
242
|
+
expect(problems()).toEqual([]);
|
|
243
|
+
close_gobj_tree_view(again);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
async function mount(gclass_name, name, attrs)
|
|
249
|
+
{
|
|
250
|
+
const $container = document.createElement("div");
|
|
251
|
+
document.body.appendChild($container);
|
|
252
|
+
const view = gobj_create_pure_child(name, gclass_name,
|
|
253
|
+
Object.assign({$container: $container}, attrs), yuno);
|
|
254
|
+
document.body.appendChild(gobj_read_attr(view, "$container"));
|
|
255
|
+
gobj_start(view);
|
|
256
|
+
await settle();
|
|
257
|
+
return view;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const FSM = {
|
|
261
|
+
entry_state: "ST_IDLE",
|
|
262
|
+
states: [{name: "ST_IDLE"}, {name: "ST_BUSY"}],
|
|
263
|
+
rows: [
|
|
264
|
+
{event: "EV_GO", cells: [{next_state: "ST_BUSY"}, null]},
|
|
265
|
+
{event: "EV_DONE", cells: [null, {next_state: "ST_IDLE"}]},
|
|
266
|
+
],
|
|
267
|
+
published: [],
|
|
268
|
+
unreachable: [],
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
describe("the other G6 views named by data", () => {
|
|
272
|
+
for(const name of NAMES) {
|
|
273
|
+
test(`C_YUI_JSON_GRAPH ${JSON.stringify(name)}: fold handles and resize on its canvas`, async () => {
|
|
274
|
+
let view = null;
|
|
275
|
+
await expect((async () => {
|
|
276
|
+
view = await mount("C_YUI_JSON_GRAPH", `json-${++seq}-${name}`, {json_data: {a: 1}});
|
|
277
|
+
})()).resolves.toBeUndefined();
|
|
278
|
+
const $canvas = document.getElementById(gobj_read_str_attr(view, "canvas_id"));
|
|
279
|
+
expect($canvas).toBeTruthy();
|
|
280
|
+
expect(view.priv.fold_listener).toBeTruthy();
|
|
281
|
+
expect(observed).toContain($canvas);
|
|
282
|
+
expect(problems()).toEqual([]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test(`C_YUI_FSM_GRAPH ${JSON.stringify(name)}: the graph is built on its canvas`, async () => {
|
|
286
|
+
let view = null;
|
|
287
|
+
await expect((async () => {
|
|
288
|
+
view = await mount("C_YUI_FSM_GRAPH", `fsm-${++seq}-${name}`, {fsm: FSM});
|
|
289
|
+
})()).resolves.toBeUndefined();
|
|
290
|
+
const $canvas = document.getElementById(gobj_read_str_attr(view, "canvas_id"));
|
|
291
|
+
expect($canvas).toBeTruthy();
|
|
292
|
+
expect(view.priv.graph).toBeTruthy();
|
|
293
|
+
expect(problems()).toEqual([]);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_selector.js
|
|
3
|
+
*
|
|
4
|
+
* A NAME IS DATA, NOT A SELECTOR.
|
|
5
|
+
*
|
|
6
|
+
* A gobj name, a topic, a route, a key: any of them may hold a
|
|
7
|
+
* character that means something to CSS. Pasted into a selector,
|
|
8
|
+
* it changes what the selector says or breaks it:
|
|
9
|
+
*
|
|
10
|
+
* - `~ + > space` are combinators: `#a~b` is "a b after an #a",
|
|
11
|
+
* and the lookup answers null;
|
|
12
|
+
* - `.` `#` `:` `[` start another simple selector: `#a.b` is the
|
|
13
|
+
* element #a with the class b;
|
|
14
|
+
* - `%` `^` `"` `\` and the rest make it INVALID: querySelector
|
|
15
|
+
* THROWS a SyntaxError, out of whatever action was running.
|
|
16
|
+
*
|
|
17
|
+
* REV-CLOUD V40.3.1: the gobj tree found its canvas with
|
|
18
|
+
* `querySelector("#" + id)`, and gui_agent named the window
|
|
19
|
+
* `node~key` -- every open logged "no canvas mount" and the
|
|
20
|
+
* canvas never resized; a `^` in the key (`%5E`) threw out of
|
|
21
|
+
* mt_start and left an orphan window behind it.
|
|
22
|
+
*
|
|
23
|
+
* So data reaches a selector in one of two ways only:
|
|
24
|
+
*
|
|
25
|
+
* find_by_id($root, id) the element below $root whose id is
|
|
26
|
+
* `id` -- no selector is built at all.
|
|
27
|
+
* It works in a tree that is not in the
|
|
28
|
+
* document yet, where getElementById()
|
|
29
|
+
* answers null.
|
|
30
|
+
*
|
|
31
|
+
* css_string(value) the value written inside a DOUBLE
|
|
32
|
+
* quoted CSS string, for an attribute
|
|
33
|
+
* selector:
|
|
34
|
+
* '[data-x="' + css_string(v) + '"]'
|
|
35
|
+
*
|
|
36
|
+
* `CSS.escape()` is not used: it does not exist in node, where the
|
|
37
|
+
* wiring tests run, and inside a quoted string only the quote, the
|
|
38
|
+
* backslash and the control characters have to be escaped.
|
|
39
|
+
*
|
|
40
|
+
* Copyright (c) 2026, ArtGins.
|
|
41
|
+
* All Rights Reserved.
|
|
42
|
+
***********************************************************************/
|
|
43
|
+
|
|
44
|
+
/************************************************************
|
|
45
|
+
* The element below `$root` (not `$root` itself, as with
|
|
46
|
+
* querySelector) whose id is exactly `id`, or null.
|
|
47
|
+
************************************************************/
|
|
48
|
+
export function find_by_id($root, id)
|
|
49
|
+
{
|
|
50
|
+
if(!$root || typeof $root.querySelectorAll !== "function") {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if(id === null || id === undefined || id === "") {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
let wanted = String(id);
|
|
57
|
+
for(let $el of $root.querySelectorAll("[id]")) {
|
|
58
|
+
if($el.id === wanted) {
|
|
59
|
+
return $el;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/************************************************************
|
|
66
|
+
* `value` as the body of a double-quoted CSS string.
|
|
67
|
+
*
|
|
68
|
+
* The quote and the backslash take a backslash; a control
|
|
69
|
+
* character (a newline ends a CSS string, it is a parse
|
|
70
|
+
* error inside one) is written as its hex escape, which a
|
|
71
|
+
* space ends so the next character is never read as hex.
|
|
72
|
+
************************************************************/
|
|
73
|
+
export function css_string(value)
|
|
74
|
+
{
|
|
75
|
+
return String(value)
|
|
76
|
+
.replace(/[\\"]/g, "\\$&")
|
|
77
|
+
.replace(/[\u0000-\u001f\u007f]/g,
|
|
78
|
+
(c) => "\\" + c.charCodeAt(0).toString(16) + " ");
|
|
79
|
+
}
|