Skip to content

Commit

Permalink
fix: allow address update for new entries (#1331)
Browse files Browse the repository at this point in the history
* fix: allow address update for new entries

Signed-off-by: Stef3st <steffen.van.den.driest@alliander.com>

* chore: added tests

Signed-off-by: Stef3st <steffen.van.den.driest@alliander.com>

---------

Signed-off-by: Stef3st <steffen.van.den.driest@alliander.com>
  • Loading branch information
Stef3st authored Nov 7, 2023
1 parent 2066e4c commit d1f4ff9
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/open-scd/src/wizards/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export function contentGseOrSmvWizard(
}

function isEqualAddress(oldAddr: Element, newAdddr: Element): boolean {
if (
oldAddr.querySelectorAll('P').length !==
newAdddr.querySelectorAll('P').length
)
return false;

return (
Array.from(oldAddr.querySelectorAll('P')).filter(
pType =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { expect, fixture, html } from '@open-wc/testing';

import '../../mock-wizard-editor.js';
import { MockWizardEditor } from '../../mock-wizard-editor.js';
import { editGseWizard } from '../../../src/wizards/gse.js';
import { WizardTextField } from '../../../src/wizard-textfield.js';

describe('address wizarding editing integration', () => {
let doc: XMLDocument;
let element: MockWizardEditor;

beforeEach(async () => {
element = await fixture(html`<mock-wizard-editor></mock-wizard-editor>`);
doc = await fetch('/test/testfiles/wizards/gsecontrol.scd')
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
});

describe('editGseWizard', () => {
let primaryAction: HTMLElement;
let vlanPriorityField: WizardTextField;
let vlanIdField: WizardTextField;

beforeEach(async () => {
const wizard = editGseWizard(
doc.querySelector('GSE[ldInst="CircuitBreaker_CB1"][cbName="GCB"]')!
);

element.workflow.push(() => wizard);
await element.requestUpdate();
primaryAction = <HTMLElement>(
element.wizardUI.dialog?.querySelector(
'mwc-button[slot="primaryAction"]'
)
);
vlanIdField = element.wizardUI.dialog!.querySelector(
'wizard-textfield[label="VLAN-ID"]'
)!;
vlanPriorityField = element.wizardUI.dialog!.querySelector(
'wizard-textfield[label="VLAN-PRIORITY"]'
)!;
await vlanPriorityField.updateComplete;
});

it('VLAN-ID gets saved after nullswitch toggle', async () => {
expect(
doc
.querySelector(
'GSE[ldInst="CircuitBreaker_CB1"][cbName="GCB"] > Address > P[type="VLAN-ID"]'
)
?.textContent?.trim()
).to.be.undefined;

expect(vlanIdField.nullSwitch?.checked).to.be.false;

vlanIdField.nullSwitch?.click();
vlanIdField.value = '007';
primaryAction.click();
await element.updateComplete;

expect(vlanIdField.nullSwitch?.checked).to.be.true;

expect(
doc
.querySelector(
'GSE[ldInst="CircuitBreaker_CB1"][cbName="GCB"] > Address > P[type="VLAN-ID"]'
)
?.textContent?.trim()
).to.equal('007');
});
});
});
1 change: 0 additions & 1 deletion packages/open-scd/test/testfiles/wizards/gsecontrol.scd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<GSE ldInst="CircuitBreaker_CB1" cbName="GCB">
<Address>
<P type="MAC-Address">01-0C-CD-01-00-10</P>
<P type="VLAN-ID">005</P>
<P type="VLAN-PRIORITY">4</P>
<P type="APPID">0010</P>
</Address>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ snapshots["address renderGseSmvAddress looks like the latest snapshot"] =
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="VLAN-ID"
nullable=""
pattern="[0-9A-F]{3}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ snapshots["gse wizards editGseWizard looks like the latest snapshot"] =
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="VLAN-ID"
nullable=""
pattern="[0-9A-F]{3}"
Expand Down
33 changes: 29 additions & 4 deletions packages/open-scd/test/unit/wizards/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ describe('address', () => {
expect(actions).to.be.empty;
});

it('update a Address element when VLAN ID gets created', async () => {
const input = <WizardTextField>inputs[2];
const type = input.label;
const newValue = 'newValue';

input.maybeValue = newValue;
await input.requestUpdate();

const actions = updateAddress(gse, addressContent(inputs), false);
expect(actions.length).to.equal(2);
expect(actions[0]).to.satisfy(isDelete);
expect(actions[1]).to.satisfy(isCreate);
const oldElement = <Element>(<Delete>actions[0]).old.element;
const newElement = <Element>(<Create>actions[1]).new.element;
expect(
oldElement.querySelector(`P[type="${type}"]`)?.textContent?.trim()
).to.be.undefined;
expect(
newElement.querySelector(`P[type="${type}"]`)?.textContent?.trim()
).to.equal(newValue);
expect(
newElement.querySelector(`P[type="${type}"]`)
).to.not.have.attribute('xsi:type', `tP_${type}`);
});

it('update a Address element when at least one attribute changes', async () => {
for (const rawInput of inputs) {
const input =
Expand All @@ -132,9 +157,9 @@ describe('address', () => {

const type = input.label;
const newValue = 'newValue';
const oldValue = input.value;
const oldValue = input.value || undefined;

input.value = newValue;
input.maybeValue = newValue;
await input.requestUpdate();

const actions = updateAddress(gse, addressContent(inputs), false);
Expand Down Expand Up @@ -164,9 +189,9 @@ describe('address', () => {

const type = input.label;
const newValue = input.value;
const oldValue = input.value;
const oldValue = input.value || undefined;

input.value = newValue;
input.maybeValue = newValue;
await input.requestUpdate();

const actions = updateAddress(gse, addressContent(inputs), true);
Expand Down
7 changes: 3 additions & 4 deletions packages/open-scd/test/unit/wizards/gse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('gse wizards', () => {
});
it('update a GSE element when only VLAN-ID attribute changed', async () => {
const input = <WizardTextField>inputs[2];
input.value = '0F1';
input.maybeValue = '0F1';
await input.requestUpdate();
const editorAction = updateGSEAction(gse);
const complexAction = editorAction(inputs, newWizard());
Expand All @@ -132,9 +132,8 @@ describe('gse wizards', () => {
expect(actions[1]).to.satisfy(isCreate);
const oldElement = <Element>(<Delete>actions[0]).old.element;
const newElement = <Element>(<Create>actions[1]).new.element;
expect(
oldElement.querySelector('P[type="VLAN-ID"]')?.textContent?.trim()
).to.equal('005');
expect(oldElement.querySelector('P[type="VLAN-ID"]')?.textContent?.trim())
.to.be.undefined;
expect(
newElement.querySelector('P[type="VLAN-ID"]')?.textContent?.trim()
).to.equal('0F1');
Expand Down

0 comments on commit d1f4ff9

Please sign in to comment.