Testing mouseMove throttling
This commit is contained in:
parent
016f99daf6
commit
d758775ab7
|
@ -150,4 +150,97 @@ Arguments [
|
|||
// screen.debug();
|
||||
expect(transformMapParams).toBeUndefined();
|
||||
});
|
||||
|
||||
test('throttle mouseMove events', () => {
|
||||
var transformMapParams: any;
|
||||
function transformMap(
|
||||
deltaShift: Point | null,
|
||||
deltaZoom: number | null,
|
||||
zoomCenter: Point | null
|
||||
) {
|
||||
console.log(`transformMap${JSON.stringify(arguments)}`);
|
||||
transformMapParams = arguments;
|
||||
}
|
||||
render(<Handlers transformMap={transformMap} />);
|
||||
const handlers = screen.getByRole('presentation');
|
||||
fireEvent(
|
||||
handlers,
|
||||
createEvent.mouseDown(handlers, {
|
||||
clientX: 10,
|
||||
clientY: 20,
|
||||
})
|
||||
);
|
||||
fireEvent(
|
||||
handlers,
|
||||
createEvent.mouseMove(handlers, {
|
||||
clientX: 20,
|
||||
clientY: 50,
|
||||
})
|
||||
);
|
||||
fireEvent(
|
||||
handlers,
|
||||
createEvent.mouseMove(handlers, {
|
||||
clientX: 30,
|
||||
clientY: 60,
|
||||
})
|
||||
);
|
||||
// screen.debug();
|
||||
expect(transformMapParams).toMatchInlineSnapshot(`
|
||||
Arguments [
|
||||
Object {
|
||||
"x": 10,
|
||||
"y": 30,
|
||||
},
|
||||
null,
|
||||
null,
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('throttle mouseMove events', async () => {
|
||||
var transformMapParams: any;
|
||||
function transformMap(
|
||||
deltaShift: Point | null,
|
||||
deltaZoom: number | null,
|
||||
zoomCenter: Point | null
|
||||
) {
|
||||
console.log(`transformMap${JSON.stringify(arguments)}`);
|
||||
transformMapParams = arguments;
|
||||
}
|
||||
render(<Handlers transformMap={transformMap} />);
|
||||
const handlers = screen.getByRole('presentation');
|
||||
fireEvent(
|
||||
handlers,
|
||||
createEvent.mouseDown(handlers, {
|
||||
clientX: 10,
|
||||
clientY: 20,
|
||||
})
|
||||
);
|
||||
fireEvent(
|
||||
handlers,
|
||||
createEvent.mouseMove(handlers, {
|
||||
clientX: 20,
|
||||
clientY: 50,
|
||||
})
|
||||
);
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
fireEvent(
|
||||
handlers,
|
||||
createEvent.mouseMove(handlers, {
|
||||
clientX: 5,
|
||||
clientY: 5,
|
||||
})
|
||||
);
|
||||
// screen.debug();
|
||||
expect(transformMapParams).toMatchInlineSnapshot(`
|
||||
Arguments [
|
||||
Object {
|
||||
"x": -15,
|
||||
"y": -45,
|
||||
},
|
||||
null,
|
||||
null,
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue