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

add options to click, doubleClick, tap #398

Merged
merged 2 commits into from
Sep 27, 2018

Conversation

BryanCrotaz
Copy link

Add options to public api which are passed down to the relevant MouseEvent and TouchEvent

@BryanCrotaz
Copy link
Author

@rwjblue build failed with a curl error - can't see how to rerun tests - are you able to?

@rwjblue
Copy link
Member

rwjblue commented Jul 15, 2018

Restarted


if (isFocusable(element)) {
__focus__(element);
}

fireEvent(element, 'mouseup');
fireEvent(element, 'click');
fireEvent(element, 'mouseup', options);
Copy link
Member

Choose a reason for hiding this comment

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

It seems really odd to me to have the same options for mousedown, mouseup, and click 🤔

Copy link
Author

Choose a reason for hiding this comment

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

The common options are going to be button, x, y. Which options would you want to be different for each event?

fireEvent(element, 'mousedown', options);
fireEvent(element, 'mouseup', options);
fireEvent(element, 'click', options);
fireEvent(element, 'dblclick', options);
Copy link
Member

Choose a reason for hiding this comment

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

Same concern here. If we are going to allow event options I think we need a system that allows us to customize each of the events individually...

@mmun and I had discussed this somewhat recently, but I can’t recall if we came to a good conclusion 🤔

Copy link
Author

Choose a reason for hiding this comment

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

We’re simulating a click. We don’t need to do anything that the browser doesn’t do. Does the browser provide different data for each of these calls?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe allow options to either be a POJO or a function, and if a function, gets invoked with the name of the event and its return value is the options POJO?

@sdhull
Copy link

sdhull commented Aug 9, 2018

👋 Hi! Absolutely love that you're working on this @BryanCrotaz, thank you!

I'm not sure what @rwjblue has in mind in terms of customizing "each of the events individually." What has been done in this PR makes perfect sense to me -- that is to say, you pass options through to fireEvent, which then constructs the event with some default options & merges the passed options in. That's what these helpers should do IMO.

And specifically for mousedown, mouseup and click, these events all appear to have the same properties according to MDN.

Perhaps @rwjblue is concerned with developers passing an option like charCode to a click event? Or clientX to a keyboard event? Personally I wouldn't worry about that in this PR.

Maybe in a followup PR we could add some checks to warn developers they're trying to use options that don't make sense, but for simply enabling a developer to specify specific coordinates in a click (or double-click or tap), I would urge maintainers to merge this to enable ambitious testing of our ambitious apps 😎


tl;dr -- 🙏 please merge this and ship a patch release so I can get off of @BryanCrotaz's branch 😬

@mmun
Copy link
Member

mmun commented Aug 9, 2018

@rwjblue This PR seems ok to me as is. My main concern would be passing the event options to unrelated kinds of events (e.g. passing mouse options to the focus event).

You could argue that the mousedown and mouseup events could have different options (if you move your mouse during the press), however even then I think it just makes more sense to manually trigger each event individually in your test.

tl;dr I think it's good as is.

BTW, thanks for putting this issue back on our radar @sdhull.

@BryanCrotaz
Copy link
Author

I agree. The method is to simulate a click. If you want to simulate down-drag-up you wouldn’t use it - you’d definitely simulate individual events.

@cibernox
Copy link
Contributor

cibernox commented Sep 25, 2018

I think it makes sense to pass the same options for both mousedown/mouseup and click. For instance, if the user is pressing shift, that key will be pressed for all three events.

It is true that there may be some situation where someone could desite to simulate each event of a click with different options (a mousedown in one x/y coordinate and a mouseup in different coordinates), but in those situation are uncommon and seems reasonable to ask the developer to resort to a lower-level approach, firing each even independently.

await triggerEvent('mousedown', { screenX: 1, screenY: 1 } );
await triggerEvent('mouseup', { screenX: 1, screenY: 5 } );

The current proposal sounds good. Is there anything else to do here?

@rwjblue rwjblue merged commit ec3983e into emberjs:master Sep 27, 2018
@rwjblue
Copy link
Member

rwjblue commented Sep 27, 2018

Thank you!

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

Successfully merging this pull request may close these issues.

6 participants