@yuneta/gobj-ui 7.23.140 → 7.23.141

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.
@@ -26,6 +26,11 @@ import {
26
26
  fold_split_group_key,
27
27
  fold_main_topic,
28
28
  fold_group_shown,
29
+ fold_is_open,
30
+ fold_level_clamp,
31
+ fold_open_levels,
32
+ fold_close_levels,
33
+ fold_expand_to_level,
29
34
  } from "./treedb_fold_model.js";
30
35
 
31
36
  const places_desc = {
@@ -323,6 +328,81 @@ describe("depth", () => {
323
328
  });
324
329
  });
325
330
 
331
+ describe("levels of the main tree (the toolbar's stepper)", () => {
332
+ test("levels count from the main topic's roots, down every hook", () => {
333
+ let m = fold_build_model(descs, make_records(30));
334
+ /* es 1, norte/sur 2, nave1 3, its devices and c1 4 */
335
+ expect(m.levels).toBe(4);
336
+ expect(m.level_of.get(K("places", "es"))).toBe(1);
337
+ expect(m.level_of.get(K("places", "nave1"))).toBe(3);
338
+ /* d0 hangs from nave1 (3) and c1 (4): the shallowest wins */
339
+ expect(m.level_of.get(K("devices", "d0"))).toBe(4);
340
+ /* device_groups is not tied to places: a tree of its own, no level */
341
+ expect(m.level_of.has(K("device_groups", "g1"))).toBe(false);
342
+ });
343
+
344
+ test("a hidden topic takes its levels with it", () => {
345
+ let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices", "controllers"]});
346
+ expect(m.levels).toBe(3);
347
+ let m0 = fold_build_model({}, {});
348
+ expect(m0.levels).toBe(0);
349
+ expect(fold_level_clamp(m0, 5)).toBe(1);
350
+ });
351
+
352
+ test("clamp keeps a level between 1 and the deepest one", () => {
353
+ let m = fold_build_model(descs, make_records(3));
354
+ expect(fold_level_clamp(m, 0)).toBe(1);
355
+ expect(fold_level_clamp(m, 3)).toBe(3);
356
+ expect(fold_level_clamp(m, 9)).toBe(4);
357
+ expect(fold_level_clamp(m, "2")).toBe(2);
358
+ });
359
+
360
+ test("level 1 is the roots of every tree, and each step opens one more", () => {
361
+ let m = fold_build_model(descs, make_records(30));
362
+ let st = fold_new_state(24);
363
+ fold_expand_to_level(m, st, 1);
364
+ expect([...fold_visible_set(m, st)].sort())
365
+ .toEqual([K("device_groups", "g1"), K("places", "es")]);
366
+ fold_open_levels(m, st, 2);
367
+ let v = fold_visible_set(m, st);
368
+ expect(v.has(K("places", "norte"))).toBe(true);
369
+ expect(v.has(K("places", "nave1"))).toBe(false);
370
+ fold_open_levels(m, st, 3);
371
+ expect(fold_visible_set(m, st).has(K("places", "nave1"))).toBe(true);
372
+ expect(fold_visible_set(m, st).has(K("devices", "d0"))).toBe(false);
373
+ fold_open_levels(m, st, 4);
374
+ v = fold_visible_set(m, st);
375
+ expect(v.has(K("devices", "d23"))).toBe(true);
376
+ expect(v.has(K("devices", "d24"))).toBe(false); /* one page */
377
+ expect(v.has(K("controllers", "c1"))).toBe(true);
378
+ });
379
+
380
+ test("opening keeps the pages already shown; closing folds only from its level down", () => {
381
+ let m = fold_build_model(descs, make_records(30));
382
+ let st = fold_new_state(24);
383
+ fold_expand_to_level(m, st, 4);
384
+ let g = fold_group_key(K("places", "nave1"), "devices");
385
+ fold_show_more(m, st, g); /* 30 */
386
+ fold_open_levels(m, st, 4);
387
+ expect(fold_group_shown(m, st, g)).toBe(30);
388
+ fold_close_levels(m, st, 3);
389
+ let v = fold_visible_set(m, st);
390
+ expect(v.has(K("places", "nave1"))).toBe(true); /* level 3 stays */
391
+ expect(v.has(K("devices", "d0"))).toBe(false); /* its hooks folded */
392
+ expect(v.has(K("controllers", "c1"))).toBe(false);
393
+ expect(fold_is_open(st, fold_group_key(K("places", "norte"), "places"))).toBe(true);
394
+ });
395
+
396
+ test("closing does not reopen what the reader folded above the level", () => {
397
+ let m = fold_build_model(descs, make_records(3));
398
+ let st = fold_new_state(24);
399
+ fold_expand_to_level(m, st, 4);
400
+ fold_toggle(m, st, fold_group_key(K("places", "es"), "places")); /* fold es */
401
+ fold_close_levels(m, st, 3);
402
+ expect(fold_is_open(st, fold_group_key(K("places", "es"), "places"))).toBe(false);
403
+ });
404
+ });
405
+
326
406
  describe("toggle and pages", () => {
327
407
  test("a folded group opens on its first page and closes again", () => {
328
408
  let m = fold_build_model(descs, make_records(30));