Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(editors/IED): Added some missing unit tests #487

Merged
merged 4 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions test/testfiles/valid2007B4withIEDModifications.scd
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
</LN>
<LN lnClass="CSWI" inst="1" lnType="Dummy.CSWIwithoutCtlModel">
<DOI name="Pos">
<SDI name="anotherPosDo">
</SDI>
<DAI name="ctlModel">
<Val>sbo-with-enhanced-security</Val>
</DAI>
Expand All @@ -163,7 +165,7 @@
<DAI name="numPls">
<Val>1</Val>
</DAI>
</SDI>
</SDI>
<DAI name="ctlModel">
<Val>sbo-with-enhanced-security</Val>
</DAI>
Expand Down Expand Up @@ -330,6 +332,7 @@
</Inputs>
</LN>
<LN lnClass="tHarde" lnType="lnTypeWithoutDOs" />
<LN lnClass="CSWI" lnType="nonExistingLnType" />
</LDevice>
</Server>
</AccessPoint>
Expand Down Expand Up @@ -479,6 +482,8 @@
<DA fc="CF" name="sVC" bType="Struct" type="ScaledValueConfig"/>
</DOType>
<DOType cdc="ENC" id="Dummy.LLN0.Mod">
<SDO fc="ST" name="sdoName2" type="nonExistingDoType"/>
<SDO fc="ST" name="sdoName3" type="doTypeNotHavingAnyDaElements"/>
<DA fc="ST" name="stVal" bType="Enum" type="Dummy_Beh" />
<DA fc="ST" name="q" bType="Quality" />
<DA fc="ST" name="t" bType="Timestamp" />
Expand Down Expand Up @@ -531,12 +536,12 @@
<DA fc="ST" name="q" bType="Quality" />
<DA fc="ST" name="t" bType="Timestamp" />
</DOType>
<DOType cdc="LPL" id="Dummy.LLN0.NamPlt">
<DA fc="DC" name="vendor" bType="VisString255" />
<DA fc="DC" name="swRev" bType="VisString255" />
<DA fc="DC" name="d" bType="VisString255" />
<DA fc="DC" name="configRev" bType="VisString255" />
<DA fc="EX" name="ldNs" bType="VisString255" />
<DOType cdc="ENS" id="Dummy.LLN0.Health">
<DA fc="ST" name="stVal" bType="Enum" type="Dummy_Health" />
<DA fc="ST" name="q" bType="Quality" />
<DA fc="ST" name="t" bType="Timestamp" />
</DOType>
<DOType cdc="LPLSDF" id="doTypeNotHavingAnyDaElements">
</DOType>
<DOType cdc="DPL" id="Dummy.LPHD1.PhyNam">
<DA fc="DC" name="vendor" bType="VisString255" />
Expand Down Expand Up @@ -579,6 +584,8 @@
<DA fc="DC" name="d" bType="VisString255" />
</DOType>
<DOType cdc="DPC" id="Dummy.CSWI.Pos2">
<SDO fc="ST" name="anotherPosDo" type="Quality"/>
<SDO fc="ST" name="someQualityThing" type="Quality"/>
<DA fc="ST" name="stVal" bType="Dbpos" />
<DA fc="ST" name="q" bType="Quality" />
<DA fc="ST" name="t" bType="Timestamp" />
Expand Down
132 changes: 132 additions & 0 deletions test/unit/editors/ied/do-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ describe('do-container', () => {
expect(nestedDOs!.length).to.eql(1);
expect(nestedDOs![0].getAttribute('name')).to.eql('anotherSdo');
});

it('which return an empty array if the DoType cannot be found', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > DOType[id="Dummy.LLN0.Mod"] > SDO[name="sdoName2"]')}
></do-container>`);

const nestedDOs = element['getDOElements']();
expect(nestedDOs).to.be.empty;
});

it('which return an empty array if a DO doesn\t have child (S)DO\'s.', async () => {
element = await fixture(html`<do-container
Expand All @@ -106,4 +116,126 @@ describe('do-container', () => {
expect(nestedDOs).to.be.empty;
});
});

