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

Draggable doesn't recognize MouseEvent and dont work with Playwright #737

Open
AndreyMiloserdov opened this issue Oct 25, 2023 · 0 comments

Comments

@AndreyMiloserdov
Copy link

For E2E we have to simulate DnD, and code

const triggerMouseEvent = (node: HTMLElement, eventType: string, data: { clientX: number; clientY: number }) => {
       const evt = new MouseEvent(eventType, data);
       node.dispatchEvent(evt);
};

triggerMouseEvent('mousedown', {clientX: 0, clientY: 0 });
triggerMouseEvent('mousemove', {clientX: 50, clientY: 0 });
triggerMouseEvent('mouseup', {clientX: 50, clientY: 0 });

Don't work, but

const triggerMouseEvent = (node: HTMLElement, eventType: string, data: { clientX: number; clientY: number }) => {
    const evt = document.createEvent('MouseEvents');

    evt.initMouseEvent(
        eventType,
        true,
        true,
        window,
        0,
        data.clientX,
        data.clientY,
        data.clientX,
        data.clientY,
        false,
        false,
        false,
        false,
        0,
        null,
    );

    node.dispatchEvent(evt);
};

triggerMouseEvent('mousedown', {clientX: 0, clientY: 0 });
triggerMouseEvent('mousemove', {clientX: 50, clientY: 0 });
triggerMouseEvent('mouseup', {clientX: 50, clientY: 0 });

Seem to be works fine!
PS: I can't use TestUtils, because code above injected to the document via Playwright, and it should be 'clearable', without dependency links.

But! initMouseEvent is deprecated... and wanna have more actual solution

PS: The better if would work default playwright D'n'D code like

await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + deltaX, y + deltaY);
await page.mouse.up();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant