From b38fa45443fbe2b74273b4cf4061a4f9956360d9 Mon Sep 17 00:00:00 2001 From: Flurb Date: Fri, 14 Jan 2022 15:14:25 +0100 Subject: [PATCH 1/3] Add missing LN unit test --- test/testfiles/valid2007B4withIEDModifications.scd | 1 + test/unit/editors/ied/ln-container.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/test/testfiles/valid2007B4withIEDModifications.scd b/test/testfiles/valid2007B4withIEDModifications.scd index 39e9ce1f5b..5de1a56972 100644 --- a/test/testfiles/valid2007B4withIEDModifications.scd +++ b/test/testfiles/valid2007B4withIEDModifications.scd @@ -328,6 +328,7 @@ + diff --git a/test/unit/editors/ied/ln-container.test.ts b/test/unit/editors/ied/ln-container.test.ts index a9917ea72a..f3345174e6 100644 --- a/test/unit/editors/ied/ln-container.test.ts +++ b/test/unit/editors/ied/ln-container.test.ts @@ -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``); + + const nestedDOs = element['getDOElements'](); + expect(nestedDOs).to.be.empty; + }); }); describe('has a getInstanceElement function ', () => { From f2de920147a5a3d092d6ec4347ed64a81994df75 Mon Sep 17 00:00:00 2001 From: Flurb Date: Sun, 16 Jan 2022 22:30:17 +0100 Subject: [PATCH 2/3] Added next few unit tests --- .../valid2007B4withIEDModifications.scd | 14 +++--- test/unit/editors/ied/do-container.test.ts | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/test/testfiles/valid2007B4withIEDModifications.scd b/test/testfiles/valid2007B4withIEDModifications.scd index 82ca0f8269..3b1287154a 100644 --- a/test/testfiles/valid2007B4withIEDModifications.scd +++ b/test/testfiles/valid2007B4withIEDModifications.scd @@ -480,6 +480,8 @@ + + @@ -532,12 +534,12 @@ - - - - - - + + + + + + diff --git a/test/unit/editors/ied/do-container.test.ts b/test/unit/editors/ied/do-container.test.ts index b4c3b49801..449093aefb 100644 --- a/test/unit/editors/ied/do-container.test.ts +++ b/test/unit/editors/ied/do-container.test.ts @@ -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` DOType[id="Dummy.LLN0.Mod"] > SDO[name="sdoName2"]')} + >`); + + 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` { 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` LNodeType[id="Dummy.LLN0"] > DO[name="ExtendedMod"]')} + >`); + + 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` DOType[id="Dummy.LLN0.Mod"] > SDO[name="sdoName2"]')} + >`); + + 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` DOType[id="Dummy.LLN0.Mod"] > SDO[name="sdoName3"]')} + >`); + + const nestedDOs = element['getDOElements'](); + expect(nestedDOs).to.be.empty; + }); + }); }); From ba70a60320caa43ffe54e7193f679c21ad3135cc Mon Sep 17 00:00:00 2001 From: Flurb Date: Sun, 16 Jan 2022 23:35:31 +0100 Subject: [PATCH 3/3] Added some more unit tests for IED edtiro --- .../valid2007B4withIEDModifications.scd | 6 +- test/unit/editors/ied/do-container.test.ts | 88 +++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/test/testfiles/valid2007B4withIEDModifications.scd b/test/testfiles/valid2007B4withIEDModifications.scd index 3b1287154a..72443afded 100644 --- a/test/testfiles/valid2007B4withIEDModifications.scd +++ b/test/testfiles/valid2007B4withIEDModifications.scd @@ -145,6 +145,8 @@ + + sbo-with-enhanced-security @@ -163,7 +165,7 @@ 1 - + sbo-with-enhanced-security @@ -582,6 +584,8 @@ + + diff --git a/test/unit/editors/ied/do-container.test.ts b/test/unit/editors/ied/do-container.test.ts index 449093aefb..5f79747243 100644 --- a/test/unit/editors/ied/do-container.test.ts +++ b/test/unit/editors/ied/do-container.test.ts @@ -150,4 +150,92 @@ describe('do-container', () => { 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` 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"]')} + >`); + + 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` 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"]')} + >`); + + 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` LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')} + >`); + + 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` 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"]')} + >`); + + 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` 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"]')} + >`); + + 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` LNodeType[id="Dummy.CSWIwithoutCtlModel"] > DO[name="Pos"]')} + >`); + + const da = validSCL.querySelector('DataTypeTemplates > DOType[id="Dummy.CSWI.Pos2"] > DA[name="d"]') + + const dai = element['getInstanceDAElement'](da!); + expect(dai).to.be.null; + }); + }); });