From 0202fa92570e667814a26768b52c482b7ebaf24c Mon Sep 17 00:00:00 2001 From: Kevin Dietrich Date: Fri, 19 Feb 2016 17:23:10 +0100 Subject: [PATCH 1/5] Updated .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3c3629e64..bb93d680a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +bower_components \ No newline at end of file From b9b52603e8713d1264c30bc0aaf3736206eca5fe Mon Sep 17 00:00:00 2001 From: Kevin Dietrich Date: Fri, 19 Feb 2016 17:23:22 +0100 Subject: [PATCH 2/5] Setup unit tests --- karma.conf.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 8 +++++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 karma.conf.js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..c0dc84a90 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,73 @@ +// Karma configuration +// Generated on Thu Feb 18 2016 22:00:23 GMT+0100 (CET) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + 'bower_components/jquery/dist/jquery.min.js', + 'bower_components/jquery-ui/jquery-ui.min.js', + 'bower_components/lodash/dist/lodash.min.js', + 'src/gridstack.js', + 'spec/*-spec.js' + ], + + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} diff --git a/package.json b/package.json index c2f81dea3..1af5493f7 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,13 @@ "grunt-contrib-copy": "^0.8.2", "grunt-contrib-cssmin": "^0.14.0", "grunt-contrib-uglify": "^0.10.1", + "grunt-doctoc": "^0.1.1", "grunt-sass": "^1.1.0", - "grunt-doctoc": "^0.1.1" + "jasmine-core": "^2.4.1", + "karma": "^0.13.21", + "karma-jasmine": "^0.3.7", + "karma-phantomjs-launcher": "^1.0.0", + "phantomjs": "^2.1.3", + "phantomjs-prebuilt": "^2.1.4" } } From 504b0ad4ac0fb5d2c7e28011c8b4f00b23c3237c Mon Sep 17 00:00:00 2001 From: Kevin Dietrich Date: Fri, 19 Feb 2016 19:58:32 +0100 Subject: [PATCH 3/5] Added coverage --- .gitignore | 3 ++- karma.conf.js | 3 ++- package.json | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bb93d680a..186552a71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -bower_components \ No newline at end of file +bower_components +coverage \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index c0dc84a90..c59bab7e2 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -31,13 +31,14 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { + 'src/gridstack.js': ['coverage'] }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], + reporters: ['progress', 'coverage'], // web server port diff --git a/package.json b/package.json index 1af5493f7..2e6c4a541 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "grunt-sass": "^1.1.0", "jasmine-core": "^2.4.1", "karma": "^0.13.21", + "karma-coverage": "^0.5.3", "karma-jasmine": "^0.3.7", "karma-phantomjs-launcher": "^1.0.0", "phantomjs": "^2.1.3", From d3d00d563f5b76d4ba3b29f1864636198514975b Mon Sep 17 00:00:00 2001 From: Kevin Dietrich Date: Fri, 19 Feb 2016 19:59:58 +0100 Subject: [PATCH 4/5] Set engine for testing purposes --- src/gridstack.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gridstack.js b/src/gridstack.js index 73bdd2852..c4d140a0e 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -1290,6 +1290,7 @@ scope.GridStackUI = GridStack; scope.GridStackUI.Utils = Utils; + scope.GridStackUI.Engine = GridStackEngine; $.fn.gridstack = function(opts) { return this.each(function() { From 1c4738084ab4c8a065f8c3cf4dbf43c4e4505720 Mon Sep 17 00:00:00 2001 From: Kevin Dietrich Date: Mon, 22 Feb 2016 19:06:54 +0100 Subject: [PATCH 5/5] Added first tests --- spec/gridstack-spec.js | 92 ++++++++++++++++++++++++++++++++++++++++++ spec/utils-spec.js | 43 ++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 spec/gridstack-spec.js create mode 100644 spec/utils-spec.js diff --git a/spec/gridstack-spec.js b/spec/gridstack-spec.js new file mode 100644 index 000000000..84026fe0a --- /dev/null +++ b/spec/gridstack-spec.js @@ -0,0 +1,92 @@ +describe('gridstack', function() { + 'use strict'; + + var e; + var w; + + beforeEach(function() { + w = window; + e = w.GridStackUI.Engine; + }); + + describe('setup of gridstack', function() { + + it('should exist setup function.', function() { + + expect(e).not.toBeNull(); + expect(typeof e).toBe('function'); + }); + + it('should set default params correctly.', function() { + e.call(w); + expect(w.width).toBeUndefined(); + expect(w.float).toBe(false); + expect(w.height).toEqual(0); + expect(w.nodes).toEqual([]); + expect(typeof w.onchange).toBe('function'); + expect(w._updateCounter).toEqual(0); + expect(w._float).toEqual(w.float); + }); + + it('should set params correctly.', function() { + var fkt = function() { }; + var arr = [1,2,3]; + + e.call(w, 1, fkt, true, 2, arr); + expect(w.width).toEqual(1); + expect(w.float).toBe(true); + expect(w.height).toEqual(2); + expect(w.nodes).toEqual(arr); + expect(w.onchange).toEqual(fkt); + expect(w._updateCounter).toEqual(0); + expect(w._float).toEqual(w.float); + }); + + + }); + + describe('batch update', function() { + + it('should set float and counter when calling batchUpdate.', function() { + e.prototype.batchUpdate.call(w); + expect(w.float).toBe(true); + expect(w._updateCounter).toEqual(1); + }); + + //test commit function + + }); + + describe('sorting of nodes', function() { + + it('should sort ascending with width.', function() { + w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}]; + e.prototype._sortNodes.call(w, 1); + expect(w.nodes).toEqual([{x: 0, y: 1}, {x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}]); + }); + + it('should sort descending with width.', function() { + w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}]; + e.prototype._sortNodes.call(w, -1); + expect(w.nodes).toEqual([{x: 9, y: 0}, {x: 4, y: 4}, {x: 7, y: 0}, {x: 0, y: 1}]); + }); + + it('should sort ascending without width.', function() { + w.width = false; + w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}]; + e.prototype._sortNodes.call(w, 1); + expect(w.nodes).toEqual([{x: 0, y: 1}, {x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}]); + }); + + it('should sort descending without width.', function() { + w.width = false; + w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}]; + e.prototype._sortNodes.call(w, -1); + expect(w.nodes).toEqual([{x: 9, y: 0}, {x: 4, y: 4}, {x: 7, y: 0}, {x: 0, y: 1}]); + }); + + }); + + + +}); \ No newline at end of file diff --git a/spec/utils-spec.js b/spec/utils-spec.js new file mode 100644 index 000000000..45b17dc31 --- /dev/null +++ b/spec/utils-spec.js @@ -0,0 +1,43 @@ +describe('gridstack utils', function() { + 'use strict'; + + var utils; + + beforeEach(function() { + utils = window.GridStackUI.Utils; + }); + + describe('setup of utils', function() { + + it('should set gridstack utils.', function() { + expect(utils).not.toBeNull(); + expect(typeof utils).toBe('object'); + }); + + }); + + describe('test toBool', function() { + + it('should return booleans.', function() { + expect(utils.toBool(true)).toEqual(true); + expect(utils.toBool(false)).toEqual(false); + }); + + it('should work with integer.', function() { + expect(utils.toBool(1)).toEqual(true); + expect(utils.toBool(0)).toEqual(false); + }); + + it('should work with Strings.', function() { + expect(utils.toBool('')).toEqual(false); + expect(utils.toBool('0')).toEqual(false); + expect(utils.toBool('no')).toEqual(false); + expect(utils.toBool('false')).toEqual(false); + expect(utils.toBool('yes')).toEqual(true); + expect(utils.toBool('yadda')).toEqual(true); + }); + + }); + + +}); \ No newline at end of file