Skip to content

Commit

Permalink
test(drag-event-interactive): add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 7, 2021
1 parent 0798245 commit 6a5a2f7
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion test/drag-event-interactive.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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(
<div style={{ position: 'relative', width: 320, height: 16 }}>
<Interactive
title="test"
onMove={() => {
console.log('test');
}}
onDown={(offset, event) => {
expect(isTouch(event)).toBeFalsy();
expect(Object.keys(offset)).toEqual(expect.arrayContaining(['left', 'top']));
}}
>
<div>xxx</div>
</Interactive>
</div>,
);
getByTitle('test').focus();
fireEvent.mouseDown(getByTitle('test'), { clientX: 1 });
fireEvent.mouseMove(getByTitle('test'), { clientX: 24 });
});

it('Interactive mouseDown', async () => {
const { getByTitle } = render(
<div style={{ position: 'relative', width: 320, height: 16 }}>
<Interactive
title="test"
onMove={() => {
console.log('touchmove');
}}
onDown={(offset, event) => {
console.log('tonDownest xxxx', isTouch(event));
expect(Object.keys(offset)).toEqual(expect.arrayContaining(['left', 'top']));
}}
>
<div>xxx</div>
</Interactive>
</div>,
);
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,
}),
);
});

0 comments on commit 6a5a2f7

Please sign in to comment.