Add tests for draw interaction events
This commit is contained in:
@@ -67,12 +67,14 @@ describe('ol.interaction.Draw', function() {
|
||||
});
|
||||
|
||||
describe('drawing points', function() {
|
||||
var draw;
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
draw = new ol.interaction.Draw({
|
||||
layer: layer,
|
||||
type: ol.geom.GeometryType.POINT
|
||||
}));
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('draws a point on click', function() {
|
||||
@@ -97,6 +99,20 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(features).to.have.length(0);
|
||||
});
|
||||
|
||||
it('triggers draw events', function() {
|
||||
var ds = sinon.spy();
|
||||
var de = sinon.spy();
|
||||
goog.events.listen(draw, ol.DrawEventType.DRAWSTART, ds);
|
||||
goog.events.listen(draw, ol.DrawEventType.DRAWEND, de);
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
simulateEvent('mousemove', 20, 20);
|
||||
expect(ds).to.be.called(2);
|
||||
expect(de).to.be.called(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multipoints', function() {
|
||||
@@ -123,12 +139,14 @@ describe('ol.interaction.Draw', function() {
|
||||
});
|
||||
|
||||
describe('drawing linestrings', function() {
|
||||
var draw;
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
draw = new ol.interaction.Draw({
|
||||
layer: layer,
|
||||
type: ol.geom.GeometryType.LINE_STRING
|
||||
}));
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('draws linestring with clicks, finishing on last point', function() {
|
||||
@@ -189,6 +207,34 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
|
||||
});
|
||||
|
||||
it('triggers draw events', function() {
|
||||
var ds = sinon.spy();
|
||||
var de = sinon.spy();
|
||||
goog.events.listen(draw, ol.DrawEventType.DRAWSTART, ds);
|
||||
goog.events.listen(draw, ol.DrawEventType.DRAWEND, de);
|
||||
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// finish on second point
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
|
||||
expect(ds).to.be.called(1);
|
||||
expect(de).to.be.called(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multi-linestrings', function() {
|
||||
@@ -228,12 +274,14 @@ describe('ol.interaction.Draw', function() {
|
||||
});
|
||||
|
||||
describe('drawing polygons', function() {
|
||||
var draw;
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
draw = new ol.interaction.Draw({
|
||||
layer: layer,
|
||||
type: ol.geom.GeometryType.POLYGON
|
||||
}));
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('draws polygon with clicks, finishing on first point', function() {
|
||||
@@ -272,6 +320,40 @@ describe('ol.interaction.Draw', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('triggers draw events', function() {
|
||||
var ds = sinon.spy();
|
||||
var de = sinon.spy();
|
||||
goog.events.listen(draw, ol.DrawEventType.DRAWSTART, ds);
|
||||
goog.events.listen(draw, ol.DrawEventType.DRAWEND, de);
|
||||
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// third point
|
||||
simulateEvent('mousemove', 30, 10);
|
||||
simulateEvent('mousedown', 30, 10);
|
||||
simulateEvent('mouseup', 30, 10);
|
||||
simulateEvent('click', 30, 10);
|
||||
|
||||
// finish on first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
expect(ds).to.be.called(1);
|
||||
expect(de).to.be.called(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multi-polygons', function() {
|
||||
|
||||
Reference in New Issue
Block a user