From 6c4b0fe1e5586c00ecb1e02a52df55589b24cad6 Mon Sep 17 00:00:00 2001 From: Ezequiel Bergamaschi Date: Sat, 27 Sep 2014 14:35:49 -0300 Subject: [PATCH] unit testing for events --- core-js/pom.xml | 1 - mindplot/pom.xml | 10 +++-- .../src/test/javascript/EventsTestSuite.js | 43 +++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 mindplot/src/test/javascript/EventsTestSuite.js diff --git a/core-js/pom.xml b/core-js/pom.xml index d1d20d72..9591eb2d 100644 --- a/core-js/pom.xml +++ b/core-js/pom.xml @@ -56,7 +56,6 @@ Functions.js - CHROME diff --git a/mindplot/pom.xml b/mindplot/pom.xml index ffe8f675..18d2c385 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -257,7 +257,7 @@ com.github.searls jasmine-maven-plugin - 1.3.1.4 + 1.3.1.5 @@ -266,12 +266,16 @@ + - libraries/mootools/mootools-core-1.4.5-full-nocompat.js - header.js + libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js + header.js + libraries/jquery/jquery-2.1.0.min.js + Events.js static/test/*.js diff --git a/mindplot/src/test/javascript/EventsTestSuite.js b/mindplot/src/test/javascript/EventsTestSuite.js new file mode 100644 index 00000000..6f2c548b --- /dev/null +++ b/mindplot/src/test/javascript/EventsTestSuite.js @@ -0,0 +1,43 @@ +var TestClass = new Class({ + Extends: mindplot.Events, + + getEvents: function() { + return this.$events; + }, + + removeEvents: function() { + this.$events = {}; + } +}); + +// Test class and variables +var expectedChangeFn1 = function () {return 'change1';}; +var expectedChangeFn2 = function () {return 'change2';}; +var expectedLoadFn = function() {return 'loaded';}; +var myTestClass = new TestClass(); + + +describe("Events class suite", function() { + + afterEach(function() { + myTestClass.removeEvents(); + }); + + it("addEventTest", function() { + expect(myTestClass.getEvents()).toEqual({}); + myTestClass.addEvent('change', expectedChangeFn1); + expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1]}); + myTestClass.addEvent('change', expectedChangeFn2); + expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1, expectedChangeFn2]}); + myTestClass.addEvent('load', expectedLoadFn); + expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1, expectedChangeFn2], load: [expectedLoadFn]}); + }); + it("removeEventTest", function() { + expect(myTestClass.getEvents()).toEqual({}); + myTestClass.addEvent('change', expectedChangeFn1); + myTestClass.addEvent('change', expectedChangeFn2); + expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1, expectedChangeFn2]}); + myTestClass.removeEvent('change', expectedChangeFn1); + expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn2]}); + }); +});