|
2 | 2 | /* eslint-disable import/no-extraneous-dependencies */ |
3 | 3 | import { expect } from '@open-wc/testing'; |
4 | 4 | import { iedWithLDevice, copyControlDoc } from './xml.testfiles.js'; |
5 | | -import { queryLDevice, queryLN } from './xml.js'; |
| 5 | +import { |
| 6 | + isFCDACompatibleWithIED, |
| 7 | + queryDataTypeLeaf, |
| 8 | + queryLDevice, |
| 9 | + queryLN, |
| 10 | +} from './xml.js'; |
6 | 11 |
|
7 | 12 | function parseXml(str: string): Document { |
8 | 13 | return new DOMParser().parseFromString(str, 'application/xml'); |
@@ -65,4 +70,81 @@ describe('Xml utility', () => { |
65 | 70 | expect(ln?.getAttribute('id')).to.equal('ToBeCopied_MMXU'); |
66 | 71 | }); |
67 | 72 | }); |
| 73 | + |
| 74 | + describe('queryDataTypeLeaf', () => { |
| 75 | + it('should fetch DO leaf', () => { |
| 76 | + const dataTypeTemplates = doc.querySelector('DataTypeTemplates')!; |
| 77 | + const lnType = 'CILO$oscd$_eb5ec6bb69650d07'; |
| 78 | + |
| 79 | + const leaf = queryDataTypeLeaf(dataTypeTemplates, lnType, ['EnaOpn'], []); |
| 80 | + |
| 81 | + expect(leaf).to.not.be.null; |
| 82 | + expect(leaf?.tagName).to.equal('DOType'); |
| 83 | + expect(leaf?.getAttribute('id')).to.equal( |
| 84 | + 'EnaOpn$oscd$_55462dcb3eb76dd6' |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should return null if dataType is not found', () => { |
| 89 | + const dataTypeTemplates = doc.querySelector('DataTypeTemplates')!; |
| 90 | + const lnType = 'MMXU$oscd$_8046c36011040649'; |
| 91 | + |
| 92 | + const leaf = queryDataTypeLeaf( |
| 93 | + dataTypeTemplates, |
| 94 | + lnType, |
| 95 | + ['A', 'phsA'], |
| 96 | + ['cVal', 'ang', 'f'] |
| 97 | + ); |
| 98 | + |
| 99 | + expect(leaf).to.be.null; |
| 100 | + }); |
| 101 | + |
| 102 | + it('should fetch DA leaf', () => { |
| 103 | + const dataTypeTemplates = doc.querySelector('DataTypeTemplates')!; |
| 104 | + const lnType = 'MMXU$oscd$_bcec88edb16399a2'; |
| 105 | + |
| 106 | + const leaf = queryDataTypeLeaf( |
| 107 | + dataTypeTemplates, |
| 108 | + lnType, |
| 109 | + ['A', 'phsA'], |
| 110 | + ['cVal', 'ang', 'f'] |
| 111 | + ); |
| 112 | + |
| 113 | + expect(leaf).to.not.be.null; |
| 114 | + expect(leaf?.tagName).to.equal('DAType'); |
| 115 | + expect(leaf?.getAttribute('id')).to.equal('ang$oscd$_ed49c2f7a55ad05a'); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + describe('isFCDACompatibleWithIED', () => { |
| 120 | + it('should return true for compatible FCDA', () => { |
| 121 | + const fcda = doc.querySelector( |
| 122 | + 'IED[name="ToBeCopied"] LDevice[inst="LD1"] > LN0 > DataSet > FCDA' |
| 123 | + )!; |
| 124 | + const ied = doc.querySelector('IED[name="ToCopieTo8"]')!; |
| 125 | + |
| 126 | + const isCompatible = isFCDACompatibleWithIED(fcda, ied); |
| 127 | + expect(isCompatible).to.be.true; |
| 128 | + }); |
| 129 | + |
| 130 | + it('should return false if IED is missing LDevice', () => { |
| 131 | + const fcda = doc.querySelector( |
| 132 | + 'IED[name="ToBeCopied"] LDevice[inst="LD1"] > LN0 > DataSet > FCDA' |
| 133 | + )!; |
| 134 | + const ied = doc.querySelector('IED[name="ToCopieTo1"]')!; |
| 135 | + |
| 136 | + const isCompatible = isFCDACompatibleWithIED(fcda, ied); |
| 137 | + expect(isCompatible).to.be.false; |
| 138 | + }); |
| 139 | + |
| 140 | + it('should return false if data type is incompatible', () => { |
| 141 | + const fcda = doc.querySelector( |
| 142 | + 'IED[name="ToBeCopied"] LDevice[inst="LD1"] > LN0 > DataSet > FCDA' |
| 143 | + )!; |
| 144 | + const ied = doc.querySelector('IED[name="ToCopieTo4"]')!; |
| 145 | + |
| 146 | + const isCompatible = isFCDACompatibleWithIED(fcda, ied); |
| 147 | + expect(isCompatible).to.be.false; |
| 148 | + }); |
| 149 | + }); |
68 | 150 | }); |
0 commit comments