@yuneta/gobj-ui 7.26.6 → 7.26.7

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.
@@ -156,6 +156,8 @@ function mt_destroy(gobj)
156
156
  ************************************************************/
157
157
  function build_ui(gobj)
158
158
  {
159
+ let back_label = gobj_read_attr(gobj, "back_label");
160
+ let next_label = gobj_read_attr(gobj, "next_label");
159
161
  let $container = createElement2(
160
162
  ['div', {class: 'C_YUI_WIZARD', style: 'height:100%; display:flex; flex-direction:column;'}, [
161
163
  ['div', {class: 'yui-wizard-header is-flex is-align-items-center is-flex-grow-0',
@@ -168,17 +170,21 @@ function build_ui(gobj)
168
170
  ],
169
171
  ['div', {class: 'yui-wizard-footer is-flex is-justify-content-space-between is-flex-grow-0',
170
172
  style: 'gap:.5rem; padding:.5rem;'}, [
171
- ['button', {class: 'yui-wizard-back button', 'aria-label': t('back'), 'data-i18n-aria-label': 'back'}, [
173
+ ['button', {class: 'yui-wizard-back button',
174
+ title: t(back_label), 'data-i18n-title': back_label,
175
+ 'aria-label': t(back_label), 'data-i18n-aria-label': back_label}, [
172
176
  ['span', {class: 'icon'}, ['i', {class: 'yi-arrow-left'}]],
173
- ['span', {class: 'is-hidden-mobile', i18n: 'back'}, 'back']
177
+ ['span', {class: 'is-hidden-mobile', i18n: back_label}, back_label]
174
178
  ], {
175
179
  click: function(evt) {
176
180
  evt.stopPropagation();
177
181
  gobj_send_event(gobj, "EV_PREV", {}, gobj);
178
182
  }
179
183
  }],
180
- ['button', {class: 'yui-wizard-primary button is-link', 'aria-label': t('next'), 'data-i18n-aria-label': 'next'}, [
181
- ['span', {class: 'yui-wizard-primary-label', i18n: 'next'}, 'next']
184
+ ['button', {class: 'yui-wizard-primary button is-link',
185
+ title: t(next_label), 'data-i18n-title': next_label,
186
+ 'aria-label': t(next_label), 'data-i18n-aria-label': next_label}, [
187
+ ['span', {class: 'yui-wizard-primary-label', i18n: next_label}, next_label]
182
188
  ], {
183
189
  click: function(evt) {
184
190
  evt.stopPropagation();
@@ -243,10 +249,15 @@ function render_chrome(gobj)
243
249
  let $title = $container.querySelector('.yui-wizard-title');
244
250
  let $counter = $container.querySelector('.yui-wizard-counter');
245
251
  let $back = $container.querySelector('.yui-wizard-back');
252
+ let $primary = $container.querySelector('.yui-wizard-primary');
246
253
  let $plabel = $container.querySelector('.yui-wizard-primary-label');
247
254
 
248
- $title.setAttribute('i18n', model.title);
249
- $title.textContent = model.title;
255
+ /* render_chrome runs on every step change, AFTER the host's one-time
256
+ * refresh_language($container,t): translate HERE, and stamp the
257
+ * canonical `data-i18n` (a bare `i18n` attribute is not read by
258
+ * refresh_language) so a later language switch re-translates it. */
259
+ $title.setAttribute('data-i18n', model.title);
260
+ $title.textContent = t(model.title);
250
261
 
251
262
  if(model.count > 0) {
252
263
  $counter.textContent = `${model.idx + 1} / ${model.count}`;
@@ -256,8 +267,12 @@ function render_chrome(gobj)
256
267
 
257
268
  $back.classList.toggle('is-hidden', !model.show_back);
258
269
 
259
- $plabel.setAttribute('i18n', model.primary_label);
260
- $plabel.textContent = model.primary_label;
270
+ $plabel.setAttribute('data-i18n', model.primary_label);
271
+ $plabel.textContent = t(model.primary_label);
272
+ $primary.setAttribute('title', t(model.primary_label));
273
+ $primary.setAttribute('data-i18n-title', model.primary_label);
274
+ $primary.setAttribute('aria-label', t(model.primary_label));
275
+ $primary.setAttribute('data-i18n-aria-label', model.primary_label);
261
276
 
262
277
  /*
263
278
  * Show only the current step
@@ -78,9 +78,11 @@ function delete_impact(desc, records)
78
78
  if(n === 0) {
79
79
  continue;
80
80
  }
81
- /* A column can be BOTH (a department's `users` is a hook to its
82
- * users and a fkey to the department that manages it). Counting
83
- * it on both sides is right: the delete does both things. */
81
+ /* A column is a hook OR a fkey: the treedb refuses one flagged
82
+ * both ("A column cannot be both 'hook' and 'fkey'"), and a node
83
+ * that is a child and a parent carries two columns. A column
84
+ * read from an older store may still carry both; it is counted
85
+ * on both sides, which is what its delete would do. */
84
86
  if(col.flag.indexOf("hook") >= 0) {
85
87
  out.children += n;
86
88
  }
@@ -0,0 +1,116 @@
1
+ /***********************************************************************
2
+ * form_json_field.js
3
+ *
4
+ * Pure logic of a json field of C_YUI_FORM: what a jsoneditor
5
+ * holds, read as the value its column stores.
6
+ *
7
+ * The editor answers its content in one of two shapes -- {json}
8
+ * (tree mode) or {text} (text mode, whatever the reader typed).
9
+ * A text that does not parse used to be caught and replaced by
10
+ * `{}` or `[]`, and SAVED: a trailing comma wiped the column, with
11
+ * no log and no message. A text that is not json, or json of the
12
+ * wrong shape (a list in a dict column), is an error now, and the
13
+ * form refuses to save while a field holds one.
14
+ *
15
+ * Copyright (c) 2026, ArtGins.
16
+ * All Rights Reserved.
17
+ ***********************************************************************/
18
+
19
+ /*
20
+ * The shape a column type stores. A type not listed takes any json.
21
+ */
22
+ const SHAPE_OF_TYPE = {
23
+ object: "dict",
24
+ dict: "dict",
25
+ template: "dict",
26
+ array: "list",
27
+ list: "list",
28
+ table: "list",
29
+ coordinates: "container",
30
+ };
31
+
32
+ /************************************************************
33
+ * The shape `type` stores: "dict", "list", "container" or "any".
34
+ ************************************************************/
35
+ export function json_field_shape(type)
36
+ {
37
+ return SHAPE_OF_TYPE[type] || "any";
38
+ }
39
+
40
+ /************************************************************
41
+ * The empty value of a shape: what a blank editor stores.
42
+ ************************************************************/
43
+ export function json_field_empty(shape)
44
+ {
45
+ if(shape === "list") {
46
+ return [];
47
+ }
48
+ return {};
49
+ }
50
+
51
+ function value_fits(value, shape)
52
+ {
53
+ let is_list = Array.isArray(value);
54
+ let is_dict = value !== null && typeof value === "object" && !is_list;
55
+ switch(shape) {
56
+ case "dict":
57
+ return is_dict;
58
+ case "list":
59
+ return is_list;
60
+ case "container":
61
+ return is_dict || is_list;
62
+ default:
63
+ return true;
64
+ }
65
+ }
66
+
67
+ /************************************************************
68
+ * Parse what a json field holds.
69
+ *
70
+ * `value` is a json string (what the form reads out of an editor)
71
+ * or an already parsed value; an editor's content goes through
72
+ * json_editor_value() first.
73
+ * Returns {value, error}: `error` is "" when the value is good, else
74
+ * an i18n key; `value` is then the empty value of the shape and must
75
+ * NOT be stored.
76
+ *
77
+ * A blank text is not an error: it is the empty value.
78
+ ************************************************************/
79
+ export function parse_json_field(value, type)
80
+ {
81
+ let shape = json_field_shape(type);
82
+
83
+ if(typeof value === "string") {
84
+ if(value.trim() === "") {
85
+ return {value: json_field_empty(shape), error: ""};
86
+ }
87
+ try {
88
+ value = JSON.parse(value);
89
+ } catch(e) {
90
+ return {value: json_field_empty(shape), error: "invalid json"};
91
+ }
92
+ }
93
+
94
+ if(value === undefined) {
95
+ return {value: json_field_empty(shape), error: ""};
96
+ }
97
+ if(!value_fits(value, shape)) {
98
+ return {value: json_field_empty(shape), error: "invalid json"};
99
+ }
100
+ return {value: value, error: ""};
101
+ }
102
+
103
+ /************************************************************
104
+ * What a jsoneditor content ({text} or {json}) holds: the
105
+ * text as typed, or the tree-mode json.
106
+ ************************************************************/
107
+ export function json_editor_value(content)
108
+ {
109
+ if(!content) {
110
+ return undefined;
111
+ }
112
+ if(content.text !== undefined) {
113
+ return content.text;
114
+ }
115
+ return content.json;
116
+ }
@@ -0,0 +1,43 @@
1
+ /***********************************************************************
2
+ * form_json_field.test.js
3
+ *
4
+ * Copyright (c) 2026, ArtGins.
5
+ * All Rights Reserved.
6
+ ***********************************************************************/
7
+ import {describe, it, expect} from "vitest";
8
+ import {parse_json_field, json_field_shape, json_editor_value} from "./form_json_field.js";
9
+
10
+ describe("parse_json_field", () => {
11
+ it("a text that does not parse is an error, never an empty dict to store", () => {
12
+ expect(parse_json_field('{"a": 1,}', "dict")).toEqual({value: {}, error: "invalid json"});
13
+ expect(parse_json_field(json_editor_value({text: '[1, 2'}), "list")).toEqual({value: [], error: "invalid json"});
14
+ expect(parse_json_field('{"x": }', "template").error).toBe("invalid json");
15
+ expect(parse_json_field('nope', "blob").error).toBe("invalid json");
16
+ });
17
+
18
+ it("json of the wrong shape is an error", () => {
19
+ expect(parse_json_field('[1]', "dict").error).toBe("invalid json");
20
+ expect(parse_json_field('{"a": 1}', "list").error).toBe("invalid json");
21
+ expect(parse_json_field('null', "dict").error).toBe("invalid json");
22
+ expect(parse_json_field('3', "coordinates").error).toBe("invalid json");
23
+ });
24
+
25
+ it("good json comes back parsed", () => {
26
+ expect(parse_json_field('{"a": 1}', "dict")).toEqual({value: {a: 1}, error: ""});
27
+ expect(parse_json_field(json_editor_value({json: [1, 2]}), "table")).toEqual({value: [1, 2], error: ""});
28
+ expect(parse_json_field('[0, 1]', "coordinates")).toEqual({value: [0, 1], error: ""});
29
+ expect(parse_json_field('"s"', "blob")).toEqual({value: "s", error: ""});
30
+ expect(parse_json_field({text: 1}, "dict")).toEqual({value: {text: 1}, error: ""});
31
+ });
32
+
33
+ it("a blank editor is the empty value, not an error", () => {
34
+ expect(parse_json_field("", "dict")).toEqual({value: {}, error: ""});
35
+ expect(parse_json_field(json_editor_value({text: " "}), "list")).toEqual({value: [], error: ""});
36
+ });
37
+
38
+ it("shapes", () => {
39
+ expect(json_field_shape("object")).toBe("dict");
40
+ expect(json_field_shape("table")).toBe("list");
41
+ expect(json_field_shape("blob")).toBe("any");
42
+ });
43
+ });
@@ -0,0 +1,137 @@
1
+ /***********************************************************************
2
+ * form_json_field.wiring.test.js
3
+ *
4
+ * A C_YUI_FORM json field (a jsoneditor) whose TEXT does not parse
5
+ * was saved as `{}` or `[]`: validate_form() asked the browser
6
+ * (checkValidity) and the tables, and a jsoneditor is neither; the
7
+ * conversion then caught the parse error and stored the empty
8
+ * value. Driven through the real gclass on a document double, with
9
+ * the editor replaced by a double that answers what the real one
10
+ * answers in text mode.
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+ import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
16
+ import {install_dom_double} from "../test/dom_double.js";
17
+
18
+ install_dom_double();
19
+
20
+ if(typeof globalThis.ResizeObserver === "undefined") {
21
+ globalThis.ResizeObserver = class {
22
+ observe() {}
23
+ unobserve() {}
24
+ disconnect() {}
25
+ };
26
+ }
27
+
28
+ /* The editor: what the reader typed, in text mode. */
29
+ const editors = vi.hoisted(() => []);
30
+ vi.mock("vanilla-jsoneditor", () => ({
31
+ createJSONEditor: (opts) => {
32
+ const ed = {
33
+ content: {text: ""},
34
+ props: opts.props,
35
+ get() {
36
+ return this.content;
37
+ },
38
+ set(content) {
39
+ this.content = content;
40
+ },
41
+ destroy() {},
42
+ };
43
+ editors.push(ed);
44
+ return ed;
45
+ },
46
+ }));
47
+
48
+ const {
49
+ SDATA_END, gclass_create,
50
+ gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
51
+ gobj_start, gobj_send_event, gobj_read_attr,
52
+ set_log_callback,
53
+ } = await import("@yuneta/gobj-js");
54
+ const {register_c_yui_form} = await import("./c_yui_form.js");
55
+
56
+ const saved = [];
57
+ const logged = [];
58
+ let yuno = null;
59
+
60
+ beforeAll(async () => {
61
+ const i18next = (await import("i18next")).default;
62
+ await i18next.init({lng: "en", resources: {}});
63
+ gobj_start_up(null, null, null, null, null, null, null);
64
+ set_log_callback((level, msg) => {
65
+ logged.push({level: String(level), msg: String(msg)});
66
+ });
67
+ gclass_create("C_TEST_FORM_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
68
+ gclass_create(
69
+ "C_TEST_FORM_APP",
70
+ [["EV_SAVE_RECORD", 0], ["EV_RECORD_CHANGED", 0]],
71
+ [["ST_IDLE", [
72
+ ["EV_SAVE_RECORD", (gobj, event, kw) => {
73
+ saved.push(kw);
74
+ return 0;
75
+ }, null],
76
+ ["EV_RECORD_CHANGED", () => 0, null],
77
+ ]]],
78
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
79
+ );
80
+ register_c_yui_form();
81
+ yuno = gobj_create_yuno("form_json_yuno", "C_TEST_FORM_HOST", {});
82
+ gobj_start(yuno);
83
+ });
84
+
85
+ beforeEach(() => {
86
+ saved.length = 0;
87
+ logged.length = 0;
88
+ editors.length = 0;
89
+ });
90
+
91
+ let seq = 0;
92
+
93
+ function build()
94
+ {
95
+ const app = gobj_create_pure_child(`fapp${++seq}`, "C_TEST_FORM_APP", {}, yuno);
96
+ gobj_start(app);
97
+ const form = gobj_create_pure_child(`form${seq}`, "C_YUI_FORM", {
98
+ template: [
99
+ {id: "id", header: "id", type: "string", flag: ["persistent", "required"]},
100
+ {id: "settings", header: "settings", type: "dict", flag: ["persistent", "writable"]},
101
+ ],
102
+ record: {id: "a", settings: {}},
103
+ render_mode: "edit",
104
+ editable: true,
105
+ }, app);
106
+ gobj_start(form);
107
+ const $c = gobj_read_attr(form, "$container");
108
+ const $editor = $c.querySelector(".jsoneditor");
109
+ expect($editor).toBeTruthy();
110
+ expect(editors.length).toBe(1);
111
+ return {form, $editor, editor: editors[0]};
112
+ }
113
+
114
+ describe("a json field that does not parse", () => {
115
+ test("is refused, marked, and nothing is saved", () => {
116
+ const {form, $editor, editor} = build();
117
+ editor.content = {text: '{"a": 1,}'};
118
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
119
+ expect(saved).toEqual([]);
120
+ expect($editor.classList.contains("is-danger")).toBe(true);
121
+ expect($editor.yui_json_error).toBe("invalid json");
122
+ });
123
+
124
+ test("is saved once it holds json again", () => {
125
+ const {form, $editor, editor} = build();
126
+ editor.content = {text: '[1]'};
127
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
128
+ expect(saved).toEqual([]);
129
+
130
+ editor.content = {text: '{"a": 1}'};
131
+ editor.props.onChange();
132
+ expect($editor.classList.contains("is-danger")).toBe(false);
133
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
134
+ expect(saved.length).toBe(1);
135
+ expect(saved[0].settings).toBe('{"a": 1}');
136
+ });
137
+ });
@@ -267,7 +267,23 @@ function c_text(text)
267
267
  return text
268
268
  .replace(/\\/g, JSON_BACKSLASH)
269
269
  .replace(/"/g, JSON_DQUOTE)
270
- .replace(/'/g, JSON_QUOTE);
270
+ .replace(/'/g, JSON_QUOTE)
271
+ .replace(/[\u0000-\u001f\u007f]/g, json_control);
272
+ }
273
+
274
+ /* A control character (a newline in a description) cannot stand as
275
+ * itself in either layer: a raw newline ends the C literal's line,
276
+ * and JSON refuses any control character inside a string. It is
277
+ * written as its JSON escape, with the backslash doubled for C. */
278
+ const JSON_SHORT_ESCAPES = {"\n": "n", "\r": "r", "\t": "t", "\b": "b", "\f": "f"};
279
+
280
+ function json_control(ch)
281
+ {
282
+ let short = JSON_SHORT_ESCAPES[ch];
283
+ if(short) {
284
+ return C_BACKSLASH + short;
285
+ }
286
+ return C_BACKSLASH + "u" + ch.charCodeAt(0).toString(16).padStart(4, "0");
271
287
  }
272
288
 
273
289
  /***************************************************************
@@ -228,6 +228,13 @@ describe("the characters that cannot be written as themselves", () => {
228
228
  expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe("a\\b");
229
229
  });
230
230
 
231
+ test("a newline, a tab and another control character survive both layers", () => {
232
+ const header = "line one\nline\ttwo\r\u0001";
233
+ const src = with_header(header);
234
+ expect(src.split("\n").every((line) => !line.includes("line two"))).toBe(true);
235
+ expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe(header);
236
+ });
237
+
231
238
  test("all three at once", () => {
232
239
  const header = 'a\\b "c" d\'e';
233
240
  expect(load_like_the_yuno(with_header(header)).topics[0].cols.id.header)
@@ -249,6 +249,8 @@ function build_body(shell, t)
249
249
  ["input", {class: "input is-small ROUTEMAP_SEARCH", type: "text",
250
250
  placeholder: t("filter", {defaultValue: "Filter…"}),
251
251
  "data-i18n-placeholder": "filter",
252
+ title: t("filter", {defaultValue: "Filter"}),
253
+ "data-i18n-title": "filter",
252
254
  "aria-label": t("filter", {defaultValue: "Filter"}),
253
255
  "data-i18n-aria-label": "filter"}]
254
256
  );
@@ -334,6 +336,10 @@ function build_body(shell, t)
334
336
  $tree,
335
337
  ["div", {class: "ROUTEMAP_ACTIONS"}, [
336
338
  ["button", {class: "button is-small ROUTEMAP_PRINT",
339
+ title: t("print", {defaultValue: "Print"}),
340
+ "data-i18n-title": "print",
341
+ "aria-label": t("print", {defaultValue: "Print"}),
342
+ "data-i18n-aria-label": "print",
337
343
  i18n: "print"}, t("print", {defaultValue: "Print"})]
338
344
  ]]
339
345
  ]]
@@ -38,7 +38,7 @@ const {
38
38
  gobj_change_state, gobj_current_state,
39
39
  set_log_callback,
40
40
  } = gobj_js;
41
- const {register_c_yui_shell, yui_shell_set_connection_state} = await import("./c_yui_shell.js");
41
+ const {register_c_yui_shell, yui_shell_set_connection_state, yui_shell_icons_changed} = await import("./c_yui_shell.js");
42
42
  const {register_c_yui_treedb_topics} = await import("./c_yui_treedb_topics.js");
43
43
 
44
44
  const logged = [];
@@ -255,6 +255,14 @@ describe("a Save in flight when the backend drops", () => {
255
255
  expect(errors()).toEqual([]);
256
256
  });
257
257
 
258
+ test("nor EV_ICONS_CHANGED, which 7.26.6 added to the shell", () => {
259
+ /* An app hosting a treedb view heard it on every load of
260
+ * `__icons__` and answered "Event NOT DEFINED in state". */
261
+ const {shell} = build("t4b");
262
+ yui_shell_icons_changed(shell);
263
+ expect(errors()).toEqual([]);
264
+ });
265
+
258
266
  test("an answer from the backend settles its own form only", () => {
259
267
  const {shell, topics, forms} = build("t5");
260
268
  yui_shell_set_connection_state(shell, true);
@@ -0,0 +1,101 @@
1
+ /***********************************************************************
2
+ * window_veto_back.wiring.test.js
3
+ *
4
+ * A floating C_YUI_WINDOW registers an entry in the shell's
5
+ * overlay history, so the browser Back closes it. The shell takes
6
+ * that entry off its stack BEFORE it calls the close; when a
7
+ * subscriber vetoed the close (EV_WINDOW_TO_CLOSE + abort_close),
8
+ * the window stayed up with no entry: the next Back did not close
9
+ * it, and a route change left it floating over the next view.
10
+ *
11
+ * Copyright (c) 2026, ArtGins.
12
+ * All Rights Reserved.
13
+ ***********************************************************************/
14
+ import {describe, test, expect, beforeAll, beforeEach} from "vitest";
15
+ import {install_dom_double} from "../test/dom_double.js";
16
+
17
+ install_dom_double();
18
+
19
+ const {
20
+ SDATA_END, gclass_create,
21
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
22
+ gobj_start, gobj_read_attr, gobj_is_destroying,
23
+ set_log_callback,
24
+ } = await import("@yuneta/gobj-js");
25
+ const {register_c_yui_shell} = await import("./c_yui_shell.js");
26
+ const {register_c_yui_window} = await import("./c_yui_window.js");
27
+
28
+ const logged = [];
29
+ let veto = true;
30
+ let yuno = null;
31
+
32
+ beforeAll(async () => {
33
+ const i18next = (await import("i18next")).default;
34
+ await i18next.init({lng: "en", resources: {}});
35
+ gobj_start_up(null, null, null, null, null, null, null);
36
+ set_log_callback((level, msg) => {
37
+ logged.push({level: String(level), msg: String(msg)});
38
+ });
39
+ gclass_create("C_TEST_VETO_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
40
+ gclass_create(
41
+ "C_TEST_VETO_APP",
42
+ [["EV_WINDOW_TO_CLOSE", 0]],
43
+ [["ST_IDLE", [
44
+ ["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
45
+ kw.abort_close = veto;
46
+ return 0;
47
+ }, null]
48
+ ]]],
49
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
50
+ );
51
+ register_c_yui_shell();
52
+ register_c_yui_window();
53
+ yuno = gobj_create_yuno("veto_yuno", "C_TEST_VETO_HOST", {});
54
+ gobj_start(yuno);
55
+ });
56
+
57
+ beforeEach(() => {
58
+ logged.length = 0;
59
+ veto = true;
60
+ });
61
+
62
+ function errors()
63
+ {
64
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
65
+ }
66
+
67
+ function press_back()
68
+ {
69
+ window.history.state = null;
70
+ window.dispatchEvent(new Event("popstate", {state: null}));
71
+ }
72
+
73
+ describe("a floating window that vetoes its close", () => {
74
+ test("keeps a Back entry, and closes on the Back after the veto is lifted", () => {
75
+ const app = gobj_create("vapp", "C_TEST_VETO_APP", {}, yuno);
76
+ gobj_start(app);
77
+ const shell = gobj_create("vshell", "C_YUI_SHELL",
78
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
79
+ gobj_start(shell);
80
+ logged.length = 0; /* the shell's own start: no route table here */
81
+
82
+ const win = gobj_create_service("vwin", "C_YUI_WINDOW",
83
+ {subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
84
+ gobj_start(win);
85
+ const first = gobj_read_attr(win, "back_overlay");
86
+ expect(first).toBeTruthy();
87
+
88
+ press_back();
89
+ expect(gobj_is_destroying(win)).toBe(false);
90
+ const second = gobj_read_attr(win, "back_overlay");
91
+ expect(second).toBeTruthy();
92
+ expect(second).not.toBe(first);
93
+ expect(shell.priv.overlay_stack).toEqual([second]);
94
+
95
+ veto = false;
96
+ press_back();
97
+ expect(gobj_is_destroying(win)).toBe(true);
98
+ expect(shell.priv.overlay_stack).toEqual([]);
99
+ expect(errors()).toEqual([]);
100
+ });
101
+ });
@@ -0,0 +1,87 @@
1
+ /***********************************************************************
2
+ * wizard_chrome.wiring.test.js
3
+ *
4
+ * C_YUI_WIZARD's chrome (title, primary button) is rewritten on
5
+ * every step change, after the host's one-time refresh_language().
6
+ * It stamped a bare `i18n` attribute (which refresh_language does
7
+ * not read) and put the raw key in the text: the title never went
8
+ * through t(), and on the last step the button read `confirm`
9
+ * while its `data-i18n` still said `next`, so a language switch
10
+ * relabelled it "Next".
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+ import {describe, test, expect, beforeAll} from "vitest";
16
+ import {install_dom_double} from "../test/dom_double.js";
17
+
18
+ install_dom_double();
19
+
20
+ const {
21
+ SDATA_END, gclass_create,
22
+ gobj_start_up, gobj_create_yuno, gobj_create,
23
+ gobj_start, gobj_send_event, gobj_read_attr,
24
+ } = await import("@yuneta/gobj-js");
25
+ const {register_c_yui_wizard} = await import("./c_yui_wizard.js");
26
+
27
+ let yuno = null;
28
+ let i18next = null;
29
+
30
+ beforeAll(async () => {
31
+ i18next = (await import("i18next")).default;
32
+ await i18next.init({lng: "en", resources: {
33
+ en: {translation: {"step one": "Step one", "next": "Next", "confirm": "Confirm"}},
34
+ es: {translation: {"step one": "Paso uno", "next": "Siguiente", "confirm": "Confirmar"}},
35
+ }});
36
+ gobj_start_up(null, null, null, null, null, null, null);
37
+ gclass_create("C_TEST_WIZ_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
38
+ gclass_create(
39
+ "C_TEST_WIZ_APP",
40
+ [["EV_STEP_SHOWN", 0], ["EV_WIZARD_DONE", 0]],
41
+ [["ST_IDLE", [
42
+ ["EV_STEP_SHOWN", () => 0, null],
43
+ ["EV_WIZARD_DONE", () => 0, null],
44
+ ]]],
45
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
46
+ );
47
+ register_c_yui_wizard();
48
+ yuno = gobj_create_yuno("wizard_yuno", "C_TEST_WIZ_HOST", {});
49
+ gobj_start(yuno);
50
+ });
51
+
52
+ describe("C_YUI_WIZARD chrome", () => {
53
+ test("title and primary label are translated and keep their key", async () => {
54
+ const app = gobj_create("wapp", "C_TEST_WIZ_APP", {}, yuno);
55
+ const wiz = gobj_create("wiz", "C_YUI_WIZARD", {linear: false}, app);
56
+ gobj_send_event(wiz, "EV_SET_STEPS", {steps: [
57
+ {id: "a", title: "step one", content: ["div", {}, "A"]},
58
+ {id: "b", title: "step one", content: ["div", {}, "B"]},
59
+ ]}, app);
60
+
61
+ const $c = gobj_read_attr(wiz, "$container");
62
+ const $title = $c.querySelector(".yui-wizard-title");
63
+ const $primary = $c.querySelector(".yui-wizard-primary");
64
+ const $plabel = $c.querySelector(".yui-wizard-primary-label");
65
+
66
+ expect($title.textContent).toBe("Step one");
67
+ expect($title.getAttribute("data-i18n")).toBe("step one");
68
+ expect($plabel.textContent).toBe("Next");
69
+
70
+ gobj_send_event(wiz, "EV_NEXT", {}, app);
71
+ expect($plabel.textContent).toBe("Confirm");
72
+ expect($plabel.getAttribute("data-i18n")).toBe("confirm");
73
+ expect($primary.getAttribute("aria-label")).toBe("Confirm");
74
+ expect($primary.getAttribute("data-i18n-aria-label")).toBe("confirm");
75
+ expect($primary.getAttribute("data-i18n-title")).toBe("confirm");
76
+
77
+ /* What refresh_language() reads on a language switch: the key of
78
+ * the CURRENT label, not the one the button was built with. */
79
+ await i18next.changeLanguage("es");
80
+ try {
81
+ expect(i18next.t($plabel.getAttribute("data-i18n"))).toBe("Confirmar");
82
+ expect(i18next.t($title.getAttribute("data-i18n"))).toBe("Paso uno");
83
+ } finally {
84
+ await i18next.changeLanguage("en");
85
+ }
86
+ });
87
+ });