Skip to content

Commit

Permalink
Add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danyill committed Jan 27, 2024
1 parent 09a5aad commit c495fca
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 82 deletions.
27 changes: 26 additions & 1 deletion foundation/subscription/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export function removeSubscriptionSupervision(
return edits;
}

// TODO: Daniel has changed this function
/**
* Counts the max number of LN instances with supervision allowed for
* the given control block's type of message.
Expand Down Expand Up @@ -254,3 +253,29 @@ export function createNewSupervisionLnEvent(
}
return null;
}

export function clearSupervisionReference(ln: Element): Edit[] | undefined {
const val = ln.querySelector(
':scope > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val, :scope > DOI[name="SvCBRef"] > DAI[name="setSrcRef"] > Val'
);
if (!val || val.textContent === '') return undefined;

const edits: Edit[] = [];

// remove old element
edits.push({
node: val
});

const newValElement = <Element>val.cloneNode(true);
newValElement.textContent = '';

// add new element
edits.push({
parent: val.parentElement!,
reference: null,
node: newValElement
});

return edits;
}
24 changes: 19 additions & 5 deletions oscd-supervision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
sourceControlBlock,
instantiateSubscriptionSupervision
} from '@openenergytools/scl-lib';
import { newEditEvent, Remove } from '@openscd/open-scd-core';
import { Edit, newEditEvent, Remove } from '@openscd/open-scd-core';

import '@material/mwc-button';
import '@material/mwc-formfield';
Expand Down Expand Up @@ -50,6 +50,7 @@ import {
} from './foundation/icons.js';

import {
clearSupervisionReference,
controlBlockReference,
createNewSupervisionLnEvent as createNewSupervisionLnEdit,
isSupervisionModificationAllowed,
Expand Down Expand Up @@ -449,7 +450,7 @@ export default class OscdSupervision extends LitElement {
}
}

if (_changedProperties.has('selectedIed')) {
if (_changedProperties.has('selectedIEDs')) {
this.updateCBRefInfo(this.selectedIed, this.controlType);
this.clearListSelections();
this.resetSearchFilters();
Expand Down Expand Up @@ -943,7 +944,19 @@ export default class OscdSupervision extends LitElement {
this.selectedControl &&
(this.selectedSupervision || this.newSupervision)
) {
const edits = instantiateSubscriptionSupervision(
if (this.selectedSupervision) {
// TODO: We have to remove first to use the scl-lib function
// We hope to have an upstream overwrite option before too long
// See https://github.com/OpenEnergyTools/scl-lib/issues/79
const edits: Edit[] = [];
const removalEdit = clearSupervisionReference(
this.selectedSupervision
);
if (removalEdit) edits.push(removalEdit);
this.dispatchEvent(newEditEvent(edits));
}
const instantiationEdit = instantiateSubscriptionSupervision(
{
subscriberIedOrLn: this.newSupervision
? this.selectedIed!
Expand All @@ -953,12 +966,13 @@ export default class OscdSupervision extends LitElement {
{
newSupervisionLn: this.newSupervision,
fixedLnInst: -1,
checkEditableSrcRef: false,
checkEditableSrcRef: true,
checkDuplicateSupervisions: true,
checkMaxSupervisionLimits: true
}
);
if (edits) this.dispatchEvent(newEditEvent(edits));
if (instantiationEdit)
this.dispatchEvent(newEditEvent(instantiationEdit));
}
this.updateCBRefInfo(this.selectedIed, this.controlType);
Expand Down
16 changes: 14 additions & 2 deletions test/fixtures/supervisions.scd
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,12 @@
<LN0 lnClass="LLN0" inst="" lnType="Dummy.LLN0"/>
<LN prefix="" lnClass="CILO" inst="1" lnType="Dummy.CILO"/>
<LN prefix="" lnClass="CSWI" inst="1" lnType="Dummy.CSWI"/>
<LN prefix="" lnClass="XSWI" inst="1" lnType="Dummy.XSWI"/>
<LN prefix="" lnClass="XSWI" inst="1" lnType="Dummy.XSWI">
<Inputs>
<ExtRef iedName="GOOSE_Publisher" serviceType="GOOSE" ldInst="QB2_Disconnector" lnClass="CSWI" lnInst="1" prefix="" doName="Pos" daName="stVal" srcLDInst="QB2_Disconnector" srcPrefix="" srcLNClass="LLN0" srcCBName="GOOSE2"/>
<ExtRef iedName="GOOSE_Publisher" serviceType="GOOSE" ldInst="QB2_Disconnector" lnClass="CSWI" lnInst="1" prefix="" doName="Pos" daName="q" srcLDInst="QB2_Disconnector" srcPrefix="" srcLNClass="LLN0" srcCBName="GOOSE2"/>
</Inputs>
</LN>
</LDevice>
<LDevice inst="GOOSE_supervision">
<LN0 lnClass="LLN0" inst="" lnType="Dummy.LLN0"/>
Expand All @@ -530,7 +535,14 @@
</DAI>
</DOI>
</LN>
<LN lnClass="LGOS" inst="2" lnType="Dummy.LGOS2"/>
<LN lnClass="LGOS" inst="2" lnType="Dummy.LGOS1">
<Private type="OpenSCD.create"/>
<DOI name="GoCBRef">
<DAI name="setSrcRef">
<Val>GOOSE_PublisherQB2_Disconnector/LLN0.GOOSE1</Val>
</DAI>
</DOI>
</LN>
<LN lnClass="LGOS" inst="3" lnType="Dummy.LGOS2"/>
<LN lnClass="LGOS" inst="4" lnType="Dummy.LGOS2"/>
</LDevice>
Expand Down
213 changes: 139 additions & 74 deletions test/integration/supervision.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ describe(pluginName, () => {
await resetMouseState();
await visualDiff(plugin, testName(this));
});

it('including where supervisions cannot be changed', async function () {
await changeIED(plugin, 'GOOSE_Subscriber3');

await plugin.updateComplete;
await timeout(standardWait);
await visualDiff(plugin, testName(this));
});
});

describe('changes supervisions', () => {
Expand Down Expand Up @@ -469,80 +477,137 @@ describe(pluginName, () => {
await visualDiff(plugin, testName(this));
});

// TODO:
// it('can reassign a supervision with no local subscriptions', async function () {
// it('can reassign a supervision with an invalid control block', async function () {

// TODO: REmove comment, is caused by no local subscriptions but valid control block
// See https://github.com/OpenEnergyTools/scl-lib/issues/79
//
// it('can carry out a sequence of create, disconnect, delete and connect', async function () {
// // can create
// await changeIED(plugin, 'GOOSE_Subscriber1');
// await timeout(standardWait);

// const createNewSupLn = plugin.shadowRoot!.querySelector(
// 'section.unused mwc-icon-button#createNewLN'
// );
// await sendMouse({
// type: 'click',
// button: 'left',
// position: midEl(createNewSupLn!)
// });
// await plugin.updateComplete;
// await timeout(standardWait);

// // can disconnect
// const removeButton = plugin.shadowRoot!.querySelector(
// 'section > .mlist.remover > mwc-list-item[data-ln="GOOSE_Subscriber1>>GOOSE_Supervision> LGOS 2"] > mwc-icon'
// );
// await sendMouse({
// type: 'click',
// button: 'left',
// position: midEl(removeButton!)
// });
// await plugin.updateComplete;
// await timeout(standardWait);

// // can delete
// const deleteUnusedSupLn = plugin.shadowRoot!.querySelector(
// 'section.unused div.available-grouper > mwc-list.deleter > mwc-list-item[data-ln="GOOSE_Subscriber1>>GOOSE_Supervision> LGOS 2"]'
// );
// await sendMouse({
// type: 'click',
// button: 'left',
// position: midEl(deleteUnusedSupLn!)
// });
// await plugin.updateComplete;
// await timeout(standardWait);

// // can assign
// const assignNewSupLn = plugin.shadowRoot!.querySelector(
// 'section.unused div.available-grouper > .filteredList > mwc-list > mwc-list-item[data-ln="GOOSE_Subscriber1>>GOOSE_Supervision> LGOS 3"]'
// );
// await sendMouse({
// type: 'click',
// button: 'left',
// position: midEl(assignNewSupLn!)
// });
// await plugin.updateComplete;
// await timeout(standardWait);

// const existingCb = plugin.shadowRoot!.querySelector(
// 'section.unused oscd-filtered-list#unusedControls > mwc-list-item[data-control="GOOSE_Publisher2>>QB2_Disconnector>GOOSE2"]'
// );
// await sendMouse({
// type: 'click',
// button: 'left',
// position: midEl(existingCb!)
// });

// await plugin.updateComplete;
// await timeout(standardWait);
// await resetMouseState();

// await visualDiff(plugin, testName(this));
// });
it('can reassign a supervision with no local subscriptions', async function () {
await changeIED(plugin, 'GOOSE_Subscriber5');
await timeout(standardWait);

// can assign
const assignNewSupLn = plugin.shadowRoot!.querySelector(
'section.unused div.available-grouper > .filteredList > mwc-list > mwc-list-item[data-ln="GOOSE_Subscriber5>>GOOSE_supervision> LGOS 2"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(assignNewSupLn!)
});
await plugin.updateComplete;
await timeout(standardWait);

const existingCb = plugin.shadowRoot!.querySelector(
'section.unused oscd-filtered-list#unusedControls > mwc-list-item[data-control="GOOSE_Publisher>>QB2_Disconnector>GOOSE2"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(existingCb!)
});

await plugin.updateComplete;
await timeout(standardWait);
await resetMouseState();

await visualDiff(plugin, testName(this));
});

it('can reassign a supervision with an invalid control block', async function () {
await changeIED(plugin, 'GOOSE_Subscriber5');
await timeout(standardWait);

// can assign
const assignNewSupLn = plugin.shadowRoot!.querySelector(
'section.unused div.available-grouper > .filteredList > mwc-list > mwc-list-item[data-ln="GOOSE_Subscriber5>>GOOSE_supervision> LGOS 1"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(assignNewSupLn!)
});
await plugin.updateComplete;
await timeout(standardWait);

const existingCb = plugin.shadowRoot!.querySelector(
'section.unused oscd-filtered-list#unusedControls > mwc-list-item[data-control="GOOSE_Publisher>>QB2_Disconnector>GOOSE2"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(existingCb!)
});

await plugin.updateComplete;
await timeout(standardWait);
await resetMouseState();

await visualDiff(plugin, testName(this));
});

it('can carry out a sequence of create, disconnect, delete and connect', async function () {
// can create
await changeIED(plugin, 'GOOSE_Subscriber1');
await timeout(standardWait);

const createNewSupLn = plugin.shadowRoot!.querySelector(
'section.unused mwc-icon-button#createNewLN'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(createNewSupLn!)
});
await plugin.updateComplete;
await timeout(standardWait);

// can disconnect
const removeButton = plugin.shadowRoot!.querySelector(
'section > .mlist.remover > mwc-list-item[data-ln="GOOSE_Subscriber1>>GOOSE_Supervision> LGOS 2"] > mwc-icon'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(removeButton!)
});
await plugin.updateComplete;
await timeout(standardWait);

// can delete
const deleteUnusedSupLn = plugin.shadowRoot!.querySelector(
'section.unused div.available-grouper > mwc-list.deleter > mwc-list-item[data-ln="GOOSE_Subscriber1>>GOOSE_Supervision> LGOS 2"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(deleteUnusedSupLn!)
});
await plugin.updateComplete;
await timeout(standardWait);

// can assign
const assignNewSupLn = plugin.shadowRoot!.querySelector(
'section.unused div.available-grouper > .filteredList > mwc-list > mwc-list-item[data-ln="GOOSE_Subscriber1>>GOOSE_Supervision> LGOS 3"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(assignNewSupLn!)
});
await plugin.updateComplete;
await timeout(standardWait);

const existingCb = plugin.shadowRoot!.querySelector(
'section.unused oscd-filtered-list#unusedControls > mwc-list-item[data-control="GOOSE_Publisher2>>QB2_Disconnector>GOOSE2"]'
);
await sendMouse({
type: 'click',
button: 'left',
position: midEl(existingCb!)
});

await plugin.updateComplete;
await timeout(standardWait);
await resetMouseState();

await visualDiff(plugin, testName(this));
});

it('can carry out a sequence of delete, connect and delete, connect', async function () {
await changeIED(plugin, 'GOOSE_Subscriber1');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c495fca

Please sign in to comment.