From e1b9568a1c1d0f04f2dacea133eea04e9ee28af2 Mon Sep 17 00:00:00 2001 From: marcvanraalte <86408026+marcvanraalte@users.noreply.github.com> Date: Thu, 9 Feb 2023 15:42:10 +0100 Subject: [PATCH] 970 tapchanger editor (#1166) * feat(tapchanger-editor.ts):editor_added * feat(tapchanger-editor.test.ts):setup * feat(TapChanger-editor):editor_and_unit_test --------- Co-authored-by: Pascal Wilbrink --- src/editors/substation/tapchanger-editor.ts | 86 ++++++ .../substation/transformer-winding-editor.ts | 19 ++ .../editors/substation/TapChanger.scd | 267 ++++++++++++++++++ .../tapchanger-editor.test.snap.js | 29 ++ .../substation/tapchanger-editor.test.ts | 49 ++++ 5 files changed, 450 insertions(+) create mode 100644 src/editors/substation/tapchanger-editor.ts create mode 100644 test/testfiles/editors/substation/TapChanger.scd create mode 100644 test/unit/editors/substation/__snapshots__/tapchanger-editor.test.snap.js create mode 100644 test/unit/editors/substation/tapchanger-editor.test.ts diff --git a/src/editors/substation/tapchanger-editor.ts b/src/editors/substation/tapchanger-editor.ts new file mode 100644 index 0000000000..62e2f80b7d --- /dev/null +++ b/src/editors/substation/tapchanger-editor.ts @@ -0,0 +1,86 @@ +import { + customElement, + html, + LitElement, + TemplateResult, + property, + state, +} from 'lit-element'; + +import '../../action-pane.js'; +import './eq-function-editor.js'; +import './l-node-editor.js'; +import './sub-equipment-editor.js'; +import { getChildElementsByTagName } from '../../foundation.js'; + +@customElement('tapchanger-editor') +export class TapChangerEditor extends LitElement { + /** The document being edited as provided to editor by [[`Zeroline`]]. */ + @property({ attribute: false }) + doc!: XMLDocument; + /** SCL element TransformerWinding */ + @property({ attribute: false }) + element!: Element; + /** Whether `EqFunction` and `SubEquipment` are rendered */ + @property({ type: Boolean }) + showfunctions = false; + + @state() + get header(): string { + const name = this.element.getAttribute('name') ?? ''; + const desc = this.element.getAttribute('desc'); + + return `TapChanger.${name} ${desc ? `—TapChanger.${desc}` : ''}`; + } + + private renderLNodes(): TemplateResult { + const lNodes = getChildElementsByTagName(this.element, 'LNode'); + + return lNodes.length + ? html`
+ ${lNodes.map( + lNode => + html`` + )} +
` + : html``; + } + + renderEqFunctions(): TemplateResult { + if (!this.showfunctions) return html``; + + const eqFunctions = getChildElementsByTagName(this.element, 'EqFunction'); + return html` ${eqFunctions.map( + eqFunction => + html`` + )}`; + } + + private renderSubEquipments(): TemplateResult { + if (!this.showfunctions) return html``; + const subEquipments = getChildElementsByTagName( + this.element, + 'SubEquipment' + ); + + return html` ${subEquipments.map( + subEquipment => + html`` + )}`; + } + + render(): TemplateResult { + return html` ${this.renderLNodes()} + ${this.renderEqFunctions()} ${this.renderSubEquipments()}`; + } +} diff --git a/src/editors/substation/transformer-winding-editor.ts b/src/editors/substation/transformer-winding-editor.ts index 1f7c4f0734..f00e4d02ae 100644 --- a/src/editors/substation/transformer-winding-editor.ts +++ b/src/editors/substation/transformer-winding-editor.ts @@ -20,6 +20,9 @@ import { Menu } from '@material/mwc-menu'; import '../../action-icon.js'; import '../../action-pane.js'; +import './eq-function-editor.js'; +import './l-node-editor.js'; +import './tapchanger-editor.js'; import { styles } from './foundation.js'; import { @@ -131,6 +134,21 @@ export class TransformerWindingEditor extends LitElement { : html``; } + private renderTapChanger(): TemplateResult { + if (!this.showfunctions) return html``; + const tapChangers = getChildElementsByTagName(this.element, 'TapChanger'); + return tapChangers.length + ? html` ${tapChangers.map( + tapChanger => + html`` + )}` + : html``; + } + private renderAddButtons(): TemplateResult[] { return childTags(this.element).map( child => @@ -174,6 +192,7 @@ export class TransformerWindingEditor extends LitElement { > ${this.renderLNodes()} ${this.renderEqFunctions()} + ${this.renderTapChanger()} `; } diff --git a/test/testfiles/editors/substation/TapChanger.scd b/test/testfiles/editors/substation/TapChanger.scd new file mode 100644 index 0000000000..0c519ee311 --- /dev/null +++ b/test/testfiles/editors/substation/TapChanger.scd @@ -0,0 +1,267 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + 110 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + status-only + + + + + + + + + + + + + + + + + + sbo-with-enhanced-security + + + 30000 + + + 600 + + + + + + + + + + + + + + 1000 + + + direct-with-enhanced-security + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sbo-with-enhanced-security + + + 30000 + + + 600 + + + + + + + + + + + + IEC 61850-8-1:2003 + + + + + + + + + IEC 61850-8-1:2003 + + + + + + + + + + + + + + IEC 61850-8-1:2003 + + + + + + + + + IEC 61850-8-1:2003 + + + + + + + + IEC 61850-8-1:2003 + + + + + + + + + IEC 61850-8-1:2003 + + + + + + + status-only + + + pulse + persistent + persistent-feedback + + + Ok + Warning + Alarm + + + status-only + direct-with-normal-security + sbo-with-normal-security + direct-with-enhanced-security + sbo-with-enhanced-security + + + on + blocked + test + test/blocked + off + + + not-supported + bay-control + station-control + remote-control + automatic-bay + automatic-station + automatic-remote + maintenance + process + + + diff --git a/test/unit/editors/substation/__snapshots__/tapchanger-editor.test.snap.js b/test/unit/editors/substation/__snapshots__/tapchanger-editor.test.snap.js new file mode 100644 index 0000000000..7050dfa649 --- /dev/null +++ b/test/unit/editors/substation/__snapshots__/tapchanger-editor.test.snap.js @@ -0,0 +1,29 @@ +/* @web/test-runner snapshot v1 */ +export const snapshots = {}; + +snapshots["web component rendering TapChanger element rendering LNode and EqFunction children looks like the latest snapshot"] = +` +
+ + +
+ + +
+`; +/* end snapshot web component rendering TapChanger element rendering LNode and EqFunction children looks like the latest snapshot */ + +snapshots["web component rendering TapChanger element rendering SubEquipment looks like the latest snapshot"] = +` + + + +`; +/* end snapshot web component rendering TapChanger element rendering SubEquipment looks like the latest snapshot */ + diff --git a/test/unit/editors/substation/tapchanger-editor.test.ts b/test/unit/editors/substation/tapchanger-editor.test.ts new file mode 100644 index 0000000000..4b0f00179d --- /dev/null +++ b/test/unit/editors/substation/tapchanger-editor.test.ts @@ -0,0 +1,49 @@ +import { fixture, html, expect } from '@open-wc/testing'; + +import '../../../../src/editors/substation/tapchanger-editor.js'; +import { TapChangerEditor } from '../../../../src/editors/substation/tapchanger-editor.js'; + +describe('web component rendering TapChanger element', () => { + let element: TapChangerEditor; + let doc: XMLDocument; + + describe('rendering LNode and EqFunction children', () => { + beforeEach(async () => { + doc = await fetch('/test/testfiles/editors/substation/TapChanger.scd') + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + element = ( + await fixture( + html`` + ) + ); + element.showfunctions = true; + await element.updateComplete; + }); + it('looks like the latest snapshot', async () => { + await expect(element).shadowDom.to.equalSnapshot(); + }); + }); + + describe('rendering SubEquipment', () => { + beforeEach(async () => { + doc = await fetch('/test/testfiles/editors/substation/TapChanger.scd') + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + element = ( + await fixture( + html`` + ) + ); + element.showfunctions = true; + await element.updateComplete; + }); + it('looks like the latest snapshot', async () => { + await expect(element).shadowDom.to.equalSnapshot(); + }); + }); +});