@yuneta/gobj-ui 5.16.0 → 6.0.0
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 +62 -10
- package/dist/gobj-ui.cjs.js +363 -60
- package/dist/gobj-ui.es.js +363 -60
- package/package.json +3 -3
- package/src/c_g6_nodes_tree.js +38 -24
- package/src/c_yui_form.js +11 -3
- package/src/c_yui_treedb_schema.js +348 -43
- package/src/c_yui_treedb_topic_with_form.js +5 -1
- package/src/treedb_node_label.js +79 -0
- package/src/treedb_node_label.test.js +106 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* treedb_node_label.test.js
|
|
3
|
+
*
|
|
4
|
+
* The label of a treedb graph node: the pkey when it names the
|
|
5
|
+
* record, the secondary key when the pkey is synthetic.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2026, ArtGins.
|
|
8
|
+
* All Rights Reserved.
|
|
9
|
+
***********************************************************************/
|
|
10
|
+
import {describe, it, expect} from "vitest";
|
|
11
|
+
|
|
12
|
+
import {node_label} from "./treedb_node_label.js";
|
|
13
|
+
|
|
14
|
+
/* The `cols` topic of treedb_system_schema, as the backend describes
|
|
15
|
+
* it: keyed by rowid, named in `value` (its pkey2). */
|
|
16
|
+
const COLS_DESC = {
|
|
17
|
+
topic_name: "cols",
|
|
18
|
+
pkey: "id",
|
|
19
|
+
pkey2s: ["value"],
|
|
20
|
+
cols: [
|
|
21
|
+
{id: "id", header: "rowid", type: "string", flag: ["persistent", "rowid"]},
|
|
22
|
+
{id: "value", header: "Column", type: "string", flag: ["persistent", "required"]},
|
|
23
|
+
{id: "header", header: "Header", type: "string", flag: ["persistent", "required"]},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/* An ordinary topic: the pkey IS the name. */
|
|
28
|
+
const REALMS_DESC = {
|
|
29
|
+
topic_name: "realms",
|
|
30
|
+
pkey: "id",
|
|
31
|
+
cols: [
|
|
32
|
+
{id: "id", header: "id", type: "string", flag: ["persistent", "required"]},
|
|
33
|
+
{id: "realm_name", header: "Name", type: "string", flag: ["persistent", "required"]},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe("node_label", () => {
|
|
38
|
+
it("uses the secondary key when the pkey is a rowid", () => {
|
|
39
|
+
expect(node_label(COLS_DESC, {id: "181", value: "yuno_role"}))
|
|
40
|
+
.toBe("yuno_role");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("uses the pkey when it names the record", () => {
|
|
44
|
+
expect(node_label(REALMS_DESC, {id: "artgins.utilities.all", realm_name: "all"}))
|
|
45
|
+
.toBe("artgins.utilities.all");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("accepts a pkey2s declared as a bare string", () => {
|
|
49
|
+
let desc = {...COLS_DESC, pkey2s: "value"};
|
|
50
|
+
expect(node_label(desc, {id: "181", value: "yuno_role"})).toBe("yuno_role");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("treats a qualified pkey like a rowid one", () => {
|
|
54
|
+
let desc = {
|
|
55
|
+
...COLS_DESC,
|
|
56
|
+
cols: [
|
|
57
|
+
{id: "id", type: "string", flag: ["persistent", "qualified"]},
|
|
58
|
+
{id: "value", type: "string", flag: ["persistent", "required"]},
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
expect(node_label(desc, {
|
|
62
|
+
id: "treedb_yunovatioscodb.yunos.yuno_role",
|
|
63
|
+
value: "yuno_role",
|
|
64
|
+
})).toBe("yuno_role");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("treats a uuid pkey like a rowid one", () => {
|
|
68
|
+
let desc = {
|
|
69
|
+
...COLS_DESC,
|
|
70
|
+
cols: [
|
|
71
|
+
{id: "id", type: "string", flag: ["persistent", "uuid"]},
|
|
72
|
+
{id: "value", type: "string", flag: ["persistent", "required"]},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
expect(node_label(desc, {id: "3f2a…", value: "named"})).toBe("named");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("falls back to the id when the desc carries no pkey2s (older node)", () => {
|
|
79
|
+
let desc = {topic_name: "cols", pkey: "id", cols: COLS_DESC.cols};
|
|
80
|
+
expect(node_label(desc, {id: "181", value: "yuno_role"})).toBe("181");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("falls back to the id when the secondary key is empty in the record", () => {
|
|
84
|
+
expect(node_label(COLS_DESC, {id: "181", value: ""})).toBe("181");
|
|
85
|
+
expect(node_label(COLS_DESC, {id: "181"})).toBe("181");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("honours a pkey that is not called 'id'", () => {
|
|
89
|
+
let desc = {
|
|
90
|
+
topic_name: "x",
|
|
91
|
+
pkey: "key",
|
|
92
|
+
pkey2s: ["name"],
|
|
93
|
+
cols: [
|
|
94
|
+
{id: "key", type: "string", flag: ["persistent", "rowid"]},
|
|
95
|
+
{id: "name", type: "string", flag: ["persistent", "required"]},
|
|
96
|
+
/* A col called `id` that is NOT the pkey must not decide. */
|
|
97
|
+
{id: "id", type: "string", flag: ["persistent"]},
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
expect(node_label(desc, {id: "7", key: "7", name: "seven"})).toBe("seven");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("survives a desc with no cols", () => {
|
|
104
|
+
expect(node_label({topic_name: "x", pkey: "id"}, {id: "42"})).toBe("42");
|
|
105
|
+
});
|
|
106
|
+
});
|