-
Notifications
You must be signed in to change notification settings - Fork 39
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: NS class selectors #175
base: master
Are you sure you want to change the base?
feat: NS class selectors #175
Conversation
This selector will act specifically on svg classes which follow a different implementation to regular HTML elements.
Svg classes will exist as an attribute "class" on the record stringAttributes.
This selector is for finding multiple classes on an svg element.
Tests the exact class value for svg elements.
These mimick the nodeRecordPredicate helpers.
I have added a few tests for attribute and class selectors to assert that these selectors will not work with svg classes.
We need this for testing NS selectors
@rtfeldman fix as promised. If I set my pedanto meter really high, I think there is a valid argument to move these selectors into their own I also noticed the Keen to get your feedback on this implementation. |
elm.json
Outdated
@@ -21,6 +21,7 @@ | |||
"elm/html": "1.0.0 <= v < 2.0.0", | |||
"elm/json": "1.0.0 <= v < 2.0.0", | |||
"elm/random": "1.0.0 <= v < 2.0.0", | |||
"elm/svg": "1.0.1 <= v < 2.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this lower bound be 1.0.0
instead of 1.0.1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
tests/elm.json
Outdated
"elm-explorations/webgl": "1.0.1", | ||
"jinjor/elm-diff": "1.0.5", | ||
"elm-explorations/webgl": "1.1.3", | ||
"jinjor/elm-diff": "1.0.6", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we not update this file if possible, just to make sure everything still works with the older versions - to minimize the chances that these changes cause regressions for anyone! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
Given how much these selectors will overlap with the @tesk9 What do you think? Also, any feedback on the PR in general? |
I'd prefer to keep this change as minimal as possible, so let's not! |
For compatibilities sake, we are using the original versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially on reading through, I felt a little unsure about the API. I wasn't sure if users would get that NS
-means-SVG, especially since the module name is Test.Html.Selector
. I wouldn't necessarily expect to have svg-specific helpers in a module with Html
in the name, you know? So I did a little exploration of what info we currently have, to see if I could suggest an alternate approach to changing the Selectors.
I printed out what is produced when running tests with
Svg.svg [ SvgAttribs.class svgClass ] [ ]
|> Query.fromHtml
and
Html.div [ Attr.class someClass ] []
|> Query.fromHtml
I found the results to be mostly the same, expect for the attribute name:
SVG node entry:
NodeEntry {
children = [],
descendantsCount = 1,
facts = {
attributeNamespace = Nothing,
boolAttributes = Dict.fromList [],
events = Dict.fromList [],
stringAttributes = Dict.fromList [("class","some-NS-class")],
styles = Dict.fromList []
},
tag = "svg"
}
HTML node entry:
NodeEntry {
children = [],
descendantsCount = 0,
facts = {
attributeNamespace = Nothing,
boolAttributes = Dict.fromList [],
events = Dict.fromList [],
stringAttributes = Dict.fromList [("className","some-class")],
styles = Dict.fromList []
},
tag = "div"
}
I think what this means is that we can change the Query inernal code instead of the Selector API code!
I'm making a PR off of this one. Let me know what you think!
[ Svg.circle [ SvgAttribs.cx "50", SvgAttribs.cy "50", SvgAttribs.r "40" ] [] ] | ||
|> Query.fromHtml | ||
|> Query.has [ classesNS [ svgClass ] ] | ||
, test "exactClassNameNS selector finds the exact class value on svg" <| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we should support exactClassName
on SVGs. Might lead to more confusion with respect to bugs like https://ellie-app.com/gsphpMkJVN5a1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. I don't quite understand? Could you elaborate? exactClassNameNS
simply queries the full class attribute on the svg which could consist of multiple classes, not sure how that pertains to the bug you linked.
I rambled here, then I realised you had a PR which addressed most of my ramblings so edited out most of said ramblings! 😆
I had the same intuition and this is very easily fixed by treating these selectors as Svg specific. i.e. I think this is analogous to the Html packages and how people import and use them and outweighs the convenience of having them all live in However, it would likely be just the
I 100% encourage exploration of this idea.
If we reflected Elm's special treatment of svg classes, might that make testing clearer? |
I'm not opposed to API changes in general, but I would want people who worked on the dom portion of the package to be pulled in before anything major changes. I also think that the key problem here doesn't necessarily require API changes to fix. My thinking is the key problem is that there are 2 ways to set the I think a solution that doesn't fix these tests:
isn't solving the problem of the Query module losing track of HTML classes. (It's not clear to me whether I agree that SVGs are related to the problem (in that you can only set classes on them in the way that elm-test can't yet test for unless you want errors in the browser), but again I think the core problem is the attribute/property distinction. I'll add these tests explicitly to my PR. |
It's a good point, I was viewing Furthermore, if we leave out Ultimately, I would rather leave the current working implementations of Html selectors alone and instead mimic those behaviours for NS elements specifically. I think this provides the least chance peoples tests will break due to something we don't know, and directly addresses issue #134 and nothing more.
The API isn't really changing, it's more so being added to, and adding these changes shouldn't cause a major change, it's a minor change because no publicly exposed function is changing? |
@rtfeldman Any chance we could get some direction here? Would be incredibly sad for this to go stale. |
Sorry, had a lot of other stuff on my plate recently - I'll circle back to this over the weekend! |
🤔 What if we changed it to pass if either the attribute or the property is present and an exact match? I can think of a downside to having them separate: getting confused when your query says it found no matches even though the property (or attribute) is clearly set, the problem is just that you were querying for the other one...but I'm having trouble thinking of what bugs would be caught by having them separate. All the scenarios I can come up with seem very unrealistic - e.g. someone sets both Maybe there's a scenario I'm not thinking of, though! |
Hey @Confidenceman02 @rtfeldman! Thank you for your work with this PR. Is there a reason why it was not merged? |
@dinopascale-prima The package has changed maintainers a few times over the past few years. I'll try and take a look at merging this sometime soon, thanks for the ping! |
fixes #134
Context
Svg and Html elements vary in the way css classes are applied. Elm sets svg classes by using the attribute "class" and other html elements by using the property "className". This follows the html/javascript specs and is a generally known quirk.
Let's see how Elm handles both the
Svg.Html.class
andHtml.class
functions.Svg.Html.class
Html.class
Because of these differences, using class selectors in tests, specifically for svg elements, causes tests to fail. This is due to the class selectors triggering internal helpers that are looking for elements with the value "className".
Because "className" is not a valid property on svg elements we get the failing tests.
Work completed
NS specific selectors now map to internal helpers that know how to extract class information from svg elements.