Skip to content

Commit

Permalink
feat(wizards/generalequipment): Add_create_wizard_GeneralEquipment_an…
Browse files Browse the repository at this point in the history
…d_test (openscd#1102)

* feat(wizard-library.ts):Add_create_wizard_GeneralEquipment_and_test

* feat(substation/GeneralEquipment):add_integration_test

* fix(generalEquipment.ts):changed_variable_names_fix(generalequipment.test.ts):added_test_item

* fix(generalequipment.test.ts):added_missing_tests
  • Loading branch information
marcvanraalte authored Jan 9, 2023
1 parent 70d6867 commit 2d1464f
Show file tree
Hide file tree
Showing 12 changed files with 714 additions and 7 deletions.
49 changes: 49 additions & 0 deletions src/wizards/generalEquipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { html, TemplateResult } from 'lit-element';
import { get, translate } from 'lit-translate';
import {
cloneElement,
createElement,
getChildElementsByTagName,
getValue,
SimpleAction,
Expand Down Expand Up @@ -112,3 +113,51 @@ export function contentGeneralEquipmentWizard(
></wizard-checkbox>`,
];
}

export function createGeneralEquipmentWizard(parent: Element): Wizard {
const name = '';
const desc = null;
const type = null;
const virtual = null;
const reservedNames = Array.from(
parent.querySelectorAll('GeneralEquipment')
).map(generalEquipment => generalEquipment.getAttribute('name')!);

return [
{
title: get('wizard.title.add', { tagName: 'GeneralEquipment' }),
primary: {
icon: 'save',
label: get('save'),
action: createGeneralEquipmentAction(parent),
},
content: [
...contentGeneralEquipmentWizard({
name,
desc,
type,
virtual,
reservedNames,
}),
],
},
];
}

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

const generalEquipment = createElement(
parent.ownerDocument,
'GeneralEquipment',
generalEquipmentAttrs
);

return [{ new: { parent, element: generalEquipment } }];
};
}
12 changes: 9 additions & 3 deletions src/wizards/wizard-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ import {
editSubFunctionWizard,
} from './subfunction.js';
import { editSampledValueControlWizard } from './sampledvaluecontrol.js';
import { createSubEquipmentWizard, editSubEquipmentWizard } from './subequipment.js';
import { editGeneralEquipmentWizard } from './generalEquipment.js';
import {
createSubEquipmentWizard,
editSubEquipmentWizard,
} from './subequipment.js';
import {
createGeneralEquipmentWizard,
editGeneralEquipmentWizard,
} from './generalEquipment.js';

type SclElementWizard = (
element: Element,
Expand Down Expand Up @@ -225,7 +231,7 @@ export const wizards: Record<
},
GeneralEquipment: {
edit: editGeneralEquipmentWizard,
create: emptyWizard,
create: createGeneralEquipmentWizard,
},
GetCBValues: {
edit: emptyWizard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,80 @@ describe('substation-editor wizarding editing integration', () => {
.to.exist;
});
});

describe('open add general-equipment wizard', () => {
let doc: XMLDocument;
let parent: MockWizardEditor;
let element: SubstationEditor | null;

let nameField: WizardTextField;
let typeField: WizardTextField;
let primaryAction: HTMLElement;

beforeEach(async () => {
doc = await fetch(
'/test/testfiles/editors/substation/generalequipment.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="GeneralEquipment"]'
)
)).click();
await parent.updateComplete;

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

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

primaryAction = <HTMLElement>(
parent.wizardUI.dialog?.querySelector(
'mwc-button[slot="primaryAction"]'
)
);
});
it('opens general-equipment wizard ', async () => {
expect(parent.wizardUI).to.exist;
});
it('has four wizard inputs', async () => {
expect(parent.wizardUI.inputs.length).to.equal(4);
});
it('does not add general-equipment if name andattribute is not unique', async () => {
nameField.value = 'genSub';
typeField.value = 'AXN';
await parent.updateComplete;
primaryAction.click();

expect(
doc.querySelectorAll('GeneralEquipment[name="genSub"]').length
).to.equal(1);
});
it('does add general-equipment if name attribute is unique', async () => {
expect(doc.querySelector('GeneralEquipment[name="newgenSub"]')).to.not
.exist;
nameField.value = 'newgenSub';
typeField.value = 'AXN';
await parent.updateComplete;
primaryAction.click();
expect(doc.querySelector('GeneralEquipment[name = "newgenSub"]')).to
.exist;
});
});
});
66 changes: 66 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 @@ -74,6 +74,17 @@ snapshots["bay-editor looks like the latest snapshot"] =
PowerTransformer
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -187,6 +198,17 @@ snapshots["bay-editor with readonly property looks like the latest snapshot"] =
PowerTransformer
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -300,6 +322,17 @@ snapshots["bay-editor with function filter deactivated looks like the latest sna
PowerTransformer
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -417,6 +450,17 @@ snapshots["bay-editor with existing LNode children looks like the latest snapsho
PowerTransformer
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -528,6 +572,17 @@ snapshots["bay-editor with general-equipment children with showfunctions false l
PowerTransformer
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -637,6 +692,17 @@ snapshots["bay-editor with general-equipment children with showfunctions true lo
PowerTransformer
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ snapshots["web component rendering EqFunction element with complete attribute se
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -108,6 +119,17 @@ snapshots["web component rendering EqFunction element with missing desc and type
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -171,6 +193,17 @@ snapshots["web component rendering EqFunction element with existing LNode childr
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -240,6 +273,17 @@ snapshots["web component rendering EqFunction element with general-equipment chi
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -301,6 +345,17 @@ snapshots["web component rendering EqFunction element with general-equipment chi
LNode
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="menuitem"
tabindex="-1"
value="GeneralEquipment"
>
<span>
GeneralEquipment
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down
Loading

0 comments on commit 2d1464f

Please sign in to comment.