@yuneta/gobj-ui 7.27.29 → 7.27.31
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 +31 -4
- package/dist/gobj-ui.cjs.js +92 -12
- package/dist/gobj-ui.es.js +92 -13
- package/index.js +1 -1
- package/package.json +2 -2
- package/src/c_yui_gclass.js +32 -0
- package/src/c_yui_gobj_tree_js.js +94 -22
- package/src/c_yui_node.js +21 -24
- package/src/c_yui_update_watch.js +48 -1
- package/src/c_yui_update_watch.wiring.test.js +80 -5
- package/src/gclass_language.wiring.test.js +141 -0
- package/src/gobj_tree_camera.wiring.test.js +81 -7
- package/src/gobj_tree_remote.wiring.test.js +173 -2
- package/src/node_stages.wiring.test.js +199 -0
- package/src/shell_view_shown.wiring.test.js +71 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* gclass_language.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* C_YUI_GCLASS, the gclass viewer, changes the language of its
|
|
5
|
+
* COUNTED words ("4 instances", "show all 25") when the app
|
|
6
|
+
* switches language. Those carry no key on purpose (a key would
|
|
7
|
+
* make refresh_language() write the bare word over the count), so
|
|
8
|
+
* only a re-render can change them, and nobody sent the viewer the
|
|
9
|
+
* switch: open_gclass_view() creates it with no subscriber and its
|
|
10
|
+
* host does not forward it. It hears the shell's
|
|
11
|
+
* EV_LANGUAGE_CHANGED itself now, as C_YUI_JSON does.
|
|
12
|
+
*
|
|
13
|
+
* The real gclass and a real C_YUI_SHELL, on a document double.
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2026, ArtGins.
|
|
16
|
+
* All Rights Reserved.
|
|
17
|
+
***********************************************************************/
|
|
18
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
19
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
20
|
+
|
|
21
|
+
install_dom_double();
|
|
22
|
+
|
|
23
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
24
|
+
globalThis.ResizeObserver = class {
|
|
25
|
+
observe() {
|
|
26
|
+
}
|
|
27
|
+
unobserve() {
|
|
28
|
+
}
|
|
29
|
+
disconnect() {
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr,
|
|
36
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop,
|
|
37
|
+
gobj_destroy, gobj_read_attr, set_log_callback,
|
|
38
|
+
} = await import("@yuneta/gobj-js");
|
|
39
|
+
const {register_c_yui_shell, yui_shell_language_changed} = await import("./c_yui_shell.js");
|
|
40
|
+
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
41
|
+
const {register_c_yui_gclass} = await import("./c_yui_gclass.js");
|
|
42
|
+
|
|
43
|
+
const logged = [];
|
|
44
|
+
let i18next = null;
|
|
45
|
+
let yuno = null;
|
|
46
|
+
let host = null;
|
|
47
|
+
let shell = null;
|
|
48
|
+
|
|
49
|
+
const DESCRIPTION = {
|
|
50
|
+
id: "C_TCP",
|
|
51
|
+
gcflag: [],
|
|
52
|
+
instances: 4,
|
|
53
|
+
attrs: Array.from({length: 25}, (_, i) => ({
|
|
54
|
+
id: `attr_${i}`, type: "string", flag: "SDF_RD",
|
|
55
|
+
default_value: "", description: `attribute ${i}`
|
|
56
|
+
})),
|
|
57
|
+
commands: [],
|
|
58
|
+
gclass_methods: [],
|
|
59
|
+
internal_methods: [],
|
|
60
|
+
FSM: {events: [], states: {}},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
beforeAll(async () => {
|
|
64
|
+
i18next = (await import("i18next")).default;
|
|
65
|
+
await i18next.init({lng: "en", resources: {
|
|
66
|
+
en: {translation: {
|
|
67
|
+
"instances": "instances",
|
|
68
|
+
"instances_one": "instance",
|
|
69
|
+
"show all {{n}}": "show all {{n}}",
|
|
70
|
+
}},
|
|
71
|
+
es: {translation: {
|
|
72
|
+
"instances": "instancias",
|
|
73
|
+
"instances_one": "instancia",
|
|
74
|
+
"show all {{n}}": "ver las {{n}}",
|
|
75
|
+
}},
|
|
76
|
+
}});
|
|
77
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
78
|
+
set_log_callback((level, msg) => {
|
|
79
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
80
|
+
});
|
|
81
|
+
gclass_create("C_TEST_GCLASS_LANG_YUNO", [], [["ST_IDLE", []]], {}, 0,
|
|
82
|
+
[SDATA_END()], {}, 0, 0, 0, 0);
|
|
83
|
+
gclass_create("C_TEST_GCLASS_LANG_VIEW", [], [["ST_IDLE", []]], {
|
|
84
|
+
mt_create: (gobj) => {
|
|
85
|
+
gobj_write_attr(gobj, "$container", document.createElement("div"));
|
|
86
|
+
}
|
|
87
|
+
}, 0, [SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "view root"), SDATA_END()],
|
|
88
|
+
{}, 0, 0, 0, 0);
|
|
89
|
+
register_c_yui_shell();
|
|
90
|
+
register_c_yui_nav();
|
|
91
|
+
register_c_yui_gclass();
|
|
92
|
+
yuno = gobj_create_yuno("gclass_lang_yuno", "C_TEST_GCLASS_LANG_YUNO", {});
|
|
93
|
+
gobj_start(yuno);
|
|
94
|
+
host = gobj_create("host", "C_TEST_GCLASS_LANG_YUNO", {}, yuno);
|
|
95
|
+
shell = gobj_create("gclass_lang_shell", "C_YUI_SHELL", {use_hash: false, config: {
|
|
96
|
+
shell: {
|
|
97
|
+
zones: {center: {host: "stage.main"}},
|
|
98
|
+
stages: {main: {zone: "center", default_route: "/a"}}
|
|
99
|
+
},
|
|
100
|
+
menu: {primary: {items: [
|
|
101
|
+
{id: "a", name: "a", route: "/a",
|
|
102
|
+
target: {stage: "main", gclass: "C_TEST_GCLASS_LANG_VIEW", kw: {}}}
|
|
103
|
+
]}}
|
|
104
|
+
}}, yuno);
|
|
105
|
+
gobj_start(shell);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
beforeEach(async () => {
|
|
109
|
+
logged.length = 0;
|
|
110
|
+
await i18next.changeLanguage("en");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
function problems()
|
|
114
|
+
{
|
|
115
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
describe("C_YUI_GCLASS: the counted words follow the language", () => {
|
|
119
|
+
test("the shell's language switch re-renders them", async () => {
|
|
120
|
+
const view = gobj_create("gclass_lang_view", "C_YUI_GCLASS",
|
|
121
|
+
{description: DESCRIPTION}, host);
|
|
122
|
+
gobj_start(view);
|
|
123
|
+
const $c = gobj_read_attr(view, "$container");
|
|
124
|
+
const $more = () => $c.querySelector('.GCLASS_SHOW_ALL[data-zone="attrs"]');
|
|
125
|
+
expect($c.querySelector(".GCLASS_INSTANCES_LABEL").textContent).toBe("instances");
|
|
126
|
+
expect($more().textContent).toBe("show all 25");
|
|
127
|
+
|
|
128
|
+
await i18next.changeLanguage("es");
|
|
129
|
+
yui_shell_language_changed(shell);
|
|
130
|
+
expect($c.querySelector(".GCLASS_INSTANCES_LABEL").textContent).toBe("instancias");
|
|
131
|
+
expect([$more().textContent, $more().getAttribute("title"), $more().getAttribute("aria-label")])
|
|
132
|
+
.toEqual(["ver las 25", "ver las 25", "ver las 25"]);
|
|
133
|
+
|
|
134
|
+
/* stopped, it no longer hears the shell */
|
|
135
|
+
gobj_stop(view);
|
|
136
|
+
gobj_destroy(view);
|
|
137
|
+
await i18next.changeLanguage("en");
|
|
138
|
+
yui_shell_language_changed(shell);
|
|
139
|
+
expect(problems()).toEqual([]);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* camera was saved as nulls (a NaN has no json text) and gobj-js
|
|
8
8
|
* 7.26.27 refuses the whole value with an ERROR. Only real numbers
|
|
9
9
|
* are written now; a camera that is not readable keeps the one
|
|
10
|
-
* saved before, and a saved camera of nulls is not restored.
|
|
10
|
+
* saved before, and a saved camera of nulls is not restored. What
|
|
11
|
+
* is saved is getPosition(), and it is brought back with
|
|
12
|
+
* translateTo() through G6's closed forms, at any zoom.
|
|
11
13
|
*
|
|
12
14
|
* The real gclass, on a G6 Graph double whose camera the test sets.
|
|
13
15
|
*
|
|
@@ -31,7 +33,14 @@ if(typeof globalThis.ResizeObserver === "undefined") {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
const camera = vi.hoisted(() => ({zoom: NaN, position: [NaN, NaN], zoomed: [], moved: [],
|
|
34
|
-
size: null, viewport: null, plugins: []}));
|
|
36
|
+
size: null, viewport: null, plugins: [], g6: null}));
|
|
37
|
+
|
|
38
|
+
/* `camera.g6`, when set, is a camera that obeys G6 5.x's own closed
|
|
39
|
+
* forms, with C the canvas centre, Z the zoom and P the camera's
|
|
40
|
+
* position: getPosition() = C/Z - P, an absolute translateTo(T) leaves
|
|
41
|
+
* P = C - T/Z, zoomTo() keeps P, and a point n lands at (n - P)*Z + C.
|
|
42
|
+
* {Z, P, node}: `node` is where every card is. */
|
|
43
|
+
const CENTRE = [400, 300];
|
|
35
44
|
vi.mock("@antv/g6", async (importOriginal) => {
|
|
36
45
|
const real = await importOriginal();
|
|
37
46
|
class FakeGraph {
|
|
@@ -50,17 +59,28 @@ vi.mock("@antv/g6", async (importOriginal) => {
|
|
|
50
59
|
on() {
|
|
51
60
|
}
|
|
52
61
|
getZoom() {
|
|
53
|
-
return camera.zoom;
|
|
62
|
+
return camera.g6? camera.g6.Z: camera.zoom;
|
|
54
63
|
}
|
|
55
64
|
getPosition() {
|
|
65
|
+
const g = camera.g6;
|
|
66
|
+
if(g) {
|
|
67
|
+
return [CENTRE[0] / g.Z - g.P[0], CENTRE[1] / g.Z - g.P[1]];
|
|
68
|
+
}
|
|
56
69
|
return camera.position;
|
|
57
70
|
}
|
|
58
71
|
zoomTo(z) {
|
|
59
72
|
camera.zoomed.push(z);
|
|
73
|
+
if(camera.g6) {
|
|
74
|
+
camera.g6.Z = z;
|
|
75
|
+
}
|
|
60
76
|
return Promise.resolve();
|
|
61
77
|
}
|
|
62
78
|
translateTo(p) {
|
|
63
79
|
camera.moved.push(p);
|
|
80
|
+
const g = camera.g6;
|
|
81
|
+
if(g) {
|
|
82
|
+
g.P = [CENTRE[0] - p[0] / g.Z, CENTRE[1] - p[1] / g.Z];
|
|
83
|
+
}
|
|
64
84
|
return Promise.resolve();
|
|
65
85
|
}
|
|
66
86
|
/* Where a card lands on screen: `camera.viewport` for every one
|
|
@@ -73,15 +93,19 @@ vi.mock("@antv/g6", async (importOriginal) => {
|
|
|
73
93
|
return camera.size;
|
|
74
94
|
}
|
|
75
95
|
getElementPosition() {
|
|
76
|
-
return [0, 0];
|
|
96
|
+
return camera.g6? camera.g6.node: [0, 0];
|
|
77
97
|
}
|
|
78
98
|
getElementData() {
|
|
79
99
|
return {};
|
|
80
100
|
}
|
|
81
101
|
getCanvasCenter() {
|
|
82
|
-
return
|
|
102
|
+
return CENTRE;
|
|
83
103
|
}
|
|
84
|
-
getViewportByCanvas() {
|
|
104
|
+
getViewportByCanvas(n) {
|
|
105
|
+
const g = camera.g6;
|
|
106
|
+
if(g) {
|
|
107
|
+
return [(n[0] - g.P[0]) * g.Z + CENTRE[0], (n[1] - g.P[1]) * g.Z + CENTRE[1]];
|
|
108
|
+
}
|
|
85
109
|
return camera.viewport;
|
|
86
110
|
}
|
|
87
111
|
getData() {
|
|
@@ -156,6 +180,7 @@ beforeEach(() => {
|
|
|
156
180
|
camera.size = null;
|
|
157
181
|
camera.viewport = null;
|
|
158
182
|
camera.plugins = [];
|
|
183
|
+
camera.g6 = null;
|
|
159
184
|
});
|
|
160
185
|
|
|
161
186
|
function errors()
|
|
@@ -249,8 +274,57 @@ describe("C_YUI_GOBJ_TREE_JS does not restore a camera that shows nothing", () =
|
|
|
249
274
|
await mount(name);
|
|
250
275
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
251
276
|
expect(camera.zoomed).toEqual([0.5]);
|
|
252
|
-
|
|
277
|
+
/* getPosition() handed back to translateTo() at zoom 0.5:
|
|
278
|
+
* T = (S + C) * Z - C, not S itself */
|
|
279
|
+
expect(camera.moved).toEqual([[(10 + 400) * 0.5 - 400, (20 + 300) * 0.5 - 300]]);
|
|
280
|
+
expect(errors()).toEqual([]);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("C_YUI_GOBJ_TREE_JS brings the camera back where it was, at any zoom", () => {
|
|
285
|
+
async function round_trip(zoom, P)
|
|
286
|
+
{
|
|
287
|
+
const name = `camera_${++seq}`;
|
|
288
|
+
camera.size = [800, 600];
|
|
289
|
+
camera.g6 = {Z: 1, P: [400, 300], node: [100, 50]};
|
|
290
|
+
const first = await mount(name);
|
|
291
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
292
|
+
|
|
293
|
+
/* the reader zooms and pans; the move is saved */
|
|
294
|
+
camera.g6.Z = zoom;
|
|
295
|
+
camera.g6.P = P.slice();
|
|
296
|
+
gobj_send_event(first, "EV_REFRESH", {}, first);
|
|
297
|
+
const S = [400 / zoom - P[0], 300 / zoom - P[1]];
|
|
298
|
+
expect(saved(name).zoom).toBe(zoom);
|
|
299
|
+
expect(saved(name).position[0]).toBeCloseTo(S[0], 6);
|
|
300
|
+
expect(saved(name).position[1]).toBeCloseTo(S[1], 6);
|
|
301
|
+
/* (the refresh frames that view again, later: let it) */
|
|
302
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
303
|
+
|
|
304
|
+
/* a new opening, on a fresh camera */
|
|
305
|
+
camera.g6 = {Z: 1, P: [400, 300], node: [100, 50]};
|
|
306
|
+
camera.zoomed = [];
|
|
307
|
+
await mount(name);
|
|
308
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
309
|
+
expect(camera.zoomed).toEqual([zoom]);
|
|
310
|
+
expect(camera.g6.Z).toBe(zoom);
|
|
311
|
+
expect(camera.g6.P[0]).toBeCloseTo(P[0], 6);
|
|
312
|
+
expect(camera.g6.P[1]).toBeCloseTo(P[1], 6);
|
|
313
|
+
expect(logged.filter((l) => l.level === "warning").map((l) => l.msg).join(" "))
|
|
314
|
+
.not.toMatch(/the saved view shows none of the/);
|
|
253
315
|
expect(errors()).toEqual([]);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
test("at zoom 0.3: kept, not judged to show nothing", async () => {
|
|
319
|
+
await round_trip(0.3, [150, 80]);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test("at zoom 0.8: not shifted", async () => {
|
|
323
|
+
await round_trip(0.8, [180, 20]);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("at zoom 2", async () => {
|
|
327
|
+
await round_trip(2, [90, 60]);
|
|
254
328
|
});
|
|
255
329
|
});
|
|
256
330
|
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* wants (the tree, the trace levels of a gclass, a trace set) and
|
|
7
7
|
* the host loads the answers. Asserted here: what reaches the host,
|
|
8
8
|
* what the TRACES block of a card shows for each origin of a level,
|
|
9
|
-
* that a reload keeps the card open,
|
|
10
|
-
*
|
|
9
|
+
* that a reload keeps the card open, that the open gclass viewer is
|
|
10
|
+
* locked only by a set that moves what it shows (and unlocked by
|
|
11
|
+
* the answer it waits for), and that a LOCAL tree publishes none of
|
|
12
|
+
* it (its hosts declare none of these events).
|
|
11
13
|
*
|
|
12
14
|
* The real gclass, on a G6 Graph double.
|
|
13
15
|
*
|
|
@@ -94,6 +96,7 @@ const {
|
|
|
94
96
|
gobj_start, gobj_read_attr, gobj_send_event, set_log_callback, register_c_timer,
|
|
95
97
|
} = await import("@yuneta/gobj-js");
|
|
96
98
|
const {register_c_yui_gobj_tree_js} = await import("./c_yui_gobj_tree_js.js");
|
|
99
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
97
100
|
|
|
98
101
|
const logged = [];
|
|
99
102
|
const wanted = [];
|
|
@@ -144,6 +147,7 @@ beforeAll(async () => {
|
|
|
144
147
|
});
|
|
145
148
|
register_c_timer();
|
|
146
149
|
register_c_yui_gobj_tree_js();
|
|
150
|
+
register_c_yui_window();
|
|
147
151
|
gclass_create("C_TEST_TREE_YUNO", [], [["ST_IDLE", []]], {}, 0,
|
|
148
152
|
[SDATA_END()], {}, 0, 0, 0, 0);
|
|
149
153
|
gclass_create("C_TEST_TREE_HOST",
|
|
@@ -379,6 +383,173 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
379
383
|
});
|
|
380
384
|
});
|
|
381
385
|
|
|
386
|
+
/* The `view-gclass` answer for C_TCP, enough for the viewer. */
|
|
387
|
+
const TCP_DESCRIPTION = {
|
|
388
|
+
id: "C_TCP", gcflag: [], instances: 1, attrs: [], commands: [],
|
|
389
|
+
gclass_methods: [], internal_methods: [],
|
|
390
|
+
FSM: {events: [], states: {}},
|
|
391
|
+
info_gclass_trace: {traffic: "Trace dump traffic", connections: "Trace connections"},
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
/* The tree with the gclass viewer of C_TCP open, and its levels read. */
|
|
395
|
+
async function open_tcp_viewer()
|
|
396
|
+
{
|
|
397
|
+
const view = await mount("remote", host);
|
|
398
|
+
await open_tcp_card(view);
|
|
399
|
+
gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
|
|
400
|
+
gobj_send_event(view, "EV_OPEN_GCLASS", {}, view);
|
|
401
|
+
gobj_send_event(view, "EV_GCLASS_DESCRIPTION",
|
|
402
|
+
{gclass: "C_TCP", description: TCP_DESCRIPTION}, host);
|
|
403
|
+
const viewer = view.priv.gclass_view && view.priv.gclass_view.json_gobj;
|
|
404
|
+
expect(viewer).toBeTruthy();
|
|
405
|
+
wanted.length = 0;
|
|
406
|
+
return {view, viewer};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function viewer_box(viewer, level)
|
|
410
|
+
{
|
|
411
|
+
return gobj_read_attr(viewer, "$container").querySelectorAll(".GCLASS_TRACE_GCLASS")
|
|
412
|
+
.find((b) => b.getAttribute("data-level") === level);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
describe("C_YUI_GOBJ_TREE_JS, source remote: the open gclass viewer", () => {
|
|
416
|
+
test("a set of the viewer's gclass locks it until ITS answer", async () => {
|
|
417
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
418
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
419
|
+
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["traffic"], set: true}, viewer);
|
|
420
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
421
|
+
|
|
422
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {gclass: "C_TIMER"}), host);
|
|
423
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
424
|
+
|
|
425
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
426
|
+
{gclass_on: ["connections", "traffic"]}), host);
|
|
427
|
+
expect([viewer_box(viewer, "traffic").checked, viewer_box(viewer, "traffic").disabled])
|
|
428
|
+
.toEqual([true, false]);
|
|
429
|
+
expect(problems()).toEqual([]);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test("a gobj set on the card of ANOTHER gclass leaves the viewer alone", async () => {
|
|
433
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
434
|
+
const root_id = node_id_of(view, "C_YUNO^gate");
|
|
435
|
+
gobj_send_event(view, "EV_NODE_CLICK", {id: root_id, client_x: 10, client_y: 10}, view);
|
|
436
|
+
gobj_send_event(view, "EV_TRACE_INFO", YUNO_INFO, host);
|
|
437
|
+
|
|
438
|
+
const {$gobj} = row_of(view, "ev_kw");
|
|
439
|
+
$gobj.checked = true;
|
|
440
|
+
$gobj.dispatchEvent(fake_event("change"));
|
|
441
|
+
expect(wanted.filter((w) => w.event === "EV_SET_TRACE_LEVEL").map((w) => [w.kw.scope, w.kw.gclass]))
|
|
442
|
+
.toEqual([["gobj", "C_YUNO"]]);
|
|
443
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
444
|
+
|
|
445
|
+
gobj_send_event(view, "EV_TRACE_INFO", YUNO_INFO, host);
|
|
446
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
447
|
+
expect(problems()).toEqual([]);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
test("a set of the yuno's scope locks it until the yuno's answer AND its own", async () => {
|
|
451
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
452
|
+
gobj_read_attr(view, "$container").querySelector(".GOBJ_TREE_YUNO_TRACES_BUTTON").click();
|
|
453
|
+
gobj_send_event(view, "EV_TRACE_INFO", YUNO_INFO, host);
|
|
454
|
+
wanted.length = 0;
|
|
455
|
+
|
|
456
|
+
const ev_kw = row_of(view, "ev_kw");
|
|
457
|
+
ev_kw.$global.checked = true;
|
|
458
|
+
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
459
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
460
|
+
|
|
461
|
+
/* the answer of an unrelated gclass, arriving first */
|
|
462
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {gclass: "C_TIMER"}), host);
|
|
463
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
464
|
+
wanted.length = 0;
|
|
465
|
+
|
|
466
|
+
/* the yuno's: the viewer's own is asked for, still locked */
|
|
467
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO,
|
|
468
|
+
{global_on: ["machine", "ev_kw"]}), host);
|
|
469
|
+
expect(wanted.map((w) => [w.event, w.kw.gclass])).toEqual([["EV_TRACE_INFO_WANTED", "C_TCP"]]);
|
|
470
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
471
|
+
|
|
472
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
473
|
+
{global_levels: YUNO_INFO.global_levels,
|
|
474
|
+
gclass_on: ["connections", "ev_kw"], global_on: ["ev_kw"]}), host);
|
|
475
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
476
|
+
expect([viewer_box(viewer, "ev_kw").checked, viewer_box(viewer, "ev_kw").disabled])
|
|
477
|
+
.toEqual([true, true]);
|
|
478
|
+
expect(problems()).toEqual([]);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test("reopened while a set of ITS gclass is in flight, it opens locked until that answer", async () => {
|
|
482
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
483
|
+
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["traffic"], set: true}, viewer);
|
|
484
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
485
|
+
|
|
486
|
+
/* The card's gclass button, while the set is in flight: the
|
|
487
|
+
* viewer is replaced by a new one of the same gclass. */
|
|
488
|
+
const reopened = reopen_tcp_viewer(view);
|
|
489
|
+
expect(reopened).not.toBe(viewer);
|
|
490
|
+
expect(viewer_box(reopened, "traffic").disabled).toBe(true);
|
|
491
|
+
|
|
492
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {gclass: "C_TIMER"}), host);
|
|
493
|
+
expect(viewer_box(reopened, "traffic").disabled).toBe(true);
|
|
494
|
+
|
|
495
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
496
|
+
{gclass_on: ["connections", "traffic"]}), host);
|
|
497
|
+
expect([viewer_box(reopened, "traffic").checked, viewer_box(reopened, "traffic").disabled])
|
|
498
|
+
.toEqual([true, false]);
|
|
499
|
+
expect(problems()).toEqual([]);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
test("reopened after the answer, or with a set of ANOTHER gclass in flight, it opens unlocked", async () => {
|
|
503
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
504
|
+
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["traffic"], set: true}, viewer);
|
|
505
|
+
gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
|
|
506
|
+
expect(viewer_box(reopen_tcp_viewer(view), "traffic").disabled).toBe(false);
|
|
507
|
+
|
|
508
|
+
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TIMER", levels: ["traffic"], set: true}, view);
|
|
509
|
+
expect(viewer_box(reopen_tcp_viewer(view), "traffic").disabled).toBe(false);
|
|
510
|
+
expect(problems()).toEqual([]);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
test("reopened while a set of the yuno's scope is in flight, it waits for the yuno's answer AND its own", async () => {
|
|
514
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
515
|
+
gobj_read_attr(view, "$container").querySelector(".GOBJ_TREE_YUNO_TRACES_BUTTON").click();
|
|
516
|
+
gobj_send_event(view, "EV_TRACE_INFO", YUNO_INFO, host);
|
|
517
|
+
const ev_kw = row_of(view, "ev_kw");
|
|
518
|
+
ev_kw.$global.checked = true;
|
|
519
|
+
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
520
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
521
|
+
|
|
522
|
+
const reopened = reopen_tcp_viewer(view);
|
|
523
|
+
expect(viewer_box(reopened, "traffic").disabled).toBe(true);
|
|
524
|
+
wanted.length = 0;
|
|
525
|
+
|
|
526
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO,
|
|
527
|
+
{global_on: ["machine", "ev_kw"]}), host);
|
|
528
|
+
expect(wanted.map((w) => [w.event, w.kw.gclass])).toEqual([["EV_TRACE_INFO_WANTED", "C_TCP"]]);
|
|
529
|
+
expect(viewer_box(reopened, "traffic").disabled).toBe(true);
|
|
530
|
+
|
|
531
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
532
|
+
{global_levels: YUNO_INFO.global_levels,
|
|
533
|
+
gclass_on: ["connections", "ev_kw"], global_on: ["ev_kw"]}), host);
|
|
534
|
+
expect(viewer_box(reopened, "traffic").disabled).toBe(false);
|
|
535
|
+
expect(problems()).toEqual([]);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
/* The card of tcp1 again, and its gclass button: the host's answer
|
|
540
|
+
* replaces the open viewer with a new one of C_TCP. */
|
|
541
|
+
function reopen_tcp_viewer(view)
|
|
542
|
+
{
|
|
543
|
+
const id = node_id_of(view, "C_YUNO^gate`C_TCP^tcp1");
|
|
544
|
+
gobj_send_event(view, "EV_NODE_CLICK", {id: id, client_x: 10, client_y: 10}, view);
|
|
545
|
+
gobj_send_event(view, "EV_OPEN_GCLASS", {}, view);
|
|
546
|
+
gobj_send_event(view, "EV_GCLASS_DESCRIPTION",
|
|
547
|
+
{gclass: "C_TCP", description: TCP_DESCRIPTION}, host);
|
|
548
|
+
const viewer = view.priv.gclass_view && view.priv.gclass_view.json_gobj;
|
|
549
|
+
expect(viewer).toBeTruthy();
|
|
550
|
+
return viewer;
|
|
551
|
+
}
|
|
552
|
+
|
|
382
553
|
describe("C_YUI_GOBJ_TREE_JS, source local", () => {
|
|
383
554
|
test("publishes nothing: its host declares none of the remote events", async () => {
|
|
384
555
|
const view = await mount("local", yuno);
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* node_stages.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A shell with TWO stages (SHELL.md §3: `right` as a secondary
|
|
5
|
+
* stage). A route of the second stage changes what THAT stage
|
|
6
|
+
* shows and nothing else: the C_YUI_NODE tree the main stage still
|
|
7
|
+
* shows stays on its path. Up to 7.27.30 the root compared only the
|
|
8
|
+
* base of the route, so a route of the other stage sent it to
|
|
9
|
+
* ST_OFF and emptied it while the shell kept it on screen.
|
|
10
|
+
*
|
|
11
|
+
* A route of its OWN stage still takes it off the path, and the
|
|
12
|
+
* showing that follows tells its content once (EV_VIEW_SHOWN).
|
|
13
|
+
*
|
|
14
|
+
* Driven through the real C_YUI_SHELL on a document double.
|
|
15
|
+
*
|
|
16
|
+
* Copyright (c) 2026, ArtGins.
|
|
17
|
+
* All Rights Reserved.
|
|
18
|
+
***********************************************************************/
|
|
19
|
+
import {describe, test, expect, beforeAll, beforeEach, afterEach} from "vitest";
|
|
20
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
21
|
+
|
|
22
|
+
install_dom_double();
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr, gobj_read_attr,
|
|
26
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_find_child,
|
|
27
|
+
gobj_start, gobj_stop, gobj_destroy, gobj_is_running, gobj_name,
|
|
28
|
+
gobj_current_state, set_log_callback,
|
|
29
|
+
} = await import("@yuneta/gobj-js");
|
|
30
|
+
const {register_c_yui_shell, yui_shell_navigate} = await import("./c_yui_shell.js");
|
|
31
|
+
const {register_c_yui_node} = await import("./c_yui_node.js");
|
|
32
|
+
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
33
|
+
|
|
34
|
+
const logged = [];
|
|
35
|
+
const alive = [];
|
|
36
|
+
const shown = []; /* {name, kw} per EV_VIEW_SHOWN received */
|
|
37
|
+
let yuno = null;
|
|
38
|
+
let seq = 0;
|
|
39
|
+
|
|
40
|
+
beforeAll(async () => {
|
|
41
|
+
const i18next = (await import("i18next")).default;
|
|
42
|
+
await i18next.init({lng: "en", resources: {}});
|
|
43
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
44
|
+
set_log_callback((level, msg) => {
|
|
45
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
46
|
+
});
|
|
47
|
+
gclass_create("C_TEST_STAGES_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
48
|
+
|
|
49
|
+
const attrs = [
|
|
50
|
+
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "view root"),
|
|
51
|
+
SDATA_END()
|
|
52
|
+
];
|
|
53
|
+
const gmt = {
|
|
54
|
+
mt_create: (gobj) => {
|
|
55
|
+
gobj_write_attr(gobj, "$container", document.createElement("div"));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
gclass_create(
|
|
59
|
+
"C_TEST_STAGES_VIEW",
|
|
60
|
+
[["EV_VIEW_SHOWN", 0]],
|
|
61
|
+
[["ST_IDLE", [
|
|
62
|
+
["EV_VIEW_SHOWN", (gobj, event, kw) => {
|
|
63
|
+
shown.push({name: gobj_name(gobj), kw: kw});
|
|
64
|
+
return 0;
|
|
65
|
+
}, null]
|
|
66
|
+
]]],
|
|
67
|
+
gmt, 0, attrs, {}, 0, 0, 0, 0
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
register_c_yui_shell();
|
|
71
|
+
register_c_yui_nav();
|
|
72
|
+
register_c_yui_node();
|
|
73
|
+
yuno = gobj_create_yuno("node_stages_yuno", "C_TEST_STAGES_HOST", {});
|
|
74
|
+
gobj_start(yuno);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
logged.length = 0;
|
|
79
|
+
shown.length = 0;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
for(const gobj of alive.splice(0)) {
|
|
84
|
+
if(gobj_is_running(gobj)) {
|
|
85
|
+
gobj_stop(gobj);
|
|
86
|
+
}
|
|
87
|
+
gobj_destroy(gobj);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
function config()
|
|
92
|
+
{
|
|
93
|
+
const view = (stage, name) => ({
|
|
94
|
+
stage: stage, gclass: "C_TEST_STAGES_VIEW", kw: {}, lifecycle: "keep_alive", name: name
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
shell: {
|
|
98
|
+
zones: {
|
|
99
|
+
left: {host: "menu.primary"},
|
|
100
|
+
center: {host: "stage.main"},
|
|
101
|
+
right: {host: "stage.detail"}
|
|
102
|
+
},
|
|
103
|
+
stages: {
|
|
104
|
+
main: {zone: "center", default_route: "/plain"},
|
|
105
|
+
detail: {zone: "right"}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
menu: {
|
|
109
|
+
primary: {
|
|
110
|
+
render: {left: {layout: "vertical", icon_pos: "left"}},
|
|
111
|
+
items: [
|
|
112
|
+
{id: "plain", name: "plain", route: "/plain", target: view("main", "plain_view")},
|
|
113
|
+
{id: "detail", name: "detail", route: "/detail", target: view("detail", "detail_view")},
|
|
114
|
+
{id: "tree", name: "tree", route: "/tree",
|
|
115
|
+
target: {
|
|
116
|
+
stage: "main", gclass: "C_YUI_NODE", lifecycle: "keep_alive",
|
|
117
|
+
name: "the_tree",
|
|
118
|
+
kw: {
|
|
119
|
+
node_id: "tree", base_route: "/tree",
|
|
120
|
+
children: [
|
|
121
|
+
{id: "acc", label: "acc",
|
|
122
|
+
content: {gclass: "C_TEST_STAGES_VIEW", kw: {}}}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
}}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function new_shell()
|
|
133
|
+
{
|
|
134
|
+
const shell = gobj_create(`stages_shell_${++seq}`, "C_YUI_SHELL",
|
|
135
|
+
{config: config(), use_hash: false}, yuno);
|
|
136
|
+
gobj_start(shell);
|
|
137
|
+
alive.push(shell);
|
|
138
|
+
return shell;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function problems()
|
|
142
|
+
{
|
|
143
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* What the main stage shows of the tree: its state, whether its
|
|
147
|
+
* container is visible, and whether the content of `acc` is in it. */
|
|
148
|
+
function tree_on_screen(shell)
|
|
149
|
+
{
|
|
150
|
+
const tree = gobj_find_child(shell, {__gobj_name__: "the_tree"});
|
|
151
|
+
expect(tree).toBeTruthy();
|
|
152
|
+
const $c = gobj_read_attr(tree, "$container");
|
|
153
|
+
const acc = tree.priv.children.find((c) => gobj_read_attr(c, "node_id") === "acc");
|
|
154
|
+
const content = acc && acc.priv.content_gobj;
|
|
155
|
+
const $content = content ? gobj_read_attr(content, "$container") : null;
|
|
156
|
+
return {
|
|
157
|
+
state: gobj_current_state(tree),
|
|
158
|
+
visible: !$c.classList.contains("is-hidden"),
|
|
159
|
+
content_drawn: !!$content && $c.contains($content),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
describe("C_YUI_NODE under a shell with two stages", () => {
|
|
164
|
+
test("a route of ANOTHER stage leaves the tree on its path", () => {
|
|
165
|
+
const shell = new_shell();
|
|
166
|
+
yui_shell_navigate(shell, "/tree/acc");
|
|
167
|
+
const before = tree_on_screen(shell);
|
|
168
|
+
expect(before.state).not.toBe("ST_OFF");
|
|
169
|
+
expect(before.visible).toBe(true);
|
|
170
|
+
expect(before.content_drawn).toBe(true);
|
|
171
|
+
|
|
172
|
+
yui_shell_navigate(shell, "/detail");
|
|
173
|
+
expect(tree_on_screen(shell)).toEqual(before);
|
|
174
|
+
|
|
175
|
+
/* Back to the tree: it was never hidden, so it is not told
|
|
176
|
+
* it is shown again. */
|
|
177
|
+
yui_shell_navigate(shell, "/tree/acc");
|
|
178
|
+
expect(tree_on_screen(shell)).toEqual(before);
|
|
179
|
+
expect(shown).toEqual([]);
|
|
180
|
+
expect(problems()).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("a route of ITS stage takes it off the path, and the next showing tells the content once", () => {
|
|
184
|
+
const shell = new_shell();
|
|
185
|
+
yui_shell_navigate(shell, "/tree/acc");
|
|
186
|
+
yui_shell_navigate(shell, "/detail");
|
|
187
|
+
yui_shell_navigate(shell, "/plain");
|
|
188
|
+
const off = tree_on_screen(shell);
|
|
189
|
+
expect([off.state, off.visible, off.content_drawn]).toEqual(["ST_OFF", false, false]);
|
|
190
|
+
|
|
191
|
+
yui_shell_navigate(shell, "/tree/acc");
|
|
192
|
+
expect(tree_on_screen(shell).content_drawn).toBe(true);
|
|
193
|
+
/* (plain_view, the default route the shell opened on, is
|
|
194
|
+
* told too: it was shown before.) */
|
|
195
|
+
expect(shown.filter((s) => s.name !== "plain_view").map((s) => s.kw.route))
|
|
196
|
+
.toEqual(["/tree/acc"]);
|
|
197
|
+
expect(problems()).toEqual([]);
|
|
198
|
+
});
|
|
199
|
+
});
|