@yuneta/gobj-ui 7.26.56 → 7.26.58

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.
@@ -2,20 +2,25 @@
2
2
  * yui_tabulator_edit.test.js
3
3
  *
4
4
  * yui_tabulator_keep_edit_on_redraw(): every Tabulator call that
5
- * builds the cells again -- a forced redraw, setColumns() and the
6
- * three height setters -- ends the open edit BEFORE it, while its
7
- * cell is alive, and opens it again on the new cell after it.
8
- * Nothing else is touched. The table is a double that records the
5
+ * builds the cells again -- a forced redraw, setColumns(), the
6
+ * three height setters, addColumn(), updateColumnDefinition() and
7
+ * moveColumn() -- ends the open edit BEFORE it, while its cell is
8
+ * alive, and opens it again on the new cell after it (after the
9
+ * promise, for a call that answers one), unless that cell is not
10
+ * in the page. Nothing else is touched. The table is a double that records the
9
11
  * order of the calls; that the real Tabulator throws without this
10
12
  * is proved in a browser by scripts/qa-cell-editor.mjs.
11
13
  *
12
14
  * Copyright (c) 2026, ArtGins.
13
15
  * All Rights Reserved.
14
16
  ***********************************************************************/
15
- import {describe, test, expect, beforeEach} from "vitest";
17
+ import {describe, test, expect, beforeEach, vi} from "vitest";
16
18
  import {yui_tabulator_keep_edit_on_redraw} from "./yui_tabulator_edit.js";
17
19
 
18
20
  let calls = [];
21
+ let connected = true;
22
+ let drawn = true; /* an undrawn row answers no cell */
23
+ let editors = {}; /* field -> its definition's editor; absent: no column */
19
24
 
20
25
  function make_cell(row, field, editing)
21
26
  {
@@ -23,7 +28,7 @@ function make_cell(row, field, editing)
23
28
  field,
24
29
  classes: new Set(editing? ["tabulator-editing"] : []),
25
30
  getElement() {
26
- return {classList: {contains: (c) => cell.classes.has(c)}};
31
+ return {classList: {contains: (c) => cell.classes.has(c)}, isConnected: connected};
27
32
  },
28
33
  getRow() {
29
34
  return row;
@@ -35,8 +40,14 @@ function make_cell(row, field, editing)
35
40
  calls.push(`cancel ${field}`);
36
41
  cell.classes.delete("tabulator-editing");
37
42
  },
43
+ getColumn() {
44
+ return {getDefinition: () => ({editor: editors[field]})};
45
+ },
38
46
  edit(force) {
39
47
  calls.push(`edit ${field} ${force}`);
48
+ if(!editors[field]) {
49
+ throw new TypeError("Cannot read properties of undefined (reading 'blocked')");
50
+ }
40
51
  },
41
52
  };
42
53
  return cell;
@@ -48,11 +59,14 @@ function make_table()
48
59
  const row = {
49
60
  getCell(field) {
50
61
  calls.push(`getCell ${field}`);
51
- return field === "gone"? false : make_cell(row, field, false);
62
+ return (field in editors && drawn)? make_cell(row, field, false) : false;
52
63
  },
53
64
  };
54
65
  const table = {
55
66
  row,
67
+ getColumns() {
68
+ return Object.keys(editors).map((f) => ({getField: () => f}));
69
+ },
56
70
  on(name, fn) {
57
71
  handlers[name] = fn;
58
72
  },
@@ -60,18 +74,34 @@ function make_table()
60
74
  handlers[name](cell);
61
75
  },
62
76
  };
63
- for(const name of ["redraw", "setColumns", "setHeight", "setMaxHeight", "setMinHeight"]) {
77
+ for(const name of ["redraw", "setColumns", "setHeight", "setMaxHeight", "setMinHeight",
78
+ "moveColumn"]) {
64
79
  table[name] = function(...args) {
65
80
  calls.push(`${name}(${args.join(",")})`);
66
81
  return `${name} done`;
67
82
  };
68
83
  }
84
+ for(const name of ["addColumn", "updateColumnDefinition"]) {
85
+ table[name] = function(...args) {
86
+ calls.push(`${name}(${args.join(",")})`);
87
+ return Promise.resolve().then(() => {
88
+ calls.push(`${name} resolved`);
89
+ if(args[0] === "reject") {
90
+ throw new Error("refused");
91
+ }
92
+ return `${name} done`;
93
+ });
94
+ };
95
+ }
69
96
  yui_tabulator_keep_edit_on_redraw(table);
70
97
  return table;
71
98
  }
72
99
 
73
100
  beforeEach(() => {
74
101
  calls = [];
102
+ connected = true;
103
+ drawn = true;
104
+ editors = {when: "input", note: "input"};
75
105
  });
76
106
 
77
107
  describe("an open edit around a call that builds the cells again", () => {
@@ -81,6 +111,7 @@ describe("an open edit around a call that builds the cells again", () => {
81
111
  ["setHeight", [300]],
82
112
  ["setMaxHeight", [400]],
83
113
  ["setMinHeight", [100]],
114
+ ["moveColumn", ["a", "b", true]],
84
115
  ]) {
85
116
  test(`${name}: ended before, opened again after, the answer passed on`, () => {
86
117
  const table = make_table();
@@ -125,8 +156,102 @@ describe("what it leaves alone", () => {
125
156
 
126
157
  test("a column the new columns do not have: the edit stays closed", () => {
127
158
  const table = make_table();
159
+ editors.gone = "input";
128
160
  table.emit("cellEditing", make_cell(table.row, "gone", true));
161
+ delete editors.gone;
129
162
  expect(table.setColumns(["other"])).toBe("setColumns done");
130
163
  expect(calls).toEqual(["cancel gone", "setColumns(other)", "getCell gone"]);
131
164
  });
132
165
  });
166
+
167
+ describe("a call that answers a promise", () => {
168
+ for(const name of ["addColumn", "updateColumnDefinition"]) {
169
+ test(`${name}: opened again after the promise, its answer passed on`, async () => {
170
+ const table = make_table();
171
+ table.emit("cellEditing", make_cell(table.row, "when", true));
172
+ const ret = table[name]("x");
173
+ expect(calls).toEqual(["cancel when", `${name}(x)`]);
174
+ expect(await ret).toBe(`${name} done`);
175
+ expect(calls).toEqual([
176
+ "cancel when", `${name}(x)`, `${name} resolved`,
177
+ "getCell when", "edit when true",
178
+ ]);
179
+ });
180
+ }
181
+
182
+ test("a refusal rebuilt nothing: not opened again, said, and passed on", async () => {
183
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
184
+ const table = make_table();
185
+ table.emit("cellEditing", make_cell(table.row, "when", true));
186
+ await expect(table.updateColumnDefinition("reject")).rejects.toThrow("refused");
187
+ expect(calls).toEqual(["cancel when", "updateColumnDefinition(reject)",
188
+ "updateColumnDefinition resolved"]);
189
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: updateColumnDefinition\(\) was refused/);
190
+ warn.mockRestore();
191
+ });
192
+
193
+ test("another edit opened before the answer keeps the edit", async () => {
194
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
195
+ const table = make_table();
196
+ table.emit("cellEditing", make_cell(table.row, "when", true));
197
+ const ret = table.addColumn("x");
198
+ table.emit("cellEditing", make_cell(table.row, "note", true));
199
+ await ret;
200
+ expect(calls).toEqual(["cancel when", "addColumn(x)", "addColumn resolved"]);
201
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: another cell \('note'\) was opened after addColumn\(\)/);
202
+ warn.mockRestore();
203
+ });
204
+
205
+ test("a table destroyed before the answer: not opened, and said so", async () => {
206
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
207
+ const table = make_table();
208
+ table.emit("cellEditing", make_cell(table.row, "when", true));
209
+ const ret = table.updateColumnDefinition("when");
210
+ table.destroyed = true;
211
+ await ret;
212
+ expect(calls).toEqual(["cancel when", "updateColumnDefinition(when)",
213
+ "updateColumnDefinition resolved"]);
214
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: the table was destroyed after updateColumnDefinition\(\)/);
215
+ warn.mockRestore();
216
+ });
217
+ });
218
+
219
+ describe("a column the call left with no editor", () => {
220
+ test("not opened (no throw), and the log says why", async () => {
221
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
222
+ const table = make_table();
223
+ table.emit("cellEditing", make_cell(table.row, "when", true));
224
+ editors.when = false;
225
+ expect(table.setColumns(["defs"])).toBe("setColumns done");
226
+ table.emit("cellEditing", make_cell(table.row, "when", true));
227
+ expect(await table.updateColumnDefinition("when")).toBe("updateColumnDefinition done");
228
+ expect(calls.filter((c) => c.startsWith("edit"))).toEqual([]);
229
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: the column has no editor after setColumns\(\)/);
230
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/after updateColumnDefinition\(\)/);
231
+ warn.mockRestore();
232
+ });
233
+ });
234
+
235
+ describe("a cell the call left out of the page", () => {
236
+ test("the edit stays closed, and the log says why", () => {
237
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
238
+ const table = make_table();
239
+ table.emit("cellEditing", make_cell(table.row, "when", true));
240
+ connected = false;
241
+ expect(table.setHeight(50)).toBe("setHeight done");
242
+ expect(calls).toEqual(["cancel when", "setHeight(50)", "getCell when"]);
243
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: its row is not in the page after setHeight\(\)/);
244
+ warn.mockRestore();
245
+ });
246
+
247
+ test("an undrawn row answers no cell: said as out of the page, not as no column", () => {
248
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
249
+ const table = make_table();
250
+ table.emit("cellEditing", make_cell(table.row, "when", true));
251
+ drawn = false;
252
+ expect(table.setColumns(["defs"])).toBe("setColumns done");
253
+ expect(calls).toEqual(["cancel when", "setColumns(defs)", "getCell when"]);
254
+ expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: its row is not in the page after setColumns\(\)/);
255
+ warn.mockRestore();
256
+ });
257
+ });
@@ -4,7 +4,7 @@
4
4
  * The texts uPlot writes for a moment -- the ticks of a time axis
5
5
  * and the reading of the legend -- in the APP's language, with a
6
6
  * clock of 24 hours, as every other time a gobj-ui view shows
7
- * (fmt_date_time of yui_time.js).
7
+ * (fmt_date_time of yui_date_text.js).
8
8
  *
9
9
  * uPlot writes them from templates of its own, in English and
10
10
  * 12 hours: "3pm", "3:05pm", "10/14" (month first), "Oct", and