Add tests and documentation for ol.events.Event

This commit is contained in:
Andreas Hocevar
2016-01-31 16:07:29 +01:00
parent 5ba8b13ccf
commit cf4556f115
2 changed files with 66 additions and 0 deletions

View File

@@ -2,6 +2,15 @@ goog.provide('ol.events.Event');
/**
* @classdesc
* Stripped down implementation of the W3C DOM Level 2 Event interface.
* @see {@link https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface}
*
* This implementation only provides `type` and `target` properties, and
* `stopPropagation` and `preventDefault` methods. It is meant as base class
* for higher level events defined in the library, and works with
* {@link ol.events.EventTarget}.
*
* @constructor
* @param {ol.events.EventType|string} type Type.
* @param {Object=} opt_target Target.

View File

@@ -0,0 +1,57 @@
goog.provide('ol.test.events.Event');
describe('ol.events.Event', function() {
describe('constructor', function() {
it('takes a type as argument', function() {
var event = new ol.events.Event('foo');
expect(event.type).to.be('foo');
});
it('can be constructed with an optional 2nd target arg', function() {
var target = {id: 1};
var event = new ol.events.Event('foo', target);
expect(event.target).to.equal(target);
});
it('does not set the propagationStopped flag', function() {
var event = new ol.events.Event('foo');
expect(event.propagationStopped).to.be(undefined);
});
});
describe('#preventDefault', function() {
it('sets the propagationStopped flag', function() {
var event = new ol.events.Event('foo');
event.preventDefault();
expect(event.propagationStopped).to.be(true);
});
it('is the same as #stopPropagation', function() {
var event = new ol.events.Event('foo');
expect(event.stopPropagation).to.equal(event.preventDefault);
});
});
describe('ol.events.Event.preventDefault', function() {
it('calls preventDefault on the event object', function() {
var event = {
preventDefault: sinon.spy()
};
ol.events.Event.preventDefault(event);
expect(event.preventDefault.called).to.be(true);
});
});
describe('ol.events.Event.stopPropagation', function() {
it('calls preventDefault on the event object', function() {
var event = {
stopPropagation: sinon.spy()
};
ol.events.Event.stopPropagation(event);
expect(event.stopPropagation.called).to.be(true);
});
});
});
goog.require('ol.events.Event');