More consistent clean up
This commit is contained in:
@@ -16,7 +16,9 @@ describe('ol.control.Control', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
map.dispose();
|
disposeMap(map);
|
||||||
|
map = null;
|
||||||
|
control = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dispose', function() {
|
describe('dispose', function() {
|
||||||
@@ -36,6 +38,7 @@ describe('ol.control.Control\'s target', function() {
|
|||||||
var ctrl = new ol.control.Control({target: 'mycontrol'});
|
var ctrl = new ol.control.Control({target: 'mycontrol'});
|
||||||
expect(ctrl.target_.id).to.equal('mycontrol');
|
expect(ctrl.target_.id).to.equal('mycontrol');
|
||||||
ctrl.dispose();
|
ctrl.dispose();
|
||||||
|
target.parentNode.removeChild(target);
|
||||||
});
|
});
|
||||||
it('accepts element for target', function() {
|
it('accepts element for target', function() {
|
||||||
var target = document.createElement('div');
|
var target = document.createElement('div');
|
||||||
@@ -44,6 +47,7 @@ describe('ol.control.Control\'s target', function() {
|
|||||||
var ctrl = new ol.control.Control({target: target});
|
var ctrl = new ol.control.Control({target: target});
|
||||||
expect(ctrl.target_.id).to.equal('mycontrol');
|
expect(ctrl.target_.id).to.equal('mycontrol');
|
||||||
ctrl.dispose();
|
ctrl.dispose();
|
||||||
|
target.parentNode.removeChild(target);
|
||||||
});
|
});
|
||||||
it('ignores non-existing target id', function() {
|
it('ignores non-existing target id', function() {
|
||||||
var ctrl = new ol.control.Control({target: 'doesnotexist'});
|
var ctrl = new ol.control.Control({target: 'doesnotexist'});
|
||||||
|
|||||||
@@ -6,19 +6,17 @@ goog.require('ol.control.ScaleLine');
|
|||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
|
||||||
describe('ol.control.ScaleLine', function() {
|
describe('ol.control.ScaleLine', function() {
|
||||||
var mapDiv;
|
|
||||||
var map;
|
var map;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
mapDiv = document.createElement('div');
|
var target = document.createElement('div');
|
||||||
document.body.appendChild(mapDiv);
|
document.body.appendChild(target);
|
||||||
map = new ol.Map({
|
map = new ol.Map({
|
||||||
target: mapDiv
|
target: target
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
map.dispose();
|
disposeMap(map);
|
||||||
mapDiv.parentNode.removeChild(mapDiv);
|
map = null;
|
||||||
mapDiv = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
@@ -34,7 +32,7 @@ describe('ol.control.ScaleLine', function() {
|
|||||||
it('defaults to "ol-scale-line"', function() {
|
it('defaults to "ol-scale-line"', function() {
|
||||||
var ctrl = new ol.control.ScaleLine();
|
var ctrl = new ol.control.ScaleLine();
|
||||||
ctrl.setMap(map);
|
ctrl.setMap(map);
|
||||||
var element = document.querySelector('.ol-scale-line', mapDiv);
|
var element = document.querySelector('.ol-scale-line', map.getTarget());
|
||||||
expect(element).to.not.be(null);
|
expect(element).to.not.be(null);
|
||||||
expect(element).to.be.a(HTMLDivElement);
|
expect(element).to.be.a(HTMLDivElement);
|
||||||
});
|
});
|
||||||
@@ -45,10 +43,10 @@ describe('ol.control.ScaleLine', function() {
|
|||||||
ctrl.setMap(map);
|
ctrl.setMap(map);
|
||||||
|
|
||||||
// check that the default was not chosen
|
// check that the default was not chosen
|
||||||
var element1 = document.querySelector('.ol-scale-line', mapDiv);
|
var element1 = document.querySelector('.ol-scale-line', map.getTarget());
|
||||||
expect(element1).to.be(null);
|
expect(element1).to.be(null);
|
||||||
// check if the configured classname was chosen
|
// check if the configured classname was chosen
|
||||||
var element2 = document.querySelector('.humpty-dumpty', mapDiv);
|
var element2 = document.querySelector('.humpty-dumpty', map.getTarget());
|
||||||
expect(element2).to.not.be(null);
|
expect(element2).to.not.be(null);
|
||||||
expect(element2).to.be.a(HTMLDivElement);
|
expect(element2).to.be.a(HTMLDivElement);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,15 +35,16 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
|||||||
describe('timeout duration', function() {
|
describe('timeout duration', function() {
|
||||||
var clock;
|
var clock;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
||||||
clock = sinon.useFakeTimers();
|
clock = sinon.useFakeTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
clock.restore();
|
clock.restore();
|
||||||
|
ol.interaction.Interaction.zoomByDelta.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with the defaut value', function(done) {
|
it('works with the defaut value', function(done) {
|
||||||
var spy = sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
|
||||||
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
||||||
type: 'mousewheel',
|
type: 'mousewheel',
|
||||||
target: map.getViewport(),
|
target: map.getViewport(),
|
||||||
@@ -52,11 +53,10 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
|||||||
map.handleMapBrowserEvent(event);
|
map.handleMapBrowserEvent(event);
|
||||||
clock.tick(50);
|
clock.tick(50);
|
||||||
// default timeout is 80 ms, not called yet
|
// default timeout is 80 ms, not called yet
|
||||||
expect(spy.called).to.be(false);
|
expect(ol.interaction.Interaction.zoomByDelta.called).to.be(false);
|
||||||
clock.tick(30);
|
clock.tick(30);
|
||||||
expect(spy.called).to.be(true);
|
expect(ol.interaction.Interaction.zoomByDelta.called).to.be(true);
|
||||||
|
|
||||||
ol.interaction.Interaction.zoomByDelta.restore();
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,66 +102,74 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
|||||||
map.handleMapBrowserEvent(event);
|
map.handleMapBrowserEvent(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
|
describe('spying on ol.interaction.Interaction.zoomByDelta', function() {
|
||||||
var spy = sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
beforeEach(function() {
|
||||||
map.once('postrender', function() {
|
sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
||||||
expect(spy.getCall(0).args[1]).to.be(-1);
|
});
|
||||||
expect(spy.getCall(0).args[2]).to.eql([0, 0]);
|
afterEach(function() {
|
||||||
ol.interaction.Interaction.zoomByDelta.restore();
|
ol.interaction.Interaction.zoomByDelta.restore();
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
var event = new ol.MapBrowserEvent('wheel', map, {
|
|
||||||
type: 'wheel',
|
it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
|
||||||
deltaMode: WheelEvent.DOM_DELTA_LINE,
|
map.once('postrender', function() {
|
||||||
deltaY: 3.714599609375,
|
var call = ol.interaction.Interaction.zoomByDelta.getCall(0);
|
||||||
target: map.getViewport(),
|
expect(call.args[1]).to.be(-1);
|
||||||
preventDefault: ol.events.Event.prototype.preventDefault
|
expect(call.args[2]).to.eql([0, 0]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
var event = new ol.MapBrowserEvent('wheel', map, {
|
||||||
|
type: 'wheel',
|
||||||
|
deltaMode: WheelEvent.DOM_DELTA_LINE,
|
||||||
|
deltaY: 3.714599609375,
|
||||||
|
target: map.getViewport(),
|
||||||
|
preventDefault: ol.events.Event.prototype.preventDefault
|
||||||
|
});
|
||||||
|
event.coordinate = [0, 0];
|
||||||
|
map.handleMapBrowserEvent(event);
|
||||||
});
|
});
|
||||||
event.coordinate = [0, 0];
|
|
||||||
map.handleMapBrowserEvent(event);
|
it('works on Safari (wheel)', function(done) {
|
||||||
|
var origHasSafari = ol.has.SAFARI;
|
||||||
|
ol.has.SAFARI = true;
|
||||||
|
map.once('postrender', function() {
|
||||||
|
var call = ol.interaction.Interaction.zoomByDelta.getCall(0);
|
||||||
|
expect(call.args[1]).to.be(-1);
|
||||||
|
expect(call.args[2]).to.eql([0, 0]);
|
||||||
|
ol.has.SAFARI = origHasSafari;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
||||||
|
type: 'mousewheel',
|
||||||
|
wheelDeltaY: -50,
|
||||||
|
target: map.getViewport(),
|
||||||
|
preventDefault: ol.events.Event.prototype.preventDefault
|
||||||
|
});
|
||||||
|
event.coordinate = [0, 0];
|
||||||
|
map.handleMapBrowserEvent(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works on other browsers (wheel)', function(done) {
|
||||||
|
var origHasSafari = ol.has.SAFARI;
|
||||||
|
ol.has.SAFARI = false;
|
||||||
|
map.once('postrender', function() {
|
||||||
|
var call = ol.interaction.Interaction.zoomByDelta.getCall(0);
|
||||||
|
expect(call.args[1]).to.be(-1);
|
||||||
|
expect(call.args[2]).to.eql([0, 0]);
|
||||||
|
ol.has.SAFARI = origHasSafari;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
||||||
|
type: 'mousewheel',
|
||||||
|
wheelDeltaY: -120,
|
||||||
|
target: map.getViewport(),
|
||||||
|
preventDefault: ol.events.Event.prototype.preventDefault
|
||||||
|
});
|
||||||
|
event.coordinate = [0, 0];
|
||||||
|
map.handleMapBrowserEvent(event);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works on Safari (wheel)', function(done) {
|
|
||||||
var origHasSafari = ol.has.SAFARI;
|
|
||||||
ol.has.SAFARI = true;
|
|
||||||
var spy = sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
|
||||||
map.once('postrender', function() {
|
|
||||||
expect(spy.getCall(0).args[1]).to.be(-1);
|
|
||||||
expect(spy.getCall(0).args[2]).to.eql([0, 0]);
|
|
||||||
ol.interaction.Interaction.zoomByDelta.restore();
|
|
||||||
ol.has.SAFARI = origHasSafari;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
|
||||||
type: 'mousewheel',
|
|
||||||
wheelDeltaY: -50,
|
|
||||||
target: map.getViewport(),
|
|
||||||
preventDefault: ol.events.Event.prototype.preventDefault
|
|
||||||
});
|
|
||||||
event.coordinate = [0, 0];
|
|
||||||
map.handleMapBrowserEvent(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('works on other browsers (wheel)', function(done) {
|
|
||||||
var origHasSafari = ol.has.SAFARI;
|
|
||||||
ol.has.SAFARI = false;
|
|
||||||
var spy = sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
|
||||||
map.once('postrender', function() {
|
|
||||||
expect(spy.getCall(0).args[1]).to.be(-1);
|
|
||||||
expect(spy.getCall(0).args[2]).to.eql([0, 0]);
|
|
||||||
ol.interaction.Interaction.zoomByDelta.restore();
|
|
||||||
ol.has.SAFARI = origHasSafari;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
|
||||||
type: 'mousewheel',
|
|
||||||
wheelDeltaY: -120,
|
|
||||||
target: map.getViewport(),
|
|
||||||
preventDefault: ol.events.Event.prototype.preventDefault
|
|
||||||
});
|
|
||||||
event.coordinate = [0, 0];
|
|
||||||
map.handleMapBrowserEvent(event);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -368,8 +368,10 @@
|
|||||||
global.disposeMap = function(map) {
|
global.disposeMap = function(map) {
|
||||||
var target = map.getTarget();
|
var target = map.getTarget();
|
||||||
map.setTarget(null);
|
map.setTarget(null);
|
||||||
|
if (target && target.parentNode) {
|
||||||
|
target.parentNode.removeChild(target);
|
||||||
|
}
|
||||||
map.dispose();
|
map.dispose();
|
||||||
document.body.removeChild(target);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
global.assertWebGL = function(map) {
|
global.assertWebGL = function(map) {
|
||||||
|
|||||||
Reference in New Issue
Block a user