From 81ee89783edf59b8a715bc5c7676cd01b921f724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Wed, 4 Dec 2024 11:08:54 +0100 Subject: [PATCH] feat: add new tree test for autorefresh and add autorefreshFields property --- src/Tree.ts | 14 +++++++++++++- src/spec/Tree.spec.ts | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Tree.ts b/src/Tree.ts index 17dee85..ef8da89 100644 --- a/src/Tree.ts +++ b/src/Tree.ts @@ -1,7 +1,7 @@ import WidgetFactory from "./WidgetFactory"; import Widget from "./Widget"; import { replaceEntities } from "./helpers/attributeParser"; -import { ParsedNode } from "./helpers/nodeParser"; +import { parseBoolAttribute, ParsedNode } from "./helpers/nodeParser"; import * as txml from "txml"; import { parseContext } from "./helpers/contextParser"; @@ -67,6 +67,14 @@ class Tree { this._contextForFields = value; } + /** + * List of autorefreshable fields + */ + _autorefreshableFields: string[] = []; + get autorefreshableFields(): string[] { + return this._autorefreshableFields; + } + /** * Is infinite */ @@ -145,6 +153,10 @@ class Tree { const widget = widgetFactory.createWidget(widgetType, mergedAttrs); this._columns.push(widget); } + + if (parseBoolAttribute(mergedAttrs.autorefresh)) { + this._autorefreshableFields.push(name); + } } }); } diff --git a/src/spec/Tree.spec.ts b/src/spec/Tree.spec.ts index c51e1e2..a2c27e3 100644 --- a/src/spec/Tree.spec.ts +++ b/src/spec/Tree.spec.ts @@ -377,4 +377,23 @@ describe("A Tree", () => { const nameWidget = tree.findById("name") as Char; expect(nameWidget.isFunction).toBeTruthy(); }); + it("Should parse autorefreshable fields", () => { + const tree = new Tree({ + name: { + required: true, + select: true, + size: 128, + string: "Potència contractada (kW)", + type: "char", + views: {}, + }, + }); + tree.parse( + ``, + ); + + const nameWidget = tree.findById("name") as Char; + expect(nameWidget.autoRefresh).toBeTruthy(); + expect(tree._autorefreshableFields.length).toBe(1); + }); });