Mock PointerEvent in tests to include target
The `target` Event property is readonly as it is set internally when an event is dispatched. This change uses a plain object with the essential properties that a PointerEvent has which is sufficent for map event handling
This commit is contained in:
@@ -73,8 +73,9 @@ describe('ol.interaction.Draw', function() {
|
||||
// calculated in case body has top < 0 (test runner with small window)
|
||||
const position = viewport.getBoundingClientRect();
|
||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||
const event = new Event();
|
||||
const event = {};
|
||||
event.type = type;
|
||||
event.target = viewport.firstChild;
|
||||
event.clientX = position.left + x + width / 2;
|
||||
event.clientY = position.top + y + height / 2;
|
||||
event.shiftKey = shiftKey;
|
||||
|
||||
@@ -50,8 +50,9 @@ describe('ol.interaction.Extent', function() {
|
||||
// calculated in case body has top < 0 (test runner with small window)
|
||||
const position = viewport.getBoundingClientRect();
|
||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||
const pointerEvent = new Event();
|
||||
const pointerEvent = {};
|
||||
pointerEvent.type = type;
|
||||
pointerEvent.target = viewport.firstChild;
|
||||
pointerEvent.button = button;
|
||||
pointerEvent.clientX = position.left + x + width / 2;
|
||||
pointerEvent.clientY = position.top - y + height / 2;
|
||||
|
||||
@@ -84,6 +84,7 @@ describe('ol.interaction.Modify', function() {
|
||||
const position = viewport.getBoundingClientRect();
|
||||
const pointerEvent = new Event();
|
||||
pointerEvent.type = type;
|
||||
pointerEvent.target = viewport.firstChild;
|
||||
pointerEvent.clientX = position.left + x + width / 2;
|
||||
pointerEvent.clientY = position.top + y + height / 2;
|
||||
pointerEvent.shiftKey = modifiers.shift || false;
|
||||
|
||||
@@ -91,11 +91,13 @@ describe('ol.interaction.Select', function() {
|
||||
// calculated in case body has top < 0 (test runner with small window)
|
||||
const position = viewport.getBoundingClientRect();
|
||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||
const event = new PointerEvent(type, {
|
||||
const event = {
|
||||
type: type,
|
||||
target: viewport.firstChild,
|
||||
clientX: position.left + x + width / 2,
|
||||
clientY: position.top + y + height / 2,
|
||||
shiftKey: shiftKey
|
||||
});
|
||||
};
|
||||
map.handleMapBrowserEvent(new MapBrowserPointerEvent(type, map, event));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,13 +65,15 @@ describe('ol.interaction.Translate', function() {
|
||||
// calculated in case body has top < 0 (test runner with small window)
|
||||
const position = viewport.getBoundingClientRect();
|
||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||
const event = new MapBrowserPointerEvent(type, map,
|
||||
new PointerEvent(type, {
|
||||
const event = new MapBrowserPointerEvent(type, map, {
|
||||
type: type,
|
||||
target: viewport.firstChild,
|
||||
pointerId: 0,
|
||||
clientX: position.left + x + width / 2,
|
||||
clientY: position.top + y + height / 2,
|
||||
shiftKey: shiftKey,
|
||||
preventDefault: function() {}
|
||||
}));
|
||||
});
|
||||
map.handleMapBrowserEvent(event);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user