Skip to content

Commit 1c47380

Browse files
committed
Added first tests
1 parent d3d00d5 commit 1c47380

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

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+
});

0 commit comments

Comments
 (0)