-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
support testing-library/user-event
#10
Comments
@smeijer what do you mean with
? What would you like to enable users to do? |
I was thinking that a user should be able to write mixed HTML in the markup editor. Something like: <label for="checkbox">Check</label>
<input id="checkbox" type="checkbox" />
<button onClick="javascript:document.querySelector('#checkbox').setAttribute('checked', true)">
Accept
</button> And that would result in a working demo in the HTML preview pane. Then just like we can currently use userEvent.click(screen.getByText(/accept/i)) I think we should then also add a 'refresh' button to the preview pane, to undo the changes that have been done by the query. I'm also not sure how useful this is without having userEvent.click(screen.getByText(/accept/i))
expect(screen.getByLabelText(/check/i)).toHaveAttribute('checked', true) |
Hey! |
Hi @smeijer! |
Hi @delca85! What do you have so far? Do you have the mixed html working in code mirror? Does that result in an interactive html preview? For example, can the user create a button, wich displays an alert on click? I think this is step 1. Once that's done, (which could be merged individually), we can figure out how to use events. I think that applying the events isn't the complicated part. The thing we need to figure out is, how to maintain state or restore the html view. One idea that I have, is to disable real time updates, when we detect a user-event call. And instead show an execute button (which can also be submitted by ctrl enter). Or just refresh the html preview on every query change. And show a toggle button in the html preview. But I don't know how performant that is. I think this would be the preferred variant. Does this answer your question? |
I have added the html mixed mode with CodeMirror and set it as mode in <label for="checkbox">Check</label>
<input
id="checkbox"
type="checkbox"
/>
<button
onClick="javascript:alert('clicked')"
>
Accept
</button> is already working in current playground version. I am sure I am missing something! I agree with your idea about showing an execute button (and make an execution by ctrl+enter), I am not sure about this but I suppose that as a user I would expect to have a button to make effective the event firing. |
I don't even know what it is 😅, do we need it? What does it do?
My bad, that example works. This one doesn't. Should itwork? Can it work? <label for="checkbox">Check</label>
<input
id="checkbox"
type="checkbox"
/>
<button id="btn">
Accept
</button>
<script>
const btn = document.getElementById('btn');
btn.addEventListener('click', () => { alert('click'); });
</script> |
:D |
The code indentation and styling is working but I need to investigate a little more to make it working in Preview panel. |
We're setting the html with Most easy solution that comes to mind, is to extract script elements from the HTML with a regex. Inject the HTML without those script elements. And |
I am reaching exactly the same idea. |
I tried an initial implementation with eval and it's working! I am going to clean it a bit. When it will be ready I could push this initial code and start workin on |
That sounds great 👍 Thanks. |
…ace eval with new Function (testing-library#10)
It sounds awesomely useful to apply events! |
Yeah, I think we can do something with it. We should figure out how exactly, to make it usefull for more than the development of |
According to you, one possible way could be dispatching an event for each |
Sorry, I'm not sure if I understand your question. Can you elaborate? |
Sorry, you are totally right. The issue I was speaking about is applied the events to the markup inserted by the user.
I don't know if this is a reasonable flow, but I hope I explained myself at least. |
Hi @smeijer! If it sounds good to you, I am going to keep on with this issue. |
Sure! The migration will (mostly) be backwards compatible. So I don't see why we should wait on user-event being merged. I expect that once they're merged, we can quite easily migrate/upgrade the references. |
I expect the same! Some days ago you told me that according to you applying the event to the markup shouldn't be so hard. Could you maybe share some of your thoughts with me (when you have some free time, obviously!)? The idea I have about it is the one I exposed here but I would be very happy to know what you think about it. |
I think that as soon as you add the user-event methods to the sandbox context, it will already work. When you would than copy/paste a query that includes an user event, you would see the updated preview. That means, we only need to add a "toggle" to the Preview, to toggle between initial markup, and resulting state. This should work out of the box, if the preview just reruns the entire query on the But I might be wrong. |
Hi! Right now I am able to execute on this markup: <label for="checkbox">Check</label>
<input id="checkbox" type="checkbox" />
<button onClick="javascript:document.querySelector('#checkbox').setAttribute('checked', true)">
Accept
</button> this query userEvent.click(screen.getByText(/accept/i)) but I am not managing yet the execution of scripts defined in this html code: <label for="checkbox">Check</label>
<input
id="checkbox"
type="checkbox"
/>
<button id="btn">
Accept
</button>
<script>
const btn = document.getElementById('btn');
btn.addEventListener('click', () => { alert('click'); });
</script> I suppose I have to work a bit on the scripts evaluation, because I think the problem is related to the moment when the scripts evaluation is performed. |
I think the trick is in the execution order of the scripts. First evaluate all scripts that have been extracted from the markup. And only after that, apply the queries. |
Hey @smeijer ! About it I maybe found a small bug: at this line If it sounds good to you I am going to proceed adding the toggle to swap between the original state and the one obtained through the |
Now it is working like in this video. EDIT: I have managed the message shown when a method from |
I'm not sure if that's a bug. Why do you think it is? Regarding the rest of the comments. I have no idea. Maybe it's easier to commit what you have, and open a pull-request in Draft state? That way we can talk while looking at code. Without the code, it's really hard to get a picture of what you're trying to explain. I, for example, do not understand why it would be hard to do the same in Let's create a pull-request and talk there further? |
Yes, sorry for the loss of time.
The problem in unsafe mode isn't the execution of the I hope this with the code pushed by PR could be more helpful. |
Ok. That sounds like an acceptable loss for me, as long as we document it in the code. The |
Sorry but I am not sure to understand, the loss you are talking about is the missing evaluation of "use scripts"?
If I got your words properly this is not needed in |
I am thinking this because an evaluator.exec method doesn't seem to exist to me, while an |
Hi! According to me the reason is that those methods does not seem to make any transformation on the attribute The interaction requested by @smeijer here are now performed and even the state toggling (before and after the method execution) but right now I am struggling a lot with this issue. |
I haven't worked out the details, but enabling users to play with user-events would awesome. Perhaps together with adding support for HTML mixed mode?
inspiration: https://twitter.com/kentcdodds/status/1270919381380284416?s=20
The text was updated successfully, but these errors were encountered: