Skip to content

Commit

Permalink
feat(wizard/wizard-library): add create wizard for Function element
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobVogelsang committed May 19, 2022
1 parent 7ac5a94 commit a4abf4a
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/wizards/wizard-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ 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 { editGseControlWizard } from './gsecontrol.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;
Expand Down Expand Up @@ -202,7 +209,7 @@ export const wizards: Record<
},
Function: {
edit: emptyWizard,
create: emptyWizard,
create: createFunctionWizard,
},
GeneralEquipment: {
edit: emptyWizard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <MockWizardEditor>(
await fixture(
html`<mock-wizard-editor
><bay-editor .element=${doc.querySelector('Bay')}></bay-editor
></mock-wizard-editor>`
)
);

element = parent.querySelector('bay-editor');

(<HTMLElement>(
element?.shadowRoot?.querySelector('mwc-list-item[value="Function"]')
)).click();
await parent.updateComplete;

nameField = <WizardTextField>(
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]')
);

primaryAction = <HTMLElement>(
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;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <MockWizardEditor>(
await fixture(
html`<mock-wizard-editor
><substation-editor
.element=${doc.querySelector('Substation')}
></substation-editor
></mock-wizard-editor>`
)
);

element = parent.querySelector('substation-editor');

(<HTMLElement>(
element?.shadowRoot?.querySelector('mwc-list-item[value="Function"]')
)).click();
await parent.updateComplete;

nameField = <WizardTextField>(
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]')
);

primaryAction = <HTMLElement>(
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;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <MockWizardEditor>(
await fixture(
html`<mock-wizard-editor
><voltage-level-editor
.element=${doc.querySelector('VoltageLevel')}
></voltage-level-editor
></mock-wizard-editor>`
)
);

element = parent.querySelector('voltage-level-editor');

(<HTMLElement>(
element?.shadowRoot?.querySelector('mwc-list-item[value="Function"]')
)).click();
await parent.updateComplete;

nameField = <WizardTextField>(
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]')
);

primaryAction = <HTMLElement>(
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;
});
});
});
33 changes: 33 additions & 0 deletions test/unit/editors/substation/__snapshots__/bay-editor.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ snapshots["bay-editor looks like the latest snapshot"] =
ConductingEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="Function"
>
<span>
Function
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<div class="actionicon content">
Expand Down Expand Up @@ -187,6 +198,17 @@ snapshots["bay-editor with readonly property looks like the latest snapshot"] =
ConductingEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="Function"
>
<span>
Function
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<div class="actionicon content">
Expand Down Expand Up @@ -289,6 +311,17 @@ snapshots["bay-editor with function filter deactivated looks like the latest sna
ConductingEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="Function"
>
<span>
Function
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<function-editor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ snapshots["substation-editor looks like the latest snapshot"] =
VoltageLevel
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="Function"
>
<span>
Function
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<voltage-level-editor>
Expand Down Expand Up @@ -179,6 +190,17 @@ snapshots["substation-editor with readonly property looks like the latest snapsh
VoltageLevel
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="Function"
>
<span>
Function
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<voltage-level-editor readonly="">
Expand Down Expand Up @@ -273,6 +295,17 @@ snapshots["substation-editor with function filter deactivated looks like the lat
VoltageLevel
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="Function"
>
<span>
Function
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<div class="container lnode">
Expand Down
Loading

0 comments on commit a4abf4a

Please sign in to comment.