@yuneta/gobj-ui 7.26.41 → 7.26.42

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.
@@ -11,6 +11,12 @@
11
11
  * from a graph went through its other canvases and the whole page
12
12
  * before it reached the graph's own buttons.
13
13
  *
14
+ * And the main canvas, a control in the Tab order, is NAMED
15
+ * (REV-CLOUD V24.5.4): a `title` and an `aria-label` through t(),
16
+ * each with its key, saying which graph it is -- and changing
17
+ * language with the page. From 7.26.28 to 7.26.41 Tab landed on it
18
+ * and a reader announced nothing.
19
+ *
14
20
  * The real gclasses, on a G6 Graph double that does what G6 does
15
21
  * here: the FIRST render() builds the four canvases with
16
22
  * `tabIndex = 1` and says so with `aftercanvasinit`; a renderer
@@ -20,10 +26,15 @@
20
26
  * All Rights Reserved.
21
27
  ***********************************************************************/
22
28
  import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
29
+ import {readFileSync} from "node:fs";
30
+ import {dirname, join} from "node:path";
31
+ import {fileURLToPath} from "node:url";
23
32
  import {install_dom_double} from "../test/dom_double.js";
24
33
 
25
34
  install_dom_double();
26
35
 
36
+ const SRC = dirname(fileURLToPath(import.meta.url));
37
+
27
38
  /* The views watch their container; nothing resizes here. */
