Add tests excercising the add/remove/toggle select logic with and without multi
This commit is contained in:
@@ -129,6 +129,20 @@ describe('ol.interaction.Select', function() {
|
||||
var features = select.getFeatures();
|
||||
expect(features.getLength()).to.equal(1);
|
||||
});
|
||||
|
||||
it('select with shift single-click', function() {
|
||||
var listenerSpy = sinon.spy(function(e) {
|
||||
expect(e.selected).to.have.length(1);
|
||||
});
|
||||
select.on('select', listenerSpy);
|
||||
|
||||
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20, true);
|
||||
|
||||
expect(listenerSpy.callCount).to.be(1);
|
||||
|
||||
var features = select.getFeatures();
|
||||
expect(features.getLength()).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiselecting polygons', function() {
|
||||
@@ -154,6 +168,20 @@ describe('ol.interaction.Select', function() {
|
||||
var features = select.getFeatures();
|
||||
expect(features.getLength()).to.equal(4);
|
||||
});
|
||||
|
||||
it('select with shift single-click', function() {
|
||||
var listenerSpy = sinon.spy(function(e) {
|
||||
expect(e.selected).to.have.length(4);
|
||||
});
|
||||
select.on('select', listenerSpy);
|
||||
|
||||
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20, true);
|
||||
|
||||
expect(listenerSpy.callCount).to.be(1);
|
||||
|
||||
var features = select.getFeatures();
|
||||
expect(features.getLength()).to.equal(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggle selecting polygons', function() {
|
||||
@@ -207,6 +235,24 @@ describe('ol.interaction.Select', function() {
|
||||
expect(features.item(0).get('type')).to.be('bar');
|
||||
expect(features.item(1).get('type')).to.be('bar');
|
||||
});
|
||||
|
||||
it('only selects features that pass the filter ' +
|
||||
'using shift single-click', function() {
|
||||
var select = new ol.interaction.Select({
|
||||
multi: true,
|
||||
filter: function(feature, layer) {
|
||||
return feature.get('type') === 'bar';
|
||||
}
|
||||
});
|
||||
map.addInteraction(select);
|
||||
|
||||
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20,
|
||||
true);
|
||||
var features = select.getFeatures();
|
||||
expect(features.getLength()).to.equal(2);
|
||||
expect(features.item(0).get('type')).to.be('bar');
|
||||
expect(features.item(1).get('type')).to.be('bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with multi set to false', function() {
|
||||
@@ -224,8 +270,23 @@ describe('ol.interaction.Select', function() {
|
||||
expect(features.getLength()).to.equal(1);
|
||||
expect(features.item(0).get('type')).to.be('bar');
|
||||
});
|
||||
});
|
||||
|
||||
it('only selects the first feature that passes the filter ' +
|
||||
'using shift single-click', function() {
|
||||
var select = new ol.interaction.Select({
|
||||
multi: false,
|
||||
filter: function(feature, layer) {
|
||||
return feature.get('type') === 'bar';
|
||||
}
|
||||
});
|
||||
map.addInteraction(select);
|
||||
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20,
|
||||
true);
|
||||
var features = select.getFeatures();
|
||||
expect(features.getLength()).to.equal(1);
|
||||
expect(features.item(0).get('type')).to.be('bar');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLayer(feature)', function() {
|
||||
|
||||
Reference in New Issue
Block a user