@yuneta/gobj-ui 7.26.41 → 7.26.43
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.
- package/README.md +510 -78
- package/dist/gobj-ui.cjs.js +1120 -326
- package/dist/gobj-ui.es.js +1120 -326
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +971 -177
- package/src/c_g6_nodes_tree.js +3 -2
- package/src/c_yui_form.js +261 -154
- package/src/c_yui_fsm_graph.js +3 -2
- package/src/c_yui_gobj_tree_js.js +3 -2
- package/src/c_yui_json_graph.js +3 -2
- package/src/c_yui_nav.js +43 -28
- package/src/c_yui_node.js +51 -7
- package/src/c_yui_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +110 -20
- package/src/c_yui_shell.css +4 -1
- package/src/c_yui_shell.js +227 -61
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window.js +373 -62
- package/src/c_yui_window_manager.js +80 -8
- package/src/escape_taken.js +58 -0
- package/src/form_close_asks_for_edits.wiring.test.js +6 -3
- package/src/form_json_editor_names.js +3 -1
- package/src/form_json_editor_names.wiring.test.js +8 -4
- package/src/form_json_expand.wiring.test.js +6 -3
- package/src/form_json_field.wiring.test.js +8 -4
- package/src/form_label_i18n.wiring.test.js +10 -5
- package/src/form_table_edits_ask.wiring.test.js +18 -8
- package/src/form_table_rearm.wiring.test.js +13 -5
- package/src/form_table_rows.wiring.test.js +489 -0
- package/src/form_table_validator.wiring.test.js +8 -4
- package/src/form_template_field.wiring.test.js +6 -3
- package/src/g6_canvas_tab_order.css +29 -0
- package/src/g6_canvas_tab_order.js +41 -9
- package/src/g6_canvas_tab_order.wiring.test.js +107 -1
- package/src/g6_long_press_clock.test.js +8 -3
- package/src/i18n_key_functions.js +81 -27
- package/src/i18n_key_functions.test.js +402 -4
- package/src/modal_guard_back.wiring.test.js +188 -0
- package/src/named_controls.wiring.test.js +323 -19
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/node_nav_events.wiring.test.js +93 -1
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_diagram_click.wiring.test.js +277 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_dialog_names.wiring.test.js +149 -0
- package/src/shell_escape_taken.wiring.test.js +142 -0
- package/src/shell_focus_trap.js +30 -2
- package/src/shell_focus_trap.test.js +90 -6
- package/src/shell_modals.js +113 -22
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/table_editor_name.wiring.test.js +10 -5
- package/src/treedb_column_title.wiring.test.js +8 -4
- package/src/treedb_graph_writes.wiring.test.js +6 -3
- package/src/treedb_json_drill.wiring.test.js +6 -3
- package/src/uplot_add_serie.test.js +6 -3
- package/src/uplot_ink.test.js +8 -4
- package/src/window_dialog.wiring.test.js +486 -0
- package/src/window_dock_band.wiring.test.js +189 -0
- package/src/window_layer.wiring.test.js +114 -0
- package/src/window_rect_rounding.wiring.test.js +121 -0
- package/src/yui_gclass_view.js +16 -1
- package/src/yui_tabulator_i18n.js +31 -1
- package/src/yui_tabulator_i18n.test.js +46 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* schema_editor_diagram_click.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A click on a topic of C_YUI_SCHEMA_EDITOR's drawing opens that
|
|
5
|
+
* topic's columns -- and leaves the drawing, which the editor takes
|
|
6
|
+
* down. It took it down INSIDE the click: the drawing
|
|
7
|
+
* (C_YUI_TREEDB_SCHEMA) publishes EV_NODE_CLICK from the action of
|
|
8
|
+
* G6's own node-click event, and the editor's answer stopped and
|
|
9
|
+
* destroyed it there -- the gobj under its own publication, and its
|
|
10
|
+
* G6 graph under G6's own event dispatch, which goes on when the
|
|
11
|
+
* handler returns.
|
|
12
|
+
*
|
|
13
|
+
* A subscriber must not destroy the tree of its publisher
|
|
14
|
+
* synchronously (the C kernel says it since 7.26.10, gobj-js since
|
|
15
|
+
* 7.26.22: "Destroying a gobj while its tree is publishing"). The
|
|
16
|
+
* screen changes at once, as before; the drawing it leaves is
|
|
17
|
+
* detached at once and destroyed on the next turn.
|
|
18
|
+
*
|
|
19
|
+
* Driven through the real C_YUI_SCHEMA_EDITOR and the real
|
|
20
|
+
* C_YUI_TREEDB_SCHEMA, on a document double, with a G6 double that
|
|
21
|
+
* remembers whether it was destroyed while it was dispatching an
|
|
22
|
+
* event of its own.
|
|
23
|
+
*
|
|
24
|
+
* Copyright (c) 2026, ArtGins.
|
|
25
|
+
* All Rights Reserved.
|
|
26
|
+
***********************************************************************/
|
|
27
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
28
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
29
|
+
|
|
30
|
+
install_dom_double();
|
|
31
|
+
|
|
32
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
33
|
+
globalThis.ResizeObserver = class {
|
|
34
|
+
observe() {
|
|
35
|
+
}
|
|
36
|
+
unobserve() {
|
|
37
|
+
}
|
|
38
|
+
disconnect() {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
vi.mock("./shell_modals.js", () => ({
|
|
44
|
+
yui_shell_show_error: () => ({close() {}}),
|
|
45
|
+
yui_shell_show_info: () => ({close() {}}),
|
|
46
|
+
yui_shell_show_modal: () => ({close() {}}),
|
|
47
|
+
yui_shell_confirm_danger: () => new Promise(() => {}),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
const graphs = vi.hoisted(() => []);
|
|
51
|
+
vi.mock("@antv/g6", async (importOriginal) => {
|
|
52
|
+
const real = await importOriginal();
|
|
53
|
+
class FakeGraph {
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.options = options;
|
|
56
|
+
this.handlers = {};
|
|
57
|
+
this.emitting = 0;
|
|
58
|
+
this.destroyed = false;
|
|
59
|
+
this.destroyed_while_emitting = false;
|
|
60
|
+
graphs.push(this);
|
|
61
|
+
return new Proxy(this, {
|
|
62
|
+
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
render() {
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
on(name, fn) {
|
|
69
|
+
(this.handlers[name] = this.handlers[name] || []).push(fn);
|
|
70
|
+
}
|
|
71
|
+
emit(name, ev) {
|
|
72
|
+
this.emitting++;
|
|
73
|
+
try {
|
|
74
|
+
for(const fn of (this.handlers[name] || [])) {
|
|
75
|
+
fn(ev);
|
|
76
|
+
}
|
|
77
|
+
} finally {
|
|
78
|
+
this.emitting--;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
getZoom() {
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
getData() {
|
|
85
|
+
return {nodes: [], edges: [], combos: []};
|
|
86
|
+
}
|
|
87
|
+
getNodeData() {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
getEdgeData() {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
getPlugins() {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
getBehaviors() {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
getOptions() {
|
|
100
|
+
return {behaviors: []};
|
|
101
|
+
}
|
|
102
|
+
getCanvas() {
|
|
103
|
+
return {getLayers: () => ({}), getContainer: () => null};
|
|
104
|
+
}
|
|
105
|
+
draw() {
|
|
106
|
+
return Promise.resolve();
|
|
107
|
+
}
|
|
108
|
+
destroy() {
|
|
109
|
+
this.destroyed = true;
|
|
110
|
+
if(this.emitting > 0) {
|
|
111
|
+
this.destroyed_while_emitting = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {...real, Graph: FakeGraph};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const {
|
|
119
|
+
SDATA_END,
|
|
120
|
+
gclass_create,
|
|
121
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
122
|
+
gobj_start, gobj_send_event, gobj_read_attr,
|
|
123
|
+
gobj_change_state, gobj_current_state, gobj_is_destroying,
|
|
124
|
+
set_log_callback,
|
|
125
|
+
} = await import("@yuneta/gobj-js");
|
|
126
|
+
const {NodeEvent} = await import("@antv/g6");
|
|
127
|
+
const {register_c_yui_treedb_schema} = await import("./c_yui_treedb_schema.js");
|
|
128
|
+
const {register_c_yui_schema_editor} = await import("./c_yui_schema_editor.js");
|
|
129
|
+
|
|
130
|
+
const logged = [];
|
|
131
|
+
const commands = [];
|
|
132
|
+
|
|
133
|
+
const RECORDS = {
|
|
134
|
+
treedbs: [{id: "db", schema_version: 4}],
|
|
135
|
+
topics: [
|
|
136
|
+
{id: "db.users", value: "users", order: 1, pkey: "id", topic_version: 2,
|
|
137
|
+
treedbs: ["treedbs^db^topics"]},
|
|
138
|
+
],
|
|
139
|
+
cols: [
|
|
140
|
+
{id: "db.users.id", value: "id", order: 1, type: "string",
|
|
141
|
+
flag: ["persistent", "required"], topics: ["topics^db.users^cols"]},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
let yuno = null;
|
|
146
|
+
|
|
147
|
+
beforeAll(async () => {
|
|
148
|
+
const i18next = (await import("i18next")).default;
|
|
149
|
+
await i18next.init({lng: "en", resources: {en: {translation: {}}}});
|
|
150
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
151
|
+
set_log_callback((level, msg) => {
|
|
152
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
153
|
+
});
|
|
154
|
+
gclass_create("C_TEST_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
155
|
+
/* The editor's host hears what the editor publishes. */
|
|
156
|
+
const EDITOR_OUT = ["EV_POSITION_CHANGED", "EV_RECORD_WRITTEN", "EV_SCHEMA_CHECKED"];
|
|
157
|
+
gclass_create(
|
|
158
|
+
"C_TEST_EDITOR_HOST",
|
|
159
|
+
EDITOR_OUT.map((ev) => [ev, 0]),
|
|
160
|
+
[["ST_IDLE", EDITOR_OUT.map((ev) => [ev, () => 0, null])]],
|
|
161
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
162
|
+
);
|
|
163
|
+
gclass_create(
|
|
164
|
+
"C_TEST_REMOTE",
|
|
165
|
+
[],
|
|
166
|
+
[["ST_DISCONNECTED", []], ["ST_SESSION", []]],
|
|
167
|
+
{mt_command_parser: (gobj, command, kw, src) => {
|
|
168
|
+
commands.push({command, kw, src});
|
|
169
|
+
return null;
|
|
170
|
+
}},
|
|
171
|
+
0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
172
|
+
);
|
|
173
|
+
register_c_yui_treedb_schema();
|
|
174
|
+
register_c_yui_schema_editor();
|
|
175
|
+
yuno = gobj_create_yuno("diagram_click_yuno", "C_TEST_HOST", {});
|
|
176
|
+
gobj_start(yuno);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
beforeEach(() => {
|
|
180
|
+
logged.length = 0;
|
|
181
|
+
commands.length = 0;
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
function answer_the_load(editor, remote)
|
|
185
|
+
{
|
|
186
|
+
const asked = commands.splice(0).filter((c) => c.command === "nodes");
|
|
187
|
+
for(const c of asked) {
|
|
188
|
+
gobj_send_event(editor, "EV_MT_COMMAND_ANSWER", {
|
|
189
|
+
result: 0,
|
|
190
|
+
comment: "",
|
|
191
|
+
data: JSON.parse(JSON.stringify(RECORDS[c.kw.topic_name])),
|
|
192
|
+
__md_iev__: {command_stack: [{command: c.command, kw: c.kw}]}
|
|
193
|
+
}, remote);
|
|
194
|
+
}
|
|
195
|
+
return asked.length;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function errors()
|
|
199
|
+
{
|
|
200
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const turn = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
204
|
+
|
|
205
|
+
describe("a topic clicked in the editor's drawing", () => {
|
|
206
|
+
|
|
207
|
+
test("opens its columns at once; the drawing goes on the next turn, not under the click", async () => {
|
|
208
|
+
const remote = gobj_create_service("click_remote", "C_TEST_REMOTE", {}, yuno);
|
|
209
|
+
gobj_change_state(remote, "ST_SESSION");
|
|
210
|
+
const host = gobj_create("click_host", "C_TEST_EDITOR_HOST", {}, yuno);
|
|
211
|
+
const editor = gobj_create("click_editor", "C_YUI_SCHEMA_EDITOR", {
|
|
212
|
+
gobj_remote_yuno: remote,
|
|
213
|
+
treedb_name: "treedb_system_schema",
|
|
214
|
+
base_route: "/schemas"
|
|
215
|
+
}, host);
|
|
216
|
+
gobj_start(editor);
|
|
217
|
+
gobj_send_event(editor, "EV_TRANSPORT_STATE", {connected: true}, host);
|
|
218
|
+
expect(answer_the_load(editor, remote)).toBe(3);
|
|
219
|
+
gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
|
|
220
|
+
expect(gobj_current_state(editor)).toBe("ST_DIAGRAM");
|
|
221
|
+
|
|
222
|
+
const diagram = editor.priv.diagram_gobj;
|
|
223
|
+
expect(diagram).toBeTruthy();
|
|
224
|
+
const graph = graphs[graphs.length - 1];
|
|
225
|
+
expect(graph).toBeTruthy();
|
|
226
|
+
|
|
227
|
+
graph.emit(NodeEvent.CLICK, {target: {id: "users"}});
|
|
228
|
+
|
|
229
|
+
/* The screen changed in the click... */
|
|
230
|
+
expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
|
|
231
|
+
const $container = gobj_read_attr(editor, "$container");
|
|
232
|
+
expect($container.querySelector(".SCHEMA_BODY .SCHEMA_COLUMNS")).toBeTruthy();
|
|
233
|
+
/* ...and the drawing was not taken down under it. */
|
|
234
|
+
expect(graph.destroyed_while_emitting).toBe(false);
|
|
235
|
+
expect(gobj_is_destroying(diagram)).toBe(false);
|
|
236
|
+
|
|
237
|
+
await turn();
|
|
238
|
+
expect(gobj_is_destroying(diagram)).toBe(true);
|
|
239
|
+
expect(graph.destroyed).toBe(true);
|
|
240
|
+
expect(editor.priv.diagram_gobj).toBe(null);
|
|
241
|
+
expect(errors()).toEqual([]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("a drawing left on a stop goes with the stop", async () => {
|
|
245
|
+
const remote = gobj_create_service("stop_remote", "C_TEST_REMOTE", {}, yuno);
|
|
246
|
+
gobj_change_state(remote, "ST_SESSION");
|
|
247
|
+
const host = gobj_create("stop_host", "C_TEST_EDITOR_HOST", {}, yuno);
|
|
248
|
+
const editor = gobj_create("stop_editor", "C_YUI_SCHEMA_EDITOR", {
|
|
249
|
+
gobj_remote_yuno: remote,
|
|
250
|
+
treedb_name: "treedb_system_schema",
|
|
251
|
+
base_route: "/schemas"
|
|
252
|
+
}, host);
|
|
253
|
+
gobj_start(editor);
|
|
254
|
+
gobj_send_event(editor, "EV_TRANSPORT_STATE", {connected: true}, host);
|
|
255
|
+
answer_the_load(editor, remote);
|
|
256
|
+
gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
|
|
257
|
+
const diagram = editor.priv.diagram_gobj;
|
|
258
|
+
const graph = graphs[graphs.length - 1];
|
|
259
|
+
|
|
260
|
+
graph.emit(NodeEvent.CLICK, {target: {id: "users"}});
|
|
261
|
+
expect(gobj_is_destroying(diagram)).toBe(false);
|
|
262
|
+
|
|
263
|
+
/* Stopped before the next turn: nothing of the drawing is left
|
|
264
|
+
* for a turn that finds the editor stopped. */
|
|
265
|
+
gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
|
|
266
|
+
const second = editor.priv.diagram_gobj;
|
|
267
|
+
expect(second).toBeTruthy();
|
|
268
|
+
expect(second).not.toBe(diagram);
|
|
269
|
+
const {gobj_stop} = await import("@yuneta/gobj-js");
|
|
270
|
+
gobj_stop(editor);
|
|
271
|
+
expect(gobj_is_destroying(diagram)).toBe(true);
|
|
272
|
+
expect(gobj_is_destroying(second)).toBe(true);
|
|
273
|
+
|
|
274
|
+
await turn();
|
|
275
|
+
expect(errors()).toEqual([]);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* schema_editor_openers.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* What opens something in C_YUI_SCHEMA_EDITOR is a NAMED control
|
|
5
|
+
* (REV-CLOUD V24.5.4):
|
|
6
|
+
*
|
|
7
|
+
* - a card of the treedbs screen (a treedb, the leftovers of a
|
|
8
|
+
* deletion) is a role=button with a title and an aria-label,
|
|
9
|
+
* its counts its description; up to 7.26.40 it had neither;
|
|
10
|
+
* - a row of the topics screen keeps the table's semantics: it was
|
|
11
|
+
* a `<tr role=button>`, which unmakes the row for a reader (a
|
|
12
|
+
* button has no cells) and had no name either. Its opener is a
|
|
13
|
+
* real button in the name cell, named by the topic; the pointer
|
|
14
|
+
* still opens the topic from anywhere in the row.
|
|
15
|
+
*
|
|
16
|
+
* A real C_YUI_SCHEMA_EDITOR on a document double, driven through
|
|
17
|
+
* its FSM.
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2026, ArtGins.
|
|
20
|
+
* All Rights Reserved.
|
|
21
|
+
***********************************************************************/
|
|
22
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
23
|
+
import {install_dom_double, fake_event} from "../test/dom_double.js";
|
|
24
|
+
|
|
25
|
+
install_dom_double();
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
SDATA_END,
|
|
29
|
+
gclass_create,
|
|
30
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
31
|
+
gobj_start, gobj_send_event, gobj_read_attr, gobj_current_state,
|
|
32
|
+
gobj_change_state, refresh_language,
|
|
33
|
+
set_log_callback,
|
|
34
|
+
} = await import("@yuneta/gobj-js");
|
|
35
|
+
const {register_c_yui_schema_editor} = await import("./c_yui_schema_editor.js");
|
|
36
|
+
|
|
37
|
+
const logged = [];
|
|
38
|
+
const commands = [];
|
|
39
|
+
|
|
40
|
+
/* One treedb with two topics, and a topic whose treedb is gone (the
|
|
41
|
+
* leftover of a deletion: the orphans card). */
|
|
42
|
+
const RECORDS = {
|
|
43
|
+
treedbs: [{id: "db", schema_version: 4}],
|
|
44
|
+
topics: [
|
|
45
|
+
{id: "db.users", value: "users", order: 1, pkey: "id", topic_version: 2,
|
|
46
|
+
treedbs: ["treedbs^db^topics"]},
|
|
47
|
+
{id: "db.roles", value: "roles", order: 2, pkey: "id", topic_version: 1,
|
|
48
|
+
treedbs: ["treedbs^db^topics"]},
|
|
49
|
+
{id: "gone.left", value: "left", order: 1, pkey: "id", topic_version: 1,
|
|
50
|
+
treedbs: ["treedbs^gone^topics"]},
|
|
51
|
+
],
|
|
52
|
+
cols: [
|
|
53
|
+
{id: "db.users.id", value: "id", order: 1, type: "string",
|
|
54
|
+
flag: ["persistent", "required"], topics: ["topics^db.users^cols"]},
|
|
55
|
+
{id: "db.roles.id", value: "id", order: 1, type: "string",
|
|
56
|
+
flag: ["persistent", "required"], topics: ["topics^db.roles^cols"]},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function remote_command_parser(gobj, command, kw, src)
|
|
61
|
+
{
|
|
62
|
+
commands.push({command, kw, src});
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let yuno = null;
|
|
67
|
+
let seq = 0;
|
|
68
|
+
|
|
69
|
+
beforeAll(async () => {
|
|
70
|
+
const i18next = (await import("i18next")).default;
|
|
71
|
+
await i18next.init({lng: "en", resources: {}});
|
|
72
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
73
|
+
set_log_callback((level, msg) => {
|
|
74
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
75
|
+
});
|
|
76
|
+
gclass_create("C_TEST_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
77
|
+
gclass_create(
|
|
78
|
+
"C_TEST_EDITOR_HOST",
|
|
79
|
+
[["EV_POSITION_CHANGED", 0], ["EV_RECORD_WRITTEN", 0], ["EV_SCHEMA_CHECKED", 0]],
|
|
80
|
+
[["ST_IDLE", [
|
|
81
|
+
["EV_POSITION_CHANGED", () => 0, null],
|
|
82
|
+
["EV_RECORD_WRITTEN", () => 0, null],
|
|
83
|
+
["EV_SCHEMA_CHECKED", () => 0, null]
|
|
84
|
+
]]],
|
|
85
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
86
|
+
);
|
|
87
|
+
gclass_create(
|
|
88
|
+
"C_TEST_REMOTE",
|
|
89
|
+
[],
|
|
90
|
+
[["ST_SESSION", []]],
|
|
91
|
+
{mt_command_parser: remote_command_parser},
|
|
92
|
+
0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
93
|
+
);
|
|
94
|
+
register_c_yui_schema_editor();
|
|
95
|
+
yuno = gobj_create_yuno("openers_yuno", "C_TEST_HOST", {});
|
|
96
|
+
gobj_start(yuno);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
logged.length = 0;
|
|
101
|
+
commands.length = 0;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
function errors()
|
|
105
|
+
{
|
|
106
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Answer every `nodes` the editor asked, as a transport does. */
|
|
110
|
+
function answer_the_load(editor, remote, records)
|
|
111
|
+
{
|
|
112
|
+
const asked = commands.filter((c) => c.command === "nodes");
|
|
113
|
+
commands.length = 0;
|
|
114
|
+
for(const c of asked) {
|
|
115
|
+
gobj_send_event(editor, "EV_MT_COMMAND_ANSWER", {
|
|
116
|
+
result: 0,
|
|
117
|
+
data: (records || RECORDS)[c.kw.topic_name],
|
|
118
|
+
__md_iev__: {command_stack: [{command: "nodes", kw: c.kw}]}
|
|
119
|
+
}, remote);
|
|
120
|
+
}
|
|
121
|
+
return asked.length;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* An editor with its schemas loaded, on the screen of `subpath`. */
|
|
125
|
+
function build(subpath, records)
|
|
126
|
+
{
|
|
127
|
+
const name = `openers_${++seq}`;
|
|
128
|
+
const remote = gobj_create_service(`${name}_remote`, "C_TEST_REMOTE", {}, yuno);
|
|
129
|
+
gobj_change_state(remote, "ST_SESSION");
|
|
130
|
+
const host = gobj_create(`${name}_host`, "C_TEST_EDITOR_HOST", {}, yuno);
|
|
131
|
+
const editor = gobj_create(`${name}_editor`, "C_YUI_SCHEMA_EDITOR", {
|
|
132
|
+
gobj_remote_yuno: remote,
|
|
133
|
+
treedb_name: "treedb_system_schema",
|
|
134
|
+
base_route: "/schemas"
|
|
135
|
+
}, host);
|
|
136
|
+
gobj_start(editor);
|
|
137
|
+
expect(answer_the_load(editor, remote, records)).toBe(3);
|
|
138
|
+
gobj_send_event(editor, "EV_SHOW", {subpath: subpath}, host);
|
|
139
|
+
return editor;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function root(editor)
|
|
143
|
+
{
|
|
144
|
+
return gobj_read_attr(editor, "$container");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* The text of the element an IDREF of `$el` points at, in its tree. */
|
|
148
|
+
function referenced_text($el, attr)
|
|
149
|
+
{
|
|
150
|
+
let $top = $el;
|
|
151
|
+
while($top.parentNode) {
|
|
152
|
+
$top = $top.parentNode;
|
|
153
|
+
}
|
|
154
|
+
return ($el.getAttribute(attr) || "").split(/\s+/).filter(Boolean).map((id) => {
|
|
155
|
+
const $ref = $top.querySelector(`#${id}`);
|
|
156
|
+
expect(!!$ref, `${attr} points at '${id}', which is not in its tree`).toBe(true);
|
|
157
|
+
return $ref.textContent;
|
|
158
|
+
}).join(" ");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
describe("a card of the treedbs screen", () => {
|
|
162
|
+
test("is a named control: a title, an aria-label, and its counts as its description", () => {
|
|
163
|
+
const editor = build("");
|
|
164
|
+
expect(gobj_current_state(editor)).toBe("ST_TREEDBS");
|
|
165
|
+
|
|
166
|
+
const $card = root(editor).querySelector(".SCHEMA_TREEDB_CARD");
|
|
167
|
+
expect(!!$card).toBe(true);
|
|
168
|
+
expect($card.getAttribute("role")).toBe("button");
|
|
169
|
+
expect($card.getAttribute("tabindex")).toBe("0");
|
|
170
|
+
/* The treedb's name is DATA: it is not translated. */
|
|
171
|
+
expect($card.getAttribute("title")).toBe("db");
|
|
172
|
+
expect($card.getAttribute("aria-label")).toBe("db");
|
|
173
|
+
expect($card.getAttribute("data-i18n-aria-label")).toBe(null);
|
|
174
|
+
expect(referenced_text($card, "aria-describedby")).toBe("topics2version4");
|
|
175
|
+
expect(errors()).toEqual([]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("the orphans card is named by its key, and changes language with the page", async () => {
|
|
179
|
+
const i18next = (await import("i18next")).default;
|
|
180
|
+
i18next.addResourceBundle("es", "translation", {"orphans": "Huérfanos"}, true, true);
|
|
181
|
+
const editor = build("");
|
|
182
|
+
|
|
183
|
+
const $card = root(editor).querySelector(".SCHEMA_ORPHAN_CARD");
|
|
184
|
+
expect(!!$card).toBe(true);
|
|
185
|
+
expect($card.getAttribute("role")).toBe("button");
|
|
186
|
+
expect($card.getAttribute("title")).toBe("orphans");
|
|
187
|
+
expect($card.getAttribute("aria-label")).toBe("orphans");
|
|
188
|
+
expect($card.getAttribute("data-i18n-title")).toBe("orphans");
|
|
189
|
+
expect($card.getAttribute("data-i18n-aria-label")).toBe("orphans");
|
|
190
|
+
expect($card.querySelector(".SCHEMA_ORPHAN_CARD_NAME").getAttribute("data-i18n")).toBe("orphans");
|
|
191
|
+
|
|
192
|
+
/* The text of its name carries the key too (data-i18n): the
|
|
193
|
+
* double does not translate text nodes, a browser does. */
|
|
194
|
+
refresh_language(root(editor), i18next.getFixedT("es"));
|
|
195
|
+
expect($card.getAttribute("title")).toBe("Huérfanos");
|
|
196
|
+
expect($card.getAttribute("aria-label")).toBe("Huérfanos");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("Enter and Space open it, through the machine", () => {
|
|
200
|
+
for(const key of ["Enter", " "]) {
|
|
201
|
+
const editor = build("");
|
|
202
|
+
const $card = root(editor).querySelector(".SCHEMA_TREEDB_CARD");
|
|
203
|
+
const ev = fake_event("keydown", {key: key});
|
|
204
|
+
$card.dispatchEvent(ev);
|
|
205
|
+
expect(ev.defaultPrevented).toBe(true); // Space would scroll the page
|
|
206
|
+
expect(gobj_current_state(editor)).toBe("ST_TOPICS");
|
|
207
|
+
}
|
|
208
|
+
expect(errors()).toEqual([]);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe("a row of the topics screen", () => {
|
|
213
|
+
test("is a row of the table, not a button; its opener is a real button in the name cell, named by the topic", () => {
|
|
214
|
+
const editor = build("db");
|
|
215
|
+
expect(gobj_current_state(editor)).toBe("ST_TOPICS");
|
|
216
|
+
|
|
217
|
+
const $rows = root(editor).querySelectorAll(".SCHEMA_TOPIC_ROW");
|
|
218
|
+
expect($rows.length).toBe(2);
|
|
219
|
+
for(const $row of $rows) {
|
|
220
|
+
expect($row.tagName).toBe("TR");
|
|
221
|
+
expect($row.getAttribute("role")).toBe(null);
|
|
222
|
+
expect($row.getAttribute("tabindex")).toBe(null);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const $open = $rows[0].querySelector(".SCHEMA_TOPIC_NAME .SCHEMA_TOPIC_OPEN");
|
|
226
|
+
expect(!!$open).toBe(true);
|
|
227
|
+
expect($open.tagName).toBe("BUTTON");
|
|
228
|
+
expect($open.getAttribute("type")).toBe("button");
|
|
229
|
+
/* The topic's name is DATA: it is not translated. */
|
|
230
|
+
expect($open.getAttribute("title")).toBe("users");
|
|
231
|
+
expect($open.getAttribute("aria-label")).toBe("users");
|
|
232
|
+
expect($open.textContent).toBe("users");
|
|
233
|
+
expect(errors()).toEqual([]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("its opener opens the topic -- a key presses a <button> with no handler of ours", () => {
|
|
237
|
+
const editor = build("db");
|
|
238
|
+
root(editor).querySelector(".SCHEMA_TOPIC_ROW .SCHEMA_TOPIC_OPEN").click();
|
|
239
|
+
expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
|
|
240
|
+
expect(errors()).toEqual([]);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("the pointer still opens it from anywhere in the row, and not from a row action", () => {
|
|
244
|
+
const editor = build("db");
|
|
245
|
+
const $row = root(editor).querySelector(".SCHEMA_TOPIC_ROW");
|
|
246
|
+
|
|
247
|
+
/* A press on a row action is the action's, not the row's. */
|
|
248
|
+
const $edit = $row.querySelector(".SCHEMA_TOPIC_EDIT");
|
|
249
|
+
expect(!!$edit).toBe(true);
|
|
250
|
+
$row.dispatchEvent(fake_event("click", {target: $edit}));
|
|
251
|
+
expect(gobj_current_state(editor)).toBe("ST_TOPICS");
|
|
252
|
+
|
|
253
|
+
$row.dispatchEvent(fake_event("click", {target: $row.querySelector(".SCHEMA_TOPIC_PKEY")}));
|
|
254
|
+
expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
|
|
255
|
+
expect(errors()).toEqual([]);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
/* Two generations of one schema in a store: two topics named
|
|
259
|
+
* "users", told apart only by their ids. */
|
|
260
|
+
test("two topics of one name: each opener says the id that tells them apart", () => {
|
|
261
|
+
const records = {
|
|
262
|
+
treedbs: RECORDS.treedbs,
|
|
263
|
+
topics: [
|
|
264
|
+
{id: "db.users", value: "users", order: 1, pkey: "id", topic_version: 2,
|
|
265
|
+
treedbs: ["treedbs^db^topics"]},
|
|
266
|
+
{id: "17", value: "users", order: 2, pkey: "id", topic_version: 1,
|
|
267
|
+
treedbs: ["treedbs^db^topics"]},
|
|
268
|
+
],
|
|
269
|
+
cols: [],
|
|
270
|
+
};
|
|
271
|
+
const editor = build("db", records);
|
|
272
|
+
const $opens = root(editor).querySelectorAll(".SCHEMA_TOPIC_OPEN");
|
|
273
|
+
expect($opens.length).toBe(2);
|
|
274
|
+
expect($opens.map(($o) => $o.getAttribute("aria-label"))).toEqual(["users", "users"]);
|
|
275
|
+
expect($opens.map(($o) => referenced_text($o, "aria-describedby"))).toEqual(["db.users", "17"]);
|
|
276
|
+
|
|
277
|
+
/* And each opens its own: by id, the name would open the first. */
|
|
278
|
+
$opens[1].click();
|
|
279
|
+
expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
|
|
280
|
+
expect(editor.priv.topic_name).toBe("17");
|
|
281
|
+
expect(errors()).toEqual([]);
|
|
282
|
+
});
|
|
283
|
+
});
|