28
39
  if(typeof globalThis.ResizeObserver === "undefined") {
29
40
  globalThis.ResizeObserver = class {
@@ -132,7 +143,7 @@ vi.mock("@antv/g6", async (importOriginal) => {
132
143
 
133
144
  const {
134
145
  SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
135
- gobj_start, gobj_read_attr, set_log_callback, register_c_timer,
146
+ gobj_start, gobj_read_attr, set_log_callback, register_c_timer, refresh_language,
136
147
  } = await import("@yuneta/gobj-js");
137
148
  const {register_c_yui_json_graph} = await import("./c_yui_json_graph.js");
138
149
  const {register_c_yui_gobj_tree_js} = await import("./c_yui_gobj_tree_js.js");
@@ -215,6 +226,28 @@ function tab_order(graph)
215
226
  return order;
216
227
  }
217
228
 
229
+ /* The name each view gives its main canvas: the key, and its text in
230
+ * the two languages of this test. */
231
+ const NAMES = {
232
+ C_YUI_JSON_GRAPH: {key: "json graph", en: "JSON graph", es: "Grafo del JSON"},
233
+ C_YUI_GOBJ_TREE_JS: {key: "gobj tree graph", en: "Gobj tree graph", es: "Grafo del árbol de gobjs"},
234
+ C_YUI_FSM_GRAPH: {key: "fsm graph", en: "State machine graph", es: "Grafo de la máquina de estados"},
235
+ C_YUI_TREEDB_SCHEMA: {key: "schema graph", en: "Schema graph", es: "Grafo del esquema"},
236
+ C_G6_NODES_TREE: {key: "treedb graph", en: "Treedb graph", es: "Grafo de la treedb"},
237
+ };
238
+
239
+ function name_of_canvas(graph)
240
+ {
241
+ const $main = graph.layers.main.el;
242
+ return {
243
+ role: $main.getAttribute("role"),
244
+ title: $main.getAttribute("title"),
245
+ aria: $main.getAttribute("aria-label"),
246
+ title_key: $main.getAttribute("data-i18n-title"),
247
+ aria_key: $main.getAttribute("data-i18n-aria-label"),
248
+ };
249
+ }
250
+
218
251
  describe("every G6 view: the main canvas in the Tab order, the other layers out", () => {
219
252
  for(const [gclass_name, attrs] of Object.entries(VIEWS)) {
220
253
  test(`${gclass_name}: after its first render, and after a renderer change`, async () => {
@@ -230,3 +263,76 @@ describe("every G6 view: the main canvas in the Tab order, the other layers out"
230
263
  });
231
264
  }
232
265
  });
266
+
267
+ describe("REV-CLOUD V24.5.4: the main canvas is named, says which graph it is, and changes language", () => {
268
+ for(const [gclass_name, attrs] of Object.entries(VIEWS)) {
269
+ test(`${gclass_name}: "${NAMES[gclass_name].key}", after its first render and a renderer change`, async () => {
270
+ const i18next = (await import("i18next")).default;
271
+ const name = NAMES[gclass_name];
272
+ i18next.addResourceBundle("en", "translation", {[name.key]: name.en}, true, true);
273
+ i18next.addResourceBundle("es", "translation", {[name.key]: name.es}, true, true);
274
+ await i18next.changeLanguage("en");
275
+
276
+ const {graph, $container} = await mount(gclass_name, attrs);
277
+ const named = {
278
+ role: "region", title: name.en, aria: name.en,
279
+ title_key: name.key, aria_key: name.key
280
+ };
281
+ expect(name_of_canvas(graph)).toEqual(named);
282
+
283
+ /* The other layers are out of the Tab order: no control,
284
+ * no name. */
285
+ for(const layer of ["background", "label", "transient"]) {
286
+ expect(graph.layers[layer].el.getAttribute("aria-label")).toBe(null);
287
+ }
288
+
289
+ graph.setRenderer();
290
+ expect(name_of_canvas(graph)).toEqual(named);
291
+
292
+ /* A language switch reaches it as it reaches every control:
293
+ * by its keys (the shell's refresh over the page). */
294
+ await i18next.changeLanguage("es");
295
+ refresh_language(document.body, i18next.t.bind(i18next));
296
+ expect(name_of_canvas(graph)).toEqual(Object.assign({}, named,
297
+ {title: name.es, aria: name.es}));
298
+ await i18next.changeLanguage("en");
299
+
300
+ expect($container).toBeTruthy();
301
+ expect(logged.filter((l) => l.level === "error").map((l) => l.msg)).toEqual([]);
302
+ });
303
+ }
304
+ });
305
+
306
+ /* G6 writes `outline: none` on its canvases, INLINE, and the main one
307
+ * is a control in the Tab order now: a keyboard that landed on the
308
+ * graph saw no sign of where it was. CSS is read as text: the double
309
+ * has no layout. */
310
+ describe("the focused canvas can be SEEN: a ring G6's inline outline does not erase", () => {
311
+ test("every view marks its main canvas, and only that one, with the class the ring hangs from", async () => {
312
+ for(const [gclass_name, attrs] of Object.entries(VIEWS)) {
313
+ const {graph} = await mount(gclass_name, attrs);
314
+ expect(graph.layers.main.el.classList.contains("G6_MAIN_CANVAS"), gclass_name).toBe(true);
315
+ for(const layer of ["background", "label", "transient"]) {
316
+ expect(graph.layers[layer].el.classList.contains("G6_MAIN_CANVAS"), layer).toBe(false);
317
+ }
318
+ graph.setRenderer();
319
+ expect(graph.layers.main.el.classList.contains("G6_MAIN_CANVAS"), gclass_name).toBe(true);
320
+ }
321
+ expect(logged.filter((l) => l.level === "error").map((l) => l.msg)).toEqual([]);
322
+ });
323
+
324
+ test("the ring: on :focus-visible, !important over the inline outline, the ink of the scheme, no transition", () => {
325
+ const css = readFileSync(join(SRC, "g6_canvas_tab_order.css"), "utf8");
326
+ const m = css.match(/\.G6_MAIN_CANVAS:focus-visible\s*\{([^}]*)\}/);
327
+ expect(!!m, "a .G6_MAIN_CANVAS:focus-visible rule").toBe(true);
328
+ const body = m[1];
329
+ expect(body).toMatch(/outline:\s*2px solid var\(--bulma-link-on-scheme,[^;]*\)\s*!important\s*;/);
330
+ expect(body).toMatch(/outline-offset:[^;]*!important\s*;/);
331
+ expect(body).not.toMatch(/transition/);
332
+
333
+ /* The module brings it along: every view that draws a graph
334
+ * imports the module. */
335
+ const js = readFileSync(join(SRC, "g6_canvas_tab_order.js"), "utf8");
336
+ expect(js).toMatch(/import\s+"\.\/g6_canvas_tab_order\.css";/);
337
+ });
338
+ });
@@ -137,13 +137,18 @@ export const I18N_KEY_FUNCTIONS = Object.freeze([
137
137
  {module: "table_cell_text.js", name: "hook_cell_spec", exported: true, keys: ["4"]},
138
138
  /* yui_time.js -- a granularity names itself by its id */
139
139
  {module: "yui_time.js", name: "period_name", exported: true, keys: ["0", "0.id"]},
140
- /* nav_cards_helpers.js -- a nav item's name, tooltip and aria label */
140
+ /* nav_cards_helpers.js -- a nav item's name, tooltip and aria label,
141
+ * and its id: the key of an item with no `name` */
141
142
  {module: "nav_cards_helpers.js", name: "card_descriptor", exported: true,
142
- keys: ["0.name", "0.tooltip", "0.aria_label"]},
143
+ keys: ["0.name", "0.tooltip", "0.aria_label", "0.id"]},
143
144
  {module: "nav_cards_helpers.js", name: "cards_grid_descriptor", exported: true,
144
- keys: ["0[].name", "0[].tooltip", "0[].aria_label"]},
145
+ keys: ["0[].name", "0[].tooltip", "0[].aria_label", "0[].id"]},
145
146
  /* yui_gclass_view.js -- the dialog's title is the gclass name */
146
147
  {module: "yui_gclass_view.js", name: "open_gclass_view", exported: true, keys: ["1"]},
148
+ /* g6_canvas_tab_order.js -- the name of a graph's main canvas, the
149
+ * one control of the graph in the Tab order */
150
+ {module: "g6_canvas_tab_order.js", name: "set_canvas_tab_order", exported: true, keys: ["2"]},
151
+ {module: "g6_canvas_tab_order.js", name: "keep_canvas_tab_order", exported: true, keys: ["2"]},
147
152
 
148
153
  /*
149
154
  * Helpers of their own module
@@ -204,7 +209,7 @@ export const I18N_KEY_FUNCTIONS = Object.freeze([
204
209
  {module: "c_yui_schema_editor.js", name: "end_writes", exported: false, keys: ["1"]},
205
210
  {module: "c_yui_schema_editor.js", name: "open_dialog", exported: false, keys: ["1", "2"]},
206
211
  {module: "c_yui_schema_editor.js", name: "refuse_bad_name", exported: false, keys: ["1"]},
207
- {module: "c_yui_schema_editor.js", name: "open_card", exported: false, keys: ["4[].i18n"]},
212
+ {module: "c_yui_schema_editor.js", name: "open_card", exported: false, keys: ["2.i18n", "4[].i18n"]},
208
213
  {module: "c_yui_schema_editor.js", name: "open_report", exported: false,
209
214
  keys: ["1[].severity", "1[].code"]},
210
215
  {module: "c_yui_schema_editor.js", name: "render_import_plan", exported: false,
@@ -222,42 +227,53 @@ export const I18N_KEY_FUNCTIONS = Object.freeze([
222
227
  {module: "yui_dev.js", name: "mk_dir", exported: false, keys: ["3"]},
223
228
  {module: "yui_dev.js", name: "grp", exported: false, keys: ["0"]},
224
229
  {module: "yui_dev.js", name: "grp_scroll", exported: false, keys: ["0"]},
225
- /* c_yui_nav.js -- the items of a menu: the app's nav declaration */
226
- {module: "c_yui_nav.js", name: "item_li", exported: false, keys: ["1.name", "1.tooltip", "1.aria_label"]},
227
- {module: "c_yui_nav.js", name: "item_iconbar", exported: false, keys: ["1.name", "1.tooltip", "1.aria_label"]},
230
+ /* c_yui_nav.js -- the items of a menu: the app's nav declaration.
231
+ * The id is the key of an item with no `name`. */
232
+ {module: "c_yui_nav.js", name: "item_li", exported: false,
233
+ keys: ["1.name", "1.tooltip", "1.aria_label", "1.id"]},
234
+ {module: "c_yui_nav.js", name: "item_iconbar", exported: false,
235
+ keys: ["1.name", "1.tooltip", "1.aria_label", "1.id"]},
228
236
  {module: "c_yui_nav.js", name: "render_vertical", exported: false,
229
- keys: ["1[].name", "1[].tooltip", "1[].aria_label"]},
237
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id"]},
230
238
  {module: "c_yui_nav.js", name: "render_icon_bar", exported: false,
231
- keys: ["1[].name", "1[].tooltip", "1[].aria_label"]},
239
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id"]},
232
240
  {module: "c_yui_nav.js", name: "render_tabs", exported: false,
233
- keys: ["1[].name", "1[].tooltip", "1[].aria_label"]},
241
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id"]},
234
242
  {module: "c_yui_nav.js", name: "render_cards", exported: false,
235
- keys: ["1[].name", "1[].tooltip", "1[].aria_label"]},
243
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id"]},
236
244
  {module: "c_yui_nav.js", name: "render_submenu", exported: false,
237
- keys: ["1[].name", "1[].tooltip", "1[].aria_label"]},
245
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id"]},
238
246
  {module: "c_yui_nav.js", name: "render_drawer", exported: false,
239
- keys: ["1[].name", "1[].tooltip", "1[].aria_label"]},
247
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id"]},
240
248
  {module: "c_yui_nav.js", name: "render_breadcrumb", exported: false,
241
249
  keys: ["1[].name", "1[].id", "1[].tooltip", "1[].aria_label"]},
242
250
  {module: "c_yui_nav.js", name: "render_accordion", exported: false,
243
- keys: ["1[].name", "1[].submenu.items[].name", "1[].submenu.items[].tooltip",
244
- "1[].submenu.items[].aria_label"]},
245
- /* c_yui_shell.js -- the toolbar items: the app's shell declaration */
251
+ keys: ["1[].name", "1[].tooltip", "1[].aria_label", "1[].id",
252
+ "1[].submenu.items[].name", "1[].submenu.items[].tooltip",
253
+ "1[].submenu.items[].aria_label", "1[].submenu.items[].id"]},
254
+ /* c_yui_shell.js -- the toolbar items: the app's shell declaration.
255
+ * The id is the key of an item with no `aria_label` nor `name`, and
256
+ * of the menu it opens. */
246
257
  {module: "c_yui_shell.js", name: "build_toolbar", exported: false,
247
258
  keys: ["1.toolbar.aria_label", "1.toolbar.items[].name", "1.toolbar.items[].aria_label",
248
- "1.toolbar.items[].tooltip", "1.toolbar.items[].wordmark"]},
259
+ "1.toolbar.items[].tooltip", "1.toolbar.items[].wordmark", "1.toolbar.items[].id"]},
249
260
  {module: "c_yui_shell.js", name: "build_toolbar_action_item", exported: false,
250
- keys: ["1.name", "1.aria_label", "1.tooltip"]},
261
+ keys: ["1.name", "1.aria_label", "1.tooltip", "1.id"]},
251
262
  {module: "c_yui_shell.js", name: "build_toolbar_brand_item", exported: false,
252
- keys: ["1.name", "1.aria_label", "1.tooltip", "1.wordmark"]},
263
+ keys: ["1.name", "1.aria_label", "1.tooltip", "1.wordmark", "1.id"]},
253
264
  {module: "c_yui_shell.js", name: "build_toolbar_avatar_item", exported: false,
254
- keys: ["1.name", "1.aria_label", "1.tooltip"]},
265
+ keys: ["1.name", "1.aria_label", "1.tooltip", "1.id"]},
255
266
  {module: "c_yui_shell.js", name: "build_toolbar_connection_item", exported: false,
256
- keys: ["1.name", "1.aria_label", "1.tooltip"]},
257
- {module: "c_yui_shell.js", name: "handle_toolbar_action", exported: false, keys: ["1.name", "1.aria_label"]},
258
- {module: "c_yui_shell.js", name: "toggle_toolbar_dropdown", exported: false, keys: ["1.name", "1.aria_label"]},
259
- {module: "c_yui_shell.js", name: "open_toolbar_dropdown", exported: false, keys: ["1.name", "1.aria_label"]},
260
- {module: "c_yui_shell.js", name: "build_dropdown_row", exported: false, keys: ["1.name", "1.aria_label"]},
267
+ keys: ["1.name", "1.aria_label", "1.tooltip", "1.id"]},
268
+ {module: "c_yui_shell.js", name: "attach_context_action", exported: false, keys: ["2.id"]},
269
+ {module: "c_yui_shell.js", name: "handle_toolbar_action", exported: false,
270
+ keys: ["1.name", "1.aria_label", "1.id"]},
271
+ {module: "c_yui_shell.js", name: "toggle_toolbar_dropdown", exported: false,
272
+ keys: ["1.name", "1.aria_label", "1.id"]},
273
+ {module: "c_yui_shell.js", name: "open_toolbar_dropdown", exported: false,
274
+ keys: ["1.name", "1.aria_label", "1.id"]},
275
+ {module: "c_yui_shell.js", name: "build_dropdown_row", exported: false,
276
+ keys: ["1.name", "1.aria_label", "1.id"]},
261
277
  /* c_yui_shell.js -- the name of a badged item, said with its count:
262
278
  * the app's shell declaration */
