@yuneta/gobj-ui 7.27.29 → 7.27.30

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.
@@ -295,7 +295,10 @@ function restore_view_state(gobj)
295
295
  done = true;
296
296
  }
297
297
  if(position !== null) {
298
- graph.translateTo(position);
298
+ /* What was saved is getPosition(), and translateTo() does
299
+ * not take it back: see translate_of_position(). */
300
+ graph.translateTo(translate_of_position(graph, position,
301
+ (zoom !== null)? zoom: graph.getZoom()));
299
302
  done = true;
300
303
  }
301
304
  if(state.anchor) {
@@ -317,14 +320,38 @@ function restore_view_state(gobj)
317
320
  return done;
318
321
  }
319
322
 
323
+ /* The translateTo() argument that puts the camera back where
324
+ * getPosition() answered `position`, at zoom `zoom` (the one the
325
+ * camera has when the translate is applied).
326
+ *
327
+ * The two are each other's inverse only at zoom 1. In G6 5.x, with C
328
+ * the canvas centre, Z the zoom and P the camera's own position,
329
+ * getPosition() answers S = C/Z - P, and an absolute translateTo(T)
330
+ * leaves P = C - T/Z. So the same camera is T = (S + C) * Z - C.
331
+ * Handing S to translateTo() as it came brought the zoom back and put
332
+ * the graph elsewhere, further on every close and open (and a camera
333
+ * saved at 0.3 was judged to show nothing, and framed again). The
334
+ * treedb graph met the same pair (c_g6_nodes_tree.js, "A camera is
335
+ * saved as a NODE at a VIEWPORT PIXEL"). */
336
+ function translate_of_position(graph, position, zoom)
337
+ {
338
+ let z = (zoom > 0)? zoom: 1;
339
+ let c = graph.getCanvasCenter();
340
+ return [
341
+ (position[0] + c[0]) * z - c[0],
342
+ (position[1] + c[1]) * z - c[1]
343
+ ];
344
+ }
345
+
320
346
  /* Would the centre of at least one card land inside the canvas under
321
347
  * this camera? `zoom` and `position` are what getZoom()/getPosition()
322
- * answer (a null one: the current). A camera absolute-translated to T
323
- * at zoom Z puts a point n of the graph at (n - C) * Z + T + C on the
324
- * canvas, C its centre -- the closed form of G6's own
325
- * getTranslateOptions(), the one yui_graph_center_on() relies on.
326
- * True when there is nothing to show or it cannot be computed: only a
327
- * camera KNOWN to show nothing is refused. */
348
+ * answer (a null one: the current). Under that camera a point n of the
349
+ * graph lands at (n + S) * Z on the canvas: from G6's closed forms
350
+ * (translate_of_position() above), v = (n - P) * Z + C with
351
+ * P = C/Z - S. NOT (n - C) * Z + S + C, which takes S for a translate
352
+ * and is right only at zoom 1. True when there is nothing to show or
353
+ * it cannot be computed: only a camera KNOWN to show nothing is
354
+ * refused. */
328
355
  function camera_shows_a_card(gobj, zoom, position)
329
356
  {
330
357
  let priv = gobj.priv;
@@ -335,9 +362,8 @@ function camera_shows_a_card(gobj, zoom, position)
335
362
  }
