From fb01f43017b2b464c10bd424ff003450f4e6c312 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Mon, 10 Feb 2025 12:57:40 +0100 Subject: [PATCH] Adding test for disabled button --- dev/html/public/playwright/gestures/press.html | 1 + .../src/gestures/__tests__/press.test.tsx | 15 +++++++++++++++ tests/gestures/press.spec.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/dev/html/public/playwright/gestures/press.html b/dev/html/public/playwright/gestures/press.html index dc6df72f99..23d6f6f509 100644 --- a/dev/html/public/playwright/gestures/press.html +++ b/dev/html/public/playwright/gestures/press.html @@ -20,6 +20,7 @@
press
press
+ diff --git a/packages/framer-motion/src/gestures/__tests__/press.test.tsx b/packages/framer-motion/src/gestures/__tests__/press.test.tsx index a946d0c108..03e424d66b 100644 --- a/packages/framer-motion/src/gestures/__tests__/press.test.tsx +++ b/packages/framer-motion/src/gestures/__tests__/press.test.tsx @@ -32,6 +32,21 @@ describe("press", () => { expect(press).toBeCalledTimes(1) }) + test("press event listeners don't fire if element is disabled", async () => { + const press = jest.fn() + const Component = () => press()} /> + + const { container, rerender } = render() + rerender() + + pointerDown(container.firstChild as Element) + pointerUp(container.firstChild as Element) + + await nextFrame() + + expect(press).toBeCalledTimes(0) + }) + test("global press event listeners fire", async () => { const press = jest.fn() const Component = () => ( diff --git a/tests/gestures/press.spec.ts b/tests/gestures/press.spec.ts index 5978e66eb6..b672ddf018 100644 --- a/tests/gestures/press.spec.ts +++ b/tests/gestures/press.spec.ts @@ -96,6 +96,20 @@ test.describe("press events", () => { await expect(pressDiv).toHaveText("end") }) + test("press doesn't handle events when element is disabled", async ({ + page, + }) => { + const pressDiv = page.locator("#press-button-disabled") + + // Start press + await pressDiv.dispatchEvent("pointerdown", { isPrimary: true }) + await expect(pressDiv).not.toHaveText("start") + + // Release pointer - should trigger press end + await page.dispatchEvent("body", "pointerup", { isPrimary: true }) + await expect(pressDiv).not.toHaveText("end") + }) + test("press handles pointer movement correctly", async ({ page }) => { const pressDiv = page.locator("#press-div") const pressDivCancel = page.locator("#press-div-cancel")