@yuneta/gobj-ui 7.27.30 → 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 CHANGED
@@ -4449,7 +4449,12 @@ its third number, in the same edit), installs, builds, deploys
4449
4449
  and reads back the bundle each host serves (`--check` only reads back,
4450
4450
  `--only <name>` does one app, `--no-wait` skips the registry). The private
4451
4451
  consumers are listed in `~/.yuneta/gobj-ui-consumers.json` (see
4452
- `scripts/gobj-ui-consumers.example.json`); the demo (`test-app/`) is built in.
4452
+ `scripts/gobj-ui-consumers.example.json`). The round commits nothing: each
4453
+ app's commit carries its `package.json` and the `package-lock.json` the
4454
+ install rewrote (every app commits its lockfile, and a fresh checkout installs
4455
+ with `npm ci`). The demo is the one exception (below).
4456
+
4457
+ The demo (`test-app/`) is built in.
4453
4458
  It is built from the working trees of this repo and of the sibling `gobj-js`
4454
4459
  (`test-app/vite.config.js` bundles `../../gobj-js/src`), so it goes out only
4455
4460
  when each is a clean tree of its own (untracked files count; a copy with no
@@ -4457,7 +4462,11 @@ when each is a clean tree of its own (untracked files count; a copy with no
4457
4462
  holds on the remote; otherwise it is `NOT DEPLOYED`, with the reason, and the
4458
4463
  round exits 1 (since `7.26.55`, the sibling `gobj-js` since `7.26.57`; up to
4459
4464
  `7.26.54` any copy of the repo, on any commit, deployed the public demo). The
4460
- demo's target is named `test-app` (`--only test-app`).
4465
+ demo's target is named `test-app` (`--only test-app`). The round does not
4466
+ install it, and its `package-lock.json` is not in git, on purpose
4467
+ (`test-app/.gitignore` lists it): its two Yuneta dependencies are `file:`
4468
+ links to those working trees, which a lockfile cannot pin, and the lockfile
4469
+ would change with every version of gobj-ui or gobj-js.
4461
4470
 
4462
4471
  An app whose range cannot be raised safely is refused and left as it was --
4463
4472
  every package.json of it, since all are checked before any is written: a
@@ -52441,6 +52441,7 @@ var PRIVATE_DATA$9 = {
52441
52441
  popover_mode: "",
52442
52442
  viewer_awaits: "",
52443
52443
  viewer_stale: "",
52444
+ set_in_flight: null,
52444
52445
  view_refused: false
52445
52446
  };
52446
52447
  var __gclass__$9 = null;
@@ -54842,6 +54843,7 @@ function open_gclass_window(gobj, gclass, description, d) {
54842
54843
  priv.gclass_view = null;
54843
54844
  priv.viewer_awaits = "";
54844
54845
  priv.viewer_stale = "";
54846
+ if (priv.set_in_flight) lock_viewer_for_set(gobj, gclass, priv.set_in_flight);
54845
54847
  let opts = {
54846
54848
  title_prefix: is_remote(gobj) ? (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "yuno_name") || "" : (0, _yuneta_gobj_js.gobj_yuno_name)() || "",
54847
54849
  current_state: d && d.state || "",
@@ -54908,6 +54910,7 @@ function ac_trace_info(gobj, event, kw, src) {
54908
54910
  error: kw.error || ""
54909
54911
  };
54910
54912
  priv.trace_pending = false;
54913
+ if (priv.set_in_flight && priv.set_in_flight.gclass === kw.gclass) priv.set_in_flight = null;
54911
54914
  let d = priv.popover_node;
54912
54915
  let root = priv.remote_root;
54913
54916
  if (priv.popover_mode === "node" && d && d.gclass === kw.gclass || priv.popover_mode === "yuno" && root && root.gclass === kw.gclass) render_current_popover(gobj);
@@ -54919,6 +54922,10 @@ function ac_trace_info(gobj, event, kw, src) {
54919
54922
  if (priv.viewer_stale === shown && shown !== kw.gclass) {
54920
54923
  priv.viewer_stale = "";
54921
54924
  priv.viewer_awaits = shown;
54925
+ priv.set_in_flight = {
54926
+ gclass: shown,
54927
+ scope: "gclass"
54928
+ };
54922
54929
  (0, _yuneta_gobj_js.gobj_publish_event)(gobj, "EV_TRACE_INFO_WANTED", { gclass: shown });
54923
54930
  }
54924
54931
  }
@@ -55024,14 +55031,14 @@ function set_trace_levels(gobj, target, scope, levels, set) {
55024
55031
  let priv = gobj.priv;
55025
55032
  priv.trace_pending = true;
55026
55033
  render_current_popover(gobj);
55034
+ priv.set_in_flight = {
55035
+ gclass: target.gclass,
55036
+ scope
55037
+ };
55027
55038
  let viewer = gclass_viewer_gobj(gobj);
55028
55039
  if (viewer) {
55029
55040
  let shown = (0, _yuneta_gobj_js.gobj_read_str_attr)(viewer, "gclass_name");
55030
- if (shown === target.gclass || scope === "global") {
55031
- priv.viewer_awaits = target.gclass;
55032
- priv.viewer_stale = shown !== target.gclass ? shown : "";
55033
- (0, _yuneta_gobj_js.gobj_send_event)(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
55034
- }
55041
+ if (lock_viewer_for_set(gobj, shown, priv.set_in_flight)) (0, _yuneta_gobj_js.gobj_send_event)(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
55035
55042
  }
55036
55043
  (0, _yuneta_gobj_js.gobj_publish_event)(gobj, "EV_SET_TRACE_LEVEL", {
55037
55044
  scope,
@@ -55041,6 +55048,13 @@ function set_trace_levels(gobj, target, scope, levels, set) {
55041
55048
  set
55042
55049
  });
55043
55050
  }
55051
+ function lock_viewer_for_set(gobj, shown, set) {
55052
+ let priv = gobj.priv;
55053
+ if (!(shown === set.gclass || set.scope === "global")) return false;
55054
+ priv.viewer_awaits = set.gclass;
55055
+ priv.viewer_stale = shown !== set.gclass ? shown : "";
55056
+ return true;
55057
+ }
55044
55058
  /************************************************************
55045
55059
  * The toolbar's "traces of the yuno": the popover shows the
55046
55060
  * yuno's scope, read from the answer for the root's gclass.
@@ -52436,6 +52436,7 @@ var PRIVATE_DATA$9 = {
52436
52436
  popover_mode: "",
52437
52437
  viewer_awaits: "",
52438
52438
  viewer_stale: "",
52439
+ set_in_flight: null,
52439
52440
  view_refused: false
52440
52441
  };
52441
52442
  var __gclass__$9 = null;
@@ -54837,6 +54838,7 @@ function open_gclass_window(gobj, gclass, description, d) {
54837
54838
  priv.gclass_view = null;
54838
54839
  priv.viewer_awaits = "";
54839
54840
  priv.viewer_stale = "";
54841
+ if (priv.set_in_flight) lock_viewer_for_set(gobj, gclass, priv.set_in_flight);
54840
54842
  let opts = {
54841
54843
  title_prefix: is_remote(gobj) ? gobj_read_str_attr(gobj, "yuno_name") || "" : gobj_yuno_name() || "",
54842
54844
  current_state: d && d.state || "",
@@ -54903,6 +54905,7 @@ function ac_trace_info(gobj, event, kw, src) {
54903
54905
  error: kw.error || ""
54904
54906
  };
54905
54907
  priv.trace_pending = false;
54908
+ if (priv.set_in_flight && priv.set_in_flight.gclass === kw.gclass) priv.set_in_flight = null;
54906
54909
  let d = priv.popover_node;
54907
54910
  let root = priv.remote_root;
54908
54911
  if (priv.popover_mode === "node" && d && d.gclass === kw.gclass || priv.popover_mode === "yuno" && root && root.gclass === kw.gclass) render_current_popover(gobj);
@@ -54914,6 +54917,10 @@ function ac_trace_info(gobj, event, kw, src) {
54914
54917
  if (priv.viewer_stale === shown && shown !== kw.gclass) {
54915
54918
  priv.viewer_stale = "";
54916
54919
  priv.viewer_awaits = shown;
54920
+ priv.set_in_flight = {
54921
+ gclass: shown,
54922
+ scope: "gclass"
54923
+ };
54917
54924
  gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", { gclass: shown });
54918
54925
  }
54919
54926
  }
@@ -55019,14 +55026,14 @@ function set_trace_levels(gobj, target, scope, levels, set) {
55019
55026
  let priv = gobj.priv;
55020
55027
  priv.trace_pending = true;
55021
55028
  render_current_popover(gobj);
55029
+ priv.set_in_flight = {
55030
+ gclass: target.gclass,
55031
+ scope
55032
+ };
55022
55033
  let viewer = gclass_viewer_gobj(gobj);
55023
55034
  if (viewer) {
55024
55035
  let shown = gobj_read_str_attr(viewer, "gclass_name");
55025
- if (shown === target.gclass || scope === "global") {
55026
- priv.viewer_awaits = target.gclass;
55027
- priv.viewer_stale = shown !== target.gclass ? shown : "";
55028
- gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
55029
- }
55036
+ if (lock_viewer_for_set(gobj, shown, priv.set_in_flight)) gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
55030
55037
  }
55031
55038
  gobj_publish_event(gobj, "EV_SET_TRACE_LEVEL", {
55032
55039
  scope,
@@ -55036,6 +55043,13 @@ function set_trace_levels(gobj, target, scope, levels, set) {
55036
55043
  set
55037
55044
  });
55038
55045
  }
55046
+ function lock_viewer_for_set(gobj, shown, set) {
55047
+ let priv = gobj.priv;
55048
+ if (!(shown === set.gclass || set.scope === "global")) return false;
55049
+ priv.viewer_awaits = set.gclass;
55050
+ priv.viewer_stale = shown !== set.gclass ? shown : "";
55051
+ return true;
55052
+ }
55039
55053
  /************************************************************
55040
55054
  * The toolbar's "traces of the yuno": the popover shows the
55041
55055
  * yuno's scope, read from the answer for the root's gclass.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.27.30",
3
+ "version": "7.27.31",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -498,6 +498,7 @@ let PRIVATE_DATA = {
498
498
  popover_mode: "", // what the popover shows: "node" (a card) | "yuno" (the yuno's traces)
499
499
  viewer_awaits: "", // the gclass whose answer unlocks the open viewer ("" = not locked)
500
500
  viewer_stale: "", // a gclass whose open viewer must be asked again after a yuno set
501
+ set_in_flight: null, // {gclass, scope}: the set whose answer (EV_TRACE_INFO of gclass) is owed
501
502
  view_refused: false, // the saved camera showed no card: the opening's framing replaces it
502
503
  };
503
504
 
@@ -3597,6 +3598,11 @@ function open_gclass_window(gobj, gclass, description, d)
3597
3598
  priv.gclass_view = null;
3598
3599
  priv.viewer_awaits = "";
3599
3600
  priv.viewer_stale = "";
3601
+ /* A viewer opened while a set that moves what it shows is still
3602
+ * in flight opens locked, as the one it replaces was. */
3603
+ if(priv.set_in_flight) {
3604
+ lock_viewer_for_set(gobj, gclass, priv.set_in_flight);
3605
+ }
3600
3606
 
3601
3607
  let opts = {
3602
3608
  title_prefix: is_remote(gobj)?
@@ -3686,6 +3692,9 @@ function ac_trace_info(gobj, event, kw, src)
3686
3692
  error: kw.error || "",
3687
3693
  };
3688
3694
  priv.trace_pending = false;
3695
+ if(priv.set_in_flight && priv.set_in_flight.gclass === kw.gclass) {
3696
+ priv.set_in_flight = null;
3697
+ }
3689
3698
 
3690
3699
  let d = priv.popover_node;
3691
3700
  let root = priv.remote_root;
@@ -3708,6 +3717,9 @@ function ac_trace_info(gobj, event, kw, src)
3708
3717
  * only the root's gclass. Locked until its own. */
3709
3718
  priv.viewer_stale = "";
3710
3719
  priv.viewer_awaits = shown;
3720
+ /* Owed like a set of its own: a viewer of it reopened
3721
+ * before the answer opens locked too. */
3722
+ priv.set_in_flight = {gclass: shown, scope: "gclass"};
3711
3723
  gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: shown});
3712
3724
  }
3713
3725
  }
@@ -3846,14 +3858,14 @@ function set_trace_levels(gobj, target, scope, levels, set)
3846
3858
  /* The viewer is locked only by a set that moves what it shows:
3847
3859
  * one of its own gclass, or one of the yuno's scope. A gobj or
3848
3860
  * gclass set of ANOTHER gclass leaves it alone -- the answer that
3849
- * ends that set is not one the viewer would ever be sent. */
3861
+ * ends that set is not one the viewer would ever be sent. The set
3862
+ * is remembered for a viewer opened before its answer, and only
3863
+ * the LAST one: the host overtakes an earlier set in flight. */
3864
+ priv.set_in_flight = {gclass: target.gclass, scope: scope};
3850
3865
  let viewer = gclass_viewer_gobj(gobj);
3851
3866
  if(viewer) {
3852
3867
  let shown = gobj_read_str_attr(viewer, "gclass_name");
3853
- let concerned = (shown === target.gclass) || scope === "global";
3854
- if(concerned) {
3855
- priv.viewer_awaits = target.gclass;
3856
- priv.viewer_stale = (shown !== target.gclass)? shown: "";
3868
+ if(lock_viewer_for_set(gobj, shown, priv.set_in_flight)) {
3857
3869
  gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
3858
3870
  }
3859
3871
  }
@@ -3867,6 +3879,22 @@ function set_trace_levels(gobj, target, scope, levels, set)
3867
3879
  });
3868
3880
  }
3869
3881
 
3882
+ /* The viewer of `shown` waits for the answer of `set` when the set
3883
+ * moves what it shows: one of its own gclass, or one of the yuno's
3884
+ * scope (then its own levels are asked for again after the yuno's,
3885
+ * see ac_trace_info). Returns whether it was locked. */
3886
+ function lock_viewer_for_set(gobj, shown, set)
3887
+ {
3888
+ let priv = gobj.priv;
3889
+ let concerned = (shown === set.gclass) || set.scope === "global";
3890
+ if(!concerned) {
3891
+ return false;
3892
+ }
3893
+ priv.viewer_awaits = set.gclass;
3894
+ priv.viewer_stale = (shown !== set.gclass)? shown: "";
3895
+ return true;
3896
+ }
3897
+
3870
3898
  /************************************************************
3871
3899
  * The toolbar's "traces of the yuno": the popover shows the
3872
3900
  * yuno's scope, read from the answer for the root's gclass.
package/src/c_yui_node.js CHANGED
@@ -79,7 +79,9 @@
79
79
  * Only the ROOT node (the one whose parent is not a C_YUI_NODE)
80
80
  * talks to the shell: it subscribes to EV_ROUTE_CHANGED, resolves
81
81
  * the subpath and activates the branch. Inner nodes only ever
82
- * hear their parent.
82
+ * hear their parent. A route of ANOTHER stage (a secondary stage,
83
+ * SHELL.md §3) is not the root's business: the shell keeps showing
84
+ * the tree in its own stage, so the tree stays on its path.
83
85
  *
84
86
  * A path segment that names no living child is not silently
85
87
  * swallowed: it logs and the URL is rewritten (replace) to the
@@ -198,6 +200,7 @@ let PRIVATE_DATA = {
198
200
  distance: 0, /* segments from me down to the tip */
199
201
  chain: null, /* nodes from my child down to the tip */
200
202
  is_root: false,
203
+ stage: "", /* root: the shell stage that shows me ("" = not shown yet) */
201
204
  $chrome: null,
202
205
  $body: null
203
206
  };