336
363
  try {
337
364
  let size = graph.getSize();
338
- let c = graph.getCanvasCenter();
339
365
  let z = (zoom !== null)? zoom: graph.getZoom();
340
- let t = (position !== null)? position: graph.getPosition();
366
+ let s = (position !== null)? position: graph.getPosition();
341
367
  let w = size[0];
342
368
  let h = size[1];
343
369
  if(!(w > 0 && h > 0) || !(z > 0)) {
@@ -345,8 +371,8 @@ function camera_shows_a_card(gobj, zoom, position)
345
371
  }
346
372
  for(let id of ids) {
347
373
  let n = graph.getElementPosition(id);
348
- let vx = (n[0] - c[0]) * z + t[0] + c[0];
349
- let vy = (n[1] - c[1]) * z + t[1] + c[1];
374
+ let vx = (n[0] + s[0]) * z;
375
+ let vy = (n[1] + s[1]) * z;
350
376
  if(vx >= 0 && vx <= w && vy >= 0 && vy <= h) {
351
377
  return true;
352
378
  }
@@ -470,6 +496,7 @@ let PRIVATE_DATA = {
470
496
  trace_info: {}, // gclass -> {gclass_levels, global_levels, gclass_on, global_on, error}
471
497
  trace_pending: false, // a trace was set: the block is locked until the host answers
472
498
  popover_mode: "", // what the popover shows: "node" (a card) | "yuno" (the yuno's traces)
499
+ viewer_awaits: "", // the gclass whose answer unlocks the open viewer ("" = not locked)
473
500
  viewer_stale: "", // a gclass whose open viewer must be asked again after a yuno set
474
501
  view_refused: false, // the saved camera showed no card: the opening's framing replaces it
475
502
  };
@@ -3568,6 +3595,8 @@ function open_gclass_window(gobj, gclass, description, d)
3568
3595
 
3569
3596
  close_gclass_view(priv.gclass_view);
3570
3597
  priv.gclass_view = null;
3598
+ priv.viewer_awaits = "";
3599
+ priv.viewer_stale = "";
3571
3600
 
3572
3601
  let opts = {
3573
3602
  title_prefix: is_remote(gobj)?
@@ -3668,16 +3697,24 @@ function ac_trace_info(gobj, event, kw, src)
3668
3697
  let viewer = gclass_viewer_gobj(gobj);
3669
3698
  if(viewer) {
3670
3699
  let shown = gobj_read_str_attr(viewer, "gclass_name");
3700
+ /* Only the answer the viewer waits for unlocks it: an answer
3701
+ * for another gclass (another card's set) is none of its
3702
+ * business. */
3703
+ if(priv.viewer_awaits === kw.gclass) {
3704
+ priv.viewer_awaits = "";
3705
+ if(priv.viewer_stale === shown && shown !== kw.gclass) {
3706
+ /* A set of the YUNO's scope: what the viewer shows as
3707
+ * held by the yuno moved too, and the host refreshed
3708
+ * only the root's gclass. Locked until its own. */
3709
+ priv.viewer_stale = "";
3710
+ priv.viewer_awaits = shown;
3711
+ gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: shown});
3712
+ }
3713
+ }
3671
3714
  if(shown === kw.gclass) {
3672
3715
  gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
3673
- } else if(priv.viewer_stale === shown) {
3674
- /* A set of the YUNO's scope: what the viewer shows as held by
3675
- * the yuno moved too, and the host refreshed only the root's
3676
- * gclass. */
3677
- gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: shown});
3678
3716
  }
3679
3717
  }
3680
- priv.viewer_stale = "";
3681
3718
  return 0;
3682
3719
  }
3683
3720
 
@@ -3693,14 +3730,15 @@ function gclass_viewer_gobj(gobj)
3693
3730
  /************************************************************
3694
3731
  * What the gclass viewer needs to draw the traces of `gclass`
3695
3732
  * for every gobj of it: the levels the host read, and whether a
3696
- * set is still in flight. Plain json: it rides in a kw.
3733
+ * set that concerns it is still in flight. Plain json: it rides
3734
+ * in a kw.
3697
3735
  ************************************************************/
3698
3736
  function viewer_traces(gobj, gclass)
3699
3737
  {
3700
3738
  let priv = gobj.priv;
3701
3739
  return {
3702
3740
  info: priv.trace_info[gclass] || null,
3703
- pending: !!priv.trace_pending,
3741
+ pending: !!priv.viewer_awaits,
3704
3742
  };
3705
3743
  }
3706
3744
 
@@ -3805,13 +3843,19 @@ function set_trace_levels(gobj, target, scope, levels, set)
3805
3843
  priv.trace_pending = true;
3806
3844
  render_current_popover(gobj);
3807
3845
 
3846
+ /* The viewer is locked only by a set that moves what it shows:
3847
+ * one of its own gclass, or one of the yuno's scope. A gobj or
3848
+ * gclass set of ANOTHER gclass leaves it alone -- the answer that
3849
+ * ends that set is not one the viewer would ever be sent. */
3808
3850
  let viewer = gclass_viewer_gobj(gobj);
3809
3851
  if(viewer) {
3810
3852
  let shown = gobj_read_str_attr(viewer, "gclass_name");
3811
- if(scope === "global" && shown !== target.gclass) {
3812
- priv.viewer_stale = shown;
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: "";
3857
+ gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
3813
3858
  }
3814
- gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
3815
3859
  }
3816
3860
 
