Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions tDataTypeTemplates/insertSelecetdLNodeType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@ 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;
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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions tDataTypeTemplates/insertSelectedLNodeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<string>();
const elements: Templates = {
Expand All @@ -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);
Expand Down Expand Up @@ -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 });

Expand Down