Skip to content

Commit

Permalink
Added create subequipment wizard (#1097)
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Wilbrink <pascal.wilbrink@alliander.com>

Signed-off-by: Pascal Wilbrink <pascal.wilbrink@alliander.com>
Co-authored-by: Dennis Labordus <dennis.labordus@alliander.com>
  • Loading branch information
pascalwilbrink and Dennis Labordus authored Nov 29, 2022
1 parent 9fbfbcd commit 875b255
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,6 @@ export const tags: Record<
'TransformerWinding',
'SubEquipment',
'EqFunction',
'SubEquipment',
],
},
Private: {
Expand Down
54 changes: 52 additions & 2 deletions src/wizards/subequipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { get, translate } from 'lit-translate';

import {
cloneElement,
createElement,
getChildElementsByTagName,
getValue,
SimpleAction,
Expand All @@ -22,7 +23,7 @@ interface ContentOptions {
reservedNames: string[];
}

export function contentFunctionWizard(
export function contentSubEquipmentWizard(
content: ContentOptions
): TemplateResult[] {
return [
Expand Down Expand Up @@ -112,7 +113,7 @@ export function editSubEquipmentWizard(element: Element): Wizard {
action: updateSubEquipmentAction(element),
},
content: [
...contentFunctionWizard({
...contentSubEquipmentWizard({
name,
desc,
phase,
Expand All @@ -123,3 +124,52 @@ export function editSubEquipmentWizard(element: Element): Wizard {
},
];
}

function createSubEquipmentAction(parent: Element): WizardActor {
return (inputs: WizardInputElement[]) => {
const subEquipmentAttrs: Record<string, string | null> = {};
const subEquipmentKeys = ['name', 'desc', 'phase', 'virtual'];
subEquipmentKeys.forEach(key => {
subEquipmentAttrs[key] = getValue(inputs.find(i => i.label === key)!);
});

const subEquipment = createElement(
parent.ownerDocument,
'SubEquipment',
subEquipmentAttrs
);

return [{ new: { parent, element: subEquipment } }];
};
}

export function createSubEquipmentWizard(parent: Element): Wizard {
const name = '';
const desc = null;
const phase = null;
const virtual = null;
const reservedNames = Array.from(parent.querySelectorAll('SubEquipment')).map(
subEquipment => subEquipment.getAttribute('name')!
);

return [
{
title: get('wizard.title.add', { tagName: 'SubEquipment' }),
primary: {
icon: 'save',
label: get('save'),
action: createSubEquipmentAction(parent),
},
content: [
...contentSubEquipmentWizard({
name,
desc,
phase,
virtual,
reservedNames,
}),
],
},
];
}

4 changes: 2 additions & 2 deletions src/wizards/wizard-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
editSubFunctionWizard,
} from './subfunction.js';
import { editSampledValueControlWizard } from './sampledvaluecontrol.js';
import { editSubEquipmentWizard } from './subequipment.js';
import { createSubEquipmentWizard, editSubEquipmentWizard } from './subequipment.js';
import { editGeneralEquipmentWizard } from './generalEquipment.js';

type SclElementWizard = (
Expand Down Expand Up @@ -485,7 +485,7 @@ export const wizards: Record<
},
SubEquipment: {
edit: editSubEquipmentWizard,
create: emptyWizard,
create: createSubEquipmentWizard,
},
SubFunction: {
edit: editSubFunctionWizard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const openAndCancelMenu: (
new Promise(async resolve => {
expect(parent.wizardUI.dialog).to.be.undefined;

element?.shadowRoot?.querySelector<MenuBase>("mwc-icon-button[icon='playlist_add']")!.click();
element?.shadowRoot
?.querySelector<MenuBase>("mwc-icon-button[icon='playlist_add']")!
.click();
const lnodMenuItem: ListItemBase =
element?.shadowRoot?.querySelector<ListItemBase>(
`mwc-list-item[value='LNode']`
Expand Down Expand Up @@ -151,5 +153,47 @@ describe('powertransformer-editor wizarding editing integration', () => {
await openAndCancelMenu(parent, element!);
await openAndCancelMenu(parent, element!);
});

it('Should add SubEquipment', async () => {
expect(parent.wizardUI.dialog).to.be.undefined;

element?.shadowRoot
?.querySelector<MenuBase>("mwc-icon-button[icon='playlist_add']")!
.click();

element?.shadowRoot
?.querySelector<ListItemBase>(`mwc-list-item[value='SubEquipment']`)!
.click();

await new Promise(resolve => setTimeout(resolve, 100)); // await animation

expect(parent.wizardUI.dialog).to.exist;

const nameTextField: WizardTextField =
parent.wizardUI!.dialog!.querySelector<WizardTextField>(
'wizard-textfield[label="name"]'
)!;

const subEquipmentName = 'unique-name';

nameTextField.value = subEquipmentName;

await parent.updateComplete;

const primaryAction: HTMLElement = <HTMLElement>(
parent.wizardUI.dialog?.querySelector(
'mwc-button[slot="primaryAction"]'
)
);

primaryAction.click();
await parent.updateComplete;

expect(
doc.querySelectorAll(
`PowerTransformer[name="myPtr2"] > SubEquipment[name="${subEquipmentName}"]`
).length
).to.equal(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ snapshots["conducting-equipment-editor rendered as action pane looks like the la
EqFunction
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
</action-pane>
Expand Down Expand Up @@ -216,6 +227,17 @@ snapshots["conducting-equipment-editor rendered as action pane with EqFunction c
EqFunction
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<eq-function-editor showfunctions="">
Expand Down Expand Up @@ -311,6 +333,17 @@ snapshots["conducting-equipment-editor rendered as action pane with LNode childr
EqFunction
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<div class="container lnode">
Expand Down Expand Up @@ -412,6 +445,17 @@ snapshots["conducting-equipment-editor rendered as action pane with SubEquipment
EqFunction
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
</mwc-menu>
</abbr>
<div class="container subequipment">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ snapshots["powertransformer-editor rendered as action pane looks like the latest
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -212,6 +223,17 @@ snapshots["powertransformer-editor rendered as action pane with EqFunction child
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -307,6 +329,17 @@ snapshots["powertransformer-editor rendered as action pane with LNode children l
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -404,6 +437,17 @@ snapshots["powertransformer-editor rendered as action pane with SubEquipment chi
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="SubEquipment"
>
<span>
SubEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down
Loading

0 comments on commit 875b255

Please sign in to comment.