diff --git a/packages/open-scd/src/wizards/address.ts b/packages/open-scd/src/wizards/address.ts index 131296195..fbdff0651 100644 --- a/packages/open-scd/src/wizards/address.ts +++ b/packages/open-scd/src/wizards/address.ts @@ -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 => diff --git a/packages/open-scd/test/integration/wizards/address-wizarding-editing.test.ts b/packages/open-scd/test/integration/wizards/address-wizarding-editing.test.ts new file mode 100644 index 000000000..b69fa8c80 --- /dev/null +++ b/packages/open-scd/test/integration/wizards/address-wizarding-editing.test.ts @@ -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``); + 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 = ( + 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'); + }); + }); +}); diff --git a/packages/open-scd/test/testfiles/wizards/gsecontrol.scd b/packages/open-scd/test/testfiles/wizards/gsecontrol.scd index d4591941d..289a1b27c 100644 --- a/packages/open-scd/test/testfiles/wizards/gsecontrol.scd +++ b/packages/open-scd/test/testfiles/wizards/gsecontrol.scd @@ -23,7 +23,6 @@

01-0C-CD-01-00-10

-

005

4

0010

diff --git a/packages/open-scd/test/unit/wizards/__snapshots__/address.test.snap.js b/packages/open-scd/test/unit/wizards/__snapshots__/address.test.snap.js index e9a06d047..4f6747779 100644 --- a/packages/open-scd/test/unit/wizards/__snapshots__/address.test.snap.js +++ b/packages/open-scd/test/unit/wizards/__snapshots__/address.test.snap.js @@ -26,6 +26,7 @@ snapshots["address renderGseSmvAddress looks like the latest snapshot"] = > { expect(actions).to.be.empty; }); + it('update a Address element when VLAN ID gets created', async () => { + const input = 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 = (actions[0]).old.element; + const newElement = (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 = @@ -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); @@ -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); diff --git a/packages/open-scd/test/unit/wizards/gse.test.ts b/packages/open-scd/test/unit/wizards/gse.test.ts index 14712dcd3..4743767b9 100644 --- a/packages/open-scd/test/unit/wizards/gse.test.ts +++ b/packages/open-scd/test/unit/wizards/gse.test.ts @@ -121,7 +121,7 @@ describe('gse wizards', () => { }); it('update a GSE element when only VLAN-ID attribute changed', async () => { const input = inputs[2]; - input.value = '0F1'; + input.maybeValue = '0F1'; await input.requestUpdate(); const editorAction = updateGSEAction(gse); const complexAction = editorAction(inputs, newWizard()); @@ -132,9 +132,8 @@ describe('gse wizards', () => { expect(actions[1]).to.satisfy(isCreate); const oldElement = (actions[0]).old.element; const newElement = (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');