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
8 changes: 4 additions & 4 deletions tDataSet/removeDataSet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
});

Expand Down
12 changes: 6 additions & 6 deletions tExtRef/unsubscribe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]',
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);

Expand All @@ -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", () => {
Expand Down
24 changes: 18 additions & 6 deletions tLN/removeSubscriptionSupervision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down