Skip to content

Commit f38c439

Browse files
feat: insertLNodeTypeFromSelection
1 parent 0642317 commit f38c439

File tree

7 files changed

+1469
-19
lines changed

7 files changed

+1469
-19
lines changed

foundation/utils.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/** User selection of a data structure
2+
* @example
3+
* user selects data object `Beh` to be enum `on` and `test`
4+
* ```ts
5+
* {
6+
* Beh: {
7+
* stVal: {on: {}, test: {}}
8+
* q: {}
9+
* t: {}
10+
* }
11+
* }
12+
* ```
13+
*/
14+
export type TreeSelection = {
15+
[name: string]: TreeSelection;
16+
};
17+
118
/** Intent to `parent.insertBefore(node, reference)` */
219
export type Insert = {
320
parent: Node;
@@ -35,12 +52,12 @@ export function isInsert(edit: Edit): edit is Insert {
3552
export function createElement(
3653
doc: XMLDocument,
3754
tag: string,
38-
attrs: Record<string, string | null>,
55+
attrs: Record<string, string | null | undefined>,
3956
): Element {
4057
const element = doc.createElementNS(doc.documentElement.namespaceURI, tag);
4158
Object.entries(attrs)
4259
// eslint-disable-next-line @typescript-eslint/no-unused-vars
43-
.filter(([_, value]) => value !== null)
60+
.filter(([_, value]) => typeof value === "string")
4461
.forEach(([name, value]) => element.setAttribute(name, value!));
4562

4663
return element;

index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
export { Edit } from "./foundation/utils.js";
2-
export { Update } from "./foundation/utils.js";
3-
export { Insert } from "./foundation/utils.js";
4-
export { Remove } from "./foundation/utils.js";
1+
export {
2+
Edit,
3+
Update,
4+
Insert,
5+
Remove,
6+
TreeSelection,
7+
} from "./foundation/utils.js";
58

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

7174
export { importLNodeType } from "./tDataTypeTemplates/importLNodeType.js";
72-
export {
73-
lNodeTypeToSelection,
74-
TreeSelection,
75-
} from "./tDataTypeTemplates/lNodeTypeToSelection.js";
75+
export { lNodeTypeToSelection } from "./tDataTypeTemplates/lNodeTypeToSelection.js";
7676

7777
export {
7878
LNodeDescription,
7979
NameSpaceDescription,
8080
nsdToJson,
8181
} from "./tDataTypeTemplates/nsdToJson.js";
8282

83+
export { insertSelectedLNodeType } from "./tDataTypeTemplates/insertSelectedLNodeType.js";
84+
8385
export {
8486
Supervision,
8587
SupervisionOptions,
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import { expect } from "chai";
2+
3+
import { findElement } from "../foundation/helpers.test.js";
4+
5+
import {
6+
atccSelection,
7+
ltrkSelection,
8+
mmxuSelection,
9+
} from "./insertSelectedLNodeType.testdata.js";
10+
11+
import {
12+
incompleteAtccTypes,
13+
missingMmxuTypes,
14+
incompleteLtrkTypes,
15+
emptySSD,
16+
} from "./insertSelectedDataType.testfiles.js";
17+
18+
import { insertSelectedLNodeType } from "./insertSelectedLNodeType.js";
19+
20+
const incompleteMmxu = findElement(missingMmxuTypes) as XMLDocument;
21+
const imcompleteLtrk = findElement(incompleteLtrkTypes) as XMLDocument;
22+
const incompleteAtcc = findElement(incompleteAtccTypes) as XMLDocument;
23+
const missingDataTypes = findElement(emptySSD) as XMLDocument;
24+
25+
describe("insertLNodeTypeSelection", () => {
26+
it("return empty array with invlaid lnClass", () => {
27+
expect(
28+
insertSelectedLNodeType(incompleteMmxu, mmxuSelection, "ERRO").length,
29+
).to.equal(0);
30+
});
31+
32+
it("insert MMXU LNodeType including missing sub data", () => {
33+
const edits = insertSelectedLNodeType(
34+
incompleteMmxu,
35+
mmxuSelection,
36+
"MMXU",
37+
);
38+
39+
expect(edits.length).to.equal(6);
40+
41+
const lNodeType = edits[0].node as Element;
42+
expect(lNodeType.tagName).to.equal("LNodeType");
43+
expect(lNodeType.getAttribute("lnClass")).to.equal("MMXU");
44+
expect(lNodeType.getAttribute("id")).to.equal(
45+
"MMXU$oscd$_3f831c4c0fa5f6bd",
46+
);
47+
48+
const doTypeCmv = edits[1].node as Element;
49+
expect(doTypeCmv.tagName).to.equal("DOType");
50+
expect(doTypeCmv.getAttribute("cdc")).to.equal("CMV");
51+
expect(doTypeCmv.getAttribute("id")).to.equal(
52+
"phsB$oscd$_3a6c99c1de0ca1c1",
53+
);
54+
55+
const doTypeWye = edits[2].node as Element;
56+
expect(doTypeWye.tagName).to.equal("DOType");
57+
expect(doTypeWye.getAttribute("cdc")).to.equal("WYE");
58+
expect(doTypeWye.getAttribute("id")).to.equal("A$oscd$_bd01f85651a2b3ee");
59+
60+
const daTypecVal = edits[3].node as Element;
61+
expect(daTypecVal.tagName).to.equal("DAType");
62+
expect(daTypecVal.getAttribute("id")).to.equal(
63+
"cVal$oscd$_21f679e08734a896",
64+
);
65+
66+
const daTypeSBOw = edits[4].node as Element;
67+
expect(daTypeSBOw.tagName).to.equal("DAType");
68+
expect(daTypeSBOw.getAttribute("id")).to.equal(
69+
"SBOw$oscd$_264aab113bc4c3d7",
70+
);
71+
72+
const enumType = edits[5].node as Element;
73+
expect(enumType.tagName).to.equal("EnumType");
74+
expect(enumType.getAttribute("id")).to.equal(
75+
"stVal$oscd$_48ba16345b8e7f5b",
76+
);
77+
});
78+
79+
it("insert LTRK LNodeType including missing sub data", () => {
80+
const edits = insertSelectedLNodeType(
81+
imcompleteLtrk,
82+
ltrkSelection,
83+
"LTRK",
84+
);
85+
86+
expect(edits.length).to.equal(7);
87+
88+
const lNodeType = edits[0].node as Element;
89+
expect(lNodeType.tagName).to.equal("LNodeType");
90+
expect(lNodeType.getAttribute("lnClass")).to.equal("LTRK");
91+
expect(lNodeType.getAttribute("id")).to.equal(
92+
"LTRK$oscd$_f8074960800758df",
93+
);
94+
95+
const doTypeCmv = edits[1].node as Element;
96+
expect(doTypeCmv.tagName).to.equal("DOType");
97+
expect(doTypeCmv.getAttribute("cdc")).to.equal("CTS");
98+
expect(doTypeCmv.getAttribute("id")).to.equal(
99+
"ApcFTrk$oscd$_9039fc5f67d3778a",
100+
);
101+
102+
const doTypeWye = edits[2].node as Element;
103+
expect(doTypeWye.tagName).to.equal("DOType");
104+
expect(doTypeWye.getAttribute("cdc")).to.equal("CTS");
105+
expect(doTypeWye.getAttribute("id")).to.equal(
106+
"ApcIntTrk$oscd$_0b6b0a301af5aa77",
107+
);
108+
109+
const daTypecVal = edits[3].node as Element;
110+
expect(daTypecVal.tagName).to.equal("DAType");
111+
expect(daTypecVal.getAttribute("id")).to.equal(
112+
"ctlVal$oscd$_ed49c2f7a55ad05a",
113+
);
114+
115+
const daTypeSBOw = edits[4].node as Element;
116+
expect(daTypeSBOw.tagName).to.equal("DAType");
117+
expect(daTypeSBOw.getAttribute("id")).to.equal(
118+
"ctlVal$oscd$_5a5af9e249dc7f84",
119+
);
120+
121+
const enumTypeStVal = edits[5].node as Element;
122+
expect(enumTypeStVal.tagName).to.equal("EnumType");
123+
expect(enumTypeStVal.getAttribute("id")).to.equal(
124+
"stVal$oscd$_74dd2cc4b188b4ad",
125+
);
126+
127+
const enumTypeOrCat = edits[6].node as Element;
128+
expect(enumTypeOrCat.tagName).to.equal("EnumType");
129+
expect(enumTypeOrCat.getAttribute("id")).to.equal(
130+
"orCat$oscd$_929ee017c8f9feb5",
131+
);
132+
});
133+
134+
it("insert ATCC LNodeType including missing sub data", () => {
135+
const edits = insertSelectedLNodeType(
136+
incompleteAtcc,
137+
atccSelection,
138+
"ATCC",
139+
);
140+
141+
expect(edits.length).to.equal(5);
142+
143+
const lNodeType = edits[0].node as Element;
144+
expect(lNodeType.tagName).to.equal("LNodeType");
145+
expect(lNodeType.getAttribute("lnClass")).to.equal("ATCC");
146+
expect(lNodeType.getAttribute("id")).to.equal(
147+
"ATCC$oscd$_f9d7914eb0ce0e92",
148+
);
149+
150+
const doTypeCmv = edits[1].node as Element;
151+
expect(doTypeCmv.tagName).to.equal("DOType");
152+
expect(doTypeCmv.getAttribute("cdc")).to.equal("APC");
153+
expect(doTypeCmv.getAttribute("id")).to.equal(
154+
"VolSpt$oscd$_ef3a36fd78b41086",
155+
);
156+
157+
const daTypecVal = edits[2].node as Element;
158+
expect(daTypecVal.tagName).to.equal("DAType");
159+
expect(daTypecVal.getAttribute("id")).to.equal(
160+
"SBOw$oscd$_61d7e600207c9456",
161+
);
162+
163+
const daTypeSBOw = edits[3].node as Element;
164+
expect(daTypeSBOw.tagName).to.equal("DAType");
165+
expect(daTypeSBOw.getAttribute("id")).to.equal(
166+
"Oper$oscd$_5b11d63fa0ade588",
167+
);
168+
169+
const enumTypeOrCat = edits[4].node as Element;
170+
expect(enumTypeOrCat.tagName).to.equal("EnumType");
171+
expect(enumTypeOrCat.getAttribute("id")).to.equal(
172+
"ctlModel$oscd$_e975941313cb546c",
173+
);
174+
});
175+
176+
it("insert DataTypeTemplates when missing", () => {
177+
const edits = insertSelectedLNodeType(
178+
missingDataTypes,
179+
atccSelection,
180+
"ATCC",
181+
);
182+
183+
expect(edits.length).to.equal(19);
184+
185+
const lNodeType = edits[0].node as Element;
186+
expect(lNodeType.tagName).to.equal("DataTypeTemplates");
187+
});
188+
});

0 commit comments

Comments
 (0)