Skip to content

Commit f990b71

Browse files
committed
Merge commit 'fcae35661fc549c831d1b596272f35aead0c618c'
2 parents 78058d9 + fcae356 commit f990b71

File tree

7 files changed

+222
-1
lines changed

7 files changed

+222
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
bower_components
3+
coverage

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
gridstack.js
22
============
33

4+
[![Build Status](https://travis-ci.org/troolee/gridstack.js.svg?branch=master)](https://travis-ci.org/troolee/gridstack.js)
5+
46
gridstack.js is a jQuery plugin for widget layout. This is drag-and-drop multi-column grid. It allows you to build
57
draggable responsive bootstrap v3 friendly layouts. It also works great with [knockout.js](http://knockoutjs.com), [angular.js](https://angularjs.org) and touch devices.
68

karma.conf.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Karma configuration
2+
// Generated on Thu Feb 18 2016 22:00:23 GMT+0100 (CET)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['jasmine'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
'bower_components/jquery/dist/jquery.min.js',
19+
'bower_components/jquery-ui/jquery-ui.min.js',
20+
'bower_components/lodash/dist/lodash.min.js',
21+
'src/gridstack.js',
22+
'spec/*-spec.js'
23+
],
24+
25+
26+
// list of files to exclude
27+
exclude: [
28+
],
29+
30+
31+
// preprocess matching files before serving them to the browser
32+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
33+
preprocessors: {
34+
'src/gridstack.js': ['coverage']
35+
},
36+
37+
38+
// test results reporter to use
39+
// possible values: 'dots', 'progress'
40+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
41+
reporters: ['progress', 'coverage'],
42+
43+
44+
// web server port
45+
port: 9876,
46+
47+
48+
// enable / disable colors in the output (reporters and logs)
49+
colors: true,
50+
51+
52+
// level of logging
53+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
54+
logLevel: config.LOG_INFO,
55+
56+
57+
// enable / disable watching file and executing tests whenever any file changes
58+
autoWatch: true,
59+
60+
61+
// start these browsers
62+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
63+
browsers: ['PhantomJS'],
64+
65+
66+
// Continuous Integration mode
67+
// if true, Karma captures browsers, runs the tests and exits
68+
singleRun: false,
69+
70+
// Concurrency level
71+
// how many browser should be started simultaneous
72+
concurrency: Infinity
73+
})
74+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@
2626
"grunt-contrib-cssmin": "^0.14.0",
2727
"grunt-contrib-jshint": "^1.0.0",
2828
"grunt-contrib-uglify": "^0.10.1",
29-
"grunt-contrib-watch": "^0.6.1",
3029
"grunt-doctoc": "^0.1.1",
3130
"grunt-sass": "^1.1.0",
31+
"jasmine-core": "^2.4.1",
32+
"karma": "^0.13.21",
33+
"karma-coverage": "^0.5.3",
34+
"karma-jasmine": "^0.3.7",
35+
"karma-phantomjs-launcher": "^1.0.0",
36+
"phantomjs": "^2.1.3",
37+
"phantomjs-prebuilt": "^2.1.4",
38+
"grunt-contrib-watch": "^0.6.1",
3239
"grunt-jscs": "^2.7.0"
3340
}
3441
}

