-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: find element based on identity strings
- Loading branch information
1 parent
2df4a18
commit be1d382
Showing
9 changed files
with
1,577 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { getReference } from './utils/tags.js'; | ||
export { identity } from './utils/identity.js'; | ||
export { selector } from './utils/selector.js'; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { expect } from '@open-wc/testing'; | ||
|
||
import { validScl } from './validScl.js'; | ||
|
||
import { find, isPublic, selectorTags } from './find.js'; | ||
import { identity } from './identity.js'; | ||
|
||
const doc = new DOMParser().parseFromString(validScl, 'application/xml')!; | ||
|
||
describe('Function returning query selector', () => { | ||
it('returns negation pseudo-class for identity of type NaN', () => | ||
expect(find(doc, 'Association', NaN)).to.be.null); | ||
|
||
it('returns tagName with non SCL tag', () => | ||
expect(find(doc, 'LNodeSpec', 'someLNodeSpec')).to.be.null); | ||
|
||
it('returns null for invalid extRefIdentity with non SCL tag', () => { | ||
expect(find(doc, 'ExtRef', '@intAddr5]')).to.be.null; | ||
expect(find(doc, 'ExtRef', ':GCB CBSW/ LLN0 / 2 stVal')).to.be.null; | ||
expect(find(doc, 'Substation', 'IED1')).to.be.null; | ||
}); | ||
|
||
it('returns null for invalid iEDNameIdentity with non SCL tag', () => | ||
expect(find(doc, 'IEDName', '@invalidId]')).to.be.null); | ||
|
||
it('returns null for invalid pIdentity with non SCL tag', () => { | ||
expect(find(doc, 'P', '@invalidId')).to.be.null; | ||
expect(find(doc, 'P', 'IED1 P1> [0]')).to.be.null; | ||
}); | ||
|
||
it('returns null for invalid protNsIdentity with non SCL tag', () => | ||
expect(find(doc, 'ProtNs', '@invalidId')).to.be.null); | ||
|
||
it('returns null for invalid valIdentity with non SCL tag', () => | ||
expect(find(doc, 'Val', '@invalidId')).to.be.null); | ||
|
||
it('returns null for LNode identity without lnType', () => | ||
expect(find(doc, 'LNode', '(IED1)')).to.be.null); | ||
|
||
it('returns null for LNode identity without lnType', () => { | ||
expect(find(doc, 'DAI', 'stVal')).to.be.null; | ||
}); | ||
|
||
it('returns correct element for all tags', () => { | ||
Object.keys(selectorTags).forEach(tag => { | ||
const elements = Array.from(doc.querySelectorAll(tag)).filter( | ||
item => !item.closest('Private') | ||
); | ||
|
||
elements.forEach(element => { | ||
if (element && isPublic(element)) | ||
expect(element).to.satisfy( | ||
// eslint-disable-next-line no-shadow | ||
(element: Element) => element === find(doc, tag, identity(element)) | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.