describe('has a getDAElements function ', () => {
it('which return the DA containers underneath a given DO.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.LLN0"] > DO[name="ExtendedMod"]')}
></do-container>`);

const nestedDOs = element['getDAElements']();
expect(nestedDOs).to.not.be.empty;
expect(nestedDOs!.length).to.eql(14);
expect(nestedDOs![2].getAttribute('name')).to.eql('t');
});

it('which return an empty array if the DoType cannot be found', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > DOType[id="Dummy.LLN0.Mod"] > SDO[name="sdoName2"]')}
></do-container>`);

const nestedDOs = element['getDAElements']();
expect(nestedDOs).to.be.empty;
});

it('which return an empty array if a DO doesn\t have child DA\'s.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > DOType[id="Dummy.LLN0.Mod"] > SDO[name="sdoName3"]')}
></do-container>`);

const nestedDOs = element['getDOElements']();
expect(nestedDOs).to.be.empty;
});
});

describe('has a getInstanceDOElement function ', () => {
it('which return a DOI when a DO has a valid instance element.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')}
.instanceElement=${validSCL.querySelector(
'IED[name="IED1"] > AccessPoint[name="P1"] > Server > LDevice[inst="CircuitBreaker_CB1"] > LN[lnClass="CSWI"] > DOI[name="Pos"]')}
></do-container>`);

const sdo = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > SDO[name="anotherPosDo"]')

const doi = element['getInstanceDOElement'](sdo!);
expect(doi).to.not.be.null;
expect(doi?.tagName).to.eql('SDI');
expect(doi?.getAttribute('name')).to.eql('anotherPosDo');
});

it('which returns null if there\'s no SDI available within a DOI.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')}
.instanceElement=${validSCL.querySelector(
'IED[name="IED1"] > AccessPoint[name="P1"] > Server > LDevice[inst="CircuitBreaker_CB1"] > LN[lnClass="CSWI"] > DOI[name="Pos"]')}
></do-container>`);

const sdo = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > SDO[name="someQualityThing"]')

const doi = element['getInstanceDOElement'](sdo!);
expect(doi).to.be.null;
});

it('which returns null if no root DOI is available.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')}
></do-container>`);

const sdo = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > SDO[name="someQualityThing"]')

const doi = element['getInstanceDOElement'](sdo!);
expect(doi).to.be.null;
});
});

describe('has a getInstanceDAElement function ', () => {
it('which return a DAI when a DA has a valid instance element.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')}
.instanceElement=${validSCL.querySelector(
'IED[name="IED1"] > AccessPoint[name="P1"] > Server > LDevice[inst="CircuitBreaker_CB1"] > LN[lnClass="CSWI"] > DOI[name="Pos"]')}
></do-container>`);

const da = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > DA[name="ctlModel"]')

const dai = element['getInstanceDAElement'](da!);
expect(dai).to.not.be.null;
expect(dai?.tagName).to.eql('DAI');
expect(dai?.getAttribute('name')).to.eql('ctlModel');
});

it('which returns null if there\'s no DAI available within a DOI.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')}
.instanceElement=${validSCL.querySelector(
'IED[name="IED1"] > AccessPoint[name="P1"] > Server > LDevice[inst="CircuitBreaker_CB1"] > LN[lnClass="CSWI"] > DOI[name="Pos"]')}
></do-container>`);

const da = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > DA[name="d"]')

const dai = element['getInstanceDAElement'](da!);
expect(dai).to.be.null;
});

it('which returns null if no root DOI is available.', async () => {
element = await fixture(html`<do-container
.element=${validSCL.querySelector(
'DataTypeTemplates > LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')}
></do-container>`);

const da = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > DA[name="d"]')

const dai = element['getInstanceDAElement'](da!);
expect(dai).to.be.null;
});
});
});
9 changes: 9 additions & 0 deletions test/unit/editors/ied/ln-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ describe('ln-container', () => {
const nestedDOs = element['getDOElements']();
expect(nestedDOs).to.be.empty;
});

it('which return an empty array if the LNodeType of a LN doesn\'t exist.', async () => {
element = await fixture(html`<ln-container
.element=${validSCL.querySelector('LN[lnType="nonExistingLnType"]')}
></ln-container>`);

const nestedDOs = element['getDOElements']();
expect(nestedDOs).to.be.empty;
});
});

describe('has a getInstanceElement function ', () => {
Expand Down