feat: release Symcon 0.2.2 with object tree selection and hook recovery
This commit is contained in:
1 parent
4a875aa8ea
commit
eff9eb83d7
19 files changed
+2273
-1064
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import type { SymconObject } from "../types.ts";
|
||||
import { indexSymconTree, symconAncestors, symconTreeRows, SYMCON_SYSTEM_ROOT } from "./symcon-tree.ts";
|
||||
|
||||
const node = (object_id: number, parent_id: number, name: string, object_type = 0, position = 0): SymconObject =>
|
||||
({ object_id, parent_id, name, object_type, position, path: name, hidden: false, icon: "" });
|
||||
|
||||
test("native position, type and name order are kept, including empty categories and non-variable objects", () => {
|
||||
const tree = indexSymconTree([node(4, 0, "Variable", 2), node(2, 0, "Zentrale", 1), node(3, 0, "Zweiter Ordner"), node(1, 0, "Erster Ordner"), node(5, 0, "Skript", 3, -1)]);
|
||||
assert.deepEqual(symconTreeRows(tree, new Set()).map((row) => row.node.object_id), [5, 1, 3, 2, 4]);
|
||||
});
|
||||
|
||||
test("equal names and a slash inside a name remain distinct native branches", () => {
|
||||
const tree = indexSymconTree([node(1, 0, "Haus / Altbau"), node(2, 1, "Heizung", 1), node(3, 0, "Heizung", 1), node(4, 2, "Temperatur", 2), node(5, 3, "Temperatur", 2)]);
|
||||
assert.deepEqual(symconAncestors(tree, 4), [2, 1]);
|
||||
assert.deepEqual(symconAncestors(tree, 5), [3]);
|
||||
assert.deepEqual(symconTreeRows(tree, new Set([1, 2])).map((row) => [row.node.object_id, row.depth]), [[1, 0], [2, 1], [4, 2], [3, 0]]);
|
||||
});
|
||||
|
||||
test("search opens the original ancestors and never searches internal IDs", () => {
|
||||
const tree = indexSymconTree([node(1, 0, "Haus"), node(2, 1, "Küche", 1), node(3, 2, "Temperatur", 2), node(4, 1, "Garten")]);
|
||||
const expanded = new Set<number>();
|
||||
assert.deepEqual(symconTreeRows(tree, expanded, "temperatur").map((row) => row.node.object_id), [1, 2, 3]);
|
||||
assert.equal(expanded.size, 0, "search must not change manual expansion state");
|
||||
assert.deepEqual(symconTreeRows(tree, expanded, "3"), []);
|
||||
});
|
||||
|
||||
test("hidden categories and their variables stay in the main category without a visibility filter", () => {
|
||||
const objects = [{ ...node(1, 0, "Versteckt"), hidden: true }, { ...node(2, 1, "Technik"), hidden: true }, { ...node(3, 2, "Temperatur", 2), entity_id: "sensor.3" }];
|
||||
const tree = indexSymconTree(objects);
|
||||
const rows = symconTreeRows(tree, new Set([1, 2]));
|
||||
assert.deepEqual(rows.map((row) => row.node.object_id), [1, 2, 3]);
|
||||
assert.equal(rows[0].node.hidden, true);
|
||||
assert.equal(rows[1].node.hidden, true);
|
||||
assert.equal(rows[2].node.entity_id, "sensor.3");
|
||||
});
|
||||
|
||||
test("all six system module types move into virtual groups while devices stay in the main category", () => {
|
||||
const objects = [node(1, 0, "Haus"), { ...node(2, 1, "Heizung", 1), module_type: 3 }, node(3, 2, "Temperatur", 2)];
|
||||
const types = [1, 2, 0, 4, 5, 6];
|
||||
for (const type of types) {
|
||||
objects.push({ ...node(20 + type, 0, `Modul ${type}`, 1), module_type: type });
|
||||
objects.push({ ...node(40 + type, 20 + type, "Wert", 2), entity_id: `sensor.${40 + type}` });
|
||||
}
|
||||
const original = structuredClone(objects);
|
||||
const tree = indexSymconTree(objects);
|
||||
assert.deepEqual(symconTreeRows(tree, new Set()).map((row) => row.node.name), ["Haus", "System"]);
|
||||
assert.deepEqual((tree.children.get(SYMCON_SYSTEM_ROOT) ?? []).map((entry) => entry.name), ["I/O", "Splitter", "Kerninstanzen", "Konfiguratoren", "Discovery", "Visualisierungen"]);
|
||||
assert.equal(tree.nodes.get(2)?.parent_id, 1);
|
||||
for (const type of types) {
|
||||
assert.equal(tree.nodes.get(20 + type)?.parent_id, -10 - type);
|
||||
assert.deepEqual(symconAncestors(tree, 40 + type), [20 + type, -10 - type, SYMCON_SYSTEM_ROOT]);
|
||||
assert.equal(tree.nodes.get(40 + type)?.entity_id, `sensor.${40 + type}`);
|
||||
}
|
||||
assert.deepEqual(objects, original, "grouping must never mutate native parents or object data");
|
||||
assert.ok([...tree.nodes.values()].filter((entry) => entry.virtual).every((entry) => !entry.entity_id && entry.object_id < 0));
|
||||
});
|
||||
|
||||
test("system subtrees remain intact and searchable, including native folders already named System", () => {
|
||||
const objects = [node(1, 0, "System"), { ...node(2, 1, "LAN", 1), module_type: 1 }, { ...node(3, 2, "Splitter", 1), module_type: 2 },
|
||||
{ ...node(4, 3, "Betriebsstunden", 2), hidden: true, entity_id: "sensor.4" }];
|
||||
const tree = indexSymconTree(objects);
|
||||
assert.equal(tree.nodes.get(1)?.parent_id, 0, "an actual user category named System must not be merged or moved");
|
||||
assert.equal(tree.nodes.get(3)?.parent_id, 2, "nested instances stay with their original parent");
|
||||
assert.deepEqual(symconTreeRows(tree, new Set(), "System I/O Betriebsstunden").map((row) => row.node.object_id), [SYMCON_SYSTEM_ROOT, -11, 2, 3, 4]);
|
||||
assert.equal(tree.nodes.get(4)?.hidden, true);
|
||||
assert.equal(tree.nodes.get(4)?.path, "System / I/O / LAN / Splitter / Betriebsstunden");
|
||||
});
|
||||
Reference in new issue
Block a user