Changes following code review

Add a type for FilterFunction and add tests for filter option.
This commit is contained in:
André Garneau
2019-06-04 17:45:28 -04:00
parent b42ee8ca0f
commit 7817cf31c6
2 changed files with 48 additions and 0 deletions
@@ -216,6 +216,47 @@ describe('ol.interaction.Translate', function() {
});
});
describe('moving features, with filter option', function() {
let translate;
beforeEach(function() {
translate = new Translate({
filter: function(feature, layer) {
return feature == features[0];
}
});
map.addInteraction(translate);
});
it('moves a filter-passing feature', function() {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerdrag', 50, -40);
simulateEvent('pointerup', 50, -40);
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(Point);
expect(geometry.getCoordinates()).to.eql([50, 40]);
validateEvents(events, [features[0]]);
});
it('does not move a filter-discarded feature', function() {
const events = trackEvents(features[0], translate);
simulateEvent('pointermove', 20, 30);
simulateEvent('pointerdown', 20, 30);
simulateEvent('pointerdrag', 50, -40);
simulateEvent('pointerup', 50, -40);
const geometry = features[1].getGeometry();
expect(geometry).to.be.a(Point);
expect(geometry.getCoordinates()).to.eql([20, -30]);
expect(events).to.be.empty();
});
});
describe('changes css cursor', function() {
let element, translate;