diff --git a/src/wizards/wizard-library.ts b/src/wizards/wizard-library.ts index d993403bcd..d628e62141 100644 --- a/src/wizards/wizard-library.ts +++ b/src/wizards/wizard-library.ts @@ -15,14 +15,21 @@ import { voltageLevelCreateWizard, voltageLevelEditWizard, } from './voltagelevel.js'; -import { createPowerTransformerWizard, editPowerTransformerWizard } from './powertransformer.js'; +import { + createPowerTransformerWizard, + editPowerTransformerWizard, +} from './powertransformer.js'; import { editSubNetworkWizard } from './subnetwork.js'; import { editIEDWizard } from './ied.js'; import { editTrgOpsWizard } from './trgops.js'; import { createDaWizard } from './da.js'; import { editDAIWizard } from './dai.js'; +import { createFunctionWizard } from './function.js'; -type SclElementWizard = (element: Element, instanceElement?: Element) => Wizard | undefined; +type SclElementWizard = ( + element: Element, + instanceElement?: Element +) => Wizard | undefined; export function emptyWizard(): Wizard | undefined { return; @@ -201,7 +208,7 @@ export const wizards: Record< }, Function: { edit: emptyWizard, - create: emptyWizard, + create: createFunctionWizard, }, GeneralEquipment: { edit: emptyWizard, diff --git a/test/integration/editors/substation/bay-editor-wizarding-editing.test.ts b/test/integration/editors/substation/bay-editor-wizarding-editing.test.ts index 86f737074a..cd5629f711 100644 --- a/test/integration/editors/substation/bay-editor-wizarding-editing.test.ts +++ b/test/integration/editors/substation/bay-editor-wizarding-editing.test.ts @@ -342,4 +342,77 @@ describe('bay-editor wizarding editing integration', () => { ); }); }); + + describe('open create wizard for element Function', () => { + let doc: XMLDocument; + let parent: MockWizardEditor; + let element: BayEditor | null; + + let nameField: WizardTextField; + let primaryAction: HTMLElement; + + beforeEach(async () => { + doc = await fetch('/test/testfiles/zeroline/functions.scd') + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + parent = ( + await fixture( + html`` + ) + ); + + element = parent.querySelector('bay-editor'); + + (( + element?.shadowRoot?.querySelector('mwc-list-item[value="Function"]') + )).click(); + await parent.updateComplete; + + nameField = ( + parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]') + ); + + primaryAction = ( + parent.wizardUI.dialog?.querySelector( + 'mwc-button[slot="primaryAction"]' + ) + ); + }); + + it('does not add Function if name attribute is not unique', async () => { + expect( + doc.querySelector('Bay[name="COUPLING_BAY"] > Function[name="bayName"]') + ).to.exist; + + nameField.value = 'bayName'; + primaryAction.click(); + await parent.updateComplete; + + expect( + doc.querySelectorAll( + 'Bay[name="COUPLING_BAY"] > Function[name="bayName"]' + ).length + ).to.equal(1); + }); + + it('does add Function if name attribute is unique', async () => { + expect( + doc.querySelector( + 'Bay[name="COUPLING_BAY"] > Function[name="someNewFunction"]' + ) + ).to.not.exist; + + nameField.value = 'someNewFunction'; + await parent.updateComplete; + primaryAction.click(); + + expect( + doc.querySelector( + 'Bay[name="COUPLING_BAY"] > Function[name="someNewFunction"]' + ) + ).to.exist; + }); + }); }); diff --git a/test/integration/editors/substation/substation-editor-wizarding-editing.test.ts b/test/integration/editors/substation/substation-editor-wizarding-editing.test.ts index 65e7780fa7..d1e80b5365 100644 --- a/test/integration/editors/substation/substation-editor-wizarding-editing.test.ts +++ b/test/integration/editors/substation/substation-editor-wizarding-editing.test.ts @@ -210,4 +210,70 @@ describe('substation-editor wizarding editing integration', () => { expect(doc.querySelector('Substation')).to.not.exist; }); }); + + describe('open create wizard for element Function', () => { + let doc: XMLDocument; + let parent: MockWizardEditor; + let element: SubstationEditor | null; + + let nameField: WizardTextField; + let primaryAction: HTMLElement; + + beforeEach(async () => { + doc = await fetch('/test/testfiles/zeroline/functions.scd') + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + parent = ( + await fixture( + html`` + ) + ); + + element = parent.querySelector('substation-editor'); + + (( + element?.shadowRoot?.querySelector('mwc-list-item[value="Function"]') + )).click(); + await parent.updateComplete; + + nameField = ( + parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]') + ); + + primaryAction = ( + parent.wizardUI.dialog?.querySelector( + 'mwc-button[slot="primaryAction"]' + ) + ); + }); + + it('does not add Function if name attribute is not unique', async () => { + expect(doc.querySelector('Substation > Function[name="myFunc"]')).to + .exist; + + nameField.value = 'myFunc'; + primaryAction.click(); + await parent.updateComplete; + + expect( + doc.querySelectorAll('Substation > Function[name="myFunc"]').length + ).to.equal(1); + }); + + it('does add Function if name attribute is unique', async () => { + expect(doc.querySelector('Substation > Function[name="someNewFunction"]')) + .to.not.exist; + + nameField.value = 'someNewFunction'; + await parent.updateComplete; + primaryAction.click(); + + expect(doc.querySelector('Substation > Function[name="someNewFunction"]')) + .to.exist; + }); + }); }); diff --git a/test/integration/editors/substation/voltage-level-editor-wizarding-editing.test.ts b/test/integration/editors/substation/voltage-level-editor-wizarding-editing.test.ts index e2c9670038..2f75d96ed7 100644 --- a/test/integration/editors/substation/voltage-level-editor-wizarding-editing.test.ts +++ b/test/integration/editors/substation/voltage-level-editor-wizarding-editing.test.ts @@ -428,4 +428,81 @@ describe('voltage-level-editor wizarding editing integration', () => { ); }); }); + + describe('open create wizard for element Function', () => { + let doc: XMLDocument; + let parent: MockWizardEditor; + let element: VoltageLevelEditor | null; + + let nameField: WizardTextField; + let primaryAction: HTMLElement; + + beforeEach(async () => { + doc = await fetch('/test/testfiles/zeroline/functions.scd') + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + parent = ( + await fixture( + html`` + ) + ); + + element = parent.querySelector('voltage-level-editor'); + + (( + element?.shadowRoot?.querySelector('mwc-list-item[value="Function"]') + )).click(); + await parent.updateComplete; + + nameField = ( + parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]') + ); + + primaryAction = ( + parent.wizardUI.dialog?.querySelector( + 'mwc-button[slot="primaryAction"]' + ) + ); + }); + + it('does not add Function if name attribute is not unique', async () => { + expect( + doc.querySelector( + 'VoltageLevel[name="E1"] > Function[name="voltLvName"]' + ) + ).to.exist; + + nameField.value = 'voltLvName'; + primaryAction.click(); + await parent.updateComplete; + + expect( + doc.querySelectorAll( + 'VoltageLevel[name="E1"] > Function[name="voltLvName"]' + ).length + ).to.equal(1); + }); + + it('does add Function if name attribute is unique', async () => { + expect( + doc.querySelector( + 'VoltageLevel[name="E1"] > Function[name="someNewFunction"]' + ) + ).to.not.exist; + + nameField.value = 'someNewFunction'; + await parent.updateComplete; + primaryAction.click(); + + expect( + doc.querySelector( + 'VoltageLevel[name="E1"] > Function[name="someNewFunction"]' + ) + ).to.exist; + }); + }); }); diff --git a/test/unit/editors/substation/__snapshots__/bay-editor.test.snap.js b/test/unit/editors/substation/__snapshots__/bay-editor.test.snap.js index c9cf9629b7..07cdf86415 100644 --- a/test/unit/editors/substation/__snapshots__/bay-editor.test.snap.js +++ b/test/unit/editors/substation/__snapshots__/bay-editor.test.snap.js @@ -85,6 +85,17 @@ snapshots["bay-editor looks like the latest snapshot"] = ConductingEquipment + + + Function + +
@@ -187,6 +198,17 @@ snapshots["bay-editor with readonly property looks like the latest snapshot"] = ConductingEquipment + + + Function + +
@@ -289,6 +311,17 @@ snapshots["bay-editor with function filter deactivated looks like the latest sna ConductingEquipment + + + Function + + diff --git a/test/unit/editors/substation/__snapshots__/substation-editor.test.snap.js b/test/unit/editors/substation/__snapshots__/substation-editor.test.snap.js index 45962bfda5..ba9c015999 100644 --- a/test/unit/editors/substation/__snapshots__/substation-editor.test.snap.js +++ b/test/unit/editors/substation/__snapshots__/substation-editor.test.snap.js @@ -85,6 +85,17 @@ snapshots["substation-editor looks like the latest snapshot"] = VoltageLevel + + + Function + + @@ -179,6 +190,17 @@ snapshots["substation-editor with readonly property looks like the latest snapsh VoltageLevel + + + Function + + @@ -273,6 +295,17 @@ snapshots["substation-editor with function filter deactivated looks like the lat VoltageLevel + + + Function + + diff --git a/test/unit/editors/substation/__snapshots__/voltage-level-editor.test.snap.js b/test/unit/editors/substation/__snapshots__/voltage-level-editor.test.snap.js index c87b96a48f..6ec0e16378 100644 --- a/test/unit/editors/substation/__snapshots__/voltage-level-editor.test.snap.js +++ b/test/unit/editors/substation/__snapshots__/voltage-level-editor.test.snap.js @@ -86,6 +86,17 @@ snapshots["voltage-level-editor looks like the latest snapshot"] = Bay + + + Function + +
@@ -183,6 +194,17 @@ snapshots["voltage-level-editor with readonly property looks like the latest sna Bay + + + Function + +
@@ -280,6 +302,17 @@ snapshots["voltage-level-editor with function filter deactivated looks like the Bay + + + Function + +