spec/gridstack-spec.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
describe('gridstack', function() {
2+
'use strict';
3+
4+
var e;
5+
var w;
6+
7+
beforeEach(function() {
8+
w = window;
9+
e = w.GridStackUI.Engine;
10+
});
11+
12+
describe('setup of gridstack', function() {
13+
14+
it('should exist setup function.', function() {
15+
16+
expect(e).not.toBeNull();
17+
expect(typeof e).toBe('function');
18+
});
19+
20+
it('should set default params correctly.', function() {
21+
e.call(w);
22+
expect(w.width).toBeUndefined();
23+
expect(w.float).toBe(false);
24+
expect(w.height).toEqual(0);
25+
expect(w.nodes).toEqual([]);
26+
expect(typeof w.onchange).toBe('function');
27+
expect(w._updateCounter).toEqual(0);
28+
expect(w._float).toEqual(w.float);
29+
});
30+
31+
it('should set params correctly.', function() {
32+
var fkt = function() { };
33+
var arr = [1,2,3];
34+
35+
e.call(w, 1, fkt, true, 2, arr);
36+
expect(w.width).toEqual(1);
37+
expect(w.float).toBe(true);
38+
expect(w.height).toEqual(2);
39+
expect(w.nodes).toEqual(arr);
40+
expect(w.onchange).toEqual(fkt);
41+
expect(w._updateCounter).toEqual(0);
42+
expect(w._float).toEqual(w.float);
43+
});
44+
45+
46+
});
47+
48+
describe('batch update', function() {
49+
50+
it('should set float and counter when calling batchUpdate.', function() {
51+
e.prototype.batchUpdate.call(w);
52+
expect(w.float).toBe(true);
53+
expect(w._updateCounter).toEqual(1);
54+
});
55+
56+
//test commit function
57+
58+
});
59+
60+
describe('sorting of nodes', function() {
61+
62+
it('should sort ascending with width.', function() {
63+
w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}];
64+
e.prototype._sortNodes.call(w, 1);
65+
expect(w.nodes).toEqual([{x: 0, y: 1}, {x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}]);
66+
});
67+
68+
it('should sort descending with width.', function() {
69+
w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}];
70+
e.prototype._sortNodes.call(w, -1);
71+
expect(w.nodes).toEqual([{x: 9, y: 0}, {x: 4, y: 4}, {x: 7, y: 0}, {x: 0, y: 1}]);
72+
});
73+
74+
it('should sort ascending without width.', function() {
75+
w.width = false;
76+
w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}];
77+
e.prototype._sortNodes.call(w, 1);
78+
expect(w.nodes).toEqual([{x: 0, y: 1}, {x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}]);
79+
});
80+
81+
it('should sort descending without width.', function() {
82+
w.width = false;
83+
w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}];
84+
e.prototype._sortNodes.call(w, -1);
85+
expect(w.nodes).toEqual([{x: 9, y: 0}, {x: 4, y: 4}, {x: 7, y: 0}, {x: 0, y: 1}]);
86+
});
87+
88+
});
89+
90+
91+
92+
});

spec/utils-spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
describe('gridstack utils', function() {
2+
'use strict';
3+
4+
var utils;
5+
6+
beforeEach(function() {
7+
utils = window.GridStackUI.Utils;
8+
});
9+
10+
describe('setup of utils', function() {
11+
12+
it('should set gridstack utils.', function() {
13+
expect(utils).not.toBeNull();
14+
expect(typeof utils).toBe('object');
15+
});
16+
17+
});
18+
19+
describe('test toBool', function() {
20+
21+
it('should return booleans.', function() {
22+
expect(utils.toBool(true)).toEqual(true);
23+
expect(utils.toBool(false)).toEqual(false);
24+
});
25+
26+
it('should work with integer.', function() {
27+
expect(utils.toBool(1)).toEqual(true);
28+
expect(utils.toBool(0)).toEqual(false);
29+
});
30+
31+
it('should work with Strings.', function() {
32+
expect(utils.toBool('')).toEqual(false);
33+
expect(utils.toBool('0')).toEqual(false);
34+
expect(utils.toBool('no')).toEqual(false);
35+
expect(utils.toBool('false')).toEqual(false);
36+
expect(utils.toBool('yes')).toEqual(true);
37+
expect(utils.toBool('yadda')).toEqual(true);
38+
});
39+
40+
});
41+
42+
43+
});

src/gridstack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@
14501450
scope.GridStackUI = GridStack;
14511451

14521452
scope.GridStackUI.Utils = Utils;
1453+
scope.GridStackUI.Engine = GridStackEngine;
14531454

14541455
$.fn.gridstack = function(opts) {
14551456
return this.each(function() {

0 commit comments

Comments
 (0)