Skip to content

Commit 2a09fe0

Browse files
fix(substation/lnodewizard): localize LNode changes (#245)
1 parent 07c8b3e commit 2a09fe0

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

src/editors/substation/lnodewizard.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { get, translate } from 'lit-translate';
44
import {
55
createElement,
66
EditorAction,
7+
getChildElementsByTagName,
78
getReference,
89
identity,
10+
isPublic,
911
referencePath,
1012
selector,
1113
Wizard,
@@ -131,8 +133,8 @@ export function lNodeWizardAction(parent: Element): WizardActor {
131133
})
132134
.filter(item => item !== null);
133135

134-
const oldLNodes = Array.from(parent.getElementsByTagName('LNode')).filter(
135-
item => !item.closest('Private')
136+
const oldLNodes = getChildElementsByTagName(parent, 'LNode').filter(
137+
isPublic
136138
);
137139

138140
const deleteActions = oldLNodes

src/foundation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,15 @@ export function getVersion(element: Element): string {
24932493
return header[0].getAttribute('version') ?? '2003';
24942494
}
24952495

2496+
export function getChildElementsByTagName(
2497+
element: Element,
2498+
tag: string
2499+
): Element[] {
2500+
return Array.from(element.children).filter(
2501+
element => element.tagName === tag
2502+
);
2503+
}
2504+
24962505
declare global {
24972506
interface ElementEventMap {
24982507
['pending-state']: PendingStateEvent;

test/integration/editors/substation/lnodewizard.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ describe('lnodewizard', () => {
125125
)
126126
).to.exist;
127127
});
128+
it('only create and remove its own logical node references', async () => {
129+
const allLNodesNumber = doc.querySelectorAll(
130+
'Bay[name="COUPLING_BAY"] LNode'
131+
).length;
132+
(<List>(
133+
element.wizardUI.shadowRoot
134+
?.querySelector('mwc-dialog:nth-child(2)')
135+
?.querySelector('filtered-list')
136+
)).items[3].click();
137+
await element.updateComplete;
138+
(<HTMLElement>(
139+
element.wizardUI.shadowRoot
140+
?.querySelector('mwc-dialog:nth-child(2)')
141+
?.querySelector('mwc-button[slot="primaryAction"]')
142+
)).click();
143+
await element.updateComplete;
144+
expect(
145+
doc.querySelectorAll('Bay[name="COUPLING_BAY"] LNode').length
146+
).to.equal(allLNodesNumber + 1);
147+
});
128148
});
129149
});
130150
});

test/unit/foundation.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
tags,
2222
getReference,
2323
SCLTag,
24+
getChildElementsByTagName,
2425
} from '../../src/foundation.js';
2526

2627
import { MockAction } from './mock-actions.js';
@@ -486,4 +487,21 @@ describe('foundation', () => {
486487
);
487488
});
488489
});
490+
491+
describe('getChildElementsByTagName', () => {
492+
let doc: Document;
493+
beforeEach(async () => {
494+
doc = await fetch('/base/test/testfiles/lnodewizard.scd')
495+
.then(response => response.text())
496+
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
497+
});
498+
it('returns a child Element array with a specific tag', () => {
499+
const parent = doc.querySelector('Bay[name="COUPLING_BAY"]');
500+
expect(getChildElementsByTagName(parent!, 'LNode').length).to.have.equal(
501+
parent?.querySelectorAll(
502+
':root > Substation > VoltageLevel > Bay[name="COUPLING_BAY"] > LNode'
503+
).length
504+
);
505+
});
506+
});
489507
});

0 commit comments

Comments
 (0)