From e3e9c5dca1a4a5a449e542947afd35900eea9929 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 10:50:05 +0100 Subject: [PATCH 1/8] refactor(subscriber/subscriber-ied-list): split into functions --- .../subscription/subscriber-ied-list-goose.ts | 173 +++++++++--------- 1 file changed, 85 insertions(+), 88 deletions(-) diff --git a/src/editors/subscription/subscriber-ied-list-goose.ts b/src/editors/subscription/subscriber-ied-list-goose.ts index ef837f1e0..532a76353 100644 --- a/src/editors/subscription/subscriber-ied-list-goose.ts +++ b/src/editors/subscription/subscriber-ied-list-goose.ts @@ -59,12 +59,14 @@ const fcdaReferences = [ */ function getFcdaReferences(elementContainingFcdaReferences: Element): string { return fcdaReferences - .map(fcdaRef => - elementContainingFcdaReferences.getAttribute(fcdaRef) - ? `[${fcdaRef}="${elementContainingFcdaReferences.getAttribute(fcdaRef)}"]` - : '' - ) - .join(''); + .map(fcdaRef => + elementContainingFcdaReferences.getAttribute(fcdaRef) + ? `[${fcdaRef}="${elementContainingFcdaReferences.getAttribute( + fcdaRef + )}"]` + : '' + ) + .join(''); } /** @@ -111,10 +113,7 @@ export class SubscriberIEDListGoose extends LitElement { const parentDiv = this.closest('div[id="containerTemplates"]'); if (parentDiv) { - parentDiv.addEventListener( - 'goose-dataset', - this.onGOOSEDataSetEvent - ); + parentDiv.addEventListener('goose-dataset', this.onGOOSEDataSetEvent); parentDiv.addEventListener( 'ied-subscription', this.onIEDSubscriptionEvent @@ -128,7 +127,7 @@ export class SubscriberIEDListGoose extends LitElement { * @param event - Incoming event. */ private async onGOOSEDataSetEvent(event: GOOSESelectEvent) { - console.log('onGOOSESelect') + console.log('onGOOSESelect'); localState.currentGseControl = event.detail.gseControl; localState.currentDataset = event.detail.dataset; localState.currentGooseIEDName = localState.currentGseControl @@ -196,7 +195,7 @@ export class SubscriberIEDListGoose extends LitElement { * @param event - Incoming event. */ private async onIEDSubscriptionEvent(event: IEDSubscriptionEvent) { - console.log('onGOOSEIEDSub') + console.log('onGOOSEIEDSub'); switch (event.detail.subscribeStatus) { case SubscribeStatus.Full: { this.unsubscribe(event.detail.element); @@ -283,8 +282,6 @@ export class SubscriberIEDListGoose extends LitElement { if (extRef) actions.push({ old: { parent: inputs, element: extRef } }); }); - - }); this.dispatchEvent( @@ -309,30 +306,33 @@ export class SubscriberIEDListGoose extends LitElement { */ private extendDeleteActions(extRefDeleteActions: Delete[]): Delete[] { if (!extRefDeleteActions.length) return []; - + // Initialize with the already existing ExtRef Delete actions. const extendedDeleteActions: Delete[] = extRefDeleteActions; const inputsMap: Record = {}; - + for (const extRefDeleteAction of extRefDeleteActions) { const extRef = extRefDeleteAction.old.element; const inputsElement = extRefDeleteAction.old.parent; const id = identity(inputsElement); - if (!inputsMap[id]) inputsMap[id] = (inputsElement.cloneNode(true)); + if (!inputsMap[id]) + inputsMap[id] = inputsElement.cloneNode(true); + + const linkedExtRef = inputsMap[id].querySelector( + `ExtRef[iedName=${extRef.getAttribute('iedName')}]` + + `${getFcdaReferences(extRef)}` + ); - const linkedExtRef = inputsMap[id].querySelector(`ExtRef[iedName=${extRef.getAttribute('iedName')}]` + - `${getFcdaReferences(extRef)}`); - if (linkedExtRef) inputsMap[id].removeChild(linkedExtRef); } - + // create delete action for each empty inputs Object.entries(inputsMap).forEach(([key, value]) => { - if (value.children.length ! == 0) { + if (value.children.length! == 0) { const doc = extRefDeleteActions[0].old.parent.ownerDocument!; const inputs = doc.querySelector(selector('Inputs', key)); - + if (inputs && inputs.parentElement) { extendedDeleteActions.push({ old: { parent: inputs.parentElement, element: inputs }, @@ -340,7 +340,7 @@ export class SubscriberIEDListGoose extends LitElement { } } }); - + return extendedDeleteActions; } @@ -350,13 +350,66 @@ export class SubscriberIEDListGoose extends LitElement { } } + renderSubscriber(status: SubscribeStatus, element: Element): TemplateResult { + return html``; + } + + renderUnSubscribers(ieds: IED[]): TemplateResult { + return html` + ${translate('subscription.subscriberIed.availableToSubscribe')} + +
  • + ${ieds.length > 0 + ? ieds.map(ied => + this.renderSubscriber(SubscribeStatus.None, ied.element) + ) + : html` + ${translate('subscription.none')} + `}`; + } + + renderPartiallySubscribers(ieds: IED[]): TemplateResult { + return html` + ${translate('subscription.subscriberIed.partiallySubscribed')} + +
  • + ${ieds.length > 0 + ? ieds.map(ied => + this.renderSubscriber(SubscribeStatus.Partial, ied.element) + ) + : html` + ${translate('subscription.none')} + `}`; + } + + renderFullSubscribers(): TemplateResult { + return html` + ${translate('subscription.subscriberIed.subscribed')} + +
  • + ${localState.subscribedIeds.length > 0 + ? localState.subscribedIeds.map(ied => + this.renderSubscriber(SubscribeStatus.Full, ied.element) + ) + : html` + ${translate('subscription.none')} + `}`; + } + render(): TemplateResult { const partialSubscribedIeds = localState.availableIeds.filter( ied => ied.partial ); - const availableIeds = localState.availableIeds.filter( - ied => !ied.partial - ); + const availableIeds = localState.availableIeds.filter(ied => !ied.partial); const gseControlName = localState.currentGseControl?.getAttribute('name') ?? undefined; @@ -371,67 +424,11 @@ export class SubscriberIEDListGoose extends LitElement { ${localState.currentGseControl ? html`
    - - - ${translate('subscription.subscriberIed.subscribed')} - -
  • - ${localState.subscribedIeds.length > 0 - ? localState.subscribedIeds.map( - ied => - html`` - ) - : html` - ${translate('subscription.none')} - `} -
    - - - ${translate( - 'subscription.subscriberIed.partiallySubscribed' - )} - -
  • - ${partialSubscribedIeds.length > 0 - ? partialSubscribedIeds.map( - ied => - html`` - ) - : html` - ${translate('subscription.none')} - `} -
    - - - ${translate( - 'subscription.subscriberIed.availableToSubscribe' - )} - -
  • - ${availableIeds.length > 0 - ? availableIeds.map( - ied => - html`` - ) - : html` - ${translate('subscription.none')} - `} -
    + + ${this.renderFullSubscribers()} + ${this.renderPartiallySubscribers(partialSubscribedIeds)} + ${this.renderUnSubscribers(availableIeds)} +
    ` : html` From f56a91de4b656b42ace6de382aaa8b1a85b689a2 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 11:52:16 +0100 Subject: [PATCH 2/8] refactor(editors/subscribe): remove ied-element-subscriber --- .../elements/ied-element-goose.ts | 43 ------------------- .../subscription/subscriber-ied-list-goose.ts | 20 ++++++--- .../subscription/elements/ied-element.test.ts | 42 ------------------ 3 files changed, 15 insertions(+), 90 deletions(-) delete mode 100644 src/editors/subscription/elements/ied-element-goose.ts delete mode 100644 test/unit/editors/subscription/elements/ied-element.test.ts diff --git a/src/editors/subscription/elements/ied-element-goose.ts b/src/editors/subscription/elements/ied-element-goose.ts deleted file mode 100644 index 3771727c5..000000000 --- a/src/editors/subscription/elements/ied-element-goose.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { - customElement, - html, - LitElement, - property, - TemplateResult, -} from 'lit-element'; - -import '@material/mwc-icon'; -import '@material/mwc-list/mwc-list-item'; - -import { newIEDSubscriptionEvent, SubscribeStatus } from '../foundation.js'; - -@customElement('ied-element-goose') -export class IEDElementGoose extends LitElement { - /** Holding the IED element */ - @property({ attribute: false }) - element!: Element; - - @property({ attribute: false }) - status!: SubscribeStatus; - - private onIedSelect = () => { - this.dispatchEvent( - newIEDSubscriptionEvent(this.element, this.status ?? SubscribeStatus.None) - ); - }; - - render(): TemplateResult { - return html` - ${this.element.getAttribute('name')} - ${this.status == SubscribeStatus.Full - ? html`clear` - : html`add`} - `; - } -} diff --git a/src/editors/subscription/subscriber-ied-list-goose.ts b/src/editors/subscription/subscriber-ied-list-goose.ts index 532a76353..0e392c0b1 100644 --- a/src/editors/subscription/subscriber-ied-list-goose.ts +++ b/src/editors/subscription/subscriber-ied-list-goose.ts @@ -13,7 +13,6 @@ import '@material/mwc-icon'; import '@material/mwc-list'; import '@material/mwc-list/mwc-list-item'; -import './elements/ied-element-goose.js'; import { Create, createElement, @@ -23,6 +22,7 @@ import { selector, } from '../../foundation.js'; import { + newIEDSubscriptionEvent, GOOSESelectEvent, IEDSubscriptionEvent, newGOOSESelectEvent, @@ -351,10 +351,20 @@ export class SubscriberIEDListGoose extends LitElement { } renderSubscriber(status: SubscribeStatus, element: Element): TemplateResult { - return html``; + return html` { + this.dispatchEvent( + newIEDSubscriptionEvent(element, status ?? SubscribeStatus.None) + ); + }} + graphic="avatar" + hasMeta + > + ${element.getAttribute('name')} + ${status == SubscribeStatus.Full ? html`clear` : html`add`} + `; } renderUnSubscribers(ieds: IED[]): TemplateResult { diff --git a/test/unit/editors/subscription/elements/ied-element.test.ts b/test/unit/editors/subscription/elements/ied-element.test.ts deleted file mode 100644 index 185d85785..000000000 --- a/test/unit/editors/subscription/elements/ied-element.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { html, fixture, expect } from '@open-wc/testing'; -import { spy } from 'sinon'; - -import '../../../../../src/editors/subscription/elements/ied-element-goose.js' -import { IEDElementGoose } from '../../../../../src/editors/subscription/elements/ied-element-goose.js'; -import { SubscribeStatus } from '../../../../../src/editors/subscription/foundation.js'; - -describe('ied-element', () => { - let element: IEDElementGoose; - let validSCL: XMLDocument; - - let iedElement: Element; - - beforeEach(async () => { - validSCL = await fetch('/test/testfiles/valid2007B4.scd') - .then(response => response.text()) - .then(str => new DOMParser().parseFromString(str, 'application/xml')); - - iedElement = validSCL.querySelector('IED[name="IED2"]')!; - - element = await fixture(html``); - }); - - it('a newGOOSESelectEvent is fired when clicking the goose message element', async () => { - const newIEDSubscriptionEvent = spy(); - window.addEventListener('ied-subscription', newIEDSubscriptionEvent); - - const listItem = (element.shadowRoot!.querySelector('mwc-list-item')); - listItem.click(); - - await element.requestUpdate(); - expect(newIEDSubscriptionEvent).to.have.been.called; - expect(newIEDSubscriptionEvent.args[0][0].detail['element']).to.eql(iedElement); - expect(newIEDSubscriptionEvent.args[0][0].detail['subscribeStatus']).to.eql(SubscribeStatus.None); - }); - - it('looks like the latest snapshot', async () => { - await expect(element).shadowDom.to.equalSnapshot(); - }); -}); From 385accb5475f79ef346fbc254d9f3245b4991287 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 12:12:06 +0100 Subject: [PATCH 3/8] refactor(editors/subscriber): add filtered list to goose list --- .../subscription/elements/goose-message.ts | 35 ------------- .../subscription/publisher-goose-list.ts | 33 +++++++++--- .../__snapshots__/goose-message.test.snap.js | 19 ------- .../publisher-goose-list.test.snap.js | 50 +++++++++++++++---- .../__snapshots__/goose-message.test.snap.js | 19 ------- .../__snapshots__/ied-element.test.snap.js | 21 -------- .../elements/goose-message.test.ts | 41 --------------- 7 files changed, 65 insertions(+), 153 deletions(-) delete mode 100644 src/editors/subscription/elements/goose-message.ts delete mode 100644 test/unit/editors/subscription/__snapshots__/goose-message.test.snap.js delete mode 100644 test/unit/editors/subscription/elements/__snapshots__/goose-message.test.snap.js delete mode 100644 test/unit/editors/subscription/elements/__snapshots__/ied-element.test.snap.js delete mode 100644 test/unit/editors/subscription/elements/goose-message.test.ts diff --git a/src/editors/subscription/elements/goose-message.ts b/src/editors/subscription/elements/goose-message.ts deleted file mode 100644 index 3a693a386..000000000 --- a/src/editors/subscription/elements/goose-message.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - customElement, - html, - LitElement, - property, - TemplateResult, -} from 'lit-element'; - -import '@material/mwc-icon'; -import '@material/mwc-list/mwc-list-item'; - -import { newGOOSESelectEvent } from '../foundation.js'; -import { gooseIcon } from '../../../icons/icons.js'; - -@customElement('goose-message') -export class GOOSEMessage extends LitElement { - /** Holding the GSEControl element */ - @property({ attribute: false }) - element!: Element; - - private onGooseSelect = () => { - const ln = this.element.parentElement; - const dataset = ln?.querySelector( - `DataSet[name=${this.element.getAttribute('datSet')}]` - ); - this.dispatchEvent(newGOOSESelectEvent(this.element, dataset!)); - }; - - render(): TemplateResult { - return html` - ${this.element.getAttribute('name')} - ${gooseIcon} - `; - } -} diff --git a/src/editors/subscription/publisher-goose-list.ts b/src/editors/subscription/publisher-goose-list.ts index 146229b78..9760a3e4c 100644 --- a/src/editors/subscription/publisher-goose-list.ts +++ b/src/editors/subscription/publisher-goose-list.ts @@ -9,12 +9,12 @@ import { import { translate } from 'lit-translate'; import '@material/mwc-icon'; -import '@material/mwc-list'; import '@material/mwc-list/mwc-list-item'; -import './elements/goose-message.js'; +import '../../filtered-list.js'; import { compareNames, getNameAttribute } from '../../foundation.js'; -import { styles } from './foundation.js'; +import { newGOOSESelectEvent, styles } from './foundation.js'; +import { gooseIcon } from '../../icons/icons.js'; /** An sub element for showing all published GOOSE messages per IED. */ @customElement('publisher-goose-list') @@ -43,10 +43,28 @@ export class PublisherGOOSEList extends LitElement { ); } + private onGooseSelect(element: Element): void { + const ln = element.parentElement; + const dataset = ln?.querySelector( + `DataSet[name=${element.getAttribute('datSet')}]` + ); + this.dispatchEvent(newGOOSESelectEvent(element, dataset!)); + } + + renderGoose(element: Element): TemplateResult { + return html` this.onGooseSelect(element)} + graphic="large" + > + ${element.getAttribute('name')} + ${gooseIcon} + `; + } + render(): TemplateResult { return html`

    ${translate('subscription.publisherGoose.title')}

    - + ${this.ieds.map(ied => ied.querySelector('GSEControl') ? html` @@ -55,14 +73,13 @@ export class PublisherGOOSEList extends LitElement { developer_board
  • - ${this.getGSEControls(ied).map( - control => - html`` + ${this.getGSEControls(ied).map(control => + this.renderGoose(control) )} ` : `` )} -
    +
    `; } diff --git a/test/unit/editors/subscription/__snapshots__/goose-message.test.snap.js b/test/unit/editors/subscription/__snapshots__/goose-message.test.snap.js deleted file mode 100644 index 9e2e07de5..000000000 --- a/test/unit/editors/subscription/__snapshots__/goose-message.test.snap.js +++ /dev/null @@ -1,19 +0,0 @@ -/* @web/test-runner snapshot v1 */ -export const snapshots = {}; - -snapshots["goose-message looks like the latest snapshot"] = -` - - GCB - - - - -`; -/* end snapshot goose-message looks like the latest snapshot */ - diff --git a/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js b/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js index 7bf81ed85..4c3d5950a 100644 --- a/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js +++ b/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js @@ -6,7 +6,7 @@ snapshots["publisher-goose-list looks like the latest snapshot"] =

    [subscription.publisherGoose.title]

    - + - - - - + + + GCB + + + + + + + GCB2 + + + + - - - + + + GCB + + + + + `; /* end snapshot publisher-goose-list looks like the latest snapshot */ @@ -59,8 +89,8 @@ snapshots["publisher-goose-list looks like the latest snapshot without a doc loa

    [subscription.publisherGoose.title]

    - - + + `; /* end snapshot publisher-goose-list looks like the latest snapshot without a doc loaded */ diff --git a/test/unit/editors/subscription/elements/__snapshots__/goose-message.test.snap.js b/test/unit/editors/subscription/elements/__snapshots__/goose-message.test.snap.js deleted file mode 100644 index 9e2e07de5..000000000 --- a/test/unit/editors/subscription/elements/__snapshots__/goose-message.test.snap.js +++ /dev/null @@ -1,19 +0,0 @@ -/* @web/test-runner snapshot v1 */ -export const snapshots = {}; - -snapshots["goose-message looks like the latest snapshot"] = -` - - GCB - - - - -`; -/* end snapshot goose-message looks like the latest snapshot */ - diff --git a/test/unit/editors/subscription/elements/__snapshots__/ied-element.test.snap.js b/test/unit/editors/subscription/elements/__snapshots__/ied-element.test.snap.js deleted file mode 100644 index f61bc9b17..000000000 --- a/test/unit/editors/subscription/elements/__snapshots__/ied-element.test.snap.js +++ /dev/null @@ -1,21 +0,0 @@ -/* @web/test-runner snapshot v1 */ -export const snapshots = {}; - -snapshots["ied-element looks like the latest snapshot"] = -` - - IED2 - - - add - - -`; -/* end snapshot ied-element looks like the latest snapshot */ - diff --git a/test/unit/editors/subscription/elements/goose-message.test.ts b/test/unit/editors/subscription/elements/goose-message.test.ts deleted file mode 100644 index 2e4614149..000000000 --- a/test/unit/editors/subscription/elements/goose-message.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { html, fixture, expect } from '@open-wc/testing'; -import { spy } from 'sinon'; - -import '../../../../../src/editors/subscription/elements/goose-message.js' -import { GOOSEMessage } from '../../../../../src/editors/subscription/elements/goose-message.js'; - -describe('goose-message', () => { - let element: GOOSEMessage; - let validSCL: XMLDocument; - - let gseControl: Element; - - beforeEach(async () => { - validSCL = await fetch('/test/testfiles/valid2007B4.scd') - .then(response => response.text()) - .then(str => new DOMParser().parseFromString(str, 'application/xml')); - - gseControl = validSCL.querySelector('GSEControl[name="GCB"]')!; - - element = await fixture(html``); - }); - - it('a newGOOSESelectEvent is fired when clicking the goose message element', async () => { - const newGOOSESelectEvent = spy(); - window.addEventListener('goose-dataset', newGOOSESelectEvent); - - const listItem = (element.shadowRoot!.querySelector('mwc-list-item')); - listItem.click(); - - await element.requestUpdate(); - expect(newGOOSESelectEvent).to.have.been.called; - expect(newGOOSESelectEvent.args[0][0].detail['gseControl']).to.eql(gseControl); - expect(newGOOSESelectEvent.args[0][0].detail['dataset']).to.eql(gseControl.closest('IED')?.querySelector('DataSet[name="GooseDataSet1"]')); - }); - - it('looks like the latest snapshot', async () => { - await expect(element).shadowDom.to.equalSnapshot(); - }); -}); From 57850bcb38976ea2119823a056cb7139079e9d13 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 12:13:44 +0100 Subject: [PATCH 4/8] fix(editors/subscriber): add missing import statement --- src/editors/subscription/subscriber-ied-list-goose.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/editors/subscription/subscriber-ied-list-goose.ts b/src/editors/subscription/subscriber-ied-list-goose.ts index 0e392c0b1..980d61d15 100644 --- a/src/editors/subscription/subscriber-ied-list-goose.ts +++ b/src/editors/subscription/subscriber-ied-list-goose.ts @@ -13,6 +13,7 @@ import '@material/mwc-icon'; import '@material/mwc-list'; import '@material/mwc-list/mwc-list-item'; +import '../../filtered-list.js'; import { Create, createElement, From cf99ac6f6e6172ba2ca46d5614d47253dc1ab200 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 12:28:00 +0100 Subject: [PATCH 5/8] style(editors/subscriber): fix broken CSS rule --- src/editors/subscription/publisher-goose-list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editors/subscription/publisher-goose-list.ts b/src/editors/subscription/publisher-goose-list.ts index 9760a3e4c..0ecdb51af 100644 --- a/src/editors/subscription/publisher-goose-list.ts +++ b/src/editors/subscription/publisher-goose-list.ts @@ -86,7 +86,7 @@ export class PublisherGOOSEList extends LitElement { static styles = css` ${styles} - mwc-list { + filtered-list { height: 100vh; overflow-y: scroll; } From af56f0f38d30d5b6898ad7c9c224d6219c4fcd86 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 12:30:18 +0100 Subject: [PATCH 6/8] refactor(editors/substation): show all ieds in the list --- .../subscription/publisher-goose-list.ts | 25 +++++++++---------- .../publisher-goose-list.test.snap.js | 18 +++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/editors/subscription/publisher-goose-list.ts b/src/editors/subscription/publisher-goose-list.ts index 0ecdb51af..23b10cab8 100644 --- a/src/editors/subscription/publisher-goose-list.ts +++ b/src/editors/subscription/publisher-goose-list.ts @@ -65,19 +65,18 @@ export class PublisherGOOSEList extends LitElement { return html`

    ${translate('subscription.publisherGoose.title')}

    - ${this.ieds.map(ied => - ied.querySelector('GSEControl') - ? html` - - ${getNameAttribute(ied)} - developer_board - -
  • - ${this.getGSEControls(ied).map(control => - this.renderGoose(control) - )} - ` - : `` + ${this.ieds.map( + ied => + html` + + ${getNameAttribute(ied)} + developer_board + +
  • + ${this.getGSEControls(ied).map(control => + this.renderGoose(control) + )} + ` )}
    `; diff --git a/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js b/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js index 4c3d5950a..22862fc80 100644 --- a/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js +++ b/test/unit/editors/subscription/__snapshots__/publisher-goose-list.test.snap.js @@ -79,6 +79,24 @@ snapshots["publisher-goose-list looks like the latest snapshot"] =
    + + + IED3 + + + developer_board + + +
  • +
  • `; From 4436d937caf5f299b42b55f1f3b62dd5e69bab77 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 13:27:32 +0100 Subject: [PATCH 7/8] refactor(editors/subscriber): remove unused console.log --- src/editors/subscription/subscriber-ied-list-goose.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/editors/subscription/subscriber-ied-list-goose.ts b/src/editors/subscription/subscriber-ied-list-goose.ts index 980d61d15..89d8d1f22 100644 --- a/src/editors/subscription/subscriber-ied-list-goose.ts +++ b/src/editors/subscription/subscriber-ied-list-goose.ts @@ -196,7 +196,6 @@ export class SubscriberIEDListGoose extends LitElement { * @param event - Incoming event. */ private async onIEDSubscriptionEvent(event: IEDSubscriptionEvent) { - console.log('onGOOSEIEDSub'); switch (event.detail.subscribeStatus) { case SubscribeStatus.Full: { this.unsubscribe(event.detail.element); From 6d6a8809cbfd6e4abb1752014cfc350aae3e1c35 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Fri, 25 Mar 2022 13:28:02 +0100 Subject: [PATCH 8/8] test(editors/Subscriber): fix integration tests --- .../editors/subscription/Subscription.test.ts | 69 ++-- .../__snapshots__/Subscription.test.snap.js | 320 ++++++++++++------ 2 files changed, 269 insertions(+), 120 deletions(-) diff --git a/test/integration/editors/subscription/Subscription.test.ts b/test/integration/editors/subscription/Subscription.test.ts index f64df1ece..72899c2d0 100644 --- a/test/integration/editors/subscription/Subscription.test.ts +++ b/test/integration/editors/subscription/Subscription.test.ts @@ -7,7 +7,10 @@ import { Editing } from '../../../../src/Editing.js'; import { Wizarding } from '../../../../src/Wizarding.js'; describe('Subscription Plugin', () => { - customElements.define('subscription-plugin', Wizarding(Editing(Subscription))); + customElements.define( + 'subscription-plugin', + Wizarding(Editing(Subscription)) + ); let element: Subscription; let doc: XMLDocument; @@ -16,62 +19,88 @@ describe('Subscription Plugin', () => { .then(response => response.text()) .then(str => new DOMParser().parseFromString(str, 'application/xml')); - element = await fixture(html``); + element = await fixture( + html`` + ); }); describe('initially', () => { it('the GOOSE list looks like the latest snapshot', async () => { - await expect(element.shadowRoot?.querySelector('publisher-goose-list')).shadowDom.to.equalSnapshot(); + await expect( + element.shadowRoot?.querySelector('publisher-goose-list') + ).shadowDom.to.equalSnapshot(); }); it('the IED list looks like the latest snapshot', async () => { - await expect(element.shadowRoot?.querySelector('subscriber-ied-list-goose')).shadowDom.to.equalSnapshot(); + await expect( + element.shadowRoot?.querySelector('subscriber-ied-list-goose') + ).shadowDom.to.equalSnapshot(); }); }); describe('when selecting a GOOSE message', () => { beforeEach(async () => { - const gseMsg = element.shadowRoot?.querySelector('publisher-goose-list') - ?.shadowRoot?.querySelectorAll('goose-message')[2].shadowRoot?.querySelector('mwc-list-item'); + const gseMsg = Array.from( + element.shadowRoot + ?.querySelector('publisher-goose-list') + ?.shadowRoot?.querySelectorAll('mwc-list-item') ?? [] + ).filter(item => !item.noninteractive)[2]; - ((gseMsg)).click(); + (gseMsg).click(); }); it('the list on the right will initially show the subscribed / partially subscribed / not subscribed IEDs', async () => { await element.updateComplete; - expect(element.shadowRoot?.querySelector('subscriber-ied-list-goose')).shadowDom.to.equalSnapshot(); + expect( + element.shadowRoot?.querySelector('subscriber-ied-list-goose') + ).shadowDom.to.equalSnapshot(); }); describe('and you subscribe a non-subscribed IED', () => { it('it looks like the latest snapshot', async () => { - const ied = element.shadowRoot?.querySelector('subscriber-ied-list-goose') - ?.shadowRoot?.querySelectorAll('ied-element-goose')[2].shadowRoot?.querySelector('mwc-list-item'); + const ied = Array.from( + element.shadowRoot + ?.querySelector('subscriber-ied-list-goose') + ?.shadowRoot?.querySelectorAll('mwc-list-item') ?? [] + ).filter(item => !item.noninteractive)[2]; - ((ied)).click(); + (ied).click(); await element.updateComplete; - expect(element.shadowRoot?.querySelector('subscriber-ied-list-goose')).shadowDom.to.equalSnapshot(); + expect( + element.shadowRoot?.querySelector('subscriber-ied-list-goose') + ).shadowDom.to.equalSnapshot(); }); }); describe('and you unsubscribe a subscribed IED', () => { it('it looks like the latest snapshot', async () => { - const ied = element.shadowRoot?.querySelector('subscriber-ied-list-goose') - ?.shadowRoot?.querySelectorAll('ied-element-goose')[0].shadowRoot?.querySelector('mwc-list-item'); + const ied = Array.from( + element.shadowRoot + ?.querySelector('subscriber-ied-list-goose') + ?.shadowRoot?.querySelectorAll('mwc-list-item') ?? [] + ).filter(item => !item.noninteractive)[1]; - ((ied)).click(); + (ied).click(); await element.updateComplete; - expect(element.shadowRoot?.querySelector('subscriber-ied-list-goose')).shadowDom.to.equalSnapshot(); + expect( + element.shadowRoot?.querySelector('subscriber-ied-list-goose') + ).shadowDom.to.equalSnapshot(); }); }); describe('and you subscribe a partially subscribed IED', () => { it('it looks like the latest snapshot', async () => { - const ied = element.shadowRoot?.querySelector('subscriber-ied-list-goose') - ?.shadowRoot?.querySelectorAll('ied-element-goose')[1].shadowRoot?.querySelector('mwc-list-item'); + const ied = Array.from( + element.shadowRoot + ?.querySelector('subscriber-ied-list-goose') + ?.shadowRoot?.querySelectorAll('mwc-list-item') ?? [] + ).filter(item => !item.noninteractive)[1]; - ((ied)).click(); + (ied).click(); await element.updateComplete; - expect(element.shadowRoot?.querySelector('subscriber-ied-list-goose')).shadowDom.to.equalSnapshot(); + expect( + element.shadowRoot?.querySelector('subscriber-ied-list-goose') + ).shadowDom.to.equalSnapshot(); }); }); }); diff --git a/test/integration/editors/subscription/__snapshots__/Subscription.test.snap.js b/test/integration/editors/subscription/__snapshots__/Subscription.test.snap.js index 9fdce293c..d84e5695d 100644 --- a/test/integration/editors/subscription/__snapshots__/Subscription.test.snap.js +++ b/test/integration/editors/subscription/__snapshots__/Subscription.test.snap.js @@ -6,7 +6,7 @@ snapshots["Subscription Plugin initially the GOOSE list looks like the latest sn

    [subscription.publisherGoose.title]

    - + - - - - + + + GCB + + + + + + + GCB2 + + + + - - + + + GCB + + + + + + + IED3 + + + developer_board + + +
  • +
  • - - - - -
    + + + GCB + + + + + + + GCB2 + + + + + `; /* end snapshot Subscription Plugin initially the GOOSE list looks like the latest snapshot */ @@ -97,12 +165,32 @@ snapshots["Subscription Plugin initially the IED list looks like the latest snap /* end snapshot Subscription Plugin initially the IED list looks like the latest snapshot */ snapshots["Subscription Plugin when selecting a GOOSE message the list on the right will initially show the subscribed / partially subscribed / not subscribed IEDs"] = +`
    +

    + [subscription.subscriberIed.title] +

    + + + + [subscription.subscriberIed.noGooseMessageSelected] + + + +
    +`; +/* end snapshot Subscription Plugin when selecting a GOOSE message the list on the right will initially show the subscribed / partially subscribed / not subscribed IEDs */ + +snapshots["Subscription Plugin when selecting a GOOSE message and you subscribe a non-subscribed IED it looks like the latest snapshot"] = `

    [subscription.subscriberIed.title]

    - + - - - - - - [subscription.subscriberIed.partiallySubscribed] + + IED3 + + clear + -
  • -
  • - - -
    - - [subscription.subscriberIed.availableToSubscribe] + [subscription.subscriberIed.partiallySubscribed]
  • - - -
    -
    -
    -`; -/* end snapshot Subscription Plugin when selecting a GOOSE message the list on the right will initially show the subscribed / partially subscribed / not subscribed IEDs */ - -snapshots["Subscription Plugin when selecting a GOOSE message and you subscribe a non-subscribed IED it looks like the latest snapshot"] = -`
    -

    - [subscription.subscriberIed.title] -

    -
    - - - [subscription.subscriberIed.subscribed] + + [subscription.none] -
  • -
  • - - - - -
    - - [subscription.subscriberIed.partiallySubscribed] + [subscription.subscriberIed.availableToSubscribe]
  • - - -
    - - - [subscription.subscriberIed.availableToSubscribe] + + IED1 + + add + -
  • -
  • - [subscription.none] + IED2 + + add + -
    +
    `; @@ -242,7 +298,7 @@ snapshots["Subscription Plugin when selecting a GOOSE message and you unsubscrib [subscription.subscriberIed.title]
    - + - - - - - - + + + [subscription.none] + + - - - - - + + + IED1 + + + add + + + + + IED2 + + + add + + + + + IED3 + + + add + + +
    `; @@ -317,7 +415,7 @@ snapshots["Subscription Plugin when selecting a GOOSE message and you subscribe [subscription.subscriberIed.title]
    - + - - - - - - + + + IED1 + + + clear + + - [subscription.none] + IED4 + + add + - - - - - + + + IED3 + + + add + + +
    `;