Initial stopPropagation support for PluggableMap

This commit is contained in:
Greg Gianforcaro
2020-12-09 00:46:56 -05:00
parent 38585d6945
commit 99f23caf03
3 changed files with 74 additions and 1 deletions

View File

@@ -105,6 +105,9 @@ describe('ol.interaction.Select', function () {
clientX: position.left + x + width / 2,
clientY: position.top + y + height / 2,
shiftKey: shiftKey,
stopPropagation: () => {
event.propagationStopped = true;
},
};
map.handleMapBrowserEvent(new MapBrowserEvent(type, map, event));
}
@@ -459,4 +462,55 @@ describe('ol.interaction.Select', function () {
});
});
});
describe('supports stop propagation', function () {
let firstInteraction, secondInteraction;
beforeEach(function () {
firstInteraction = new Select();
secondInteraction = new Select();
map.addInteraction(firstInteraction);
// note second interaction added to map last
map.addInteraction(secondInteraction);
});
afterEach(function () {
map.removeInteraction(firstInteraction);
map.removeInteraction(secondInteraction);
});
//base case sanity check
describe('without stop propagation', function () {
it('both interactions dispatch select', function () {
const firstSelectSpy = sinon.spy();
firstInteraction.on('select', firstSelectSpy);
const secondSelectSpy = sinon.spy();
secondInteraction.on('select', secondSelectSpy);
simulateEvent('singleclick', 10, -20);
expect(firstSelectSpy.callCount).to.be(1);
expect(secondSelectSpy.callCount).to.be(1);
});
});
describe('calling stop propagation', function () {
it('only "last" added interaction dispatches select', function () {
const firstSelectSpy = sinon.spy();
firstInteraction.on('select', firstSelectSpy);
const secondSelectSpy = sinon.spy(function (e) {
e.mapBrowserEvent.stopPropagation();
});
secondInteraction.on('select', secondSelectSpy);
simulateEvent('singleclick', 10, -20);
expect(firstSelectSpy.callCount).to.be(0);
expect(secondSelectSpy.callCount).to.be(1);
});
});
});
});