@yuneta/gobj-ui 7.29.5 → 7.29.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.
- package/README.md +30 -29
- package/dist/gobj-ui.cjs.js +19 -19
- package/dist/gobj-ui.es.js +19 -19
- package/package.json +2 -2
- package/scripts/validate-locales.mjs +1 -1
- package/src/c_g6_nodes_tree.js +3 -3
- package/src/c_yui_treedb_topics.js +5 -5
- package/src/c_yui_window.js +1 -1
- package/src/lib_icons.test.js +1 -1
- package/src/named_controls.wiring.test.js +2 -2
- package/src/schema_version_bump.test.js +6 -6
- package/src/shell_dialog_names.wiring.test.js +2 -2
- package/src/treedb_fold_model.js +4 -4
- package/src/treedb_fold_model.test.js +182 -160
- package/src/treedb_layout.js +9 -9
- package/src/treedb_layout.test.js +17 -17
- package/src/yui_dev.js +1 -1
- package/src/yui_dev_copy.test.js +2 -2
- package/src/yui_icons.css +5 -6
- package/src/yui_row_search.test.js +16 -16
- package/src/yui_shell_last_route.test.js +2 -2
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The fold arithmetic of the treedb graph, pinned.
|
|
5
5
|
*
|
|
6
|
-
* A small
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* A small inventory on two axes: sites (a self-referent tree,
|
|
7
|
+
* where a thing is), owners (a self-referent tree of its own, who
|
|
8
|
+
* owns it), devices hanging from a site AND an owner, notes
|
|
9
|
+
* hanging from a site or a device, and a topic with hooks and no
|
|
10
|
+
* fkeys (extended) whose children must be roots.
|
|
10
11
|
***********************************************************************/
|
|
11
12
|
import { describe, test, expect } from "vitest";
|
|
12
13
|
import {
|
|
@@ -34,45 +35,51 @@ import {
|
|
|
34
35
|
fold_is_hierarchical,
|
|
35
36
|
} from "./treedb_fold_model.js";
|
|
36
37
|
|
|
37
|
-
const
|
|
38
|
-
topic_name: "
|
|
38
|
+
const sites_desc = {
|
|
39
|
+
topic_name: "sites",
|
|
39
40
|
node_treedb_type: "entity",
|
|
40
41
|
cols: [
|
|
41
42
|
{id: "id", flag: []},
|
|
42
|
-
{id: "
|
|
43
|
-
{id: "
|
|
44
|
-
{id: "devices", flag: ["hook"], hook: {devices: "
|
|
45
|
-
{id: "
|
|
43
|
+
{id: "site", flag: ["fkey"], fkey: {sites: "sites"}},
|
|
44
|
+
{id: "sites", flag: ["hook"], hook: {sites: "site"}},
|
|
45
|
+
{id: "devices", flag: ["hook"], hook: {devices: "site"}},
|
|
46
|
+
{id: "notes", flag: ["hook"], hook: {notes: "site"}},
|
|
46
47
|
],
|
|
47
48
|
};
|
|
48
49
|
const devices_desc = {
|
|
49
50
|
topic_name: "devices",
|
|
50
|
-
node_treedb_type: "
|
|
51
|
+
node_treedb_type: "entity",
|
|
51
52
|
cols: [
|
|
52
53
|
{id: "id", flag: []},
|
|
53
|
-
{id: "
|
|
54
|
-
{id: "
|
|
54
|
+
{id: "site", flag: ["fkey"], fkey: {sites: "devices"}},
|
|
55
|
+
{id: "owner", flag: ["fkey"], fkey: {owners: "devices"}},
|
|
55
56
|
{id: "photo", flag: ["fkey", "file"], fkey: {__assets__: "photos"}},
|
|
57
|
+
{id: "notes", flag: ["hook"], hook: {notes: "device"}},
|
|
56
58
|
],
|
|
57
59
|
};
|
|
58
|
-
const
|
|
59
|
-
topic_name: "
|
|
60
|
+
const notes_desc = {
|
|
61
|
+
topic_name: "notes",
|
|
62
|
+
node_treedb_type: "child",
|
|
63
|
+
cols: [
|
|
64
|
+
{id: "id", flag: []},
|
|
65
|
+
{id: "site", flag: ["fkey"], fkey: {sites: "notes"}},
|
|
66
|
+
{id: "device", flag: ["fkey"], fkey: {devices: "notes"}},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
/* owners inside owners: a second HIERARCHICAL topic, on an axis the
|
|
70
|
+
* sites know nothing of */
|
|
71
|
+
const owners_desc = {
|
|
72
|
+
topic_name: "owners",
|
|
60
73
|
node_treedb_type: "entity",
|
|
61
74
|
cols: [
|
|
62
75
|
{id: "id", flag: []},
|
|
63
|
-
{id: "
|
|
64
|
-
{id: "
|
|
76
|
+
{id: "parent", flag: ["fkey"], fkey: {owners: "owners"}},
|
|
77
|
+
{id: "owners", flag: ["hook"], hook: {owners: "parent"}},
|
|
78
|
+
{id: "devices", flag: ["hook"], hook: {devices: "owner"}},
|
|
65
79
|
],
|
|
66
80
|
};
|
|
67
|
-
/* controllers inside controllers: a second HIERARCHICAL topic */
|
|
68
|
-
const controllers_self = Object.assign({}, controllers_desc, {
|
|
69
|
-
cols: controllers_desc.cols.concat([
|
|
70
|
-
{id: "controllers", flag: ["hook"], hook: {controllers: "parent"}},
|
|
71
|
-
{id: "parent", flag: ["fkey"], fkey: {controllers: "controllers"}},
|
|
72
|
-
]),
|
|
73
|
-
});
|
|
74
81
|
const groups_desc = {
|
|
75
|
-
topic_name: "
|
|
82
|
+
topic_name: "groups",
|
|
76
83
|
node_treedb_type: "extended",
|
|
77
84
|
cols: [
|
|
78
85
|
{id: "id", flag: []},
|
|
@@ -82,34 +89,36 @@ const groups_desc = {
|
|
|
82
89
|
|
|
83
90
|
const descs = {
|
|
84
91
|
__graphs__: {topic_name: "__graphs__", cols: []},
|
|
85
|
-
|
|
92
|
+
sites: sites_desc,
|
|
86
93
|
devices: devices_desc,
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
notes: notes_desc,
|
|
95
|
+
owners: owners_desc,
|
|
96
|
+
groups: groups_desc,
|
|
89
97
|
};
|
|
90
98
|
|
|
91
|
-
/* region > (north, south); north > site1; site1
|
|
92
|
-
*
|
|
99
|
+
/* region > (north, south); north > site1; site1 holds the devices and
|
|
100
|
+
* one note n1; the owner o1, a root of the owners tree, owns d0..d9. */
|
|
93
101
|
function make_records(n_devices)
|
|
94
102
|
{
|
|
95
103
|
let devices = [];
|
|
96
104
|
for(let i = 0; i < n_devices; i++) {
|
|
97
|
-
let rec = {id: `d${i}`,
|
|
105
|
+
let rec = {id: `d${i}`, site: "sites^site1^devices", photo: "x^y^photos"};
|
|
98
106
|
if(i < 10) {
|
|
99
|
-
rec.
|
|
107
|
+
rec.owner = ["owners^o1^devices"];
|
|
100
108
|
}
|
|
101
109
|
devices.push(rec);
|
|
102
110
|
}
|
|
103
111
|
return {
|
|
104
|
-
|
|
105
|
-
{id: "region",
|
|
106
|
-
{id: "north",
|
|
107
|
-
{id: "south",
|
|
108
|
-
{id: "site1",
|
|
112
|
+
sites: [
|
|
113
|
+
{id: "region", site: ""},
|
|
114
|
+
{id: "north", site: "sites^region^sites"},
|
|
115
|
+
{id: "south", site: "sites^region^sites"},
|
|
116
|
+
{id: "site1", site: "sites^north^sites"},
|
|
109
117
|
],
|
|
110
118
|
devices: devices,
|
|
111
|
-
|
|
112
|
-
|
|
119
|
+
notes: [{id: "n1", site: "sites^site1^notes"}],
|
|
120
|
+
owners: [{id: "o1", parent: ""}],
|
|
121
|
+
groups: [{id: "g1"}],
|
|
113
122
|
};
|
|
114
123
|
}
|
|
115
124
|
|
|
@@ -118,106 +127,111 @@ const K = (t, id) => `${t}^${id}`;
|
|
|
118
127
|
describe("the model", () => {
|
|
119
128
|
test("every record is a node, system topics are skipped", () => {
|
|
120
129
|
let m = fold_build_model(descs, make_records(3));
|
|
121
|
-
expect(m.nodes.size).toBe(4 + 3 + 1 + 1);
|
|
122
|
-
expect(m.topics).toEqual(["
|
|
130
|
+
expect(m.nodes.size).toBe(4 + 3 + 1 + 1 + 1);
|
|
131
|
+
expect(m.topics).toEqual(["sites", "devices", "notes", "owners", "groups"]);
|
|
123
132
|
});
|
|
124
133
|
|
|
125
134
|
test("children hang from the hook the fkey names, in record order", () => {
|
|
126
135
|
let m = fold_build_model(descs, make_records(3));
|
|
127
|
-
expect(m.groups.get(fold_group_key(K("
|
|
128
|
-
.toEqual([K("
|
|
129
|
-
expect(m.groups.get(fold_group_key(K("
|
|
136
|
+
expect(m.groups.get(fold_group_key(K("sites", "region"), "sites")))
|
|
137
|
+
.toEqual([K("sites", "north"), K("sites", "south")]);
|
|
138
|
+
expect(m.groups.get(fold_group_key(K("sites", "site1"), "devices")))
|
|
130
139
|
.toEqual([K("devices", "d0"), K("devices", "d1"), K("devices", "d2")]);
|
|
131
|
-
expect(m.groups.get(fold_group_key(K("
|
|
140
|
+
expect(m.groups.get(fold_group_key(K("owners", "o1"), "devices")))
|
|
132
141
|
.toEqual([K("devices", "d0"), K("devices", "d1"), K("devices", "d2")]);
|
|
133
142
|
});
|
|
134
143
|
|
|
135
|
-
test("a device has two parents and is one node", () => {
|
|
144
|
+
test("a device has two parents, of two topics, and is one node", () => {
|
|
136
145
|
let m = fold_build_model(descs, make_records(3));
|
|
137
146
|
let d0 = m.nodes.get(K("devices", "d0"));
|
|
138
147
|
expect(d0.parents.map((p) => p.node_key).sort())
|
|
139
|
-
.toEqual([K("
|
|
148
|
+
.toEqual([K("owners", "o1"), K("sites", "site1")]);
|
|
140
149
|
});
|
|
141
150
|
|
|
142
151
|
test("roots: no drawable parent -- and a fkey into a topic nobody fetched is not a parent", () => {
|
|
143
152
|
let m = fold_build_model(descs, make_records(3));
|
|
144
|
-
expect(m.groups.get(fold_root_group_key("
|
|
153
|
+
expect(m.groups.get(fold_root_group_key("sites"))).toEqual([K("sites", "region")]);
|
|
145
154
|
expect(m.groups.get(fold_root_group_key("devices"))).toBeUndefined();
|
|
146
155
|
/* `photo` names __assets__, which has no desc: ignored */
|
|
147
156
|
expect(m.nodes.get(K("devices", "d0")).parents.length).toBe(2);
|
|
148
|
-
expect(m.groups.get(fold_root_group_key("
|
|
157
|
+
expect(m.groups.get(fold_root_group_key("groups"))).toEqual([K("groups", "g1")]);
|
|
158
|
+
expect(m.groups.get(fold_root_group_key("owners"))).toEqual([K("owners", "o1")]);
|
|
149
159
|
});
|
|
150
160
|
|
|
151
161
|
test("a child of an `extended` parent only has no parent: the engine draws no edge to one", () => {
|
|
152
162
|
let recs = make_records(1);
|
|
153
|
-
recs.devices[0] = {id: "d0", group: "
|
|
163
|
+
recs.devices[0] = {id: "d0", group: "groups^g1^members"};
|
|
154
164
|
let m = fold_build_model(descs, recs);
|
|
155
|
-
expect(m.nodes.get(K("
|
|
156
|
-
/* devices hang from
|
|
165
|
+
expect(m.nodes.get(K("groups", "g1")).hooks).toEqual({});
|
|
166
|
+
/* devices hang from sites (the main topic), so a device with
|
|
157
167
|
* no parent is LOOSE, not a root -- see the "main topic" block */
|
|
158
168
|
expect(m.loose.devices).toEqual([K("devices", "d0")]);
|
|
159
169
|
expect(m.groups.get(fold_root_group_key("devices"))).toBeUndefined();
|
|
160
170
|
/* and with no main topic it is a plain root */
|
|
161
|
-
let m2 = fold_build_model({
|
|
162
|
-
expect(m2.main_topic).toBe("
|
|
163
|
-
let m3 = fold_build_model({devices: devices_desc,
|
|
171
|
+
let m2 = fold_build_model({sites: sites_desc, devices: devices_desc, groups: groups_desc}, recs, {main_topic: ""});
|
|
172
|
+
expect(m2.main_topic).toBe("sites"); /* "" means "deduce", and sites reaches devices */
|
|
173
|
+
let m3 = fold_build_model({devices: devices_desc, groups: groups_desc}, recs);
|
|
164
174
|
expect(m3.main_topic).toBe("");
|
|
165
175
|
expect(m3.groups.get(fold_root_group_key("devices"))).toEqual([K("devices", "d0")]);
|
|
166
176
|
});
|
|
167
177
|
|
|
168
178
|
test("a cycle with no way in gets one root, not a row of them", () => {
|
|
169
179
|
let recs = {
|
|
170
|
-
|
|
171
|
-
{id: "a",
|
|
172
|
-
{id: "b",
|
|
173
|
-
{id: "c",
|
|
180
|
+
sites: [
|
|
181
|
+
{id: "a", site: "sites^c^sites"},
|
|
182
|
+
{id: "b", site: "sites^a^sites"},
|
|
183
|
+
{id: "c", site: "sites^b^sites"},
|
|
174
184
|
],
|
|
175
185
|
};
|
|
176
|
-
let m = fold_build_model({
|
|
177
|
-
expect(m.groups.get(fold_root_group_key("
|
|
186
|
+
let m = fold_build_model({sites: sites_desc}, recs);
|
|
187
|
+
expect(m.groups.get(fold_root_group_key("sites"))).toEqual([K("sites", "a")]);
|
|
178
188
|
let st = fold_new_state(24);
|
|
179
189
|
fold_expand_all(m, st);
|
|
180
190
|
expect(fold_visible_set(m, st).size).toBe(3);
|
|
181
191
|
});
|
|
182
192
|
|
|
183
193
|
test("group keys split back", () => {
|
|
184
|
-
expect(fold_split_group_key("
|
|
185
|
-
.toEqual({node_key: "
|
|
194
|
+
expect(fold_split_group_key("sites^site1|devices"))
|
|
195
|
+
.toEqual({node_key: "sites^site1", hook: "devices"});
|
|
186
196
|
expect(fold_split_group_key("|devices")).toEqual({node_key: "", hook: "devices"});
|
|
187
197
|
expect(fold_split_group_key("nope")).toBeNull();
|
|
188
198
|
});
|
|
189
199
|
});
|
|
190
200
|
|
|
191
201
|
describe("main topic, hidden topics, loose records", () => {
|
|
192
|
-
test("the main topic is the one whose hooks reach the most others;
|
|
193
|
-
expect(fold_main_topic(descs)).toBe("
|
|
202
|
+
test("the main topic is the one whose hooks reach the most others; sites, not groups", () => {
|
|
203
|
+
expect(fold_main_topic(descs)).toBe("sites");
|
|
194
204
|
let m = fold_build_model(descs, make_records(3));
|
|
195
|
-
expect(m.main_topic).toBe("
|
|
196
|
-
expect([...m.linked].sort()).toEqual(["
|
|
197
|
-
|
|
205
|
+
expect(m.main_topic).toBe("sites");
|
|
206
|
+
expect([...m.linked].sort()).toEqual(["devices", "notes", "sites"]);
|
|
207
|
+
/* owners is a tree of its own: the sites reach none of it */
|
|
208
|
+
expect(m.linked.has("owners")).toBe(false);
|
|
209
|
+
expect(m.linked.has("groups")).toBe(false);
|
|
198
210
|
});
|
|
199
211
|
|
|
200
212
|
test("only a topic hooked to ITSELF can be the main one", () => {
|
|
201
|
-
expect(fold_is_hierarchical(descs, "
|
|
202
|
-
expect(fold_is_hierarchical(descs, "
|
|
203
|
-
expect(fold_is_hierarchical(descs, "
|
|
213
|
+
expect(fold_is_hierarchical(descs, "sites")).toBe(true);
|
|
214
|
+
expect(fold_is_hierarchical(descs, "owners")).toBe(true);
|
|
215
|
+
expect(fold_is_hierarchical(descs, "devices")).toBe(false);
|
|
216
|
+
expect(fold_is_hierarchical(descs, "notes")).toBe(false);
|
|
217
|
+
expect(fold_is_hierarchical(descs, "groups")).toBe(false);
|
|
204
218
|
/* c reaches x and nothing reaches itself: no trunk at all */
|
|
205
219
|
let c = {topic_name: "c", cols: [{id: "id", flag: []},
|
|
206
220
|
{id: "xs", flag: ["hook"], hook: {x: "c"}}]};
|
|
207
221
|
let x = {topic_name: "x", cols: [{id: "id", flag: []}, {id: "c", flag: ["fkey"]}]};
|
|
208
222
|
expect(fold_main_topic({c: c, x: x})).toBe("");
|
|
209
|
-
/* a tree of
|
|
210
|
-
expect(fold_main_topic({
|
|
223
|
+
/* a tree of sites alone, reaching no other topic, is still a trunk */
|
|
224
|
+
expect(fold_main_topic({sites: sites_desc})).toBe("sites");
|
|
211
225
|
});
|
|
212
226
|
|
|
213
227
|
test("the schema's mark wins over the deduction, among hierarchical topics", () => {
|
|
214
|
-
|
|
215
|
-
expect(fold_main_topic(
|
|
216
|
-
let marked = Object.assign({},
|
|
217
|
-
expect(fold_main_topic(marked)).toBe("
|
|
228
|
+
/* two hierarchical topics; sites reaches more (devices, notes) */
|
|
229
|
+
expect(fold_main_topic(descs)).toBe("sites");
|
|
230
|
+
let marked = Object.assign({}, descs, {owners: Object.assign({}, owners_desc, {main_topic: true})});
|
|
231
|
+
expect(fold_main_topic(marked)).toBe("owners");
|
|
218
232
|
/* a mark on a topic that is not hierarchical is not a trunk */
|
|
219
233
|
let wrong = Object.assign({}, descs, {devices: Object.assign({}, devices_desc, {main_topic: true})});
|
|
220
|
-
expect(fold_main_topic(wrong)).toBe("
|
|
234
|
+
expect(fold_main_topic(wrong)).toBe("sites");
|
|
221
235
|
});
|
|
222
236
|
|
|
223
237
|
test("a self-referent hook breaks a tie", () => {
|
|
@@ -233,18 +247,17 @@ describe("main topic, hidden topics, loose records", () => {
|
|
|
233
247
|
});
|
|
234
248
|
|
|
235
249
|
test("the reader's pick wins -- if it is a hierarchical topic", () => {
|
|
236
|
-
let
|
|
237
|
-
|
|
238
|
-
expect(m.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
expect(m.groups.get(fold_root_group_key("places"))).toEqual([K("places", "region")]);
|
|
250
|
+
let m = fold_build_model(descs, make_records(3), {main_topic: "owners"});
|
|
251
|
+
expect(m.main_topic).toBe("owners");
|
|
252
|
+
expect([...m.linked].sort()).toEqual(["devices", "notes", "owners"]);
|
|
253
|
+
/* sites is not linked to owners, so its roots are roots */
|
|
254
|
+
expect(m.groups.get(fold_root_group_key("sites"))).toEqual([K("sites", "region")]);
|
|
242
255
|
/* a pick the rule refuses is ignored, and the trunk is deduced */
|
|
243
|
-
let m2 = fold_build_model(descs, make_records(3), {main_topic: "
|
|
244
|
-
expect(m2.main_topic).toBe("
|
|
256
|
+
let m2 = fold_build_model(descs, make_records(3), {main_topic: "devices"});
|
|
257
|
+
expect(m2.main_topic).toBe("sites");
|
|
245
258
|
});
|
|
246
259
|
|
|
247
|
-
test("a device with no
|
|
260
|
+
test("a device with no site is LOOSE: counted, not a root, unless asked for", () => {
|
|
248
261
|
let recs = make_records(3);
|
|
249
262
|
recs.devices.push({id: "d_loose"});
|
|
250
263
|
let m = fold_build_model(descs, recs);
|
|
@@ -256,55 +269,56 @@ describe("main topic, hidden topics, loose records", () => {
|
|
|
256
269
|
expect(m2.loose.devices).toEqual([K("devices", "d_loose")]);
|
|
257
270
|
});
|
|
258
271
|
|
|
259
|
-
test("a
|
|
272
|
+
test("a note on a loose device only is loose too, and follows it", () => {
|
|
260
273
|
let recs = make_records(0);
|
|
261
|
-
recs.
|
|
262
|
-
recs.
|
|
274
|
+
recs.devices.push({id: "d_loose"});
|
|
275
|
+
recs.notes.push({id: "n_under", device: ["devices^d_loose^notes"]});
|
|
263
276
|
let m = fold_build_model(descs, recs);
|
|
264
|
-
expect(m.loose.
|
|
265
|
-
expect(m.loose.
|
|
277
|
+
expect(m.loose.devices).toEqual([K("devices", "d_loose")]);
|
|
278
|
+
expect(m.loose.notes).toEqual([K("notes", "n_under")]);
|
|
266
279
|
let st = fold_new_state(24);
|
|
267
280
|
fold_expand_all(m, st);
|
|
268
|
-
expect(fold_visible_set(m, st).has(K("
|
|
269
|
-
let m2 = fold_build_model(descs, recs, {loose_topics: ["
|
|
281
|
+
expect(fold_visible_set(m, st).has(K("notes", "n_under"))).toBe(false);
|
|
282
|
+
let m2 = fold_build_model(descs, recs, {loose_topics: ["devices"]});
|
|
270
283
|
fold_expand_all(m2, st);
|
|
271
|
-
expect(fold_visible_set(m2, st).has(K("
|
|
284
|
+
expect(fold_visible_set(m2, st).has(K("notes", "n_under"))).toBe(true);
|
|
272
285
|
});
|
|
273
286
|
|
|
274
287
|
test("a hidden topic leaves the model whole: no node, no pill, no edge", () => {
|
|
275
288
|
let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices"]});
|
|
276
|
-
expect(m.topics).toEqual(["
|
|
289
|
+
expect(m.topics).toEqual(["sites", "notes", "owners", "groups"]);
|
|
277
290
|
expect(m.totals.devices).toBe(30);
|
|
278
|
-
expect(m.nodes.get(K("
|
|
279
|
-
expect(fold_pills_of(m, fold_new_state(24), K("
|
|
280
|
-
.toEqual(["
|
|
291
|
+
expect(m.nodes.get(K("sites", "site1")).hooks.devices).toBeUndefined();
|
|
292
|
+
expect(fold_pills_of(m, fold_new_state(24), K("sites", "site1")).map((p) => p.hook))
|
|
293
|
+
.toEqual(["notes"]);
|
|
281
294
|
expect(m.hidden.has("devices")).toBe(true);
|
|
282
295
|
});
|
|
283
296
|
|
|
284
297
|
test("hiding a topic in the middle: what hung from it alone becomes loose", () => {
|
|
285
|
-
let m = fold_build_model(descs, make_records(12), {hidden_topics: ["
|
|
286
|
-
/* d0..d9 hang from site1 AND
|
|
298
|
+
let m = fold_build_model(descs, make_records(12), {hidden_topics: ["owners"]});
|
|
299
|
+
/* d0..d9 hang from site1 AND o1: still under site1 */
|
|
287
300
|
expect(m.nodes.get(K("devices", "d0")).parents.length).toBe(1);
|
|
288
301
|
expect(m.loose.devices).toEqual([]);
|
|
289
|
-
/*
|
|
290
|
-
* whatever has no parent left is a root --
|
|
291
|
-
* still hanging from it */
|
|
292
|
-
let m2 = fold_build_model(descs, make_records(2), {hidden_topics: ["
|
|
302
|
+
/* sites hidden = the main topic gone: nothing governs, and
|
|
303
|
+
* whatever has no parent left is a root -- o1, with d0 and d1
|
|
304
|
+
* still hanging from it, and n1 */
|
|
305
|
+
let m2 = fold_build_model(descs, make_records(2), {hidden_topics: ["sites"]});
|
|
293
306
|
expect(m2.main_topic).toBe("");
|
|
294
|
-
expect(m2.groups.get(fold_root_group_key("
|
|
307
|
+
expect(m2.groups.get(fold_root_group_key("owners"))).toEqual([K("owners", "o1")]);
|
|
308
|
+
expect(m2.groups.get(fold_root_group_key("notes"))).toEqual([K("notes", "n1")]);
|
|
295
309
|
expect(m2.groups.get(fold_root_group_key("devices"))).toBeUndefined();
|
|
296
|
-
let m3 = fold_build_model(descs, {devices: [{id: "d9"}]}, {hidden_topics: ["
|
|
310
|
+
let m3 = fold_build_model(descs, {devices: [{id: "d9"}]}, {hidden_topics: ["sites"]});
|
|
297
311
|
expect(m3.groups.get(fold_root_group_key("devices"))).toEqual([K("devices", "d9")]);
|
|
298
312
|
});
|
|
299
313
|
|
|
300
314
|
test("a topic shown again opens on its roots' first page: nobody folds the roots", () => {
|
|
301
315
|
let recs = make_records(3);
|
|
302
316
|
let st = fold_new_state(24);
|
|
303
|
-
let m = fold_build_model(descs, recs, {hidden_topics: ["
|
|
317
|
+
let m = fold_build_model(descs, recs, {hidden_topics: ["groups"]});
|
|
304
318
|
fold_expand_to_depth(m, st, 2);
|
|
305
|
-
expect(fold_visible_set(m, st).has(K("
|
|
319
|
+
expect(fold_visible_set(m, st).has(K("groups", "g1"))).toBe(false);
|
|
306
320
|
let m2 = fold_build_model(descs, recs);
|
|
307
|
-
expect(fold_visible_set(m2, st).has(K("
|
|
321
|
+
expect(fold_visible_set(m2, st).has(K("groups", "g1"))).toBe(true);
|
|
308
322
|
expect(fold_pending_groups(m2, st, fold_visible_set(m2, st))).toEqual([]);
|
|
309
323
|
});
|
|
310
324
|
|
|
@@ -313,7 +327,7 @@ describe("main topic, hidden topics, loose records", () => {
|
|
|
313
327
|
let st = fold_new_state(24);
|
|
314
328
|
let m = fold_build_model(descs, recs);
|
|
315
329
|
fold_expand_to_depth(m, st, 4);
|
|
316
|
-
let g = fold_group_key(K("
|
|
330
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
317
331
|
expect(fold_group_shown(m, st, g)).toBe(24);
|
|
318
332
|
let m_hidden = fold_build_model(descs, recs, {hidden_topics: ["devices"]});
|
|
319
333
|
expect(fold_group_shown(m_hidden, st, g)).toBe(0); /* no group: nothing shown */
|
|
@@ -328,7 +342,7 @@ describe("depth", () => {
|
|
|
328
342
|
let st = fold_new_state(24);
|
|
329
343
|
fold_expand_to_depth(m, st, 1);
|
|
330
344
|
expect([...fold_visible_set(m, st)].sort())
|
|
331
|
-
.toEqual([K("
|
|
345
|
+
.toEqual([K("groups", "g1"), K("owners", "o1"), K("sites", "region")]);
|
|
332
346
|
});
|
|
333
347
|
|
|
334
348
|
test("depth 2 opens the roots' hooks on their first page", () => {
|
|
@@ -336,10 +350,12 @@ describe("depth", () => {
|
|
|
336
350
|
let st = fold_new_state(24);
|
|
337
351
|
fold_expand_to_depth(m, st, 2);
|
|
338
352
|
let v = fold_visible_set(m, st);
|
|
339
|
-
expect(v.has(K("
|
|
340
|
-
expect(v.has(K("
|
|
341
|
-
expect(v.has(K("
|
|
342
|
-
expect(v.has(K("devices", "
|
|
353
|
+
expect(v.has(K("sites", "north"))).toBe(true);
|
|
354
|
+
expect(v.has(K("sites", "south"))).toBe(true);
|
|
355
|
+
expect(v.has(K("sites", "site1"))).toBe(false);
|
|
356
|
+
expect(v.has(K("devices", "d15"))).toBe(false);
|
|
357
|
+
/* o1 is a root: its devices are one level down */
|
|
358
|
+
expect(v.has(K("devices", "d0"))).toBe(true);
|
|
343
359
|
});
|
|
344
360
|
|
|
345
361
|
test("depth 4 reaches the devices, one page of them", () => {
|
|
@@ -350,7 +366,7 @@ describe("depth", () => {
|
|
|
350
366
|
expect(v.has(K("devices", "d0"))).toBe(true);
|
|
351
367
|
expect(v.has(K("devices", "d23"))).toBe(true);
|
|
352
368
|
expect(v.has(K("devices", "d24"))).toBe(false);
|
|
353
|
-
expect(v.has(K("
|
|
369
|
+
expect(v.has(K("notes", "n1"))).toBe(true);
|
|
354
370
|
});
|
|
355
371
|
|
|
356
372
|
test("expand all shows everything, collapse all the roots' first page", () => {
|
|
@@ -359,25 +375,29 @@ describe("depth", () => {
|
|
|
359
375
|
fold_expand_all(m, st);
|
|
360
376
|
expect(fold_visible_set(m, st).size).toBe(m.nodes.size);
|
|
361
377
|
fold_collapse_all(m, st);
|
|
362
|
-
expect(fold_visible_set(m, st).size).toBe(
|
|
378
|
+
expect(fold_visible_set(m, st).size).toBe(3);
|
|
363
379
|
});
|
|
364
380
|
});
|
|
365
381
|
|
|
366
382
|
describe("levels of the main tree (the toolbar's stepper)", () => {
|
|
367
383
|
test("levels count from the main topic's roots, down every hook", () => {
|
|
368
|
-
let
|
|
369
|
-
|
|
384
|
+
let recs = make_records(30);
|
|
385
|
+
recs.notes.push({id: "n2", site: "sites^north^notes", device: ["devices^d0^notes"]});
|
|
386
|
+
let m = fold_build_model(descs, recs);
|
|
387
|
+
/* region 1, north/south 2, site1 3, its devices and n1 4 */
|
|
370
388
|
expect(m.levels).toBe(4);
|
|
371
|
-
expect(m.level_of.get(K("
|
|
372
|
-
expect(m.level_of.get(K("
|
|
373
|
-
/* d0 hangs from site1 (3) and c1 (4): the shallowest wins */
|
|
389
|
+
expect(m.level_of.get(K("sites", "region"))).toBe(1);
|
|
390
|
+
expect(m.level_of.get(K("sites", "site1"))).toBe(3);
|
|
374
391
|
expect(m.level_of.get(K("devices", "d0"))).toBe(4);
|
|
375
|
-
/*
|
|
376
|
-
expect(m.level_of.
|
|
392
|
+
/* n2 hangs from north (2) and d0 (4): the shallowest wins */
|
|
393
|
+
expect(m.level_of.get(K("notes", "n2"))).toBe(3);
|
|
394
|
+
/* owners and groups are not tied to sites: trees of their own, no level */
|
|
395
|
+
expect(m.level_of.has(K("owners", "o1"))).toBe(false);
|
|
396
|
+
expect(m.level_of.has(K("groups", "g1"))).toBe(false);
|
|
377
397
|
});
|
|
378
398
|
|
|
379
399
|
test("a hidden topic takes its levels with it", () => {
|
|
380
|
-
let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices", "
|
|
400
|
+
let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices", "notes"]});
|
|
381
401
|
expect(m.levels).toBe(3);
|
|
382
402
|
let m0 = fold_build_model({}, {});
|
|
383
403
|
expect(m0.levels).toBe(0);
|
|
@@ -397,44 +417,46 @@ describe("levels of the main tree (the toolbar's stepper)", () => {
|
|
|
397
417
|
let st = fold_new_state(24);
|
|
398
418
|
fold_expand_to_level(m, st, 1);
|
|
399
419
|
expect([...fold_visible_set(m, st)].sort())
|
|
400
|
-
.toEqual([K("
|
|
420
|
+
.toEqual([K("groups", "g1"), K("owners", "o1"), K("sites", "region")]);
|
|
401
421
|
fold_open_levels(m, st, 2);
|
|
402
422
|
let v = fold_visible_set(m, st);
|
|
403
|
-
expect(v.has(K("
|
|
404
|
-
expect(v.has(K("
|
|
423
|
+
expect(v.has(K("sites", "north"))).toBe(true);
|
|
424
|
+
expect(v.has(K("sites", "site1"))).toBe(false);
|
|
405
425
|
fold_open_levels(m, st, 3);
|
|
406
|
-
expect(fold_visible_set(m, st).has(K("
|
|
426
|
+
expect(fold_visible_set(m, st).has(K("sites", "site1"))).toBe(true);
|
|
407
427
|
expect(fold_visible_set(m, st).has(K("devices", "d0"))).toBe(false);
|
|
408
428
|
fold_open_levels(m, st, 4);
|
|
409
429
|
v = fold_visible_set(m, st);
|
|
410
430
|
expect(v.has(K("devices", "d23"))).toBe(true);
|
|
411
431
|
expect(v.has(K("devices", "d24"))).toBe(false); /* one page */
|
|
412
|
-
expect(v.has(K("
|
|
432
|
+
expect(v.has(K("notes", "n1"))).toBe(true);
|
|
433
|
+
/* the owners tree has no level: the stepper leaves it to its pills */
|
|
434
|
+
expect(fold_is_open(st, fold_group_key(K("owners", "o1"), "devices"))).toBe(false);
|
|
413
435
|
});
|
|
414
436
|
|
|
415
437
|
test("opening keeps the pages already shown; closing folds only from its level down", () => {
|
|
416
438
|
let m = fold_build_model(descs, make_records(30));
|
|
417
439
|
let st = fold_new_state(24);
|
|
418
440
|
fold_expand_to_level(m, st, 4);
|
|
419
|
-
let g = fold_group_key(K("
|
|
441
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
420
442
|
fold_show_more(m, st, g); /* 30 */
|
|
421
443
|
fold_open_levels(m, st, 4);
|
|
422
444
|
expect(fold_group_shown(m, st, g)).toBe(30);
|
|
423
445
|
fold_close_levels(m, st, 3);
|
|
424
446
|
let v = fold_visible_set(m, st);
|
|
425
|
-
expect(v.has(K("
|
|
447
|
+
expect(v.has(K("sites", "site1"))).toBe(true); /* level 3 stays */
|
|
426
448
|
expect(v.has(K("devices", "d0"))).toBe(false); /* its hooks folded */
|
|
427
|
-
expect(v.has(K("
|
|
428
|
-
expect(fold_is_open(st, fold_group_key(K("
|
|
449
|
+
expect(v.has(K("notes", "n1"))).toBe(false);
|
|
450
|
+
expect(fold_is_open(st, fold_group_key(K("sites", "north"), "sites"))).toBe(true);
|
|
429
451
|
});
|
|
430
452
|
|
|
431
453
|
test("closing does not reopen what the reader folded above the level", () => {
|
|
432
454
|
let m = fold_build_model(descs, make_records(3));
|
|
433
455
|
let st = fold_new_state(24);
|
|
434
456
|
fold_expand_to_level(m, st, 4);
|
|
435
|
-
fold_toggle(m, st, fold_group_key(K("
|
|
457
|
+
fold_toggle(m, st, fold_group_key(K("sites", "region"), "sites")); /* fold region */
|
|
436
458
|
fold_close_levels(m, st, 3);
|
|
437
|
-
expect(fold_is_open(st, fold_group_key(K("
|
|
459
|
+
expect(fold_is_open(st, fold_group_key(K("sites", "region"), "sites"))).toBe(false);
|
|
438
460
|
});
|
|
439
461
|
});
|
|
440
462
|
|
|
@@ -443,17 +465,17 @@ describe("toggle and pages", () => {
|
|
|
443
465
|
let m = fold_build_model(descs, make_records(30));
|
|
444
466
|
let st = fold_new_state(24);
|
|
445
467
|
fold_expand_to_depth(m, st, 3);
|
|
446
|
-
let g = fold_group_key(K("
|
|
468
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
447
469
|
expect(fold_toggle(m, st, g)).toBe(true);
|
|
448
|
-
expect(fold_visible_set(m, st).has(K("devices", "
|
|
470
|
+
expect(fold_visible_set(m, st).has(K("devices", "d15"))).toBe(true);
|
|
449
471
|
expect(fold_toggle(m, st, g)).toBe(false);
|
|
450
|
-
expect(fold_visible_set(m, st).has(K("devices", "
|
|
472
|
+
expect(fold_visible_set(m, st).has(K("devices", "d15"))).toBe(false);
|
|
451
473
|
});
|
|
452
474
|
|
|
453
475
|
test("show more adds a page and stops at the total", () => {
|
|
454
476
|
let m = fold_build_model(descs, make_records(30));
|
|
455
477
|
let st = fold_new_state(24);
|
|
456
|
-
let g = fold_group_key(K("
|
|
478
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
457
479
|
expect(fold_show_more(m, st, g)).toBe(24);
|
|
458
480
|
expect(fold_show_more(m, st, g)).toBe(30);
|
|
459
481
|
expect(fold_show_more(m, st, g)).toBe(30);
|
|
@@ -463,24 +485,24 @@ describe("toggle and pages", () => {
|
|
|
463
485
|
let m = fold_build_model(descs, make_records(30));
|
|
464
486
|
let st = fold_new_state(24);
|
|
465
487
|
fold_expand_to_depth(m, st, 4);
|
|
466
|
-
fold_toggle(m, st, fold_group_key(K("
|
|
488
|
+
fold_toggle(m, st, fold_group_key(K("sites", "region"), "sites")); /* close */
|
|
467
489
|
let v = fold_visible_set(m, st);
|
|
468
|
-
expect(v.has(K("devices", "
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
490
|
+
expect(v.has(K("devices", "d15"))).toBe(false);
|
|
491
|
+
/* the three roots, and o1's ten devices, which o1 still shows */
|
|
492
|
+
expect(v.size).toBe(3 + 10);
|
|
493
|
+
fold_toggle(m, st, fold_group_key(K("sites", "region"), "sites")); /* reopen */
|
|
494
|
+
expect(fold_visible_set(m, st).has(K("devices", "d15"))).toBe(true);
|
|
472
495
|
});
|
|
473
496
|
|
|
474
497
|
test("the union: folding one parent leaves the child where the other shows it", () => {
|
|
475
498
|
let m = fold_build_model(descs, make_records(30));
|
|
476
499
|
let st = fold_new_state(24);
|
|
477
|
-
fold_expand_to_depth(m, st, 4);
|
|
478
|
-
let
|
|
479
|
-
|
|
480
|
-
fold_toggle(m, st,
|
|
481
|
-
fold_toggle(m, st, g_place); /* site1's devices folded */
|
|
500
|
+
fold_expand_to_depth(m, st, 4); /* site1's and o1's devices open */
|
|
501
|
+
let g_site = fold_group_key(K("sites", "site1"), "devices");
|
|
502
|
+
expect(fold_is_open(st, fold_group_key(K("owners", "o1"), "devices"))).toBe(true);
|
|
503
|
+
fold_toggle(m, st, g_site); /* site1's devices folded */
|
|
482
504
|
let v = fold_visible_set(m, st);
|
|
483
|
-
expect(v.has(K("devices", "d3"))).toBe(true); /* via
|
|
505
|
+
expect(v.has(K("devices", "d3"))).toBe(true); /* via o1 */
|
|
484
506
|
expect(v.has(K("devices", "d15"))).toBe(false); /* only via site1 */
|
|
485
507
|
});
|
|
486
508
|
|
|
@@ -492,8 +514,8 @@ describe("toggle and pages", () => {
|
|
|
492
514
|
let pending = fold_pending_groups(m, st, v);
|
|
493
515
|
expect(pending.length).toBe(1);
|
|
494
516
|
expect(pending[0]).toMatchObject({
|
|
495
|
-
group_key: fold_group_key(K("
|
|
496
|
-
node_key: K("
|
|
517
|
+
group_key: fold_group_key(K("sites", "site1"), "devices"),
|
|
518
|
+
node_key: K("sites", "site1"), hook: "devices",
|
|
497
519
|
shown: 24, total: 30, rest: 6,
|
|
498
520
|
});
|
|
499
521
|
});
|
|
@@ -502,11 +524,11 @@ describe("toggle and pages", () => {
|
|
|
502
524
|
let m = fold_build_model(descs, make_records(30));
|
|
503
525
|
let st = fold_new_state(24);
|
|
504
526
|
fold_expand_to_depth(m, st, 4);
|
|
505
|
-
let pills = fold_pills_of(m, st, K("
|
|
506
|
-
expect(pills.map((p) => p.hook)).toEqual(["devices", "
|
|
527
|
+
let pills = fold_pills_of(m, st, K("sites", "site1"));
|
|
528
|
+
expect(pills.map((p) => p.hook)).toEqual(["devices", "notes"]);
|
|
507
529
|
expect(pills[0]).toMatchObject({total: 30, shown: 24, open: true, child_topic: "devices"});
|
|
508
|
-
expect(pills[1]).toMatchObject({total: 1, shown: 1, open: true, child_topic: "
|
|
509
|
-
expect(fold_pills_of(m, st, K("
|
|
530
|
+
expect(pills[1]).toMatchObject({total: 1, shown: 1, open: true, child_topic: "notes"});
|
|
531
|
+
expect(fold_pills_of(m, st, K("sites", "south"))).toEqual([]);
|
|
510
532
|
});
|
|
511
533
|
});
|
|
512
534
|
|
|
@@ -521,14 +543,14 @@ describe("reveal", () => {
|
|
|
521
543
|
/* d40 is the 41st: two pages, not three, and not all */
|
|
522
544
|
expect(v.has(K("devices", "d47"))).toBe(true);
|
|
523
545
|
expect(v.has(K("devices", "d48"))).toBe(false);
|
|
524
|
-
expect(v.has(K("
|
|
546
|
+
expect(v.has(K("sites", "south"))).toBe(true); /* region|sites opened whole page */
|
|
525
547
|
});
|
|
526
548
|
|
|
527
549
|
test("does not close what was open", () => {
|
|
528
550
|
let m = fold_build_model(descs, make_records(60));
|
|
529
551
|
let st = fold_new_state(24);
|
|
530
552
|
fold_expand_to_depth(m, st, 4);
|
|
531
|
-
fold_show_more(m, st, fold_group_key(K("
|
|
553
|
+
fold_show_more(m, st, fold_group_key(K("sites", "site1"), "devices")); /* 48 */
|
|
532
554
|
fold_reveal(m, st, K("devices", "d3"));
|
|
533
555
|
expect(fold_visible_set(m, st).has(K("devices", "d47"))).toBe(true);
|
|
534
556
|
});
|