263
279
  {module: "c_yui_shell.js", name: "announce_badge", exported: false, keys: ["1"]},
@@ -40,6 +40,10 @@
40
40
  * from one (`t("k") + ":"`) -- marked or not. A translator handed
41
41
  * as a callback (V23.5: `keys.map(t)`, `promise.then(t)`) is held
42
42
  * the same way, each element it walks a key position;
43
+ * - no module hands a TRANSLATED text to any other place a key is
44
+ * read -- t(), an i18n / code / data-i18n* value, a data-i18n*
45
+ * attribute --, marked or not (V24.5.2: up to 7.26.41 only a
46
+ * marked one failed);
43
47
  * - every marker is one and stands where a key is read; the lists
44
48
  * it names are published by its module or one it imports; the
45
49
  * keys it marks that can be read are in them -- a marked `let`
@@ -2009,8 +2013,9 @@ describe("REV-CLOUD V23.5: a translator as a callback, by destructuring; setAttr
2009
2013
  let r = scan([`t(/* i18n: data */ t("k") + "!");`,
2010
2014
  `x.i18n = /* i18n: data */ t("k").trim();`,
2011
2015
  `t(/* i18n: data */ kw.comment + "!");`]);
2012
- expect(r.marker_errors.map((e) => e.line)).toEqual([3, 4]);
2013
- expect(r.marker_errors[0].why).toMatch(/^marked as data, but `t\("k"\) \+ "!"` is a TRANSLATED text: .*hand the key, not t\(key\)$/);
2016
+ expect(r.translated_errors.map((e) => e.line)).toEqual([3, 4]);
2017
+ expect(r.translated_errors[0].why).toMatch(/^marked as data, but `t\("k"\) \+ "!"` is a TRANSLATED text: .*hand the key, not t\(key\)$/);
2018
+ expect(r.marker_errors).toEqual([]);
2014
2019
  });
