ember-native-dom-helpers
ember-native-dom-helpers copied to clipboard
Clicking certain coordinates within an element
I'd like to be able to do something like click('.my-map', { xOffset: 5, yOffset: 5 }), since there isn't usually anything to select on to click on a map if you are doing testing that requires drawing on the map, and not clicking existing objects.
So it's possible to pass client* or screen*, but not possible to do a relative offset, which is far more useful, especially when the browser can change sizes during tests.
@knownasilya it should be possible to build a wrapper around find() and click() that does what you're looking for. essentially something like:
async clickXY(selector, x, y) {
let element = find(selector);
let elementX = element.foobarX;
let elementY = element.foobarY;
let globalX = elementX + x;
let globalY = elementY + y;
await click(element, { x: globalX, y: globalY });
}
I also lean to think that click should remain "bare metal" and just forward options to the event, since it's pretty easy to create an utility like @Turbo87 did. With async/await and this helpers you can don't need to worry about asynchrony and that helper will work both in acceptance and integration