Skip to content

Commit 122963d

Browse files
feat(insertSelectedLNodeType): allow data to be defined
1 parent 0405921 commit 122963d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tDataTypeTemplates/insertSelecetdLNodeType.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,24 @@ import {
1717
} from "./insertSelectedDataType.testfiles.js";
1818

1919
import { insertSelectedLNodeType } from "./insertSelectedLNodeType.js";
20+
import { LNodeDescription, nsdToJson } from "./nsdToJson.js";
2021

2122
const incompleteMmxu = findElement(missingMmxuTypes) as XMLDocument;
2223
const imcompleteLtrk = findElement(incompleteLtrkTypes) as XMLDocument;
2324
const incompleteAtcc = findElement(incompleteAtccTypes) as XMLDocument;
2425
const missingDataTypes = findElement(emptySSD) as XMLDocument;
2526

2627
describe("insertLNodeTypeSelection", () => {
27-
it("return empty array with invlaid lnClass", () => {
28-
expect(
29-
insertSelectedLNodeType(incompleteMmxu, mmxuSelection, "ERRO").length,
30-
).to.equal(0);
31-
});
32-
33-
it('is insensitive for invalid EnumTypes',()=>
34-
insertSelectedLNodeType(incompleteMmxu, invalidSelection, "LLN0"))
28+
it('is insensitive for invalid EnumTypes',()=> {
29+
const data = nsdToJson("LLN0") as LNodeDescription;
30+
insertSelectedLNodeType(incompleteMmxu, invalidSelection, {class:"LLN0", data});
31+
})
3532

3633
it("insert MMXU LNodeType including missing sub data", () => {
3734
const edits = insertSelectedLNodeType(
3835
incompleteMmxu,
3936
mmxuSelection,
40-
"MMXU",
37+
{class:"MMXU"},
4138
);
4239

4340
expect(edits.length).to.equal(6);
@@ -81,10 +78,11 @@ describe("insertLNodeTypeSelection", () => {
8178
});
8279

8380
it("insert LTRK LNodeType including missing sub data", () => {
81+
const data = nsdToJson("LTRK") as LNodeDescription;
8482
const edits = insertSelectedLNodeType(
8583
imcompleteLtrk,
8684
ltrkSelection,
87-
"LTRK",
85+
{class:"LTRK", data},
8886
);
8987

9088
expect(edits.length).to.equal(7);
@@ -136,10 +134,11 @@ describe("insertLNodeTypeSelection", () => {
136134
});
137135

138136
it("insert ATCC LNodeType including missing sub data", () => {
137+
const data = nsdToJson("ATCC") as LNodeDescription;
139138
const edits = insertSelectedLNodeType(
140139
incompleteAtcc,
141140
atccSelection,
142-
"ATCC",
141+
{class: "ATCC", data},
143142
);
144143

145144
expect(edits.length).to.equal(5);
@@ -178,10 +177,11 @@ describe("insertLNodeTypeSelection", () => {
178177
});
179178

180179
it("insert DataTypeTemplates when missing", () => {
180+
const data = nsdToJson("ATCC") as LNodeDescription;
181181
const edits = insertSelectedLNodeType(
182182
missingDataTypes,
183183
atccSelection,
184-
"ATCC",
184+
{class:"ATCC", data},
185185
);
186186

187187
expect(edits.length).to.equal(19);

tDataTypeTemplates/insertSelectedLNodeType.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Basis is a copy from www.github.com/openenergytools/oscd-template-generator
33
* originally written by ca-d, thx Chris. Code has been modified!
44
*/
5-
import { nsdToJson } from "./nsdToJson.js";
5+
import { LNodeDescription, nsdToJson } from "./nsdToJson.js";
66

77
import { createElement, Insert, TreeSelection } from "../foundation/utils.js";
88

@@ -163,13 +163,13 @@ function data(lnData: any, path: string[]): any {
163163
* Creates a new data type `LNodeType` based on a user selection.
164164
* @param doc - the XML document to add the `LNodeType` to
165165
* @param selection - The user selection as a tree object
166-
* @param lnClass - the logical node class of the `LNodeType`
166+
* @param logicalnode - the logical node class and its JSON data structure of the `LNodeType`
167167
* @returns an array of inserts for the `LNodeType` and the missing subs data
168168
*/
169169
export function insertSelectedLNodeType(
170170
doc: XMLDocument,
171171
selection: TreeSelection,
172-
lnClass: string,
172+
logicalnode: {class: string, data?: LNodeDescription},
173173
): Insert[] {
174174
const types = new Set<string>();
175175
const elements: Templates = {
@@ -179,8 +179,8 @@ export function insertSelectedLNodeType(
179179
EnumType: [],
180180
};
181181

182-
const lnData = nsdToJson(lnClass);
183-
if (!lnData) return [];
182+
const lnData = logicalnode.data ?? nsdToJson(logicalnode.class);
183+
const lnClass = logicalnode.class;
184184

185185
function isUnknownId(id: string): boolean {
186186
const alreadyCreate = types.has(id);
@@ -375,7 +375,7 @@ export function insertSelectedLNodeType(
375375
Object.keys(selection).forEach((name) => {
376376
const type = createDOType([name], selection[name]);
377377

378-
const { transient } = lnData[name];
378+
const { transient } = (lnData as LNodeDescription)[name];
379379

380380
const doElement = createElement(doc, "DO", { name, type, transient });
381381

0 commit comments

Comments
 (0)