diff --git a/tDataSet/removeDataSet.spec.ts b/tDataSet/removeDataSet.spec.ts index b933101..8c8244b 100644 --- a/tDataSet/removeDataSet.spec.ts +++ b/tDataSet/removeDataSet.spec.ts @@ -18,15 +18,15 @@ describe("Utility function to remove DataSet element", () => { 'ExtRef[srcCBName="someGse"], ExtRef[srcCBName="someGse2"], ExtRef[srcCBName="someGse3"]', ), ); - const doi = extRefs[0].ownerDocument.querySelector( - 'LN[lnClass="LGOS"][inst="1"] > DOI', + const val = extRefs[0].ownerDocument.querySelector( + 'LN[lnClass="LGOS"][inst="1"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val', )!; const ln = extRefs[0].ownerDocument.querySelector( 'LN[lnClass="LGOS"][inst="2"]', ); it("returns empty string when remove.node is not DataSet", () => - expect(removeDataSet({ node: doi })).to.be.empty); + expect(removeDataSet({ node: val })).to.be.empty); it("removes DataSet also removes/updates dependant data", () => expect(edits.length).to.equal(10)); @@ -42,7 +42,7 @@ describe("Utility function to remove DataSet element", () => { }); it("including the subscriber supervision", () => { - expect((edits[5] as Remove).node).to.equal(doi); + expect((edits[5] as Remove).node).to.equal(val.firstChild); expect((edits[6] as Remove).node).to.equal(ln); }); diff --git a/tExtRef/unsubscribe.spec.ts b/tExtRef/unsubscribe.spec.ts index 897a0fe..8685acd 100644 --- a/tExtRef/unsubscribe.spec.ts +++ b/tExtRef/unsubscribe.spec.ts @@ -92,8 +92,8 @@ describe("Function allowing to unsubscribe multiple external references", () => 'ExtRef[srcCBName="someGse"], ExtRef[srcCBName="someGse2"]', ); const edits = unsubscribe(extRefs); - const doi = extRefs[0].ownerDocument.querySelector( - 'LN[lnClass="LGOS"][inst="1"] > DOI', + const val = extRefs[0].ownerDocument.querySelector( + 'LN[lnClass="LGOS"][inst="1"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val', ); const ln = extRefs[0].ownerDocument.querySelector( 'LN[lnClass="LGOS"][inst="2"]', @@ -107,7 +107,7 @@ describe("Function allowing to unsubscribe multiple external references", () => expect(edits[2]).to.satisfies(isUpdate); expect((edits[2] as Update).element).to.equal(extRefs[2]); expect(edits[3]).to.satisfies(isRemove); - expect((edits[3] as Remove).node).to.equal(doi); + expect((edits[3] as Remove).node).to.equal(val.firstChild); expect(edits[4]).to.satisfies(isRemove); expect((edits[4] as Remove).node).to.equal(ln); }); @@ -157,8 +157,8 @@ describe("Function allowing to unsubscribe multiple external references", () => withSubscriptionSupervision, 'ExtRef[srcCBName="someSmv"]', ); - const doi = extRefs[0].ownerDocument.querySelector( - 'LN[lnClass="LSVS"][inst="1"] > DOI', + const val = extRefs[0].ownerDocument.querySelector( + 'LN[lnClass="LSVS"][inst="1"] > DOI[name="SvCBRef"] > DAI[name="setSrcRef"] > Val', ); const edits = unsubscribe(extRefs); @@ -170,7 +170,7 @@ describe("Function allowing to unsubscribe multiple external references", () => expect(edits[2]).to.satisfies(isRemove); expect((edits[2] as Remove).node).to.equal(extRefs[1].parentElement); expect(edits[3]).to.satisfies(isRemove); - expect((edits[3] as Remove).node).to.equal(doi); + expect((edits[3] as Remove).node).to.equal(val!.firstChild); }); it("with ignoreSupervision do not remove subscription LGOS supervision", () => { diff --git a/tLN/removeSubscriptionSupervision.ts b/tLN/removeSubscriptionSupervision.ts index 1b2bbbd..20f5fb7 100644 --- a/tLN/removeSubscriptionSupervision.ts +++ b/tLN/removeSubscriptionSupervision.ts @@ -14,25 +14,29 @@ type GroupedExtRefs = { function removableSupervisionElement( ctrlBlock: Element, subscriberIed: Element, -): Element | null { +): Node | Element | null { const supervisionType = ctrlBlock.tagName === "GSEControl" ? "LGOS" : "LSVS"; + const doiName = ctrlBlock.tagName === "GSEControl" ? "GoCBRef" : "SvCBRef"; const valElement = Array.from( subscriberIed.querySelectorAll( - `LN[lnClass="${supervisionType}"] > DOI > DAI > Val`, + `LN[lnClass="${supervisionType}"] > DOI[name="${doiName}"] > DAI[name="setSrcRef"] > Val`, ), ).find((val) => val.textContent === controlBlockObjRef(ctrlBlock)); if (!valElement) return null; const ln = valElement.closest("LN")!; - const doi = valElement.closest("DOI")!; - // do not remove logical nodes `LGOS`, `LSVS` unless privately tagged const canRemoveLn = ln.querySelector( ':scope > Private[type="OpenSCD.create"]', ); + if (canRemoveLn) return ln; - return canRemoveLn ? ln : doi; + return ( + Array.from(valElement.childNodes).find( + (child: Node) => child.nodeType === Node.TEXT_NODE, + ) ?? null + ); } /** @returns Whether `DA` with name `setSrcRef` can edited by SCL editor */ @@ -44,7 +48,15 @@ function isSupervisionEditable( ctrlBlock, subscriberIed, ); - const supervisionLn = supervisionElement?.closest("LN") ?? null; + if (!supervisionElement) return false; + + let supervisionLn: Element | null = null; + + if (supervisionElement.nodeType === Node.TEXT_NODE) { + supervisionLn = supervisionElement.parentElement?.closest("LN") ?? null; + } else { + supervisionLn = (supervisionElement as Element).closest("LN") ?? null; + } if (!supervisionLn) return false; return isSrcRefEditable(supervisionLn);