Skip to content

Commit 82a7b99

Browse files
fix(tDataTypeTemplate): correct usage of isArray key
1 parent 5047178 commit 82a7b99

File tree

4 files changed

+124
-2
lines changed

4 files changed

+124
-2
lines changed

tDataTypeTemplates/insertSelecetdLNodeType.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
atccSelection,
77
invalidSelection,
88
ltrkSelection,
9+
mhaiSelection,
910
mmxuSelection,
11+
ptocSelection,
1012
} from "./insertSelectedLNodeType.testdata.js";
1113

1214
import {
@@ -189,4 +191,28 @@ describe("insertLNodeTypeSelection", () => {
189191
const lNodeType = edits[0].node as Element;
190192
expect(lNodeType.tagName).to.equal("DataTypeTemplates");
191193
});
194+
195+
it("add count attribute to data attribute in case is an array", () => {
196+
const data = nsdToJson("PTOC") as LNodeDescription;
197+
const edits = insertSelectedLNodeType(
198+
missingDataTypes,
199+
ptocSelection,
200+
{ class: "PTOC", data },
201+
);
202+
203+
const doTypeEdit = edits[5].node as Element;
204+
expect(doTypeEdit.querySelector('DA[name="crvPts"]')?.getAttribute('count')).to.equal("maxPts");
205+
});
206+
207+
it("add count attribute to sub data object in case is an array", () => {
208+
const data = nsdToJson("MHAI") as LNodeDescription;
209+
const edits = insertSelectedLNodeType(
210+
missingDataTypes,
211+
mhaiSelection,
212+
{ class: "MHAI", data },
213+
);
214+
215+
const doTypeEdit = edits[4].node as Element;
216+
expect(doTypeEdit.querySelector('SDO[name="phsAHar"]')?.getAttribute('count')).to.equal("maxPts");
217+
});
192218
});

tDataTypeTemplates/insertSelectedLNodeType.testdata.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,88 @@ export const invalidSelection = {
428428
"ldNs": {}
429429
}
430430
};
431+
432+
export const ptocSelection = {
433+
"Beh": {
434+
"q": {},
435+
"stVal": {
436+
"blocked": {},
437+
"off": {},
438+
"on": {},
439+
"test": {},
440+
"test/blocked": {}
441+
},
442+
"t": {}
443+
},
444+
"Op": {
445+
"general": {},
446+
"q": {},
447+
"t": {}
448+
},
449+
"Str": {
450+
"dirGeneral": {
451+
"backward": {},
452+
"both": {},
453+
"forward": {},
454+
"unknown": {}
455+
},
456+
"general": {},
457+
"q": {},
458+
"t": {}
459+
},
460+
"TmAChr": {
461+
"crvPts": {
462+
"xVal": {},
463+
"yVal": {}
464+
},
465+
"maxPts": {},
466+
"numPts": {},
467+
"xD": {},
468+
"yD": {},
469+
"yUnits": {
470+
"SIUnit": {
471+
"°C": {},
472+
"1/s": {}
473+
}
474+
},
475+
"xUnits": {
476+
"SIUnit": {
477+
"°C": {},
478+
"1/s": {}
479+
}
480+
}
481+
}
482+
}
483+
484+
export const mhaiSelection = {
485+
"Beh": {
486+
"q": {},
487+
"stVal": {
488+
"blocked": {},
489+
"off": {},
490+
"on": {},
491+
"test": {},
492+
"test/blocked": {}
493+
},
494+
"t": {}
495+
},
496+
"HA": {
497+
"evalTm": {},
498+
"frequency": {},
499+
"maxPts": {},
500+
"numCyc": {},
501+
"numHar": {},
502+
"phsAHar": {
503+
"cVal": {
504+
"mag": {
505+
"f": {}
506+
},
507+
"ang": {
508+
"f": {}
509+
}
510+
},
511+
"q": {},
512+
"t": {}
513+
}
514+
}
515+
}

tDataTypeTemplates/insertSelectedLNodeType.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function hashElement(element: Element): string {
152152
return cyrb64(JSON.stringify(describeElement(element)));
153153
}
154154

155+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
155156
function data(lnData: any, path: string[]): any {
156157
let d = lnData;
157158
for (const slug of path.slice(0, -1)) d = d[slug].children;
@@ -329,6 +330,8 @@ export function insertSelectedLNodeType(
329330
qchg?: string;
330331
typeKind?: "BASIC" | "ENUMERATED" | "CONSTRUCTED" | "undefined";
331332
type?: string;
333+
isArray?: string;
334+
sizeAttribute?: string;
332335
},
333336
][] = Object.entries(dO.children);
334337

@@ -340,11 +343,21 @@ export function insertSelectedLNodeType(
340343
const type = createDOType(path.concat([name]), selection[name]);
341344
const sdo = createElement(doc, "SDO", { name, transient, type });
342345
doType.prepend(sdo);
346+
347+
// For arrays set count attribute
348+
if (dep.isArray === "true" && dep.sizeAttribute) {
349+
sdo.setAttribute("count", dep.sizeAttribute);
350+
}
343351
} else {
344352
const { fc, dchg, dupd, qchg } = dep;
345353

346354
const da = createElement(doc, "DA", { name, fc, dchg, dupd, qchg });
347355

356+
// For arrays set count attribute
357+
if (dep.isArray === "true" && dep.sizeAttribute) {
358+
da.setAttribute("count", dep.sizeAttribute);
359+
}
360+
348361
if (dep.typeKind === "BASIC" || !dep.typeKind) {
349362
da.setAttribute("bType", dep.type!);
350363
}

tDataTypeTemplates/nsdToJson.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ describe("NSD to Json parsing function", () => {
2929
const data = nsdToJson(lnClass)!;
3030
const sClass = lnClassData[lnClass];
3131

32-
console.log(lnClass);
33-
3432
Object.keys(sClass).forEach((key) => {
3533
expect(data[key]).to.deep.equal(sClass[key]);
3634
});

0 commit comments

Comments
 (0)