Skip to content

Commit

Permalink
feat(wizards/ied): added new textfields for IED properties (openscd#822)
Browse files Browse the repository at this point in the history
* chore(translations): adding helpers for additional IED wizard-textfields
* feat(wizards/ied): added new textfields for IED properties
* test(wizard/ied): verifying correct render of IED properties as texfields
* test(wizard/ied): generated new snapshot with textfields
* feat(wizard/ied): updated IED prop texfields to match other readonly fields in the app (DO wizard)
* test(wizard/ied): updated tests to match changes in ied wizard implementation
* chore(wizard/ied): removed unused helper translations
* test(wizard/ied): fixed bug of using wrong comparative fn in tests and replaced old snapshot
* feat(wizard/ied): updated validatedVersionAttribute() with suggestion from @dlabordus
* test(wizard/ied): using ied's attributes in the XML doc instead of fixed values for comparissons
  • Loading branch information
juancho0202 authored Jun 16, 2022
1 parent 04329d9 commit 1cd6fb7
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/wizards/ied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const iedNamePattern =
export function renderIEDWizard(
name: string | null,
desc: string | null,
type: string | null,
manufacturer: string | null,
configVersion: string | null,
originalSclVersion: string,
engRight: string | null,
owner: string | null,
reservedNames: string[]
): TemplateResult[] {
return [
Expand All @@ -56,6 +62,42 @@ export function renderIEDWizard(
helper="${translate('ied.wizard.descHelper')}"
pattern="${patterns.normalizedString}"
></wizard-textfield>`,
html`<wizard-textfield
label="type"
.maybeValue=${type || "-"}
readOnly
disabled
></wizard-textfield>`,
html`<wizard-textfield
label="manufacturer"
.maybeValue=${manufacturer || "-"}
readOnly
disabled
></wizard-textfield>`,
html`<wizard-textfield
label="configVersion"
.maybeValue=${configVersion || "-"}
readOnly
disabled
></wizard-textfield>`,
html`<wizard-textfield
label="originalSclVersion"
.maybeValue=${originalSclVersion || "-"}
readOnly
disabled
></wizard-textfield>`,
html`<wizard-textfield
label="engRight"
.maybeValue=${engRight || "-"}
readOnly
disabled
></wizard-textfield>`,
html`<wizard-textfield
label="owner"
.maybeValue=${owner || "-"}
readOnly
disabled
></wizard-textfield>`
];
}

Expand All @@ -78,6 +120,12 @@ function renderIEDReferencesWizard(references: Delete[]): TemplateResult[] {
];
}

function validatedVersionAttribute(element: Element): string {
return (element.getAttribute('originalSclVersion') ?? '')
.concat(element.getAttribute('originalSclRevision') ?? '')
.concat(element.getAttribute('originalSclRelease') ?? '')
}

export function reservedNamesIED(currentElement: Element): string[] {
return Array.from(currentElement.parentNode!.querySelectorAll('IED'))
.filter(isPublic)
Expand Down Expand Up @@ -169,6 +217,12 @@ export function editIEDWizard(element: Element): Wizard {
content: renderIEDWizard(
element.getAttribute('name'),
element.getAttribute('desc'),
element.getAttribute('type'),
element.getAttribute('manufacturer'),
element.getAttribute('configVersion'),
validatedVersionAttribute(element),
element.getAttribute('engRight'),
element.getAttribute('owner'),
reservedNamesIED(element)
),
},
Expand Down
36 changes: 36 additions & 0 deletions test/unit/wizards/__snapshots__/ied.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ snapshots["Wizards for SCL element IED edit IED looks like the latest snapshot"]
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="type"
readonly=""
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="manufacturer"
readonly=""
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="configVersion"
readonly=""
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="originalSclVersion"
readonly=""
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="engRight"
readonly=""
>
</wizard-textfield>
<wizard-textfield
disabled=""
label="owner"
readonly=""
>
</wizard-textfield>
</div>
<mwc-button
dialogaction="close"
Expand Down
25 changes: 24 additions & 1 deletion test/unit/wizards/ied.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,30 @@ describe('Wizards for SCL element IED', () => {
await element.requestUpdate();
inputs = Array.from(element.wizardUI.inputs);
});

it('contains a wizard-textfield with a non-empty "type" value', async () => {
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'type')?.value).to
.be.equal(ied.getAttribute('type') || '-');
});
it('contains a wizard-textfield with a non-empty "manufacturer" value', async () => {
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'manufacturer')?.value).to
.be.equal(ied.getAttribute('manufacturer') || '-');
});
it('contains a wizard-textfield with a non-empty "configVersion" value', async () => {
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'configVersion')?.value).to
.be.equal(ied.getAttribute('configVersion') || '-');
});
it('contains a wizard-textfield with a non-empty "originalSclVersion" value', async () => {
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'originalSclVersion')?.value).to
.contain(ied.getAttribute('originalSclVersion') || '-');
});
it('contains a wizard-textfield with an empty "engRight" value', async () => {
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'engRight')?.value).to
.be.equal(ied.getAttribute('engRight') || '-');
});
it('contains a wizard-textfield with a non-empty "owner" value', async () => {
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'owner')?.value).to
.be.equal(ied.getAttribute('owner') || '-');
});
it('update name should be updated in document', async function () {
await setWizardTextFieldValue(<WizardTextField>inputs[0], 'OtherIED3');

Expand Down

0 comments on commit 1cd6fb7

Please sign in to comment.