3817
3861
  gobj_publish_event(gobj, "EV_SET_TRACE_LEVEL", {
package/src/c_yui_node.js CHANGED
@@ -1177,6 +1177,12 @@ function activate(gobj, subpath, inherited_depth)
1177
1177
  * `keep_alive` view, so the content may want to read again
1178
1178
  * what it read when it was created. Only a content that
1179
1179
  * declares EV_VIEW_SHOWN is told.
1180
+ *
1181
+ * 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
1184
+ * does not declare EV_VIEW_SHOWN and the shell does not send
1185
+ * the tree a second one.
1180
1186
  ************************************************************/
1181
1187
  function tell_content_shown(gobj)
1182
1188
  {
@@ -1320,24 +1326,6 @@ function ac_activate(gobj, event, kw, src)
1320
1326
  return 0;
1321
1327
  }
1322
1328
 
1323
- /************************************************************
1324
- * The shell (or my parent) shows the tree again after hiding
1325
- * it: down the path to the node on screen, which tells its
1326
- * content.
1327
- ************************************************************/
1328
- function ac_view_shown(gobj, event, kw, src)
1329
- {
1330
- let priv = gobj.priv;
1331
- if(gobj_current_state(gobj) === "ST_CHILD") {
1332
- if(priv.active_child) {
1333
- gobj_send_event(priv.active_child, event, kw, gobj);
1334
- }
1335
- return 0;
1336
- }
1337
- tell_content_shown(gobj);
1338
- return 0;
1339
- }
1340
-
1341
1329
  /************************************************************
1342
1330
  * My parent took me off the path.
1343
1331
  ************************************************************/
@@ -1855,7 +1843,6 @@ function create_gclass(gclass_name)
1855
1843
  ["EV_SET_NAV_MODE", ac_set_nav_mode, null],
1856
1844
  ["EV_SET_CONTENT", ac_set_content, null],
1857
1845
  ["EV_NODE_TREE_CHANGED", ac_tree_changed, null],
1858
- ["EV_VIEW_SHOWN", ac_view_shown, null],
1859
1846
  ["EV_DESTROY_NAVS", ac_destroy_navs, null]
1860
1847
  ]],
1861
1848
  ["ST_CHILD", [
@@ -1872,7 +1859,6 @@ function create_gclass(gclass_name)
1872
1859
  ["EV_SET_NAV_MODE", ac_set_nav_mode, null],
1873
1860
  ["EV_SET_CONTENT", ac_set_content, null],
1874
1861
  ["EV_NODE_TREE_CHANGED", ac_tree_changed, null],
1875
- ["EV_VIEW_SHOWN", ac_view_shown, null],
1876
1862
  ["EV_DESTROY_NAVS", ac_destroy_navs, null]
1877
1863
  ]]
1878
1864
  ];
@@ -1894,8 +1880,6 @@ function create_gclass(gclass_name)
1894
1880
  ["EV_SET_NAV_MODE", 0],
1895
1881
  ["EV_SET_CONTENT", 0],
1896
1882
  ["EV_NODE_TREE_CHANGED", 0],
1897
- /* the shell or the parent shows the tree again (keep_alive) */
1898
- ["EV_VIEW_SHOWN", 0],
1899
1883
  /* internal: posted to itself, the navs a render left */
1900
1884
  ["EV_DESTROY_NAVS", 0]
1901
1885
  ];
@@ -42,6 +42,13 @@
42
42
  * next login) in document.body. It follows the shell across a
43
43
  * logout (yui_shell_watch_changes()), as the dock does.
44
44
  *
45
+ * Its language: it hears the live shell's EV_LANGUAGE_CHANGED
46
+ * (yui_shell_language_changed()). With NO shell there is nobody
47
+ * to publish that, so an app whose login switches language
48
+ * calls yui_update_watch_language_changed() after switching its
49
+ * i18next -- it sends EV_LANGUAGE_CHANGED to every live watch.
50
+ * Calling it with a shell up too is harmless.
51
+ *
45
52
  * Usage (an app, once, after creating the yuno):
46
53
  *
47
54
  * register_c_yui_update_watch();
@@ -53,12 +60,21 @@
53
60
  * // on its backend's EV_ON_OPEN:
54
61
  * gobj_send_event(watch, "EV_CHECK_BUILD", {}, gobj);
55
62
  *
63
+ * // the login's language switch (no shell yet):
64
+ * switch_locale(locale);
65
+ * yui_update_watch_language_changed();
66
+ *
56
67
  * Input events:
57
68
  * EV_CHECK_BUILD {force?} ask the server (force skips
58
69
  * the minimum interval)
59
70
  * EV_RELOAD {} the bar's reload button
60
71
  * EV_DISMISS {} the bar's ✕: hidden for THIS
61
72
  * build, a later one shows it
73
+ * EV_LANGUAGE_CHANGED {} the app's language changed:
74
+ * the bar is re-translated
75
+ * (the live shell publishes it;
76
+ * with no shell,
77
+ * yui_update_watch_language_changed())
62
78
  *
63
79
  * Output events (optional subscribers):
64
80
  * EV_NEW_BUILD {running, deployed, version}
@@ -144,6 +160,11 @@ let PRIVATE_DATA = {
144
160
 
145
161
  let __gclass__ = null;
146
162
 
163
+ /* The watches alive (mt_create .. mt_destroy): what
164
+ * yui_update_watch_language_changed() reaches when no shell can
165
+ * publish the language switch. */
166
+ const __live_watches__ = [];
167
+
147
168
 
148
169
 
149
170
 
@@ -163,6 +184,7 @@ function mt_create(gobj)
163
184
 
164
185
  priv.running = running_build(typeof document !== "undefined" ? document : null);
165
186
  priv.dom_handlers = [];
187
+ __live_watches__.push(gobj);
166
188
 
167
189
  /*
168
190
  * Create children
@@ -247,6 +269,10 @@ function mt_destroy(gobj)
247
269
  {
248
270
  let priv = gobj.priv;
249
271
 
272
+ let idx = __live_watches__.indexOf(gobj);
273
+ if(idx >= 0) {
274
+ __live_watches__.splice(idx, 1);
275
+ }
250
276
  yui_shell_unwatch_changes(gobj);
251
277
  if(priv.lang_shell) {
252
278
  if(!gobj_is_destroying(priv.lang_shell)) {
@@ -719,4 +745,25 @@ function register_c_yui_update_watch()
719
745
  return create_gclass(GCLASS_NAME);
720
746
  }
721
747
 
722
- export { register_c_yui_update_watch };
748
+ /***************************************************************
749
+ * The app switched its language (call it AFTER switching the
750
+ * i18next): every live watch re-translates its bar.
751
+ *
752
+ * For the screens with no shell -- the login, the gap between a
753
+ * logout and the next login -- where nobody publishes the
754
+ * shell's EV_LANGUAGE_CHANGED that the watch hears otherwise.
755
+ * It is an EVENT to each watch, so the switch is in its
756
+ * machine trace. `src`: the gobj that switched, if the caller
757
+ * has one.
758
+ ***************************************************************/
759
+ function yui_update_watch_language_changed(src)
760
+ {
761
+ for(let watch of __live_watches__.slice()) {
762
+ if(gobj_is_destroying(watch)) {
763
+ continue;
764
+ }
765
+ gobj_send_event(watch, "EV_LANGUAGE_CHANGED", {}, src || watch);
766
+ }
767
+ }
768
+
769
+ export { register_c_yui_update_watch, yui_update_watch_language_changed };
@@ -5,8 +5,11 @@
5
5
  * with the server played by a fake fetch: the bar appears for
6
6
  * another build and not for the same one, the ✕ hides it for THAT
7
7
  * build only, a rollback takes it away, a check too soon or
8
- * offline asks nothing, a failure is said once, and the reload
9
- * asks the host first.
8
+ * offline asks nothing (navigator.onLine is stubbed: vitest has
9
+ * none, and the guard never ran) and coming back online asks at
10
+ * once, a failure is said once, the reload asks the host first,
11
+ * and with no shell (the login) the app's language switch reaches
12
+ * the bar through yui_update_watch_language_changed().
10
13
  *
11
14
  * Copyright (c) 2026, ArtGins.
12
15
  * All Rights Reserved.
@@ -22,7 +25,8 @@ const {
22
25
  gobj_destroy, gobj_is_running, gobj_send_event, gobj_current_state,
23
26
  set_log_callback, register_c_timer,
24
27
  } = await import("@yuneta/gobj-js");
25
- const {register_c_yui_update_watch} = await import("./c_yui_update_watch.js");
28
+ const {register_c_yui_update_watch, yui_update_watch_language_changed} =
29
+ await import("./c_yui_update_watch.js");
26
30
 
27
31
  const RUNNING = "aaaaaaaaaaaaaaaa";
28
32
 
@@ -32,6 +36,15 @@ let yuno = null;
32
36
  let host = null;
33
37
  let watch = null;
34
38
  let seq = 0;
39
+ let i18next = null;
40
+
41
+ /* navigator.onLine as the browser says it: vitest has no such
42
+ * property, so `undefined` unless a test sets it. */
43
+ const network = {online: undefined};
44
+ Object.defineProperty(globalThis.navigator, "onLine", {
45
+ configurable: true,
46
+ get: () => network.online,
47
+ });
35
48
 
36
49
  /* The server: what the next fetches answer, and what was asked. */
37
50
  const server = {
@@ -85,8 +98,14 @@ function make_watch(kw)
85
98
  }
86
99
 
87
100
  beforeAll(async () => {
88
- const i18next = (await import("i18next")).default;
89
- await i18next.init({lng: "en", resources: {}});
101
+ i18next = (await import("i18next")).default;
102
+ await i18next.init({lng: "en", resources: {
103
+ es: {translation: {
104
+ "new version available": "hay una versión nueva",
105
+ "reload": "recargar",
106
+ "close": "cerrar",
107
+ }},
108
+ }});
90
109
 
91
110
  const $meta = document.createElement("meta");
92
111
  $meta.setAttribute("name", "yuneta-build");
@@ -131,6 +150,7 @@ beforeEach(() => {
131
150
  server.version = "1.0.0";
132
151
  server.fail = null;
133
152
  server.asked = 0;
153
+ network.online = undefined;
134
154
  });
135
155
 
136
156
  afterEach(() => {
@@ -239,6 +259,61 @@ describe("C_YUI_UPDATE_WATCH", () => {
239
259
  expect(server.asked).toBeGreaterThanOrEqual(3);
240
260
  });
241
261
 
262
+ test("offline asks nothing, not even forced", async () => {
263
+ network.online = false;
264
+ make_watch({min_interval_ms: 0});
265
+ await settle();
266
+ gobj_send_event(watch, "EV_CHECK_BUILD", {force: true}, watch);
267
+ window.dispatchEvent(fake_event("focus"));
268
+ await settle();
269
+ expect(server.asked).toBe(0);
270
+ });
271
+
272
+ test("back online asks at once, inside min_interval_ms", async () => {
273
+ network.online = true;
274
+ make_watch({min_interval_ms: 60000});
275
+ await settle();
276
+ expect(server.asked).toBe(1);
277
+ window.dispatchEvent(fake_event("focus"));
278
+ await settle();
279
+ expect(server.asked).toBe(1);
280
+
281
+ network.online = false;
282
+ gobj_send_event(watch, "EV_CHECK_BUILD", {force: true}, watch);
283
+ await settle();
284
+ expect(server.asked).toBe(1);
285
+
286
+ network.online = true;
287
+ window.dispatchEvent(fake_event("online"));
288
+ await settle();
289
+ expect(server.asked).toBe(2);
290
+ });
291
+
292
+ test("with no shell, the app's language switch re-translates the bar", async () => {
293
+ server.stamp = "bbbbbbbbbbbbbbbb";
294
+ make_watch();
295
+ await settle();
296
+ const $bar = bar();
297
+ const $reload = $bar.querySelector(".UPDATE_RELOAD");
298
+ expect($reload.getAttribute("aria-label")).toBe("reload");
299
+
300
+ /* The texts carry their key; the document double's text nodes
301
+ * have no nodeValue for refresh_language() to write, so what it
302
+ * rewrites is read from the attributes. */
303
+ expect($bar.querySelector(".UPDATE_TEXT").getAttribute("data-i18n")).toBe("new version available");
304
+ await i18next.changeLanguage("es");
305
+ try {
306
+ expect($reload.getAttribute("aria-label")).toBe("reload");
307
+ yui_update_watch_language_changed();
308
+ expect([$reload.getAttribute("title"), $reload.getAttribute("aria-label")])
309
+ .toEqual(["recargar", "recargar"]);
310
+ expect($bar.querySelector(".UPDATE_DISMISS").getAttribute("aria-label")).toBe("cerrar");
311
+ expect($bar.querySelector(".UPDATE_VERSION").textContent).toBe("1.0.0");
312
+ } finally {
313
+ await i18next.changeLanguage("en");
314
+ }
315
+ });
316
+
242
317
  test("stopped, the page events ask nothing", async () => {
243
318
  make_watch({min_interval_ms: 0});
244
319
  await settle();
@@ -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
+ });