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
21 changes: 19 additions & 2 deletions foundation/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/** User selection of a data structure
* @example
* user selects data object `Beh` to be enum `on` and `test`
* ```ts
* {
* Beh: {
* stVal: {on: {}, test: {}}
* q: {}
* t: {}
* }
* }
* ```
*/
export type TreeSelection = {
[name: string]: TreeSelection;
};

/** Intent to `parent.insertBefore(node, reference)` */
export type Insert = {
parent: Node;
Expand Down Expand Up @@ -35,12 +52,12 @@ export function isInsert(edit: Edit): edit is Insert {
export function createElement(
doc: XMLDocument,
tag: string,
attrs: Record<string, string | null>,
attrs: Record<string, string | null | undefined>,
): Element {
const element = doc.createElementNS(doc.documentElement.namespaceURI, tag);
Object.entries(attrs)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([_, value]) => value !== null)
.filter(([_, value]) => typeof value === "string")
.forEach(([name, value]) => element.setAttribute(name, value!));

return element;
Expand Down
18 changes: 10 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export { Edit } from "./foundation/utils.js";
export { Update } from "./foundation/utils.js";
export { Insert } from "./foundation/utils.js";
export { Remove } from "./foundation/utils.js";
export {
Edit,
Update,
Insert,
Remove,
TreeSelection,
} from "./foundation/utils.js";

export { updateBay } from "./tBay/updateBay.js";
export { updateVoltageLevel } from "./tVoltageLevel/updateVoltageLevel.js";
Expand Down Expand Up @@ -69,17 +72,16 @@ export { sourceControlBlock } from "./tExtRef/sourceControlBlock.js";
export { isSubscribed } from "./tExtRef/isSubscribed.js";

export { importLNodeType } from "./tDataTypeTemplates/importLNodeType.js";
export {
lNodeTypeToSelection,
TreeSelection,
} from "./tDataTypeTemplates/lNodeTypeToSelection.js";
export { lNodeTypeToSelection } from "./tDataTypeTemplates/lNodeTypeToSelection.js";

export {
LNodeDescription,
NameSpaceDescription,
nsdToJson,
} from "./tDataTypeTemplates/nsdToJson.js";

export { insertSelectedLNodeType } from "./tDataTypeTemplates/insertSelectedLNodeType.js";

export {
Supervision,
SupervisionOptions,
Expand Down
188 changes: 188 additions & 0 deletions tDataTypeTemplates/insertSelecetdLNodeType.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { expect } from "chai";

import { findElement } from "../foundation/helpers.test.js";

import {
atccSelection,
ltrkSelection,
mmxuSelection,
} from "./insertSelectedLNodeType.testdata.js";

import {
incompleteAtccTypes,
missingMmxuTypes,
incompleteLtrkTypes,
emptySSD,
} from "./insertSelectedDataType.testfiles.js";

import { insertSelectedLNodeType } from "./insertSelectedLNodeType.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("insert MMXU LNodeType including missing sub data", () => {
const edits = insertSelectedLNodeType(
incompleteMmxu,
mmxuSelection,
"MMXU",
);

expect(edits.length).to.equal(6);

const lNodeType = edits[0].node as Element;
expect(lNodeType.tagName).to.equal("LNodeType");
expect(lNodeType.getAttribute("lnClass")).to.equal("MMXU");
expect(lNodeType.getAttribute("id")).to.equal(
"MMXU$oscd$_3f831c4c0fa5f6bd",
);

const doTypeCmv = edits[1].node as Element;
expect(doTypeCmv.tagName).to.equal("DOType");
expect(doTypeCmv.getAttribute("cdc")).to.equal("CMV");
expect(doTypeCmv.getAttribute("id")).to.equal(
"phsB$oscd$_3a6c99c1de0ca1c1",
);

const doTypeWye = edits[2].node as Element;
expect(doTypeWye.tagName).to.equal("DOType");
expect(doTypeWye.getAttribute("cdc")).to.equal("WYE");
expect(doTypeWye.getAttribute("id")).to.equal("A$oscd$_bd01f85651a2b3ee");

const daTypecVal = edits[3].node as Element;
expect(daTypecVal.tagName).to.equal("DAType");
expect(daTypecVal.getAttribute("id")).to.equal(
"cVal$oscd$_21f679e08734a896",
);

const daTypeSBOw = edits[4].node as Element;
expect(daTypeSBOw.tagName).to.equal("DAType");
expect(daTypeSBOw.getAttribute("id")).to.equal(
"SBOw$oscd$_264aab113bc4c3d7",
);

const enumType = edits[5].node as Element;
expect(enumType.tagName).to.equal("EnumType");
expect(enumType.getAttribute("id")).to.equal(
"stVal$oscd$_48ba16345b8e7f5b",
);
});

it("insert LTRK LNodeType including missing sub data", () => {
const edits = insertSelectedLNodeType(
imcompleteLtrk,
ltrkSelection,
"LTRK",
);

expect(edits.length).to.equal(7);

const lNodeType = edits[0].node as Element;
expect(lNodeType.tagName).to.equal("LNodeType");
expect(lNodeType.getAttribute("lnClass")).to.equal("LTRK");
expect(lNodeType.getAttribute("id")).to.equal(
"LTRK$oscd$_f8074960800758df",
);

const doTypeCmv = edits[1].node as Element;
expect(doTypeCmv.tagName).to.equal("DOType");
expect(doTypeCmv.getAttribute("cdc")).to.equal("CTS");
expect(doTypeCmv.getAttribute("id")).to.equal(
"ApcFTrk$oscd$_9039fc5f67d3778a",
);

const doTypeWye = edits[2].node as Element;
expect(doTypeWye.tagName).to.equal("DOType");
expect(doTypeWye.getAttribute("cdc")).to.equal("CTS");
expect(doTypeWye.getAttribute("id")).to.equal(
"ApcIntTrk$oscd$_0b6b0a301af5aa77",
);

const daTypecVal = edits[3].node as Element;
expect(daTypecVal.tagName).to.equal("DAType");
expect(daTypecVal.getAttribute("id")).to.equal(
"ctlVal$oscd$_ed49c2f7a55ad05a",
);

const daTypeSBOw = edits[4].node as Element;
expect(daTypeSBOw.tagName).to.equal("DAType");
expect(daTypeSBOw.getAttribute("id")).to.equal(
"ctlVal$oscd$_5a5af9e249dc7f84",
);

const enumTypeStVal = edits[5].node as Element;
expect(enumTypeStVal.tagName).to.equal("EnumType");
expect(enumTypeStVal.getAttribute("id")).to.equal(
"stVal$oscd$_74dd2cc4b188b4ad",
);

const enumTypeOrCat = edits[6].node as Element;
expect(enumTypeOrCat.tagName).to.equal("EnumType");
expect(enumTypeOrCat.getAttribute("id")).to.equal(
"orCat$oscd$_929ee017c8f9feb5",
);
});

it("insert ATCC LNodeType including missing sub data", () => {
const edits = insertSelectedLNodeType(
incompleteAtcc,
atccSelection,
"ATCC",
);

expect(edits.length).to.equal(5);

const lNodeType = edits[0].node as Element;
expect(lNodeType.tagName).to.equal("LNodeType");
expect(lNodeType.getAttribute("lnClass")).to.equal("ATCC");
expect(lNodeType.getAttribute("id")).to.equal(
"ATCC$oscd$_f9d7914eb0ce0e92",
);

const doTypeCmv = edits[1].node as Element;
expect(doTypeCmv.tagName).to.equal("DOType");
expect(doTypeCmv.getAttribute("cdc")).to.equal("APC");
expect(doTypeCmv.getAttribute("id")).to.equal(
"VolSpt$oscd$_ef3a36fd78b41086",
);

const daTypecVal = edits[2].node as Element;
expect(daTypecVal.tagName).to.equal("DAType");
expect(daTypecVal.getAttribute("id")).to.equal(
"SBOw$oscd$_61d7e600207c9456",
);

const daTypeSBOw = edits[3].node as Element;
expect(daTypeSBOw.tagName).to.equal("DAType");
expect(daTypeSBOw.getAttribute("id")).to.equal(
"Oper$oscd$_5b11d63fa0ade588",
);

const enumTypeOrCat = edits[4].node as Element;
expect(enumTypeOrCat.tagName).to.equal("EnumType");
expect(enumTypeOrCat.getAttribute("id")).to.equal(
"ctlModel$oscd$_e975941313cb546c",
);
});

it("insert DataTypeTemplates when missing", () => {
const edits = insertSelectedLNodeType(
missingDataTypes,
atccSelection,
"ATCC",
);

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

const lNodeType = edits[0].node as Element;
expect(lNodeType.tagName).to.equal("DataTypeTemplates");
});
});
Loading