Skip to content

Commit 3b0bdf0

Browse files
committed
fix(tLN): Make supervision removal only remove Val textContent (closes #129)
1 parent 0ce54df commit 3b0bdf0

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

tDataSet/removeDataSet.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ describe("Utility function to remove DataSet element", () => {
1818
'ExtRef[srcCBName="someGse"], ExtRef[srcCBName="someGse2"], ExtRef[srcCBName="someGse3"]',
1919
),
2020
);
21-
const doi = extRefs[0].ownerDocument.querySelector(
22-
'LN[lnClass="LGOS"][inst="1"] > DOI',
21+
const val = extRefs[0].ownerDocument.querySelector(
22+
'LN[lnClass="LGOS"][inst="1"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val',
2323
)!;
24-
const ln = extRefs[0].ownerDocument.querySelector(
25-
'LN[lnClass="LGOS"][inst="2"]',
24+
const val2 = extRefs[0].ownerDocument.querySelector(
25+
'LN[lnClass="LGOS"][inst="2"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val',
2626
);
2727

2828
it("returns empty string when remove.node is not DataSet", () =>
29-
expect(removeDataSet({ node: doi })).to.be.empty);
29+
expect(removeDataSet({ node: val })).to.be.empty);
3030

3131
it("removes DataSet also removes/updates dependant data", () =>
3232
expect(edits.length).to.equal(10));
@@ -42,8 +42,8 @@ describe("Utility function to remove DataSet element", () => {
4242
});
4343

4444
it("including the subscriber supervision", () => {
45-
expect((edits[5] as Remove).node).to.equal(doi);
46-
expect((edits[6] as Remove).node).to.equal(ln);
45+
expect((edits[5] as Remove).node).to.equal(val!.firstChild);
46+
expect((edits[6] as Remove).node).to.equal(val2!.firstChild);
4747
});
4848

4949
it("including control Block updates", () => {

tExtRef/unsubscribe.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ describe("Function allowing to unsubscribe multiple external references", () =>
9292
'ExtRef[srcCBName="someGse"], ExtRef[srcCBName="someGse2"]',
9393
);
9494
const edits = unsubscribe(extRefs);
95-
const doi = extRefs[0].ownerDocument.querySelector(
96-
'LN[lnClass="LGOS"][inst="1"] > DOI',
95+
const val = extRefs[0].ownerDocument.querySelector(
96+
'LN[lnClass="LGOS"][inst="1"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val',
9797
);
98-
const ln = extRefs[0].ownerDocument.querySelector(
99-
'LN[lnClass="LGOS"][inst="2"]',
98+
const val2 = extRefs[0].ownerDocument.querySelector(
99+
'LN[lnClass="LGOS"][inst="2"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val',
100100
);
101-
102101
expect(edits.length).to.equal(5);
103102
expect(edits[0]).to.satisfies(isRemove);
104103
expect((edits[0] as Remove).node).to.equal(extRefs[0]);
@@ -107,9 +106,9 @@ describe("Function allowing to unsubscribe multiple external references", () =>
107106
expect(edits[2]).to.satisfies(isUpdate);
108107
expect((edits[2] as Update).element).to.equal(extRefs[2]);
109108
expect(edits[3]).to.satisfies(isRemove);
110-
expect((edits[3] as Remove).node).to.equal(doi);
109+
expect((edits[3] as Remove).node).to.equal(val!.firstChild);
111110
expect(edits[4]).to.satisfies(isRemove);
112-
expect((edits[4] as Remove).node).to.equal(ln);
111+
expect((edits[4] as Remove).node).to.equal(val2!.firstChild);
113112
});
114113

115114
it("with ignoreSupervision do not remove subscription LGOS supervision", () => {
@@ -157,8 +156,8 @@ describe("Function allowing to unsubscribe multiple external references", () =>
157156
withSubscriptionSupervision,
158157
'ExtRef[srcCBName="someSmv"]',
159158
);
160-
const doi = extRefs[0].ownerDocument.querySelector(
161-
'LN[lnClass="LSVS"][inst="1"] > DOI',
159+
const val = extRefs[0].ownerDocument.querySelector(
160+
'LN[lnClass="LSVS"][inst="1"] > DOI[name="SvCBRef"] > DAI[name="setSrcRef"] > Val',
162161
);
163162
const edits = unsubscribe(extRefs);
164163

@@ -170,7 +169,7 @@ describe("Function allowing to unsubscribe multiple external references", () =>
170169
expect(edits[2]).to.satisfies(isRemove);
171170
expect((edits[2] as Remove).node).to.equal(extRefs[1].parentElement);
172171
expect(edits[3]).to.satisfies(isRemove);
173-
expect((edits[3] as Remove).node).to.equal(doi);
172+
expect((edits[3] as Remove).node).to.equal(val?.firstChild);
174173
});
175174

176175
it("with ignoreSupervision do not remove subscription LGOS supervision", () => {

tLN/removeSubscriptionSupervision.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type GroupedExtRefs = {
1010
subscriberIed: Element;
1111
};
1212

13-
/** @returns Element to remove the subscription supervision */
13+
/** @returns Element to remove the subscription supervision control block reference */
1414
function removableSupervisionElement(
1515
ctrlBlock: Element,
1616
subscriberIed: Element,
@@ -24,15 +24,11 @@ function removableSupervisionElement(
2424
).find((val) => val.textContent === controlBlockObjRef(ctrlBlock));
2525
if (!valElement) return null;
2626

27-
const ln = valElement.closest("LN")!;
28-
const doi = valElement.closest("DOI")!;
27+
const textContentNode = Array.from(valElement.childNodes).find(
28+
(child) => child.nodeType === Node.TEXT_NODE,
29+
) as Element;
2930

30-
// do not remove logical nodes `LGOS`, `LSVS` unless privately tagged
31-
const canRemoveLn = ln.querySelector(
32-
':scope > Private[type="OpenSCD.create"]',
33-
);
34-
35-
return canRemoveLn ? ln : doi;
31+
return textContentNode ?? null;
3632
}
3733

3834
/** @returns Whether `DA` with name `setSrcRef` can edited by SCL editor */
@@ -44,7 +40,9 @@ function isSupervisionEditable(
4440
ctrlBlock,
4541
subscriberIed,
4642
);
47-
const supervisionLn = supervisionElement?.closest("LN") ?? null;
43+
if (!supervisionElement) return false;
44+
45+
const supervisionLn = supervisionElement.parentElement?.closest("LN") ?? null;
4846
if (!supervisionLn) return false;
4947

5048
return isSrcRefEditable(supervisionLn);

0 commit comments

Comments
 (0)