Added first tests
This commit is contained in:
parent
d3d00d563f
commit
1c4738084a
92
spec/gridstack-spec.js
Normal file
92
spec/gridstack-spec.js
Normal file
|
@ -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}]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
43
spec/utils-spec.js
Normal file
43
spec/utils-spec.js
Normal file
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
Reference in a new issue