-
Notifications
You must be signed in to change notification settings - Fork 2
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
test(map-and-label): Basic test setup #3604
Conversation
if (!window.customElements.get("my-map")) { | ||
window.customElements.define("my-map", MyMap); | ||
} |
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.
As opposed to calling this in multiple place (React app, Storybook, test suites), I think it's probably a better idea to make a basic React wrapper for the map webcomponent (<my-map/>
) which includes this in a useEffect()
or similar.
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.
@jessicamcinchak @jamdelion Is this part of the test defining the <my-map>
component as "my-map" within the ShadowDOM to make it retrievable?
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.
As I understand it - this checks if our custom element is already available/found in the window, and adds it if not ! As a custom web component, it naturally has a shadow DOM representation - we don't need to specifically add it to the shadow DOM, just access it from there inherently
8c42784
to
f9a078c
Compare
Removed vultr server and associated DNS entries |
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.
Looks good to me, I was thinking of merging this and running through the .todos()
in a separate branch. Would this make sense @jamdelion @jessicamcinchak ?
if (!window.customElements.get("my-map")) { | ||
window.customElements.define("my-map", MyMap); | ||
} |
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.
@jessicamcinchak @jamdelion Is this part of the test defining the <my-map>
component as "my-map" within the ShadowDOM to make it retrievable?
Agree merging this & picking up |
What does this PR do?
map.dispatchEvent()
test.todo()
s left to pick up...!Context
It took a lot of trial and error to get here - actually simulating a user interaction with the map webcomponent is pretty tricky. Here's some of the methods tried....
The following can't access the the Shadow DOM and are either scoped to the current container or screen -
user.click()
userEvent.click()
fireEvent.click()
The following post proved helpful in demonstrating how to use shadow-dom-testing-library to interact with webcomponents - https://design.sis.gov.uk/get-started/test-components/testing-with-react-testing-library 🕵️♂️
👍 Good news - the combination of shadow-dom-testing-library and the addition of a
data-testid
does allow access to the map webcomponent.👎 Bad news - even with access, the map wasn't correctly instantiated (no layers added to map, no errors I could hit). I think this may be worth digging into a little deeper as a potential solution in future.
I've settled on dispatching an event which matches the one generated by
@opensystemslab/map
on click. This doesn't feel like a bad solution, it's actually pretty close to a user interaction from the perspective of the codebase - we're just listening and reacting to this event.Next steps...
test.todos()
that should be picked up - they cover some of the functionality already merged and it would be great to catch up here. This might be a good candidate for @RODO94 to pick up!addFeaturesToMap()
to incorporate the types introduced there -One small gotcha is that to watch out for is that all features are passed to the map component on change - this means as we test we'll need to call -
It's probably making a simple class to handle this and make it both a little safer and nice to work with. I think I'd try to spend a bit more time pursuing the
shadow-dom-testing-library
approach first before investing too much effort in this a and adding complexity here though. Something like...