diff --git a/test/drag-event-interactive.test.tsx b/test/drag-event-interactive.test.tsx index d2b1e7910..de4b4417d 100644 --- a/test/drag-event-interactive.test.tsx +++ b/test/drag-event-interactive.test.tsx @@ -3,8 +3,9 @@ */ import React, { useState } from 'react'; import TestRenderer from 'react-test-renderer'; +import { screen, render, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; -import Interactive, { clamp } from '../packages/drag-event-interactive/src'; +import Interactive, { clamp, isTouch } from '../packages/drag-event-interactive/src'; it('Interactive', async () => { const MyComponent = () => { @@ -28,3 +29,61 @@ it('clamp', () => { expect(clamp(0)).toEqual(0); expect(clamp(0.33)).toEqual(0.33); }); + +it('Interactive mouseDown', async () => { + const { getByTitle } = render( +
+ { + console.log('test'); + }} + onDown={(offset, event) => { + expect(isTouch(event)).toBeFalsy(); + expect(Object.keys(offset)).toEqual(expect.arrayContaining(['left', 'top'])); + }} + > +
xxx
+
+
, + ); + getByTitle('test').focus(); + fireEvent.mouseDown(getByTitle('test'), { clientX: 1 }); + fireEvent.mouseMove(getByTitle('test'), { clientX: 24 }); +}); + +it('Interactive mouseDown', async () => { + const { getByTitle } = render( +
+ { + console.log('touchmove'); + }} + onDown={(offset, event) => { + console.log('tonDownest xxxx', isTouch(event)); + expect(Object.keys(offset)).toEqual(expect.arrayContaining(['left', 'top'])); + }} + > +
xxx
+
+
, + ); + const elm = getByTitle('test'); + elm.focus(); + // fireEvent( + // elm, + // new MouseEvent('touchstart', { + // bubbles: true, + // cancelable: true, + // }), + // ); + fireEvent.touchMove(document, {}); + fireEvent( + elm, + new MouseEvent('touchMove', { + bubbles: true, + cancelable: true, + }), + ); +});