@@ -1179,8 +1182,10 @@ function activate(gobj, subpath, inherited_depth)
1179
1182
  * declares EV_VIEW_SHOWN is told.
1180
1183
  *
1181
1184
  * This is the ONLY way it is told: a tree the shell shows
1182
- * again comes back here too (each node on the path leaves
1183
- * ST_OFF with the shell's EV_ROUTE_CHANGED), so the node
1185
+ * again comes back here too (the shell hides it only for a
1186
+ * route of its own stage, which takes the root to ST_OFF, and
1187
+ * each node on the path leaves ST_OFF with the shell's
1188
+ * EV_ROUTE_CHANGED that shows it again), so the node
1184
1189
  * does not declare EV_VIEW_SHOWN and the shell does not send
1185
1190
  * the tree a second one.
1186
1191
  ************************************************************/
@@ -1302,17 +1307,25 @@ function notify_tree_changed(gobj)
1302
1307
  ************************************************************/
1303
1308
  function ac_route_changed(gobj, event, kw, src)
1304
1309
  {
1310
+ let priv = gobj.priv;
1305
1311
  let base = kw.base || "";
1306
1312
  let my_base = gobj_read_attr(gobj, "base_route");
1313
+ let stage = kw.stage || "main";
1307
1314
 
1308
1315
  if(base !== my_base) {
1309
- /* Another view owns the URL now. A keep_alive tree stays
1316
+ /* A route of ANOTHER stage changes what that stage shows, not
1317
+ * mine: the shell keeps showing me, so I stay on my path. */
1318
+ if(priv.stage && stage !== priv.stage) {
1319
+ return 0;
1320
+ }
1321
+ /* Another view owns my stage now. A keep_alive tree stays
1310
1322
  * created but must not keep painting a stale branch. */
1311
1323
  deactivate(gobj);
1312
1324
  gobj_change_state(gobj, "ST_OFF");
1313
1325
  return 0;
1314
1326
  }
1315
1327
 
1328
+ priv.stage = stage;
1316
1329
  gobj_change_state(gobj, activate(gobj, kw.subpath || "", null));
1317
1330
  return 0;
1318
1331
  }
@@ -477,8 +477,79 @@ describe("C_YUI_GOBJ_TREE_JS, source remote: the open gclass viewer", () => {
477
477
  .toEqual([true, true]);
478
478
  expect(problems()).toEqual([]);
479
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
+ });
480
537
  });
481
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
+
482
553
  describe("C_YUI_GOBJ_TREE_JS, source local", () => {
483
554
  test("publishes nothing: its host declares none of the remote events", async () => {
484
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
+ });