@yuneta/gobj-ui 7.27.22 → 7.27.24

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.
@@ -1520,9 +1520,15 @@ function load_json(gobj)
1520
1520
  * -- never parked at the layout's origin, which is a corner
1521
1521
  * with nothing in it and is where `1:1` used to land.
1522
1522
  */
1523
- Promise.resolve(graph.zoomTo(1)).then(() => {
1524
- if(!yui_graph_center_on(graph, priv.anchor_id)) {
1525
- yui_graph_center_on(graph, root_id);
1523
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
1524
+ /* yui_graph_center_on() is ASYNC: unawaited, its answer
1525
+ * is a promise, always truthy, so `!` of it was always
1526
+ * false and the root was never centred -- the opening
1527
+ * stayed wherever the camera happened to be. */
1528
+ let on_anchor = priv.anchor_id?
1529
+ await yui_graph_center_on(graph, priv.anchor_id): false;
1530
+ if(!on_anchor) {
1531
+ await yui_graph_center_on(graph, root_id);
1526
1532
  }
1527
1533
  priv.last_zoom = 1;
1528
1534
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
@@ -30,7 +30,8 @@ if(typeof globalThis.ResizeObserver === "undefined") {
30
30
  };
31
31
  }
32
32
 
33
- const camera = vi.hoisted(() => ({zoom: NaN, position: [NaN, NaN], zoomed: [], moved: []}));
33
+ const camera = vi.hoisted(() => ({zoom: NaN, position: [NaN, NaN], zoomed: [], moved: [],
34
+ size: null, viewport: null}));
34
35
  vi.mock("@antv/g6", async (importOriginal) => {
35
36
  const real = await importOriginal();
36
37
  class FakeGraph {
@@ -62,6 +63,27 @@ vi.mock("@antv/g6", async (importOriginal) => {
62
63
  camera.moved.push(p);
63
64
  return Promise.resolve();
64
65
  }
66
+ /* Where a card lands on screen: `camera.viewport` for every one
67
+ * of them, and the canvas `camera.size`. Unset, the camera cannot
68
+ * be read, which is what the older tests expect. */
69
+ getSize() {
70
+ if(!camera.size) {
71
+ throw new Error("no size");
72
+ }
73
+ return camera.size;
74
+ }
75
+ getElementPosition() {
76
+ return [0, 0];
77
+ }
78
+ getElementData() {
79
+ return {};
80
+ }
81
+ getCanvasCenter() {
82
+ return [400, 300];
83
+ }
84
+ getViewportByCanvas() {
85
+ return camera.viewport;
86
+ }
65
87
  getData() {
66
88
  return {nodes: [], edges: [], combos: []};
67
89
  }
@@ -122,6 +144,8 @@ beforeEach(() => {
122
144
  camera.position = [NaN, NaN];
123
145
  camera.zoomed = [];
124
146
  camera.moved = [];
147
+ camera.size = null;
148
+ camera.viewport = null;
125
149
  });
126
150
 
127
151
  function errors()
@@ -183,3 +207,49 @@ describe("C_YUI_GOBJ_TREE_JS saves only a camera of numbers", () => {
183
207
  expect(errors()).toEqual([]);
184
208
  });
185
209
  });
210
+
211
+ describe("C_YUI_GOBJ_TREE_JS does not restore a camera that shows nothing", () => {
212
+ test("a saved camera with every card off the canvas is framed again", async () => {
213
+ const name = `camera_${++seq}`;
214
+ window.localStorage.setItem(`yui_gobj_tree_view:${name}`,
215
+ JSON.stringify({layout: "", collapsed: {}, anchor: "", zoom: 0.18, position: [-20000, -20000]}));
216
+ camera.size = [800, 600];
217
+ camera.viewport = [-5000, -5000];
218
+ await mount(name);
219
+ await new Promise((resolve) => setTimeout(resolve, 0));
220
+ /* judged before it is applied: only the opening's own framing */
221
+ expect(camera.zoomed).toEqual([1]);
222
+ expect(logged.filter((l) => l.level === "warning").map((l) => l.msg).join(" "))
223
+ .toMatch(/the saved view shows none of the/);
224
+ expect(errors()).toEqual([]);
225
+ });
226
+
227
+ test("a saved camera that shows a card is kept", async () => {
228
+ const name = `camera_${++seq}`;
229
+ window.localStorage.setItem(`yui_gobj_tree_view:${name}`,
230
+ JSON.stringify({layout: "", collapsed: {}, anchor: "", zoom: 0.5, position: [10, 20]}));
231
+ camera.size = [800, 600];
232
+ camera.viewport = [400, 300];
233
+ await mount(name);
234
+ await new Promise((resolve) => setTimeout(resolve, 0));
235
+ expect(camera.zoomed).toEqual([0.5]);
236
+ expect(camera.moved).toEqual([[10, 20]]);
237
+ expect(errors()).toEqual([]);
238
+ });
239
+ });
240
+
241
+ describe("C_YUI_GOBJ_TREE_JS opens centred on its root", () => {
242
+ test("with nothing saved, the camera is moved onto the root", async () => {
243
+ /* yui_graph_center_on() is async, and its answer was read
244
+ * unawaited -- a promise, always truthy -- so the root was never
245
+ * centred and the opening stayed where the camera happened to be. */
246
+ const name = `camera_${++seq}`;
247
+ camera.viewport = [0, 0]; /* the root, 400x300 off the centre */
248
+ await mount(name);
249
+ await new Promise((resolve) => setTimeout(resolve, 0));
250
+ expect(camera.zoomed).toEqual([1]);
251
+ expect(camera.moved.length).toBeGreaterThan(0);
252
+ expect(camera.moved[0]).toEqual([400, 300]);
253
+ expect(errors()).toEqual([]);
254
+ });
255
+ });
@@ -331,6 +331,11 @@ function node_badge_keys(d)
331
331
  if(d.commands) {
332
332
  badges.push("commands");
333
333
  }
334
+ /* Only a backend answers it (`view-gobj-tree`): a card that traces
335
+ * is the one a reader is looking for when the log fills up. */
336
+ if(Array.isArray(d.gobj_trace_level) && d.gobj_trace_level.length > 0) {
337
+ badges.push("traces");
338
+ }
334
339
 
335
340
  return badges;
336
341
  }
@@ -379,6 +384,7 @@ function node_labels(t)
379
384
  "disabled": t("disabled"),
380
385
  "bottom": t("bottom"),
381
386
  "commands": t("commands"),
387
+ "traces": t("traces"),
382
388
  },
383
389
  field: {
384
390
  gclass: t("gclass"),
@@ -463,6 +469,102 @@ function node_info_rows(d, t)
463
469
  return rows;
464
470
  }
465
471
 
472
+
473
+
474
+ /******************************
475
+ * Trace levels
476
+ ******************************/
477
+
478
+
479
+ /************************************************************
480
+ * The rows of the TRACES block of a backend gobj, one per
481
+ * level it can trace: the gclass' own levels first (the ones
482
+ * that are about this gobj), then the global ones.
483
+ *
484
+ * `d` is the descriptor (its `gobj_trace_level` is what the
485
+ * gobj traces NOW, whatever the reason). `info` is what the
486
+ * host fetched for its gclass:
487
+ *
488
+ * gclass_levels {name: description} info-gclass-trace
489
+ * global_levels {name: description} info-global-trace
490
+ * gclass_on [name, ...] get-gclass-trace
491
+ * global_on [name, ...] get-global-trace
492
+ *
493
+ * `get-gclass-trace` answers the gclass' levels OR'ed with the
494
+ * global ones (gobj_get_gclass_trace_level), so a level on in
495
+ * both is counted as global: that is the one that would still
496
+ * hold it on if the gclass let go.
497
+ *
498
+ * Each row says, for the two columns of the block:
499
+ *
500
+ * gobj_on, gobj_locked the gobj traces it; locked when
501
+ * that comes from its gclass or
502
+ * from the global level -- turning
503
+ * the gobj's own bit off would not
504
+ * stop it
505
+ * gclass_on, gclass_locked every gobj of the gclass traces
506
+ * it; locked when it is global
507
+ * origin "global" | "gclass" | ""
508
+ ************************************************************/
509
+ function trace_rows(d, info)
510
+ {
511
+ let rows = [];
512
+ if(!d || !info) {
513
+ return rows;
514
+ }
515
+ let list = (x) => Array.isArray(x)? x: [];
516
+ let now = list(d.gobj_trace_level);
517
+ let global_on = list(info.global_on);
518
+ let gclass_on = list(info.gclass_on);
519
+ let seen = {};
520
+
521
+ let add = (group, levels) => {
522
+ if(!levels || typeof levels !== "object") {
523
+ return;
524
+ }
525
+ for(let level of Object.keys(levels)) {
526
+ if(seen[level]) {
527
+ continue;
528
+ }
529
+ seen[level] = true;
530
+ let by_global = global_on.indexOf(level) >= 0;
531
+ let by_gclass = !by_global && gclass_on.indexOf(level) >= 0;
532
+ rows.push({
533
+ level: level,
534
+ description: String(levels[level] || ""),
535
+ group: group,
536
+ gobj_on: now.indexOf(level) >= 0 || by_global || by_gclass,
537
+ gobj_locked: by_global || by_gclass,
538
+ gclass_on: by_global || by_gclass,
539
+ gclass_locked: by_global,
540
+ origin: by_global? "global": (by_gclass? "gclass": ""),
541
+ });
542
+ }
543
+ };
544
+ add("gclass", info.gclass_levels);
545
+ add("global", info.global_levels);
546
+ return rows;
547
+ }
548
+
549
+ /************************************************************
550
+ * The levels a scope holds ON ITS OWN -- what "remove the
551
+ * traces" of that scope has to turn off. Not the locked ones:
552
+ * they are held by a wider scope, and turning them off here
553
+ * would change nothing.
554
+ ************************************************************/
555
+ function own_trace_levels(rows, scope)
556
+ {
557
+ let out = [];
558
+ for(let r of (rows || [])) {
559
+ if(scope === "gobj" && r.gobj_on && !r.gobj_locked) {
560
+ out.push(r.level);
561
+ } else if(scope === "gclass" && r.gclass_on && !r.gclass_locked) {
562
+ out.push(r.level);
563
+ }
564
+ }
565
+ return out;
566
+ }
567
+
466
568
  export {
467
569
  ROLES,
468
570
  STATUSES,
@@ -478,4 +580,6 @@ export {
478
580
  describe_js_gobj,
479
581
  describe_backend_node,
480
582
  describe_backend_tree,
583
+ trace_rows,
584
+ own_trace_levels,
481
585
  };
@@ -8,6 +8,8 @@ import {
8
8
  node_info_rows,
9
9
  describe_backend_node,
10
10
  describe_backend_tree,
11
+ trace_rows,
12
+ own_trace_levels,
11
13
  } from "./gobj_tree_model.js";
12
14
 
13
15
  /* A `view-gobj-tree` answer, trimmed to what the view reads. */
@@ -123,7 +125,7 @@ describe("node_status", () => {
123
125
  describe("node_badge_keys", () => {
124
126
  it("marks the role and every extra fact, in a fixed order", () => {
125
127
  let root = describe_backend_tree(BACKEND_TREE);
126
- expect(node_badge_keys(root)).toEqual(["yuno", "commands"]);
128
+ expect(node_badge_keys(root)).toEqual(["yuno", "commands", "traces"]);
127
129
 
128
130
  let tcp = root.children.find(c => c.gclass === "C_TCP");
129
131
  expect(node_badge_keys(tcp))
@@ -133,6 +135,55 @@ describe("node_badge_keys", () => {
133
135
  it("a plain child carries no role badge", () => {
134
136
  expect(node_badge_keys({})).toEqual([]);
135
137
  });
138
+
139
+ it("a gobj that traces says so, last", () => {
140
+ expect(node_badge_keys({gobj_trace_level: ["machine"]})).toEqual(["traces"]);
141
+ expect(node_badge_keys({gobj_trace_level: []})).toEqual([]);
142
+ });
143
+ });
144
+
145
+ describe("trace_rows", () => {
146
+ const INFO = {
147
+ gclass_levels: {traffic: "dump", connections: "connections"},
148
+ global_levels: {machine: "machine", connections: "never listed twice"},
149
+ gclass_on: ["connections", "machine"], /* OR'ed with the global ones */
150
+ global_on: ["machine"],
151
+ };
152
+ const by_level = (rows) => {
153
+ let map = {};
154
+ for(let r of rows) {
155
+ map[r.level] = r;
156
+ }
157
+ return map;
158
+ };
159
+
160
+ it("lists the gclass levels first, then the global ones, each once", () => {
161
+ let rows = trace_rows({gobj_trace_level: []}, INFO);
162
+ expect(rows.map((r) => [r.level, r.group])).toEqual([
163
+ ["traffic", "gclass"], ["connections", "gclass"], ["machine", "global"]
164
+ ]);
165
+ });
166
+
167
+ it("locks a level held by a wider scope, and says which", () => {
168
+ let r = by_level(trace_rows({gobj_trace_level: ["traffic", "connections", "machine"]}, INFO));
169
+ expect(r.traffic).toMatchObject({gobj_on: true, gobj_locked: false,
170
+ gclass_on: false, gclass_locked: false, origin: ""});
171
+ expect(r.connections).toMatchObject({gobj_on: true, gobj_locked: true,
172
+ gclass_on: true, gclass_locked: false, origin: "gclass"});
173
+ expect(r.machine).toMatchObject({gobj_on: true, gobj_locked: true,
174
+ gclass_on: true, gclass_locked: true, origin: "global"});
175
+ });
176
+
177
+ it("what each scope holds on its own is what its remove turns off", () => {
178
+ let rows = trace_rows({gobj_trace_level: ["traffic", "connections", "machine"]}, INFO);
179
+ expect(own_trace_levels(rows, "gobj")).toEqual(["traffic"]);
180
+ expect(own_trace_levels(rows, "gclass")).toEqual(["connections"]);
181
+ });
182
+
183
+ it("no info, no rows", () => {
184
+ expect(trace_rows({gobj_trace_level: ["machine"]}, null)).toEqual([]);
185
+ expect(own_trace_levels(null, "gobj")).toEqual([]);
186
+ });
136
187
  });
137
188
 
138
189
  describe("node_info_rows", () => {
@@ -0,0 +1,314 @@
1
+ /***********************************************************************
2
+ * gobj_tree_remote.wiring.test.js
3
+ *
4
+ * C_YUI_GOBJ_TREE_JS with `source: "remote"`: the tree of a BACKEND
5
+ * yuno, which the view cannot fetch itself. It publishes what it
6
+ * wants (the tree, the trace levels of a gclass, a trace set) and
7
+ * the host loads the answers. Asserted here: what reaches the host,
8
+ * what the TRACES block of a card shows for each origin of a level,
9
+ * that a reload keeps the card open, and that a LOCAL tree publishes
10
+ * none of it (its hosts declare none of these events).
11
+ *
12
+ * The real gclass, on a G6 Graph double.
13
+ *
14
+ * Copyright (c) 2026, ArtGins.
15
+ * All Rights Reserved.
16
+ ***********************************************************************/
17
+ import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
18
+ import {install_dom_double, fake_event} from "../test/dom_double.js";
19
+
20
+ install_dom_double();
21
+
22
+ if(typeof globalThis.ResizeObserver === "undefined") {
23
+ globalThis.ResizeObserver = class {
24
+ observe() {
25
+ }
26
+ unobserve() {
27
+ }
28
+ disconnect() {
29
+ }
30
+ };
31
+ }
32
+
33
+ vi.mock("@antv/g6", async (importOriginal) => {
34
+ const real = await importOriginal();
35
+ class FakeGraph {
36
+ constructor(options) {
37
+ this.options = options;
38
+ return new Proxy(this, {
39
+ get: (t, k) => (k in t) ? t[k] : (() => undefined),
40
+ });
41
+ }
42
+ render() {
43
+ return Promise.resolve();
44
+ }
45
+ draw() {
46
+ return Promise.resolve();
47
+ }
48
+ on() {
49
+ }
50
+ getZoom() {
51
+ return 1;
52
+ }
53
+ getPosition() {
54
+ return [0, 0];
55
+ }
56
+ zoomTo() {
57
+ return Promise.resolve();
58
+ }
59
+ translateTo() {
60
+ return Promise.resolve();
61
+ }
62
+ getData() {
63
+ return {nodes: [], edges: [], combos: []};
64
+ }
65
+ getNodeData() {
66
+ return [];
67
+ }
68
+ getEdgeData() {
69
+ return [];
70
+ }
71
+ getPlugins() {
72
+ return [];
73
+ }
74
+ getBehaviors() {
75
+ return [];
76
+ }
77
+ getOptions() {
78
+ return {behaviors: []};
79
+ }
80
+ getCanvas() {
81
+ return {getLayers: () => ({}), getContainer: () => null};
82
+ }
83
+ fitView() {
84
+ return Promise.resolve();
85
+ }
86
+ destroy() {
87
+ }
88
+ }
89
+ return {...real, Graph: FakeGraph};
90
+ });
91
+
92
+ const {
93
+ SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
94
+ gobj_start, gobj_read_attr, gobj_send_event, set_log_callback, register_c_timer,
95
+ } = await import("@yuneta/gobj-js");
96
+ const {register_c_yui_gobj_tree_js} = await import("./c_yui_gobj_tree_js.js");
97
+
98
+ const logged = [];
99
+ const wanted = [];
100
+ let yuno = null;
101
+ let host = null;
102
+ let seq = 0;
103
+
104
+ /* The `view-gobj-tree` answer of a small backend yuno. */
105
+ const TREE = {
106
+ "C_YUNO^gate": {
107
+ gclass: "C_YUNO", name: "gate", shortname: "C_YUNO^gate", fullname: "C_YUNO^gate",
108
+ state: "ST_YUNO_RUNNING", running: true, playing: true,
109
+ gobj_flags: ["gobj_flag_yuno"], gobj_trace_level: [],
110
+ children: {
111
+ "C_TCP^tcp1": {
112
+ gclass: "C_TCP", name: "tcp1", shortname: "C_TCP^tcp1",
113
+ fullname: "C_YUNO^gate`C_TCP^tcp1", parent: "C_YUNO^gate",
114
+ state: "ST_CONNECTED", running: true, playing: true,
115
+ gobj_trace_level: ["traffic", "connections"],
116
+ children: {}
117
+ }
118
+ }
119
+ }
120
+ };
121
+
122
+ /* What the host fetched for C_TCP: `connections` is on for the gclass,
123
+ * `traffic` only for tcp1, `machine` for nobody. */
124
+ const TCP_INFO = {
125
+ gclass: "C_TCP",
126
+ gclass_levels: {traffic: "Trace dump traffic", connections: "Trace connections"},
127
+ global_levels: {machine: "Trace machine"},
128
+ gclass_on: ["connections"],
129
+ global_on: [],
130
+ };
131
+
132
+ function record(gobj, event, kw, src)
133
+ {
134
+ wanted.push({event: event, kw: kw});
135
+ return 0;
136
+ }
137
+
138
+ beforeAll(async () => {
139
+ const i18next = (await import("i18next")).default;
140
+ await i18next.init({lng: "en", resources: {en: {translation: {}}}});
141
+ gobj_start_up(null, null, null, null, null, null, null);
142
+ set_log_callback((level, msg) => {
143
+ logged.push({level: String(level), msg: String(msg)});
144
+ });
145
+ register_c_timer();
146
+ register_c_yui_gobj_tree_js();
147
+ gclass_create("C_TEST_TREE_YUNO", [], [["ST_IDLE", []]], {}, 0,
148
+ [SDATA_END()], {}, 0, 0, 0, 0);
149
+ gclass_create("C_TEST_TREE_HOST",
150
+ [["EV_TREE_WANTED", 0], ["EV_TRACE_INFO_WANTED", 0],
151
+ ["EV_SET_TRACE_LEVEL", 0], ["EV_GCLASS_WANTED", 0]],
152
+ [["ST_IDLE", [
153
+ ["EV_TREE_WANTED", record, null],
154
+ ["EV_TRACE_INFO_WANTED", record, null],
155
+ ["EV_SET_TRACE_LEVEL", record, null],
156
+ ["EV_GCLASS_WANTED", record, null],
157
+ ]]],
158
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
159
+ yuno = gobj_create_yuno("tree_yuno", "C_TEST_TREE_YUNO", {});
160
+ host = gobj_create("host", "C_TEST_TREE_HOST", {}, yuno);
161
+ });
162
+
163
+ beforeEach(() => {
164
+ logged.length = 0;
165
+ wanted.length = 0;
166
+ });
167
+
168
+ function problems()
169
+ {
170
+ return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
171
+ }
172
+
173
+ async function mount(source, parent)
174
+ {
175
+ const view = gobj_create(`tree_${++seq}`, "C_YUI_GOBJ_TREE_JS",
176
+ {source: source, yuno_name: "gate^1"}, parent);
177
+ document.body.appendChild(gobj_read_attr(view, "$container"));
178
+ gobj_start(view);
179
+ await new Promise((resolve) => setTimeout(resolve, 0));
180
+ return view;
181
+ }
182
+
183
+ function node_id_of(view, fullname)
184
+ {
185
+ const by_id = view.priv.node_by_id || {};
186
+ return Object.keys(by_id).find((id) => by_id[id].full_name === fullname);
187
+ }
188
+
189
+ function row_of(view, level)
190
+ {
191
+ const $pop = view.priv.$popover;
192
+ const $gobj = $pop.querySelectorAll(".GOBJ_TREE_TRACE_GOBJ")
193
+ .find((b) => b.getAttribute("data-level") === level);
194
+ const $gclass = $pop.querySelectorAll(".GOBJ_TREE_TRACE_GCLASS")
195
+ .find((b) => b.getAttribute("data-level") === level);
196
+ return {$gobj, $gclass};
197
+ }
198
+
199
+ async function open_tcp_card(view)
200
+ {
201
+ gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE}, host);
202
+ const id = node_id_of(view, "C_YUNO^gate`C_TCP^tcp1");
203
+ expect(id).toBeTruthy();
204
+ gobj_send_event(view, "EV_NODE_CLICK", {id: id, client_x: 10, client_y: 10}, view);
205
+ }
206
+
207
+ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
208
+ test("draws nothing until the host loads a tree, and asks for it on Refresh", async () => {
209
+ const view = await mount("remote", host);
210
+ expect(view.priv.node_by_id && Object.keys(view.priv.node_by_id).length || 0).toBe(0);
211
+ gobj_send_event(view, "EV_REFRESH", {}, view);
212
+ expect(wanted.map((w) => w.event)).toEqual(["EV_TREE_WANTED"]);
213
+
214
+ gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE}, host);
215
+ expect(Object.keys(view.priv.node_by_id).length).toBe(2);
216
+ expect(problems()).toEqual([]);
217
+ });
218
+
219
+ test("a card asks for the trace levels of its gclass, and shows where each comes from", async () => {
220
+ const view = await mount("remote", host);
221
+ await open_tcp_card(view);
222
+ expect(wanted.map((w) => [w.event, w.kw.gclass])).toEqual([["EV_TRACE_INFO_WANTED", "C_TCP"]]);
223
+ expect(view.priv.$popover.querySelectorAll(".GOBJ_TREE_TRACES_TABLE").length).toBe(0);
224
+
225
+ gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
226
+ const traffic = row_of(view, "traffic");
227
+ const connections = row_of(view, "connections");
228
+ const machine = row_of(view, "machine");
229
+
230
+ /* only tcp1: its own, so it can be turned off here */
231
+ expect([traffic.$gobj.checked, traffic.$gobj.disabled]).toEqual([true, false]);
232
+ expect([traffic.$gclass.checked, traffic.$gclass.disabled]).toEqual([false, false]);
233
+ /* the gclass holds it: on and locked for the gobj */
234
+ expect([connections.$gobj.checked, connections.$gobj.disabled]).toEqual([true, true]);
235
+ expect([connections.$gclass.checked, connections.$gclass.disabled]).toEqual([true, false]);
236
+ /* nobody */
237
+ expect([machine.$gobj.checked, machine.$gobj.disabled]).toEqual([false, false]);
238
+ expect(problems()).toEqual([]);
239
+ });
240
+
241
+ test("a box sends the set to the host and locks the block until the backend answers", async () => {
242
+ const view = await mount("remote", host);
243
+ await open_tcp_card(view);
244
+ gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
245
+ wanted.length = 0;
246
+
247
+ const {$gobj} = row_of(view, "machine");
248
+ $gobj.checked = true;
249
+ $gobj.dispatchEvent(fake_event("change"));
250
+ expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
251
+ scope: "gobj", gobj: "C_YUNO^gate`C_TCP^tcp1", gclass: "C_TCP",
252
+ levels: ["machine"], set: true
253
+ }}]);
254
+ expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
255
+
256
+ /* The host loads what the backend says now: the card is still
257
+ * open on tcp1, and unlocked. */
258
+ const tree = JSON.parse(JSON.stringify(TREE));
259
+ tree["C_YUNO^gate"].children["C_TCP^tcp1"].gobj_trace_level.push("machine");
260
+ gobj_send_event(view, "EV_LOAD_TREE", {tree: tree}, host);
261
+ expect(view.priv.popover_node.full_name).toBe("C_YUNO^gate`C_TCP^tcp1");
262
+ expect(view.priv.$popover.style.display).toBe("block");
263
+ expect([row_of(view, "machine").$gobj.checked, row_of(view, "machine").$gobj.disabled])
264
+ .toEqual([true, false]);
265
+ expect(problems()).toEqual([]);
266
+ });
267
+
268
+ test("remove the traces of the gobj turns off what it holds on its own, not what the gclass holds", async () => {
269
+ const view = await mount("remote", host);
270
+ await open_tcp_card(view);
271
+ gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
272
+ wanted.length = 0;
273
+
274
+ const $clear = view.priv.$popover.querySelector(".GOBJ_TREE_TRACES_CLEAR_GOBJ");
275
+ expect($clear.disabled).toBe(false);
276
+ $clear.click();
277
+ expect(wanted.map((w) => [w.kw.scope, w.kw.levels, w.kw.set])).toEqual([["gobj", ["traffic"], false]]);
278
+ expect(problems()).toEqual([]);
279
+ });
280
+
281
+ test("the gclass button asks the host for the backend gclass", async () => {
282
+ const view = await mount("remote", host);
283
+ await open_tcp_card(view);
284
+ wanted.length = 0;
285
+ gobj_send_event(view, "EV_OPEN_GCLASS", {}, view);
286
+ expect(wanted.map((w) => [w.event, w.kw.gclass])).toEqual([["EV_GCLASS_WANTED", "C_TCP"]]);
287
+ expect(view.priv.gclass_view).toBe(null);
288
+ });
289
+ });
290
+
291
+ describe("C_YUI_GOBJ_TREE_JS, source local", () => {
292
+ test("publishes nothing: its host declares none of the remote events", async () => {
293
+ const view = await mount("local", yuno);
294
+ gobj_send_event(view, "EV_REFRESH", {}, view);
295
+ expect(wanted).toEqual([]);
296
+ expect(problems()).toEqual([]);
297
+ });
298
+
299
+ test("an empty graph saves no camera: a fit before the tree loads frames nothing", async () => {
300
+ const view = await mount("remote", host);
301
+ const key = `yui_gobj_tree_view:tree_${seq}`;
302
+ gobj_send_event(view, "EV_REFRESH", {}, view);
303
+ const saved = JSON.parse(window.localStorage.getItem(key) || "null");
304
+ expect(saved).not.toBe(null);
305
+ expect("zoom" in saved).toBe(false);
306
+ expect("position" in saved).toBe(false);
307
+
308
+ gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE}, host);
309
+ gobj_send_event(view, "EV_REFRESH", {}, view);
310
+ const after = JSON.parse(window.localStorage.getItem(key));
311
+ expect(after.zoom).toBe(1);
312
+ expect(problems()).toEqual([]);
313
+ });
314
+ });
@@ -160,6 +160,8 @@ export const I18N_KEY_FUNCTIONS = Object.freeze([
160
160
  fallbacks: {"0[].id": ["0[].name", "0[].aria_label"]}},
161
161
  /* yui_gclass_view.js -- the dialog's title is the gclass name */
162
162
  {module: "yui_gclass_view.js", name: "open_gclass_view", exported: true, keys: ["1"]},
163
+ /* yui_gobj_tree_view.js -- the window's title is a key */
164
+ {module: "yui_gobj_tree_view.js", name: "open_gobj_tree_view", exported: true, keys: ["1.title"]},
163
165
  /* g6_canvas_tab_order.js -- the name of a graph's main canvas, the
164
166
  * one control of the graph in the Tab order */
165
167
  {module: "g6_canvas_tab_order.js", name: "set_canvas_tab_order", exported: true, keys: ["2"]},