Use pepjs instead of our own pointerevent polyfill
This commit is contained in:
@@ -2,7 +2,7 @@ import Map from '../../../src/ol/Map.js';
|
||||
import MapBrowserEventHandler from '../../../src/ol/MapBrowserEventHandler.js';
|
||||
import {listen} from '../../../src/ol/events.js';
|
||||
import {DEVICE_PIXEL_RATIO} from '../../../src/ol/has.js';
|
||||
import PointerEvent from '../../../src/ol/pointer/PointerEvent.js';
|
||||
import Event from '../../../src/ol/events/Event.js';
|
||||
|
||||
describe('ol.MapBrowserEventHandler', function() {
|
||||
describe('#emulateClick_', function() {
|
||||
@@ -36,22 +36,22 @@ describe('ol.MapBrowserEventHandler', function() {
|
||||
});
|
||||
|
||||
it('emulates click', function() {
|
||||
handler.emulateClick_(new PointerEvent('pointerdown', {
|
||||
type: 'mousedown',
|
||||
target: target,
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
}));
|
||||
const event = new Event();
|
||||
event.type = 'pointerdown';
|
||||
event.target = target,
|
||||
event.clientX = 0;
|
||||
event.clientY = 0;
|
||||
handler.emulateClick_(event);
|
||||
expect(clickSpy.called).to.be.ok();
|
||||
});
|
||||
|
||||
it('emulates singleclick', function() {
|
||||
handler.emulateClick_(new PointerEvent('pointerdown', {
|
||||
type: 'mousedown',
|
||||
target: target,
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
}));
|
||||
const event = new Event();
|
||||
event.type = 'pointerdown';
|
||||
event.target = target;
|
||||
event.clientX = 0;
|
||||
event.clientY = 0;
|
||||
handler.emulateClick_(event);
|
||||
expect(singleclickSpy.called).to.not.be.ok();
|
||||
expect(dblclickSpy.called).to.not.be.ok();
|
||||
|
||||
@@ -59,32 +59,22 @@ describe('ol.MapBrowserEventHandler', function() {
|
||||
expect(singleclickSpy.calledOnce).to.be.ok();
|
||||
expect(dblclickSpy.called).to.not.be.ok();
|
||||
|
||||
handler.emulateClick_(new PointerEvent('pointerdown', {
|
||||
type: 'mousedown',
|
||||
target: target,
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
}));
|
||||
handler.emulateClick_(event);
|
||||
expect(singleclickSpy.calledOnce).to.be.ok();
|
||||
expect(dblclickSpy.called).to.not.be.ok();
|
||||
});
|
||||
|
||||
it('emulates dblclick', function() {
|
||||
handler.emulateClick_(new PointerEvent('pointerdown', {
|
||||
type: 'mousedown',
|
||||
target: target,
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
}));
|
||||
const event = new Event();
|
||||
event.type = 'pointerdown';
|
||||
event.target = target;
|
||||
event.clientX = 0;
|
||||
event.clientY = 0;
|
||||
handler.emulateClick_(event);
|
||||
expect(singleclickSpy.called).to.not.be.ok();
|
||||
expect(dblclickSpy.called).to.not.be.ok();
|
||||
|
||||
handler.emulateClick_(new PointerEvent('pointerdown', {
|
||||
type: 'mousedown',
|
||||
target: target,
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
}));
|
||||
handler.emulateClick_(event);
|
||||
expect(singleclickSpy.called).to.not.be.ok();
|
||||
expect(dblclickSpy.calledOnce).to.be.ok();
|
||||
|
||||
@@ -107,7 +97,7 @@ describe('ol.MapBrowserEventHandler', function() {
|
||||
});
|
||||
|
||||
it('is an event after handlePointerDown_ has been called', function() {
|
||||
const event = new PointerEvent('pointerdown', {});
|
||||
const event = new Event('pointerdown');
|
||||
handler.handlePointerDown_(event);
|
||||
expect(handler.down_).to.be(event);
|
||||
});
|
||||
@@ -121,65 +111,65 @@ describe('ol.MapBrowserEventHandler', function() {
|
||||
beforeEach(function() {
|
||||
defaultHandler = new MapBrowserEventHandler(new Map({}));
|
||||
moveToleranceHandler = new MapBrowserEventHandler(new Map({}), 8);
|
||||
pointerdownAt0 = new PointerEvent('pointerdown', {}, {
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
});
|
||||
pointerdownAt0 = new Event();
|
||||
pointerdownAt0.type = 'pointerdown';
|
||||
pointerdownAt0.clientX = 0;
|
||||
pointerdownAt0.clientY = 0;
|
||||
defaultHandler.handlePointerDown_(pointerdownAt0);
|
||||
moveToleranceHandler.handlePointerDown_(pointerdownAt0);
|
||||
});
|
||||
|
||||
it('is not moving if distance is 0', function() {
|
||||
const pointerdownAt0 = new PointerEvent('pointerdown', {}, {
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
});
|
||||
pointerdownAt0 = new Event();
|
||||
pointerdownAt0.type = 'pointerdown';
|
||||
pointerdownAt0.clientX = 0;
|
||||
pointerdownAt0.clientY = 0;
|
||||
expect(defaultHandler.isMoving_(pointerdownAt0)).to.be(false);
|
||||
});
|
||||
|
||||
it('is moving if distance is 2', function() {
|
||||
const pointerdownAt2 = new PointerEvent('pointerdown', {}, {
|
||||
clientX: DEVICE_PIXEL_RATIO + 1,
|
||||
clientY: DEVICE_PIXEL_RATIO + 1
|
||||
});
|
||||
const pointerdownAt2 = new Event();
|
||||
pointerdownAt2.type = 'pointerdown';
|
||||
pointerdownAt2.clientX = DEVICE_PIXEL_RATIO + 1;
|
||||
pointerdownAt2.clientY = DEVICE_PIXEL_RATIO + 1;
|
||||
expect(defaultHandler.isMoving_(pointerdownAt2)).to.be(true);
|
||||
});
|
||||
|
||||
it('is moving with negative distance', function() {
|
||||
const pointerdownAt2 = new PointerEvent('pointerdown', {}, {
|
||||
clientX: -(DEVICE_PIXEL_RATIO + 1),
|
||||
clientY: -(DEVICE_PIXEL_RATIO + 1)
|
||||
});
|
||||
const pointerdownAt2 = new Event();
|
||||
pointerdownAt2.type = 'pointerdown';
|
||||
pointerdownAt2.clientX = -(DEVICE_PIXEL_RATIO + 1);
|
||||
pointerdownAt2.clientY = -(DEVICE_PIXEL_RATIO + 1);
|
||||
expect(defaultHandler.isMoving_(pointerdownAt2)).to.be(true);
|
||||
});
|
||||
|
||||
it('is not moving if distance is less than move tolerance', function() {
|
||||
const pointerdownAt2 = new PointerEvent('pointerdown', {}, {
|
||||
clientX: DEVICE_PIXEL_RATIO + 1,
|
||||
clientY: DEVICE_PIXEL_RATIO + 1
|
||||
});
|
||||
const pointerdownAt2 = new Event();
|
||||
pointerdownAt2.type = 'pointerdown';
|
||||
pointerdownAt2.clientX = DEVICE_PIXEL_RATIO + 1;
|
||||
pointerdownAt2.clientY = DEVICE_PIXEL_RATIO + 1;
|
||||
expect(moveToleranceHandler.isMoving_(pointerdownAt2)).to.be(false);
|
||||
});
|
||||
|
||||
it('is moving if distance is greater than move tolerance', function() {
|
||||
const pointerdownAt9 = new PointerEvent('pointerdown', {}, {
|
||||
clientX: (DEVICE_PIXEL_RATIO * 8) + 1,
|
||||
clientY: (DEVICE_PIXEL_RATIO * 8) + 1
|
||||
});
|
||||
const pointerdownAt9 = new Event();
|
||||
pointerdownAt9.type = 'pointerdown';
|
||||
pointerdownAt9.clientX = (DEVICE_PIXEL_RATIO * 8) + 1;
|
||||
pointerdownAt9.clientY = (DEVICE_PIXEL_RATIO * 8) + 1;
|
||||
expect(moveToleranceHandler.isMoving_(pointerdownAt9)).to.be(true);
|
||||
});
|
||||
|
||||
it('is moving when moving back close to the down pixel', function() {
|
||||
const pointermoveAt9 = new PointerEvent('pointermove', {}, {
|
||||
clientX: (DEVICE_PIXEL_RATIO * 8) + 1,
|
||||
clientY: (DEVICE_PIXEL_RATIO * 8) + 1
|
||||
});
|
||||
const pointermoveAt9 = new Event();
|
||||
pointermoveAt9.type = 'pointermove';
|
||||
pointermoveAt9.clientX = (DEVICE_PIXEL_RATIO * 8) + 1;
|
||||
pointermoveAt9.clientY = (DEVICE_PIXEL_RATIO * 8) + 1;
|
||||
moveToleranceHandler.handlePointerMove_(pointermoveAt9);
|
||||
expect(moveToleranceHandler.isMoving_(pointermoveAt9)).to.be(true);
|
||||
const pointermoveAt2 = new PointerEvent('pointermove', {}, {
|
||||
clientX: DEVICE_PIXEL_RATIO + 1,
|
||||
clientY: DEVICE_PIXEL_RATIO + 1
|
||||
});
|
||||
const pointermoveAt2 = new Event();
|
||||
pointermoveAt2.type = 'pointermove';
|
||||
pointermoveAt2.clientX = DEVICE_PIXEL_RATIO + 1;
|
||||
pointermoveAt2.clientY = DEVICE_PIXEL_RATIO + 1;
|
||||
moveToleranceHandler.handlePointerMove_(pointermoveAt2);
|
||||
expect(moveToleranceHandler.isMoving_(pointermoveAt2)).to.be(true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user