2015
2020
 
2016
2021
  test("an UNMARKED let given nothing but literals is read where a key is read -- at a key position the rule still fails it", () => {
@@ -2057,3 +2062,174 @@ describe("REV-CLOUD V23.5: a translator as a callback, by destructuring; setAttr
2057
2062
  expect(list_mutations(ast, [{name: "X_I18N_KEYS", keys: ["x"]}]).map((e) => e.line)).toEqual([5, 7, 8, 10, 18]);
2058
2063
  });
2059
2064
  });
2065
+
2066
+ describe("REV-CLOUD V24.5: every write counts; a translated text fails unmarked too; the callbacks, exactly; .bind()", () => {
2067
+ let module = "x.js";
2068
+ let head = [`import {yui_shell_show_info} from "./shell_modals.js";`,
2069
+ `import i18next from "i18next";`];
2070
+ let scan = (lines) => scan_ast(parse_as([...head, ...lines].join("\n"), module), {lib_module: module});
2071
+ let rule = (lines) => rule_report(parse_as([...head, ...lines].join("\n"), module), module);
2072
+ let keys_of = (lines) => [...scan(lines).keys].sort();
2073
+
2074
+ test("every write to an unmarked let counts: one the reader cannot read leaves it unfollowed", () => {
2075
+ /* Each body gives `key` the sentinel "-" and then a value the reader
2076
+ * does not read: up to 7.26.41 the eight first asked for "-" */
2077
+ let writes = [
2078
+ `for([key, label] of rows) { el.setAttribute("data-i18n", key); }`, // the review's probe
2079
+ `for({key} of rows) { t(key); }`,
2080
+ `for({k: key = "d"} of rows) { t(key); }`,
2081
+ `for([key] in obj) { t(key); }`,
2082
+ `for await ([key] of rows) { t(key); }`,
2083
+ `for(key of rows) { t(key); }`,
2084
+ `for(key in obj) { t(key); }`,
2085
+ `[key, x] = rows;`,
2086
+ `({key} = row);`,
2087
+ `[[key]] = rows;`,
2088
+ `rows.forEach((r) => { ({key} = r); });`,
2089
+ `key += "!";`,
2090
+ `key = kw.label;`,
2091
+ `eval(code);`
2092
+ ];
2093
+ for(let w of writes) {
2094
+ expect(keys_of([`async function f(el, rows, obj, row, kw, code) {`, ` let key = "-";`,
2095
+ ` ${w}`, ` return t(key);`, `}`]), w).not.toContain("-");
2096
+ }
2097
+ /* A `var` declared again: in a loop head (function and module), and
2098
+ * -- for one of the module -- in a block, a for(;;) init, a switch
2099
+ * case, or by an array pattern */
2100
+ let redeclared = [
2101
+ [`function f(rows) {`, ` var key = "-";`, ` for(var key of rows) {`, ` }`, ` return t(key);`, `}`],
2102
+ [`function f(obj) {`, ` var key = "-";`, ` for(var key in obj) {`, ` }`, ` return t(key);`, `}`],
2103
+ [`var key = "-";`, `for(var key of rows) {`, `}`, `t(key);`],
2104
+ [`var key = "-";`, `if(c) {`, ` var key = kw.data;`, `}`, `t(key);`],
2105
+ [`var key = "-";`, `for(var key = kw.data; c; ) {`, `}`, `t(key);`],
2106
+ [`var key = "-";`, `switch(c) {`, ` case 1:`, ` var key = kw.data;`, `}`, `t(key);`],
2107
+ [`var key = "-";`, `var [key] = rows;`, `t(key);`]
2108
+ ];
2109
+ for(let lines of redeclared) {
2110
+ expect(keys_of(lines), lines.join(" ")).not.toContain("-");
2111
+ }
2112
+ /* ...and one whose every value is a literal still asks for them, a
2113
+ * module `var` given more in a block included */
2114
+ expect(keys_of([`var key = "a module key";`, `if(c) {`, ` var key = "a block key";`, `}`, `t(key);`]))
2115
+ .toEqual(["a block key", "a module key"]);
2116
+ /* A `var` of a class's static block is the block's own: it hides an
2117
+ * outer `let` of the same name (up to 7.26.41 it was not seen) */
2118
+ expect(keys_of([`let key = "-";`, `class A {`, ` static {`, ` var key = kw.data;`, ` t(key);`,
2119
+ ` }`, `}`])).not.toContain("-");
2120
+ expect(keys_of([`class A {`, ` static {`, ` var key = "a static key";`, ` t(key);`, ` }`, `}`]))
2121
+ .toEqual(["a static key"]);
2122
+ /* A marked let written by a loop head is no "make it a const" */
2123
+ expect(scan([`export const X_I18N_KEYS = ["accept"];`, `let k = "accept";`, `for([k] of rows) {`, `}`,
2124
+ `t(/* i18n: X_I18N_KEYS */ k);`]).marker_errors).toEqual([]);
2125
+ expect(scan([`export const X_I18N_KEYS = ["accept"];`, `let LABELS = {ok: "accept"};`,
2126
+ `for(LABELS.extra of rows) {`, `}`, `t(/* i18n: X_I18N_KEYS */ LABELS[k]);`]).marker_errors).toEqual([]);
2127
+ });
2128
+
2129
+ test("the let rule is flow-INSENSITIVE: every literal the let is given in its scope is asked for; null is never", () => {
2130
+ let body = (first) => [`function f(c) {`, ` let key = ${first};`, ` if(c) {`, ` key = "save";`, ` }`,
2131
+ ` if(key !== "-") {`, ` t(key);`, ` }`, `}`];
2132
+ expect(keys_of(body(`"-"`))).toEqual(["-", "save"]); // the `if` does not hide "-"
2133
+ expect(keys_of(body(`null`))).toEqual(["save"]); // the way out for a sentinel
2134
+ expect(keys_of([`const NONE = "-";`, ...body(`NONE`)])).toEqual(["-", "save"]); // a const IS its literal
2135
+ });
2136
+
2137
+ test("a TRANSLATED text where a key is read fails, marked or not", () => {
2138
+ let r = scan([`x = {i18n: t("k")};`, // 3
2139
+ `el.setAttribute("data-i18n-title", t("k"));`, // 4
2140
+ `t(t("k") + "!");`, // 5
2141
+ `el.dataset.i18nTitle = tr("k");`, // 6
2142
+ `x = {code: i18next.t("k")};`, // 7
2143
+ `add("error", t("k"));`, // 8
2144
+ `t([t("k"), "fallback"]);`, // 9
2145
+ `const L = t("k");`, // 10: the text, read at 11
2146
+ `x = {"data-i18n": L};`,
2147
+ `x = {i18n: /* i18n: data */ t("k")};`, // 12: marked
2148
+ `x = {i18n: ["p", {}, t("k")]};`, // DOM is DOM
2149
+ `let held = t("k");`,
2150
+ `x = {i18n: held};`]); // in a let: the documented limit
2151
+ expect(r.translated_errors.map((e) => e.line)).toEqual([3, 4, 5, 6, 7, 8, 9, 10, 12]);
2152
+ expect(r.translated_errors[0].why).toBe('`t("k")` is a TRANSLATED text given to a property that holds a key ' +
2153
+ '(i18n, code, data-i18n*): the translation is kept as its key and never changes language: hand the key, ' +
2154
+ 'not t(key)');
2155
+ expect(r.translated_errors[1].why).toMatch(/^`t\("k"\)` is a TRANSLATED text given to a data-i18n\* attribute: /);
2156
+ expect(r.translated_errors[2].why).toMatch(/^`t\("k"\) \+ "!"` is a TRANSLATED text handed to a translator as its key: /);
2157
+ expect(r.translated_errors[7].why).toMatch(/^`t\("k"\)` is a TRANSLATED text given to a property .* \(read at line 11\): /);
2158
+ expect(r.translated_errors[8].why).toMatch(/^marked as data, but `t\("k"\)` is a TRANSLATED text: .*no marker excuses it/);
2159
+ expect(r.marker_errors).toEqual([]);
2160
+ });
2161
+
2162
+ test("no module of the library hands a TRANSLATED text to a place a key is read", () => {
2163
+ let wrong = [];
2164
+ for(let m of MODULES) {
2165
+ for(let e of scan_ast(ast_of(m), {lib_module: m}).translated_errors) {
2166
+ wrong.push(`${m}:${e.line}: ${e.why}`);
2167
+ }
2168
+ }
2169
+ expect(wrong).toEqual([]);
2170
+ /* ...and the check sees one: a module given one, unmarked */
2171
+ let code = readFileSync(join(SRC, "yui_text.js"), "utf8");
2172
+ let lines = code.split("\n").length;
2173
+ let mutated = parse_as(code + `\nexport function probe(el) { el.setAttribute("data-i18n", t("probe")); }\n`,
2174
+ "yui_text.js");
2175
+ expect(scan_ast(mutated, {lib_module: "yui_text.js"}).translated_errors.map((e) => e.line)).toEqual([lines + 1]);
2176
+ });
2177
+
2178
+ test("the callbacks read, exactly: findIndex, findLastIndex, .call(), .apply(), a literal name, Array.fromAsync()", () => {
2179
+ expect(keys_of([`const K = ["k1", "k2"];`,
2180
+ `K.findIndex(t);`,
2181
+ `K.findLastIndex(i18next.t);`,
2182
+ `Array.prototype.map.call(["k3"], t);`,
2183
+ `[].forEach.call(["k4"], t);`,
2184
+ `Array.prototype.some.apply(["k5"], [t]);`,
2185
+ `["k6"]["every"](t);`,
2186
+ `Array.fromAsync(["k7"], t);`,
2187
+ `["k8"].reduce(t);`, // no element is the key
2188
+ `Reflect.apply(Array.prototype.map, ["k9"], [t]);`])).toEqual( // not read: documented
2189
+ ["k1", "k2", "k3", "k4", "k5", "k6", "k7"]);
2190
+ /* A function callback's first parameter is an element in the same forms */
2191
+ expect(keys_of([`Array.prototype.forEach.call(["f1"], (k) => t(k));`,
2192
+ `[].map.apply(["f2"], [(k) => t(k)]);`,
2193
+ `Array.from(["f3"], (k) => t(k));`,
2194
+ `["f4"].findIndex((k) => t(k));`])).toEqual(["f1", "f2", "f3", "f4"]);
2195
+ /* ...and the rule holds them: an array the reader cannot follow fails unmarked */
2196
+ expect(rule([`function f(kw) {`,
2197
+ ` let rows = kw.rows;`,
2198
+ ` Array.prototype.map.call(rows, t);`,
2199
+ ` rows.findIndex(t);`,
2200
+ ` [].forEach.apply(rows, [t]);`,
2201
+ ` /* i18n: data */ Array.prototype.map.call(rows, t);`,
2202
+ `}`])).toEqual([
2203
+ `${module}:5 t() [map callback]: rows`,
2204
+ `${module}:6 t() [findIndex callback]: rows`,
2205
+ `${module}:7 t() [forEach callback]: rows`
2206
+ ]);
2207
+ /* The forwarder search sees a parameter walked through .call() */
2208
+ let ast = parse_as(`export function f_call(gobj, keys) { Array.prototype.forEach.call(keys, t); }`, module);
2209
+ let found = find_forwarders([module], () => ast, []);
2210
+ expect(found.opaque).toEqual([]);
2211
+ expect(Object.fromEntries(found.found.map((f) => [f.name, f.keys]))).toEqual({f_call: ["1[]"]});
2212
+ });
2213
+
2214
+ test("a bound translator: what a call of it is handed is i18next's options, no key; a bound key function counts them", () => {
2215
+ expect(keys_of([`const tk = t.bind(null, "bound key");`,
2216
+ `tk("an option");`,
2217
+ `tk.call(null, "another option");`,
2218
+ `t.bind(i18next).bind(null, "bound key")("a third option");`,
2219
+ `["an element"].map(tk);`,
2220
+ `["another element"].map(t.bind(null, "bound key"));`,
2221
+ `const tt = t.bind(i18next);`,
2222
+ `tt("a key: nothing bound");`])).toEqual(["a key: nothing bound"]);
2223
+ /* Its text is translated text all the same */
2224
+ expect(scan([`const tk = t.bind(null, "bound key");`, `x = {i18n: tk()};`]).translated_errors.map((e) => e.line))
2225
+ .toEqual([4]);
2226
+ /* A key function bound with its first argument: the key is the call's first one now */
2227
+ let r = scan([`const show = yui_shell_show_info.bind(null, shell);`, `show("a bound function key");`]);
2228
+ expect(r.keys.has("a bound function key")).toBe(true);
2229
+ expect(rule([`const show = yui_shell_show_info.bind(null, shell);`, `show(kw.message);`,
2230
+ `const more = yui_shell_show_info.bind(null, ...args);`, `more("k");`])).toEqual([
2231
+ `${module}:4 yui_shell_show_info() [1]: kw.message`,
2232
+ `${module}:6 yui_shell_show_info() [1]: more("k")` // a spread hides the positions: loud
2233
+ ]);
2234
+ });
2235
+ });
@@ -11,6 +11,12 @@
11
11
  * promise, and the modal takes its entry back once the question
12
12
  * is over.
13
13
  *
14
+ * And what the promise SETTLES with is the answer (REV-CLOUD V24.5,
15
+ * Info): `true` closes the modal; anything else -- what a question
16
+ * that closed the modal itself on "yes" settles with, `false`, a
17
+ * rejection -- is the veto it was. Up to 7.26.41 any promise was a
18
+ * veto, so an `async () => true` left a modal nobody could close.
19
+ *
14
20
  * Copyright (c) 2026, ArtGins.
15
21
  * All Rights Reserved.
16
22
  ***********************************************************************/
@@ -27,6 +33,7 @@ const {
27
33
  const {register_c_yui_shell} = await import("./c_yui_shell.js");
28
34
  const {
29
35
  yui_shell_show_modal,
36
+ yui_shell_confirm_yesno,
30
37
  yui_shell_confirm_yesnocancel,
31
38
  } = await import("./shell_modals.js");
32
39
 
@@ -191,3 +198,131 @@ describe("a modal whose guard asks before it closes", () => {
191
198
  expect(errors()).toEqual([]);
192
199
  });
193
200
  });
201
+
202
+ describe("what the guard's promise settles with is the answer", () => {
203
+ /* A shell, and a sheet over it guarded by `guard`; `closes` counts
204
+ * its on_close. */
205
+ function open_sheet(guard)
206
+ {
207
+ seq++;
208
+ const app = gobj_create(`papp${seq}`, "C_TEST_GUARD_HOST", {}, yuno);
209
+ gobj_start(app);
210
+ const shell = gobj_create(`pshell${seq}`, "C_YUI_SHELL",
211
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
212
+ gobj_start(shell);
213
+ logged.length = 0;
214
+
215
+ const counts = {closes: 0, asked: 0};
216
+ const handle = yui_shell_show_modal(shell, "the sheet", {
217
+ dialog: true,
218
+ logical_class: "TEST_SHEET",
219
+ title: "settings",
220
+ before_close: function() {
221
+ counts.asked++;
222
+ return guard(() => handle);
223
+ },
224
+ on_close: function() {
225
+ counts.closes++;
226
+ }
227
+ });
228
+ return {shell, handle, counts};
229
+ }
230
+
231
+ function warnings()
232
+ {
233
+ return logged.filter((l) => l.level === "warning").map((l) => l.msg);
234
+ }
235
+
236
+ test("an async guard that settles with true closes it: by Back, and by its back arrow", async () => {
237
+ const back = open_sheet(async () => true);
238
+ press_back(back.shell);
239
+ expect(sheets()).toBe(1); // the answer is not in yet
240
+ await settle();
241
+ expect(sheets()).toBe(0);
242
+ expect(back.counts.closes).toBe(1);
243
+ expect(back.shell.priv.overlay_stack).toEqual([]);
244
+
245
+ const arrow = open_sheet(async () => true);
246
+ document.querySelector(".TEST_SHEET .yui-dialog-back").click();
247
+ await settle();
248
+ expect(sheets()).toBe(0);
249
+ expect(arrow.counts.closes).toBe(1);
250
+ expect(arrow.shell.priv.overlay_stack).toEqual([]);
251
+ expect(errors()).toEqual([]);
252
+ });
253
+
254
+ test("anything else it settles with is a veto, and Back gets its entry back", async () => {
255
+ for(const answer of [false, undefined, "yes", 1]) {
256
+ const {shell, handle, counts} = open_sheet(async () => answer);
257
+ press_back(shell);
258
+ await settle();
259
+ expect(sheets()).toBe(1);
260
+ expect(counts.closes).toBe(0);
261
+ expect(shell.priv.overlay_stack.length).toBe(1);
262
+
263
+ /* And the next Back asks again: the entry is there. */
264
+ press_back(shell);
265
+ expect(counts.asked).toBe(2);
266
+ await settle();
267
+ handle.close();
268
+ expect(sheets()).toBe(0);
269
+ }
270
+ expect(errors()).toEqual([]);
271
+ });
272
+
273
+ test("a promise that rejects is a veto, said, and Back gets its entry back", async () => {
274
+ const {shell, handle, counts} = open_sheet(() => Promise.reject(new Error("no answer")));
275
+ press_back(shell);
276
+ await settle();
277
+ expect(sheets()).toBe(1);
278
+ expect(counts.closes).toBe(0);
279
+ expect(shell.priv.overlay_stack.length).toBe(1);
280
+ expect(warnings().some((m) => m.includes("before_close") && m.includes("no answer"))).toBe(true);
281
+
282
+ handle.close();
283
+ expect(sheets()).toBe(0);
284
+ });
285
+
286
+ /* The idiom the README shows: hand back the yes/no question as it
287
+ * is -- it settles with true on "yes". */
288
+ test("an async guard that answers yui_shell_confirm_yesno(): \"yes\" closes, \"no\" keeps it up", async () => {
289
+ for(const [button, stays] of [["no", 1], ["yes", 0]]) {
290
+ let shell_of = null;
291
+ const {shell, handle, counts} = open_sheet(async () => {
292
+ return yui_shell_confirm_yesno(shell_of, "all changes will be lost", {
293
+ yes_label: "yes", no_label: "no"
294
+ });
295
+ });
296
+ shell_of = shell;
297
+ press_back(shell);
298
+ await settle();
299
+ expect(questions()).toBe(1);
300
+ document.querySelector(`.CONFIRM [data-modal-button-value="${button}"]`).click();
301
+ await settle();
302
+ await settle();
303
+ expect(questions()).toBe(0);
304
+ expect(sheets()).toBe(stays);
305
+ expect(counts.closes).toBe(stays ? 0 : 1);
306
+ if(stays) {
307
+ expect(shell.priv.overlay_stack.length).toBe(1);
308
+ handle.close();
309
+ }
310
+ }
311
+ expect(errors()).toEqual([]);
312
+ });
313
+
314
+ test("a guard that closed the modal itself and then settles with true: closed once", async () => {
315
+ const {shell, counts} = open_sheet((handle_of) => {
316
+ return Promise.resolve().then(() => {
317
+ handle_of().close();
318
+ return true;
319
+ });
320
+ });
321
+ press_back(shell);
322
+ await settle();
323
+ expect(sheets()).toBe(0);
324
+ expect(counts.closes).toBe(1);
325
+ expect(shell.priv.overlay_stack).toEqual([]);
326
+ expect(errors()).toEqual([]);
327
+ });
328
+ });