diff --git a/packages/button/test/button.common.ts b/packages/button/test/button.common.ts
index 59cfc3b0f37..c003268dcfd 100644
--- a/packages/button/test/button.common.ts
+++ b/packages/button/test/button.common.ts
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
-import { fire, fixtureSync, middleOfNode, nextRender, nextUpdate } from '@vaadin/testing-helpers';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
+import { fire, fixtureSync, nextRender, nextUpdate } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import type { Button } from '../vaadin-button.js';
@@ -142,8 +142,7 @@ describe('vaadin-button', () => {
});
it('should prevent pointer focus when disabled', async () => {
- const { x, y } = middleOfNode(button);
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'click', element: button });
expect(document.activeElement).to.equal(document.body);
});
@@ -194,8 +193,7 @@ describe('vaadin-button', () => {
});
it('should allow pointer focus when disabled', async () => {
- const { x, y } = middleOfNode(button);
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'click', element: button });
expect(document.activeElement).to.equal(button);
});
diff --git a/packages/button/test/visual/lumo/button.test.js b/packages/button/test/visual/lumo/button.test.js
index 3dfb54f8e3f..ebb1a3850a3 100644
--- a/packages/button/test/visual/lumo/button.test.js
+++ b/packages/button/test/visual/lumo/button.test.js
@@ -1,4 +1,4 @@
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fixtureSync, mousedown } from '@vaadin/testing-helpers';
import { visualDiff } from '@web/test-runner-visual-regression';
import '@vaadin/icon/theme/lumo/vaadin-icon.js';
@@ -67,7 +67,7 @@ describe('button', () => {
it('primary hover', async () => {
element.setAttribute('theme', 'primary');
- await sendMouse({ type: 'move', element });
+ await sendMouseToElement(element);
await visualDiff(div, 'theme-primary-hover');
});
@@ -90,7 +90,7 @@ describe('button', () => {
it('secondary hover', async () => {
element.setAttribute('theme', 'secondary');
- await sendMouse({ type: 'move', element });
+ await sendMouseToElement(element);
await visualDiff(div, 'theme-secondary-hover');
});
@@ -107,7 +107,7 @@ describe('button', () => {
it('tertiary hover', async () => {
element.setAttribute('theme', 'tertiary');
- await sendMouse({ type: 'move', element });
+ await sendMouseToElement(element);
await visualDiff(div, 'theme-tertiary-hover');
});
diff --git a/packages/button/test/visual/material/button.test.js b/packages/button/test/visual/material/button.test.js
index 1a36edb179c..32eeac41cbd 100644
--- a/packages/button/test/visual/material/button.test.js
+++ b/packages/button/test/visual/material/button.test.js
@@ -1,4 +1,4 @@
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
import { visualDiff } from '@web/test-runner-visual-regression';
import '@vaadin/icon/theme/material/vaadin-icon.js';
@@ -65,7 +65,7 @@ describe('button', () => {
element.setAttribute('theme', `${variant}`);
await new Promise((resolve) => {
element.addEventListener('transitionend', resolve, { once: true });
- sendMouse({ type: 'move', element });
+ sendMouseToElement(element);
});
await visualDiff(div, `theme-${variant}-hover`);
});
diff --git a/packages/checkbox/test/checkbox.common.js b/packages/checkbox/test/checkbox.common.js
index 2f8a86de07d..7e3b2a6bfa6 100644
--- a/packages/checkbox/test/checkbox.common.js
+++ b/packages/checkbox/test/checkbox.common.js
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fixtureSync, mousedown, mouseup, nextFrame, nextRender, nextUpdate } from '@vaadin/testing-helpers';
import sinon from 'sinon';
@@ -156,20 +156,12 @@ describe('checkbox', () => {
});
describe('focus', () => {
- let inputX, inputY;
-
- beforeEach(() => {
- const rect = input.getBoundingClientRect();
- inputX = Math.floor(rect.x + rect.width / 2);
- inputY = Math.floor(rect.y + rect.height / 2);
- });
-
afterEach(async () => {
await resetMouse();
});
it('should focus on input click when not focused yet', async () => {
- await sendMouse({ type: 'click', position: [inputX, inputY] });
+ await sendMouseToElement({ type: 'click', element: input });
expect(checkbox.hasAttribute('focused')).to.be.true;
});
@@ -177,7 +169,7 @@ describe('checkbox', () => {
const spy = sinon.spy();
checkbox.addEventListener('focusout', spy);
input.focus();
- await sendMouse({ type: 'click', position: [inputX, inputY] });
+ await sendMouseToElement({ type: 'click', element: input });
expect(spy).to.be.not.called;
});
});
diff --git a/packages/dashboard/test/dashboard-widget-reordering.test.ts b/packages/dashboard/test/dashboard-widget-reordering.test.ts
index 5a39e85581d..61da72e9de2 100644
--- a/packages/dashboard/test/dashboard-widget-reordering.test.ts
+++ b/packages/dashboard/test/dashboard-widget-reordering.test.ts
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fixtureSync, isFirefox, nextFrame, nextResize } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../vaadin-dashboard.js';
@@ -143,7 +143,7 @@ describe('dashboard - widget reordering', () => {
dashboard.addEventListener('dashboard-item-selected-changed', spy);
await resetMouse();
// Hover over the widget drag handle
- await sendMouse({ type: 'move', element: getDraggable(getElementFromCell(dashboard, 0, 0)!) });
+ await sendMouseToElement(getDraggable(getElementFromCell(dashboard, 0, 0)!));
// Press down the left mouse button
await sendMouse({
type: 'down',
diff --git a/packages/date-time-picker/test/basic.common.js b/packages/date-time-picker/test/basic.common.js
index 9f1a8ff75b2..9121bbea83c 100644
--- a/packages/date-time-picker/test/basic.common.js
+++ b/packages/date-time-picker/test/basic.common.js
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import { aTimeout, fixtureSync, focusin, focusout, nextRender, outsideClick } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import { changeInputValue } from './helpers.js';
@@ -40,13 +40,6 @@ describe('Basic features', () => {
let datePicker;
let timePicker;
- async function click(element) {
- const rect = element.inputElement.getBoundingClientRect();
- const x = Math.floor(rect.x + rect.width / 2);
- const y = Math.floor(rect.y + rect.height / 2);
- await sendMouse({ type: 'click', position: [x, y] });
- }
-
beforeEach(async () => {
dateTimePicker = fixtureSync('');
await nextRender();
@@ -200,11 +193,11 @@ describe('Basic features', () => {
describe('date-picker focused', () => {
it('should remove focused attribute on time-picker click', async () => {
- await click(datePicker);
+ await sendMouseToElement({ type: 'click', element: datePicker.inputElement });
await nextRender();
expect(datePicker.hasAttribute('focused')).to.be.true;
- await click(timePicker);
+ await sendMouseToElement({ type: 'click', element: timePicker.inputElement });
expect(datePicker.hasAttribute('focused')).to.be.false;
});
@@ -216,7 +209,7 @@ describe('Basic features', () => {
await nextRender();
expect(datePicker.hasAttribute('focus-ring')).to.be.true;
- await click(timePicker);
+ await sendMouseToElement({ type: 'click', element: timePicker.inputElement });
expect(datePicker.hasAttribute('focus-ring')).to.be.false;
});
});
@@ -229,13 +222,13 @@ describe('Basic features', () => {
});
it('should remove focused attribute on date-picker click', async () => {
- await click(timePicker);
+ await sendMouseToElement({ type: 'click', element: timePicker.inputElement });
// Open the overlay with the keyboard
await sendKeys({ press: 'ArrowDown' });
await nextRender();
expect(timePicker.hasAttribute('focused')).to.be.true;
- await click(datePicker);
+ await sendMouseToElement({ type: 'click', element: datePicker.inputElement });
expect(timePicker.hasAttribute('focused')).to.be.false;
});
@@ -248,7 +241,7 @@ describe('Basic features', () => {
await nextRender();
expect(timePicker.hasAttribute('focus-ring')).to.be.true;
- await click(datePicker);
+ await sendMouseToElement({ type: 'click', element: datePicker.inputElement });
expect(timePicker.hasAttribute('focus-ring')).to.be.false;
});
});
diff --git a/packages/grid/test/drag-and-drop.common.js b/packages/grid/test/drag-and-drop.common.js
index 333205d83b2..7046b8cf634 100644
--- a/packages/grid/test/drag-and-drop.common.js
+++ b/packages/grid/test/drag-and-drop.common.js
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
import { aTimeout, fixtureSync, listenOnce, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import { flushGrid, getBodyCellContent, getFirstCell, getRowBodyCells, getRows } from './helpers.js';
@@ -1127,7 +1127,7 @@ describe('drag and drop', () => {
async function dragElement(element) {
await resetMouse();
- await sendMouse({ type: 'move', element });
+ await sendMouseToElement(element);
await sendMouse({ type: 'down' });
await sendMouse({ type: 'move', position: [100, 100] });
await sendMouse({ type: 'up' });
diff --git a/packages/menu-bar/test/accessible-disabled-buttons.common.js b/packages/menu-bar/test/accessible-disabled-buttons.common.js
index dcee2d6c89d..a5de294e7e3 100644
--- a/packages/menu-bar/test/accessible-disabled-buttons.common.js
+++ b/packages/menu-bar/test/accessible-disabled-buttons.common.js
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
-import { fixtureSync, middleOfNode, nextRender } from '@vaadin/testing-helpers';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
+import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
describe('accessible disabled buttons', () => {
let menuBar, buttons;
@@ -30,15 +30,13 @@ describe('accessible disabled buttons', () => {
});
it('should not open sub-menu on disabled button click', async () => {
- const { x, y } = middleOfNode(buttons[1]);
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'click', element: buttons[1] });
expect(buttons[1].hasAttribute('expanded')).to.be.false;
});
it('should not open sub-menu on disabled button hover', async () => {
menuBar.openOnHover = true;
- const { x, y } = middleOfNode(buttons[1]);
- await sendMouse({ type: 'move', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'move', element: buttons[1] });
expect(buttons[1].hasAttribute('expanded')).to.be.false;
});
diff --git a/packages/overlay/test/interactions.common.js b/packages/overlay/test/interactions.common.js
index 00a23ac6d19..49453bf6941 100644
--- a/packages/overlay/test/interactions.common.js
+++ b/packages/overlay/test/interactions.common.js
@@ -1,11 +1,10 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
import {
click,
enterKeyDown,
escKeyDown,
fixtureSync,
- middleOfNode,
mousedown,
mouseup,
nextRender,
@@ -303,10 +302,7 @@ describe('interactions', () => {
});
it('should focus overlay part on clicking the content element', async () => {
- const div = overlay.querySelector('div');
- const { x, y } = middleOfNode(div);
-
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'click', element: overlay.querySelector('div') });
await nextRender();
expect(document.activeElement).to.be.equal(overlay);
@@ -315,10 +311,7 @@ describe('interactions', () => {
it('should not focus overlay part if tabindex attribute removed', async () => {
overlay.$.overlay.removeAttribute('tabindex');
- const div = overlay.querySelector('div');
- const { x, y } = middleOfNode(div);
-
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'click', element: overlay.querySelector('div') });
await nextRender();
expect(document.activeElement).to.be.equal(document.body);
diff --git a/packages/popover/test/trigger.test.js b/packages/popover/test/trigger.test.js
index 141afcaf03b..601e80b302b 100644
--- a/packages/popover/test/trigger.test.js
+++ b/packages/popover/test/trigger.test.js
@@ -1,11 +1,10 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import {
esc,
fixtureSync,
focusin,
focusout,
- middleOfNode,
mousedown,
nextRender,
nextUpdate,
@@ -274,8 +273,7 @@ describe('trigger', () => {
});
it('should not close on overlay mousedown when target has focus', async () => {
- const { x, y } = middleOfNode(overlay.querySelector('div'));
- await sendMouse({ type: 'click', position: [Math.round(x), Math.round(y)] });
+ await sendMouseToElement({ type: 'click', element: overlay.querySelector('div') });
await nextUpdate();
expect(overlay.opened).to.be.true;
@@ -284,8 +282,7 @@ describe('trigger', () => {
it('should not close on overlay mousedown when overlay has focus', async () => {
overlay.querySelector('input').focus();
- const { x, y } = middleOfNode(overlay.querySelector('div'));
- await sendMouse({ type: 'click', position: [Math.round(x), Math.round(y)] });
+ await sendMouseToElement({ type: 'click', element: overlay.querySelector('div') });
await nextUpdate();
expect(overlay.opened).to.be.true;
@@ -295,8 +292,7 @@ describe('trigger', () => {
// Remove the input so that first Tab would leave popover
overlay.querySelector('input').remove();
- const { x, y } = middleOfNode(overlay.querySelector('div'));
- await sendMouse({ type: 'click', position: [Math.round(x), Math.round(y)] });
+ await sendMouseToElement({ type: 'click', element: overlay.querySelector('div') });
await nextUpdate();
// Tab to focus input next to the target
@@ -309,8 +305,7 @@ describe('trigger', () => {
it('should only cancel one overlay focusout after the overlay mousedown', async () => {
overlay.querySelector('input').focus();
- const { x, y } = middleOfNode(overlay.querySelector('div'));
- await sendMouse({ type: 'click', position: [Math.round(x), Math.round(y)] });
+ await sendMouseToElement({ type: 'click', element: overlay.querySelector('div') });
await nextUpdate();
// Tab to focus input inside the popover
diff --git a/packages/radio-group/test/radio-button.common.js b/packages/radio-group/test/radio-button.common.js
index b7c4a6fde5d..700c463225d 100644
--- a/packages/radio-group/test/radio-button.common.js
+++ b/packages/radio-group/test/radio-button.common.js
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fire, fixtureSync, mousedown, mouseup, nextRender, nextUpdate } from '@vaadin/testing-helpers';
import sinon from 'sinon';
@@ -102,10 +102,7 @@ describe('radio-button', () => {
});
it('should focus on input click if not focused', async () => {
- const rect = input.getBoundingClientRect();
- const middleX = Math.floor(rect.x + rect.width / 2);
- const middleY = Math.floor(rect.y + rect.height / 2);
- await sendMouse({ type: 'click', position: [middleX, middleY] });
+ await sendMouseToElement({ type: 'click', element: input });
expect(radio.hasAttribute('focused')).to.be.true;
});
});
@@ -251,15 +248,10 @@ describe('radio-button', () => {
});
describe('focus', () => {
- let inputX, inputY;
-
beforeEach(async () => {
radio = fixtureSync('');
await nextRender();
input = radio.querySelector('[slot=input]');
- const rect = input.getBoundingClientRect();
- inputX = Math.floor(rect.x + rect.width / 2);
- inputY = Math.floor(rect.y + rect.height / 2);
});
afterEach(async () => {
@@ -267,7 +259,7 @@ describe('radio-button', () => {
});
it('should focus on input click when not focused yet', async () => {
- await sendMouse({ type: 'click', position: [inputX, inputY] });
+ await sendMouseToElement({ type: 'click', element: input });
expect(radio.hasAttribute('focused')).to.be.true;
});
@@ -275,7 +267,7 @@ describe('radio-button', () => {
const spy = sinon.spy();
radio.addEventListener('focusout', spy);
input.focus();
- await sendMouse({ type: 'click', position: [inputX, inputY] });
+ await sendMouseToElement({ type: 'click', element: input });
expect(spy).to.be.not.called;
});
});
diff --git a/packages/virtual-list/test/drag-and-drop.common.js b/packages/virtual-list/test/drag-and-drop.common.js
index 190b189df10..8ad4c9d28b5 100644
--- a/packages/virtual-list/test/drag-and-drop.common.js
+++ b/packages/virtual-list/test/drag-and-drop.common.js
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
describe('drag and drop', () => {
@@ -29,7 +29,7 @@ describe('drag and drop', () => {
async function dragElement(element) {
await resetMouse();
- await sendMouse({ type: 'move', element });
+ await sendMouseToElement(element);
await sendMouse({ type: 'down' });
await sendMouse({ type: 'move', position: [100, 100] });
await sendMouse({ type: 'up' });
diff --git a/test/integration/component-tooltip.test.js b/test/integration/component-tooltip.test.js
index 3ef4df5222b..867a6d0d20c 100644
--- a/test/integration/component-tooltip.test.js
+++ b/test/integration/component-tooltip.test.js
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
-import { fixtureSync, middleOfNode, nextRender, tabKeyDown } from '@vaadin/testing-helpers';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
+import { fixtureSync, nextRender, tabKeyDown } from '@vaadin/testing-helpers';
import './not-animated-styles.js';
import { Button } from '@vaadin/button';
import { Checkbox } from '@vaadin/checkbox';
@@ -233,11 +233,10 @@ describe('accessible disabled button', () => {
});
it('should toggle tooltip on hover when button is disabled', async () => {
- const { x, y } = middleOfNode(button);
- await sendMouse({ type: 'move', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'move', element: button });
expect(tooltip._overlayElement.opened).to.be.true;
- await sendMouse({ type: 'move', position: [0, 0] });
+ await resetMouse();
expect(tooltip._overlayElement.opened).to.be.false;
});
diff --git a/test/integration/grid-pro-custom-editor.test.js b/test/integration/grid-pro-custom-editor.test.js
index 1df0f528eae..93db2f6b036 100644
--- a/test/integration/grid-pro-custom-editor.test.js
+++ b/test/integration/grid-pro-custom-editor.test.js
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
-import { fixtureSync, middleOfNode, nextRender } from '@vaadin/testing-helpers';
+import { resetMouse, sendKeys, sendMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
+import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
import '@vaadin/combo-box';
import '@vaadin/custom-field';
import '@vaadin/date-picker';
@@ -123,8 +123,8 @@ describe('grid-pro custom editor', () => {
// Open the overlay
await sendKeys({ press: 'ArrowDown' });
- const { x, y } = middleOfNode(cell._content.querySelector('input'));
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ const input = cell._content.querySelector('input');
+ await sendMouseToElement({ type: 'click', element: input });
expect(cell._content.querySelector('vaadin-date-picker')).to.be.ok;
});
@@ -136,8 +136,8 @@ describe('grid-pro custom editor', () => {
// Click between toolbar buttons
const overlayContent = document.querySelector('vaadin-date-picker-overlay-content');
- const { x, y } = middleOfNode(overlayContent.shadowRoot.querySelector('[part="toolbar"]'));
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ const toolbar = overlayContent.shadowRoot.querySelector('[part="toolbar"]');
+ await sendMouseToElement({ type: 'click', element: toolbar });
await nextRender();
expect(cell._content.querySelector('vaadin-date-picker')).to.be.ok;
@@ -305,8 +305,8 @@ describe('grid-pro custom editor', () => {
it('should not stop editing when switching between fields using mouse', async () => {
// Move focus to the second field
- const { x, y } = middleOfNode(cell._content.querySelectorAll('input')[1]);
- await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
+ const input = cell._content.querySelectorAll('input')[1];
+ await sendMouseToElement({ type: 'click', element: input });
await nextRender();
expect(cell._content.querySelector('vaadin-custom-field')).to.be.ok;
});
diff --git a/test/integration/menu-bar-tooltip.test.js b/test/integration/menu-bar-tooltip.test.js
index 31b8b5896f9..314e0865ea8 100644
--- a/test/integration/menu-bar-tooltip.test.js
+++ b/test/integration/menu-bar-tooltip.test.js
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
-import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
+import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import {
arrowDown,
arrowRight,
@@ -8,7 +8,6 @@ import {
fixtureSync,
focusin,
focusout,
- middleOfNode,
mousedown,
nextRender,
tabKeyDown,
@@ -392,11 +391,10 @@ describe('menu-bar with tooltip', () => {
});
it('should toggle tooltip on disabled button hover', async () => {
- const { x, y } = middleOfNode(buttons[1]);
- await sendMouse({ type: 'move', position: [Math.floor(x), Math.floor(y)] });
+ await sendMouseToElement({ type: 'move', element: buttons[1] });
expect(getTooltipText()).to.equal('Copy tooltip');
- await sendMouse({ type: 'move', position: [0, 0] });
+ await resetMouse();
expect(getTooltipText()).to.be.null;
});
diff --git a/test/test-runner-commands/index.js b/test/test-runner-commands/index.js
index 00d1e2d3cfd..7a2c888fc70 100644
--- a/test/test-runner-commands/index.js
+++ b/test/test-runner-commands/index.js
@@ -3,21 +3,27 @@ import { executeServerCommand } from '@web/test-runner-commands';
export * from '@web/test-runner-commands';
/**
- * Extends the `sendMouse` command to support moving the mouse
- * to the center of an element.
+ * Moves the mouse to the center of an element and
*
* Remember to call `resetMouse()` after the test to reset
* the mouse position to avoid affecting other tests.
*
* @param {Element} element
*/
-export async function sendMouse({ element, position, ...options }) {
- if (element) {
- const rect = element.getBoundingClientRect();
- const x = Math.floor(rect.x + rect.width / 2);
- const y = Math.floor(rect.y + rect.height / 2);
- position = [x, y];
+export async function sendMouseToElement(options) {
+ let element;
+
+ if (options instanceof Element) {
+ element = options;
+ options = {};
+ } else {
+ element = options.element;
}
- await executeServerCommand('send-mouse', { ...options, position });
+ const rect = element.getBoundingClientRect();
+ const x = Math.floor(rect.x + rect.width / 2);
+ const y = Math.floor(rect.y + rect.height / 2);
+ const position = [x, y];
+
+ await executeServerCommand('send-mouse', { type: 'move', position, ...options });
}