Skip to content

Commit

Permalink
feat: find element based on identity strings
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobVogelsang authored and Jakob Vogelsang committed Oct 3, 2023
1 parent 2df4a18 commit be1d382
Show file tree
Hide file tree
Showing 9 changed files with 1,577 additions and 38 deletions.
1 change: 1 addition & 0 deletions index.ts
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';
470 changes: 470 additions & 0 deletions utils/edgeScl.ts

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions utils/find.spec.ts
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))
);
});
});
});
});
Loading

0 comments on commit be1d382

Please sign in to comment.