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

feat: selector #13

Closed
wants to merge 1 commit into from
Closed

feat: selector #13

wants to merge 1 commit into from

Conversation

JakobVogelsang
Copy link
Collaborator

Closes #6

This time i did touch IEDName and ProtNS. Both were not tested and for no good reason. Along the way I have increased the test coverage on some test cases such as ExtRef with intAddr and w/o and others.

The test is running some time as we do the test for all element in the validScl file. I then also promoses to cover a lot of edge cases

@JakobVogelsang JakobVogelsang requested a review from danyill July 27, 2023 13:02
Copy link
Collaborator

@danyill danyill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for moving this important functionality, I have tried to take a look at this functionality in a few places in detail and it looks good.

I have also tried to integrate into oscd-subscriber-later-binding and I have quite a range of test failures after I do that which I have not yet found time to look at and if you can wait I would like to examine. I use both identity and selector as part of the UI so I feel that would be worth investigating.

And also I would like to integrate this into openscd/open-scd and check that tests pass and prepare a PR for this so that we can immediately benefit from this library.

Comment on lines +16 to +32
it('returns correct selector for all tags except IEDName and ProtNs', () => {
Object.keys(selectorTags).forEach(tag => {
const elements = Array.from(doc.querySelectorAll(tag)).filter(
item => !item.closest('Private')
);

elements.forEach(element => {
if (element)
expect(element).to.satisfy(
// eslint-disable-next-line no-shadow
(element: Element) =>
element === doc.querySelector(selector(tag, identity(element)))
);
});
});
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I particularly like this "battery of tests"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these seem very good to have! They could also catch #14 if the test data was extended to a case with ExtRefs sharing an intAddr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will add one more ExtRef element covering the edge case @danyill triggered here.

it('returns tagName with non SCL tag', () =>
expect(selector('LNodeSpec', 'someLNodeSpec')).to.equal('LNodeSpec'));

it('returns correct selector for all tags except IEDName and ProtNs', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really an exception now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, thank you!

it('return empty string with non SCL tag', () =>
expect(parentTags('LNodeSpec').length).to.equal(0));

it('return empty all possible parents for SCL tag', () =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('return empty all possible parents for SCL tag', () =>
it('returns all possible parents for SCL tag', () =>

@danyill
Copy link
Collaborator

danyill commented Aug 1, 2023

(At least) part of the reason for my tests failing is that the ExtRef identity function in this library is different to that in open-scd.

In open-scd we have:

function extRefIdentity(e: Element): string | number {
  if (!e.parentElement) return NaN;
  const parentIdentity = identity(e.parentElement);
  const iedName = e.getAttribute('iedName');
  const intAddr = e.getAttribute('intAddr');
  const intAddrIndex = Array.from(
    e.parentElement.querySelectorAll(`ExtRef[intAddr="${intAddr}"]`)
  ).indexOf(e);
  if (intAddr) return `${parentIdentity}>${intAddr}[${intAddrIndex}]`;
  const [

Here we have:

function extRefIdentity(e: Element): string | number {
if (!e.parentElement) return NaN;
const parentIdentity = identity(e.parentElement);
const iedName = e.getAttribute('iedName');
const intAddr = e.getAttribute('intAddr');
const intAddrIndex = Array.from(
e.parentElement.querySelectorAll(`ExtRef[intAddr="${intAddr}"]`)
).indexOf(e);
if (!iedName) return `${parentIdentity}>${intAddr}[${intAddrIndex}]`;
const [
ldInst,
prefix,

The handling of intAddr is different as per openscd/open-scd#1179

@JakobVogelsang
Copy link
Collaborator Author

I decided to close this PR. We cannot resolve some element purly based selector string. Those are in particular ExtRef with intAddr, P, IEDName, ProtNs and Val. All of those must be indexes for the one or the other reason. This conflicts with selectors. The thing that we could use is _nth-child(n of S), but I decided against it as this is a too new feature.

@JakobVogelsang
Copy link
Collaborator Author

Please look into this PR for a better way to get SCL element based on an identity string, openscd/open-scd#1285. There is also a branch in preparation that does transport it to this repository. https://github.com/JakobVogelsang/oscd-scl/tree/find

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move find function (formally know as selector)
3 participants