diff options
Diffstat (limited to 'extlib/leaflet/spec/suites/core')
-rw-r--r-- | extlib/leaflet/spec/suites/core/ClassSpec.js | 120 | ||||
-rw-r--r-- | extlib/leaflet/spec/suites/core/EventsSpec.js | 110 | ||||
-rw-r--r-- | extlib/leaflet/spec/suites/core/UtilSpec.js | 63 |
3 files changed, 293 insertions, 0 deletions
diff --git a/extlib/leaflet/spec/suites/core/ClassSpec.js b/extlib/leaflet/spec/suites/core/ClassSpec.js new file mode 100644 index 00000000..7a289154 --- /dev/null +++ b/extlib/leaflet/spec/suites/core/ClassSpec.js @@ -0,0 +1,120 @@ +describe("Class", function() {
+
+ describe("#extend", function() {
+ var Klass,
+ constructor,
+ method;
+
+ beforeEach(function() {
+ constructor = jasmine.createSpy(),
+ method = jasmine.createSpy();
+
+ Klass = L.Class.extend({
+ statics: {bla: 1},
+ includes: {mixin: true},
+
+ initialize: constructor,
+ foo: 5,
+ bar: method
+ });
+ });
+
+ it("should create a class with the given constructor & properties", function() {
+ var a = new Klass();
+
+ expect(constructor).toHaveBeenCalled();
+ expect(a.foo).toEqual(5);
+
+ a.bar();
+
+ expect(method).toHaveBeenCalled();
+ });
+
+ it("should inherit parent classes' constructor & properties", function() {
+ var Klass2 = Klass.extend({baz: 2});
+
+ var b = new Klass2();
+
+ expect(b instanceof Klass).toBeTruthy();
+ expect(b instanceof Klass2).toBeTruthy();
+
+ expect(constructor).toHaveBeenCalled();
+ expect(b.baz).toEqual(2);
+
+ b.bar();
+
+ expect(method).toHaveBeenCalled();
+ });
+
+ it("should grant the ability to call parent methods, including constructor", function() {
+ var Klass2 = Klass.extend({
+ initialize: function() {},
+ bar: function() {}
+ });
+
+ var b = new Klass2();
+
+ expect(constructor).not.toHaveBeenCalled();
+ b.superclass.initialize.call(this);
+ expect(constructor).toHaveBeenCalled();
+
+ b.superclass.bar.call(this);
+ expect(method).toHaveBeenCalled();
+ });
+
+ it("should support static properties", function() {
+ expect(Klass.bla).toEqual(1);
+ });
+
+ it("should inherit parent static properties", function() {
+ var Klass2 = Klass.extend({});
+
+ expect(Klass2.bla).toEqual(1);
+ });
+
+ it("should include the given mixin", function() {
+ var a = new Klass();
+ expect(a.mixin).toBeTruthy();
+ });
+
+ it("should be able to include multiple mixins", function() {
+ var Klass2 = L.Class.extend({
+ includes: [{mixin: true}, {mixin2: true}]
+ });
+ var a = new Klass2();
+
+ expect(a.mixin).toBeTruthy();
+ expect(a.mixin2).toBeTruthy();
+ });
+
+ it("should grant the ability to include the given mixin", function() {
+ Klass.include({mixin2: true});
+
+ var a = new Klass();
+ expect(a.mixin2).toBeTruthy();
+ });
+
+ it("should merge options instead of replacing them", function() {
+ var KlassWithOptions1 = L.Class.extend({
+ options: {
+ foo1: 1,
+ foo2: 2
+ }
+ });
+ var KlassWithOptions2 = KlassWithOptions1.extend({
+ options: {
+ foo2: 3,
+ foo3: 4
+ }
+ });
+
+ var a = new KlassWithOptions2();
+
+ expect(a.options).toEqual({
+ foo1: 1,
+ foo2: 3,
+ foo3: 4
+ });
+ });
+ });
+});
\ No newline at end of file diff --git a/extlib/leaflet/spec/suites/core/EventsSpec.js b/extlib/leaflet/spec/suites/core/EventsSpec.js new file mode 100644 index 00000000..be143866 --- /dev/null +++ b/extlib/leaflet/spec/suites/core/EventsSpec.js @@ -0,0 +1,110 @@ +describe('Events', function() {
+ var Klass;
+
+ beforeEach(function() {
+ Klass = L.Class.extend({
+ includes: L.Mixin.Events
+ });
+ });
+
+ describe('#fireEvent', function() {
+
+ it('should fire all listeners added through #addEventListener', function() {
+ var obj = new Klass(),
+ spy = jasmine.createSpy(),
+ spy2 = jasmine.createSpy(),
+ spy3 = jasmine.createSpy();
+
+ obj.addEventListener('test', spy);
+ obj.addEventListener('test', spy2);
+ obj.addEventListener('other', spy3);
+
+ expect(spy).not.toHaveBeenCalled();
+ expect(spy2).not.toHaveBeenCalled();
+ expect(spy3).not.toHaveBeenCalled();
+
+ obj.fireEvent('test');
+
+ expect(spy).toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalled();
+ expect(spy3).not.toHaveBeenCalled();
+ });
+
+ it('should provide event object to listeners and execute them in the right context', function() {
+ var obj = new Klass(),
+ obj2 = new Klass(),
+ foo = {};
+
+ function listener1(e) {
+ expect(e.type).toEqual('test');
+ expect(e.target).toEqual(obj);
+ expect(this).toEqual(obj);
+ expect(e.bar).toEqual(3);
+ };
+
+ function listener2(e) {
+ expect(e.target).toEqual(obj2);
+ expect(this).toEqual(foo);
+ };
+
+ obj.addEventListener('test', listener1);
+ obj2.addEventListener('test', listener2, foo);
+
+ obj.fireEvent('test', {bar: 3});
+ });
+
+ it('should not call listeners removed through #removeEventListener', function() {
+ var obj = new Klass(),
+ spy = jasmine.createSpy();
+
+ obj.addEventListener('test', spy);
+ obj.removeEventListener('test', spy);
+
+ obj.fireEvent('test');
+
+ expect(spy).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('#on, #off & #fire', function() {
+
+ it('should work like #addEventListener && #removeEventListener', function() {
+ var obj = new Klass(),
+ spy = jasmine.createSpy();
+
+ obj.on('test', spy);
+ obj.fire('test');
+
+ expect(spy).toHaveBeenCalled();
+
+ obj.off('test', spy);
+ obj.fireEvent('test');
+
+ expect(spy.callCount).toBeLessThan(2);
+ });
+
+ it('should not override existing methods with the same name', function() {
+ var spy1 = jasmine.createSpy(),
+ spy2 = jasmine.createSpy(),
+ spy3 = jasmine.createSpy();
+
+ var Klass2 = L.Class.extend({
+ includes: L.Mixin.Events,
+ on: spy1,
+ off: spy2,
+ fire: spy3
+ });
+
+ var obj = new Klass2();
+
+ obj.on();
+ expect(spy1).toHaveBeenCalled();
+
+ obj.off();
+ expect(spy2).toHaveBeenCalled();
+
+ obj.fire();
+ expect(spy3).toHaveBeenCalled();
+ });
+ });
+});
\ No newline at end of file diff --git a/extlib/leaflet/spec/suites/core/UtilSpec.js b/extlib/leaflet/spec/suites/core/UtilSpec.js new file mode 100644 index 00000000..46cb8fba --- /dev/null +++ b/extlib/leaflet/spec/suites/core/UtilSpec.js @@ -0,0 +1,63 @@ +describe('Util', function() {
+
+ describe('#extend', function() {
+ var a;
+
+ beforeEach(function() {
+ a = {
+ foo: 5,
+ bar: 'asd'
+ };
+ });
+
+ it('should extend the first argument with the properties of the second', function() {
+ L.Util.extend(a, {
+ bar: 7,
+ baz: 3
+ });
+
+ expect(a).toEqual({
+ foo: 5,
+ bar: 7,
+ baz: 3
+ });
+ });
+
+ it('should work with more than 2 arguments', function() {
+ L.Util.extend(a, {bar: 7}, {baz: 3});
+
+ expect(a).toEqual({
+ foo: 5,
+ bar: 7,
+ baz: 3
+ });
+ });
+ });
+
+ describe('#bind', function() {
+ it('should return the given function with the given context', function() {
+ var fn = function() {
+ return this;
+ };
+
+ var fn2 = L.Util.bind(fn, 5);
+
+ expect(fn2()).toEqual(5);
+ });
+ });
+
+ describe('#stamp', function() {
+ it('should set a unique id on the given object and return it', function() {
+ var a = {},
+ id = L.Util.stamp(a);
+
+ expect(typeof id).toEqual('number');
+ expect(L.Util.stamp(a)).toEqual(id);
+
+ var b = {},
+ id2 = L.Util.stamp(b);
+
+ expect(id2).not.toEqual(id);
+ });
+ });
+});
\ No newline at end of file |