@yuneta/gobj-ui 7.26.45 → 7.26.47

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.
@@ -0,0 +1,175 @@
1
+ /***********************************************************************
2
+ * shell_stop_overlays.wiring.test.js
3
+ *
4
+ * A shell stopped with an overlay up -- a logout, a session cut
5
+ * with the drawer or a dialog open -- closes the overlay first,
6
+ * as if it had been dismissed, and releases its focus trap. Up
7
+ * to gobj-ui 7.26.45 only the toolbar dropdown was closed: the
8
+ * trap of a drawer, a modal or a question stayed on the stack,
9
+ * every window opened afterwards believed itself under an
10
+ * overlay and took no focus, and the question's promise never
11
+ * settled.
12
+ *
13
+ * Copyright (c) 2026, ArtGins.
14
+ * All Rights Reserved.
15
+ ***********************************************************************/
16
+ import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
17
+ import {install_dom_double} from "../test/dom_double.js";
18
+
19
+ install_dom_double();
20
+
21
+ const {
22
+ SDATA_END, gclass_create,
23
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop, gobj_destroy,
24
+ set_log_callback,
25
+ } = await import("@yuneta/gobj-js");
26
+ const {register_c_yui_shell, yui_shell_open_drawer} = await import("./c_yui_shell.js");
27
+ const {register_c_yui_nav} = await import("./c_yui_nav.js");
28
+ const {yui_shell_show_modal, yui_shell_confirm_yesno} = await import("./shell_modals.js");
29
+ const {focus_trap_panel} = await import("./shell_focus_trap.js");
30
+
31
+ const logged = [];
32
+ let yuno = null;
33
+ let seq = 0;
34
+
35
+ beforeAll(async () => {
36
+ const i18next = (await import("i18next")).default;
37
+ await i18next.init({lng: "en", resources: {}});
38
+ gobj_start_up(null, null, null, null, null, null, null);
39
+ set_log_callback((level, msg) => {
40
+ logged.push({level: String(level), msg: String(msg)});
41
+ });
42
+ gclass_create("C_TEST_STOP_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
43
+ register_c_yui_nav();
44
+ register_c_yui_shell();
45
+ yuno = gobj_create_yuno("stop_overlays_yuno", "C_TEST_STOP_HOST", {});
46
+ gobj_start(yuno);
47
+ });
48
+
49
+ beforeEach(() => {
50
+ logged.length = 0;
51
+ });
52
+
53
+ function errors()
54
+ {
55
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
56
+ }
57
+
58
+ function settle()
59
+ {
60
+ return new Promise(resolve => setTimeout(resolve, 0));
61
+ }
62
+
63
+ function make_shell(use_hash)
64
+ {
65
+ seq++;
66
+ const app = gobj_create(`sapp${seq}`, "C_TEST_STOP_HOST", {}, yuno);
67
+ gobj_start(app);
68
+ const shell = gobj_create(`sshell${seq}`, "C_YUI_SHELL", {
69
+ config: {
70
+ shell: {},
71
+ menu: {
72
+ quick: {
73
+ render: {overlay: "drawer"},
74
+ items: [{id: "home", name: "home", route: "/home"}]
75
+ }
76
+ }
77
+ },
78
+ subscriber: app,
79
+ use_hash: !!use_hash
80
+ }, app);
81
+ gobj_start(shell);
82
+ logged.length = 0; /* the shell's own start: no route table here */
83
+ return shell;
84
+ }
85
+
86
+ describe("a shell stopped with an overlay up", () => {
87
+ test("the drawer, a modal and a question close, and no trap is left", async () => {
88
+ const shell = make_shell();
89
+
90
+ yui_shell_open_drawer(shell, "quick");
91
+ const $drawer = document.querySelector(".is-active");
92
+ expect($drawer).not.toBe(null);
93
+ expect(focus_trap_panel()).not.toBe(null);
94
+
95
+ let modal_closed = 0;
96
+ yui_shell_show_modal(shell, "the sheet", {
97
+ dialog: true,
98
+ logical_class: "TEST_STOP_SHEET",
99
+ title: "settings",
100
+ /* A guard is for the reader's dismissals, not for the
101
+ * shell going away. */
102
+ before_close: () => false,
103
+ on_close: () => {
104
+ modal_closed++;
105
+ }
106
+ });
107
+ let answer = null;
108
+ yui_shell_confirm_yesno(shell, "really?").then((a) => {
109
+ answer = a;
110
+ });
111
+ expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(1);
112
+ expect(document.querySelectorAll(".CONFIRM").length).toBe(1);
113
+
114
+ gobj_stop(shell);
115
+ gobj_destroy(shell);
116
+ await settle();
117
+
118
+ expect(focus_trap_panel()).toBe(null);
119
+ expect(modal_closed).toBe(1);
120
+ expect(answer).toBe(false); /* the answer Escape gives */
121
+ expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(0);
122
+ expect(document.querySelectorAll(".CONFIRM").length).toBe(0);
123
+ expect($drawer.classList.contains("is-active")).toBe(false);
124
+ expect(errors()).toEqual([]);
125
+ });
126
+
127
+ test("destroyed without a stop, it closes them too", async () => {
128
+ const shell = make_shell();
129
+
130
+ yui_shell_open_drawer(shell, "quick");
131
+ yui_shell_show_modal(shell, "the sheet", {
132
+ dialog: true, logical_class: "TEST_STOP_SHEET", title: "settings"
133
+ });
134
+ expect(focus_trap_panel()).not.toBe(null);
135
+
136
+ gobj_destroy(shell);
137
+ await settle();
138
+
139
+ expect(focus_trap_panel()).toBe(null);
140
+ expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(0);
141
+ /* gobj-js says what the test did; nothing else is said. */
142
+ expect(errors().filter((m) => !m.includes("Destroying a RUNNING gobj"))).toEqual([]);
143
+ });
144
+
145
+ test("it moves no browser history: their markers are left in place", async () => {
146
+ window.location.hash = "#/home";
147
+ const shell = make_shell(true);
148
+
149
+ yui_shell_show_modal(shell, "the sheet", {
150
+ dialog: true, logical_class: "TEST_STOP_SHEET", title: "settings"
151
+ });
152
+ let answer = null;
153
+ yui_shell_confirm_yesno(shell, "really?").then((a) => {
154
+ answer = a;
155
+ });
156
+ expect(window.history.state && window.history.state.__yui_overlay__).toBeTruthy();
157
+
158
+ /* A stopped shell hears no landing: a back() of its own would be
159
+ * taken by whatever the next shell pushed in the same turn. */
160
+ const back = vi.spyOn(window.history, "back");
161
+ try {
162
+ gobj_stop(shell);
163
+ gobj_destroy(shell);
164
+ await settle();
165
+ expect(back).not.toHaveBeenCalled();
166
+ } finally {
167
+ back.mockRestore();
168
+ window.location.hash = "";
169
+ }
170
+ expect(answer).toBe(false);
171
+ expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(0);
172
+ expect(focus_trap_panel()).toBe(null);
173
+ expect(errors()).toEqual([]);
174
+ });
175
+ });
@@ -0,0 +1,50 @@
1
+ /***********************************************************************
2
+ * tabulator_edit_internals.test.js
3
+ *
4
+ * C_YUI_FORM closes a table's open cell editor before it wipes
5
+ * the rows (close_table_editor): Tabulator 6.6.0 closes it while
6
+ * it wipes them and throws. Tabulator has no public way to ask
7
+ * which cell is being edited, so the form reads its edit module:
8
+ * `table.modules.edit`, its `currentCell` and its `cancelEdit()`.
9
+ * This pins those names against the Tabulator INSTALLED: an
10
+ * upgrade that renames them fails here, not in a reader's
11
+ * reload. (The form also says so in the log when they are
12
+ * missing.)
13
+ *
14
+ * Copyright (c) 2026, ArtGins.
15
+ * All Rights Reserved.
16
+ ***********************************************************************/
17
+ import {test, expect} from "vitest";
18
+ import {install_dom_double} from "../test/dom_double.js";
19
+
20
+ install_dom_double(); /* Tabulator reads `document` when it loads */
21
+
22
+ const {EditModule} = await import("tabulator-tables");
23
+
24
+ /* Just what the module's constructor touches. */
25
+ function stub_table()
26
+ {
27
+ const registry = {register() {}};
28
+ return {
29
+ optionsList: registry,
30
+ columnManager: {optionsList: registry},
31
+ componentFunctionBinder: {bind() {}},
32
+ eventBus: {subscribe() {}},
33
+ externalEvents: {subscribe() {}},
34
+ };
35
+ }
36
+
37
+ /* A table keeps each module under its `moduleName`. */
38
+ test("the edit module is `modules.edit`", () => {
39
+ expect(EditModule.moduleName).toBe("edit");
40
+ });
41
+
42
+ test("it holds the cell being edited in `currentCell`, false when none", () => {
43
+ const edit = new EditModule(stub_table());
44
+ expect(Object.prototype.hasOwnProperty.call(edit, "currentCell")).toBe(true);
45
+ expect(edit.currentCell).toBe(false);
46
+ });
47
+
48
+ test("and closes it with `cancelEdit()`", () => {
49
+ expect(typeof EditModule.prototype.cancelEdit).toBe("function");
50
+ });
@@ -0,0 +1,103 @@
1
+ /***********************************************************************
2
+ * treedb_time_cell.wiring.test.js
3
+ *
4
+ * A time column of C_YUI_TREEDB_TOPIC_WITH_FORM's table reads its
5
+ * value as the form does (form_time_value.js): an ISO text for a
6
+ * string column, an epoch in seconds for any other, nothing for no
7
+ * time. Up to gobj-ui 7.26.46 it read every column with parseInt --
8
+ * an ISO text as 2026 SECONDS, in January 1970 -- and showed a
9
+ * column with no time as January 1970.
10
+ *
11
+ * Copyright (c) 2026, ArtGins.
12
+ * All Rights Reserved.
13
+ ***********************************************************************/
14
+ import {describe, test, expect, beforeAll, vi} from "vitest";
15
+ import {install_dom_double} from "../test/dom_double.js";
16
+
17
+ install_dom_double();
18
+
19
+ if(typeof globalThis.ResizeObserver === "undefined") {
20
+ globalThis.ResizeObserver = class {
21
+ observe() {
22
+ }
23
+ unobserve() {
24
+ }
25
+ disconnect() {
26
+ }
27
+ };
28
+ }
29
+
30
+ const tables = vi.hoisted(() => []);
31
+ vi.mock("tabulator-tables", () => {
32
+ class FakeTabulator {
33
+ constructor($el, settings) {
34
+ this.element = $el;
35
+ this.options = settings;
36
+ tables.push(this);
37
+ return new Proxy(this, {
38
+ get(target, prop) {
39
+ if(prop in target) {
40
+ return target[prop];
41
+ }
42
+ return () => [];
43
+ }
44
+ });
45
+ }
46
+ on() {
47
+ }
48
+ off() {
49
+ }
50
+ destroy() {
51
+ }
52
+ }
53
+ return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
54
+ });
55
+
56
+ const {
57
+ SDATA_END, gclass_create, set_log_callback,
58
+ gobj_start_up, gobj_create_yuno, gobj_create_service, gobj_start,
59
+ } = await import("@yuneta/gobj-js");
60
+ const {register_c_yui_treedb_topic_with_form} = await import("./c_yui_treedb_topic_with_form.js");
61
+
62
+ const logged = [];
63
+ let yuno = null;
64
+
65
+ beforeAll(async () => {
66
+ const i18next = (await import("i18next")).default;
67
+ await i18next.init({lng: "en", resources: {}});
68
+ gobj_start_up(null, null, null, null, null, null, null);
69
+ set_log_callback((level, msg) => {
70
+ logged.push({level: String(level), msg: String(msg)});
71
+ });
72
+ gclass_create("C_TEST_TIME_CELL_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
73
+ register_c_yui_treedb_topic_with_form();
74
+ yuno = gobj_create_yuno("time_cell_yuno", "C_TEST_TIME_CELL_HOST", {});
75
+ gobj_start(yuno);
76
+ });
77
+
78
+ describe("a time column of a treedb topic's table", () => {
79
+ test("reads an ISO text column as ISO, and shows no time as nothing", () => {
80
+ const view = gobj_create_service("time_cell_view", "C_YUI_TREEDB_TOPIC_WITH_FORM", {
81
+ treedb_name: "treedb_test",
82
+ topic_name: "events",
83
+ desc: {id: "events", pkey: "id", cols: [
84
+ {id: "id", header: "Id", type: "string", flag: ["persistent", "required"]},
85
+ {id: "at", header: "at", type: "string", flag: ["persistent", "time"]},
86
+ {id: "when", header: "when", type: "integer", flag: ["persistent", "time"]}
87
+ ]}
88
+ }, yuno);
89
+ gobj_start(view);
90
+ const columns = tables[tables.length - 1].options.columns;
91
+ const text = (field, value) => {
92
+ const col = columns.find((c) => c.field === field);
93
+ const out = col.formatter({getValue: () => value, getData: () => ({}), getField: () => field}, {}, () => {});
94
+ return (out && typeof out === "object") ? out.textContent : String(out);
95
+ };
96
+ const year = (s) => (s.match(/\b(19|20)\d\d\b/) || [""])[0];
97
+ const epoch = Math.floor(new Date("2026-03-14T09:26:53").getTime() / 1000);
98
+ expect(year(text("at", new Date(epoch * 1000).toISOString()))).toBe("2026");
99
+ expect(year(text("when", epoch))).toBe("2026");
100
+ expect(text("when", null)).toBe("");
101
+ expect(logged.filter((l) => l.level === "error")).toEqual([]);
102
+ });
103
+ });
@@ -14,7 +14,7 @@
14
14
  * Copyright (c) 2026, ArtGins.
15
15
  * All Rights Reserved.
16
16
  ***********************************************************************/
17
- import {describe, test, expect, beforeAll} from "vitest";
17
+ import {describe, test, expect, beforeAll, vi} from "vitest";
18
18
  import {install_dom_double} from "../test/dom_double.js";
19
19
 
20
20
  install_dom_double();
@@ -105,6 +105,7 @@ describe("the saved rect of a window is whole pixels", () => {
105
105
  expect(attrs_rect(win)).toEqual({x: 5, y: 6, width: 300, height: 200});
106
106
  const warned = logged.filter((l) => l.level === "warning" && l.msg.includes("rect_bad-rect"));
107
107
  expect(warned.length, "the bad entry is said").toBe(1);
108
+ expect(window.localStorage.getItem("rect_bad-rect"), "and forgotten: said once").toBe(null);
108
109
  expect(errors()).toEqual([]);
109
110
 
110
111
  /* No entry at all is nothing to say. */
@@ -116,6 +117,56 @@ describe("the saved rect of a window is whole pixels", () => {
116
117
  expect(logged.filter((l) => l.msg.includes("rect_none-rect"))).toEqual([]);
117
118
  });
118
119
 
120
+ /* Not json at all, or the json `null`: kw_get_local_storage_value()
121
+ * answers nothing for either (the first with a console.warn of its
122
+ * own). Up to 7.26.46 the entry stayed, and was said on every open. */
123
+ test.each([["not json", "garbage{"], ["json null", "null"]])(
124
+ "an entry that is %s is said once, forgotten, and the window opens where it would",
125
+ (label, text) => {
126
+ const name = label === "not json" ? "rect_text" : "rect_null";
127
+ window.localStorage.setItem(`${name}-rect`, text);
128
+ logged.length = 0;
129
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
130
+ let win;
131
+ try {
132
+ win = gobj_create_service(name, "C_YUI_WINDOW", {
133
+ header: name, body: ["div", {}, name], auto_save_size_and_position: true,
134
+ x: 5, y: 6, width: 300, height: 200,
135
+ }, yuno);
136
+ gobj_start(win);
137
+ } finally {
138
+ warn.mockRestore();
139
+ }
140
+ expect(attrs_rect(win)).toEqual({x: 5, y: 6, width: 300, height: 200});
141
+ const warned = logged.filter((l) => l.level === "warning" && l.msg.includes(`${name}-rect`));
142
+ expect(warned.length, "the entry is said").toBe(1);
143
+ expect(window.localStorage.getItem(`${name}-rect`), "and forgotten").toBe(null);
144
+ expect(errors()).toEqual([]);
145
+ }
146
+ );
147
+
148
+ /* A rect with no size -- what the box of a window that is not
149
+ * drawn answers -- is no place to open in: the window was drawn at
150
+ * the CSS minimum while its attrs said 0 x 0, and every open
151
+ * restored it again. It is said, forgotten, and the window opens
152
+ * where it would. (A rect only OFF the screen is kept: the attrs
153
+ * are the DESIRED place, clamped to the viewport on every resize,
154
+ * so a window saved on a larger screen goes back there.) */
155
+ test("an entry with no size is said once, forgotten, and the window opens where it would", () => {
156
+ window.localStorage.setItem("rect_zero-rect", JSON.stringify({x: 0, y: 0, width: 0, height: 0}));
157
+ logged.length = 0;
158
+ const win = gobj_create_service("rect_zero", "C_YUI_WINDOW", {
159
+ header: "zero", body: ["div", {}, "zero"], auto_save_size_and_position: true,
160
+ x: 5, y: 6, width: 300, height: 200,
161
+ }, yuno);
162
+ gobj_start(win);
163
+ expect(attrs_rect(win)).toEqual({x: 5, y: 6, width: 300, height: 200});
164
+ const warned = logged.filter((l) => l.level === "warning" && l.msg.includes("rect_zero-rect"));
165
+ expect(warned.length, "the empty entry is said").toBe(1);
166
+ expect(window.localStorage.getItem("rect_zero-rect")).toBe(null);
167
+ expect(errors()).toEqual([]);
168
+ });
169
+
119
170
  test("a move saves whole pixels, and writes them into the attrs", () => {
120
171
  const win = gobj_create_service("rect_move", "C_YUI_WINDOW", {
121
172
  header: "move", body: ["div", {}, "move"], auto_save_size_and_position: true,
@@ -169,8 +169,14 @@ function yui_tabulator_name_filters(table, t)
169
169
  * from `yui_tabulator_relocalize()` so a language change
170
170
  * reaches them.
171
171
  *
172
- * It matches Tabulator's OWN literal and only that, so a box a
173
- * view named itself is left alone.
172
+ * It matches Tabulator's OWN literal, and the boxes it named itself
173
+ * (they carry `data-yui-row-select`), so a box a view named itself is
174
+ * left alone. Up to 7.26.46 it matched only the literal: a box named
175
+ * once was never found again, and a language change through
176
+ * yui_tabulator_relocalize() left it in the old language.
177
+ *
178
+ * The box in the HEADER selects every row, and is named so
179
+ * ("select all rows"); up to 7.26.46 it was "select row" too.
174
180
  ***************************************************************/
175
181
  const TABULATOR_ROW_SELECT_ARIA = "Select Row";
176
182
 
@@ -193,12 +199,17 @@ function yui_tabulator_name_row_selects(table, t)
193
199
  return;
194
200
  }
195
201
  let boxes = $el.querySelectorAll(
196
- `input[type=checkbox][aria-label="${TABULATOR_ROW_SELECT_ARIA}"]`);
202
+ `input[type=checkbox][aria-label="${TABULATOR_ROW_SELECT_ARIA}"], ` +
203
+ `input[type=checkbox][data-yui-row-select]`);
197
204
  for(let $box of boxes) {
198
- $box.setAttribute("aria-label", t("select row"));
199
- $box.setAttribute("data-i18n-aria-label", "select row");
200
- $box.setAttribute("title", t("select row"));
201
- $box.setAttribute("data-i18n-title", "select row");
205
+ let all = typeof $box.closest === "function" && !!$box.closest(".tabulator-header");
206
+ let name = all ? t("select all rows") : t("select row");
207
+ let key = all ? "select all rows" : "select row";
208
+ $box.setAttribute("aria-label", name);
209
+ $box.setAttribute("data-i18n-aria-label", key);
210
+ $box.setAttribute("title", name);
211
+ $box.setAttribute("data-i18n-title", key);
212
+ $box.setAttribute("data-yui-row-select", "");
202
213
  }
203
214
  } catch(e) {
204
215
  /* a table between renders has no boxes to name */
@@ -81,6 +81,42 @@ describe("yui_tabulator_name_row_selects", () => {
81
81
  expect($box.attrs["title"]).toBe("Seleccionar fila");
82
82
  expect($box.attrs["data-i18n-title"]).toBe("select row");
83
83
  });
84
+
85
+ /* Up to 7.26.46 the header's box -- which selects every row -- was
86
+ * named "select row" too. */
87
+ it("names the header's box for what it does: select all rows", () => {
88
+ const $box = element();
89
+ $box.setAttribute("aria-label", "Select Row");
90
+ $box.closest = (sel) => (sel === ".tabulator-header" ? {} : null);
91
+ const table = {element: element($box)};
92
+
93
+ yui_tabulator_name_row_selects(table, (key) => key === "select all rows" ? "Seleccionar todas las filas" : key);
94
+
95
+ expect($box.attrs["aria-label"]).toBe("Seleccionar todas las filas");
96
+ expect($box.attrs["data-i18n-aria-label"]).toBe("select all rows");
97
+ expect($box.attrs["title"]).toBe("Seleccionar todas las filas");
98
+ expect($box.attrs["data-i18n-title"]).toBe("select all rows");
99
+ });
100
+
101
+ /* Up to 7.26.46 only Tabulator's English literal was matched, so a
102
+ * box named once was never named again: a language change through
103
+ * yui_tabulator_relocalize() (C_YUI_FORM's EV_LANGUAGE_CHANGED) left
104
+ * it in the old language. */
105
+ it("names again, in the new language, a box it named before", () => {
106
+ const $box = element();
107
+ $box.setAttribute("aria-label", "Select Row");
108
+ /* Found again by the mark it left, not by Tabulator's literal */
109
+ const table = {element: {querySelectorAll: (sel) => (
110
+ sel.includes("Select Row") && $box.attrs["aria-label"] !== "Select Row" &&
111
+ !sel.includes("data-yui-row-select") ? [] : [$box])}};
112
+
113
+ yui_tabulator_name_row_selects(table, t);
114
+ expect($box.attrs["aria-label"]).toBe("Seleccionar fila");
115
+
116
+ yui_tabulator_name_row_selects(table, (key) => key === "select row" ? "Select the row" : key);
117
+ expect($box.attrs["aria-label"]).toBe("Select the row");
118
+ expect($box.attrs["title"]).toBe("Select the row");
119
+ });
84
120
  });
85
121
 
86
122
  describe("yui_tabulator_name_editor", () => {