diff --git a/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts b/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts index e16ca14..9c11799 100644 --- a/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts +++ b/tDataTypeTemplates/insertSelecetdLNodeType.spec.ts @@ -17,6 +17,7 @@ import { } from "./insertSelectedDataType.testfiles.js"; import { insertSelectedLNodeType } from "./insertSelectedLNodeType.js"; +import { LNodeDescription, nsdToJson } from "./nsdToJson.js"; const incompleteMmxu = findElement(missingMmxuTypes) as XMLDocument; const imcompleteLtrk = findElement(incompleteLtrkTypes) as XMLDocument; @@ -24,20 +25,16 @@ const incompleteAtcc = findElement(incompleteAtccTypes) as XMLDocument; const missingDataTypes = findElement(emptySSD) as XMLDocument; describe("insertLNodeTypeSelection", () => { - it("return empty array with invlaid lnClass", () => { - expect( - insertSelectedLNodeType(incompleteMmxu, mmxuSelection, "ERRO").length, - ).to.equal(0); - }); - - it('is insensitive for invalid EnumTypes',()=> - insertSelectedLNodeType(incompleteMmxu, invalidSelection, "LLN0")) + it('is insensitive for invalid EnumTypes',()=> { + const data = nsdToJson("LLN0") as LNodeDescription; + insertSelectedLNodeType(incompleteMmxu, invalidSelection, {class:"LLN0", data}); + }) it("insert MMXU LNodeType including missing sub data", () => { const edits = insertSelectedLNodeType( incompleteMmxu, mmxuSelection, - "MMXU", + {class:"MMXU"}, ); expect(edits.length).to.equal(6); @@ -81,10 +78,11 @@ describe("insertLNodeTypeSelection", () => { }); it("insert LTRK LNodeType including missing sub data", () => { + const data = nsdToJson("LTRK") as LNodeDescription; const edits = insertSelectedLNodeType( imcompleteLtrk, ltrkSelection, - "LTRK", + {class:"LTRK", data}, ); expect(edits.length).to.equal(7); @@ -136,10 +134,11 @@ describe("insertLNodeTypeSelection", () => { }); it("insert ATCC LNodeType including missing sub data", () => { + const data = nsdToJson("ATCC") as LNodeDescription; const edits = insertSelectedLNodeType( incompleteAtcc, atccSelection, - "ATCC", + {class: "ATCC", data}, ); expect(edits.length).to.equal(5); @@ -178,10 +177,11 @@ describe("insertLNodeTypeSelection", () => { }); it("insert DataTypeTemplates when missing", () => { + const data = nsdToJson("ATCC") as LNodeDescription; const edits = insertSelectedLNodeType( missingDataTypes, atccSelection, - "ATCC", + {class:"ATCC", data}, ); expect(edits.length).to.equal(19); diff --git a/tDataTypeTemplates/insertSelectedLNodeType.ts b/tDataTypeTemplates/insertSelectedLNodeType.ts index 0a6f453..030d3a1 100644 --- a/tDataTypeTemplates/insertSelectedLNodeType.ts +++ b/tDataTypeTemplates/insertSelectedLNodeType.ts @@ -2,7 +2,7 @@ * Basis is a copy from www.github.com/openenergytools/oscd-template-generator * originally written by ca-d, thx Chris. Code has been modified! */ -import { nsdToJson } from "./nsdToJson.js"; +import { LNodeDescription, nsdToJson } from "./nsdToJson.js"; import { createElement, Insert, TreeSelection } from "../foundation/utils.js"; @@ -163,13 +163,13 @@ function data(lnData: any, path: string[]): any { * Creates a new data type `LNodeType` based on a user selection. * @param doc - the XML document to add the `LNodeType` to * @param selection - The user selection as a tree object - * @param lnClass - the logical node class of the `LNodeType` + * @param logicalnode - the logical node class and its JSON data structure of the `LNodeType` * @returns an array of inserts for the `LNodeType` and the missing subs data */ export function insertSelectedLNodeType( doc: XMLDocument, selection: TreeSelection, - lnClass: string, + logicalnode: {class: string, data?: LNodeDescription}, ): Insert[] { const types = new Set(); const elements: Templates = { @@ -179,8 +179,8 @@ export function insertSelectedLNodeType( EnumType: [], }; - const lnData = nsdToJson(lnClass); - if (!lnData) return []; + const lnData = logicalnode.data ?? nsdToJson(logicalnode.class); + const lnClass = logicalnode.class; function isUnknownId(id: string): boolean { const alreadyCreate = types.has(id); @@ -375,7 +375,7 @@ export function insertSelectedLNodeType( Object.keys(selection).forEach((name) => { const type = createDOType([name], selection[name]); - const { transient } = lnData[name]; + const { transient } = (lnData as LNodeDescription)[name]; const doElement = createElement(doc, "DO", { name, type, transient });