GridStackEngine testing
This commit is contained in:
parent
6cd5084a23
commit
00d780adfa
1 changed files with 121 additions and 2 deletions
|
|
@ -3,15 +3,19 @@ describe('gridstack engine', function() {
|
|||
|
||||
var e;
|
||||
var w;
|
||||
var engine;
|
||||
|
||||
beforeEach(function() {
|
||||
w = window;
|
||||
e = w.GridStackUI.Engine;
|
||||
engine = new w.GridStackUI.Engine(12);
|
||||
});
|
||||
|
||||
describe('test constructor', function() {
|
||||
var engine;
|
||||
|
||||
beforeAll(function() {
|
||||
engine = new GridStackUI.Engine(12);
|
||||
})
|
||||
|
||||
it('should be setup properly', function() {
|
||||
expect(engine.width).toEqual(12);
|
||||
expect(engine.float).toEqual(false);
|
||||
|
|
@ -21,6 +25,12 @@ describe('gridstack engine', function() {
|
|||
});
|
||||
|
||||
describe('test _prepareNode', function() {
|
||||
var engine;
|
||||
|
||||
beforeAll(function() {
|
||||
engine = new GridStackUI.Engine(12);
|
||||
})
|
||||
|
||||
it('should prepare a node', function() {
|
||||
expect(engine._prepareNode({}, false)).toEqual(jasmine.objectContaining({x: 0, y: 0, width: 1, height: 1}));
|
||||
expect(engine._prepareNode({x: 10}, false)).toEqual(jasmine.objectContaining({x: 10, y: 0, width: 1, height: 1}));
|
||||
|
|
@ -38,4 +48,113 @@ describe('gridstack engine', function() {
|
|||
expect(engine._prepareNode({x: 4, width: 10}, true)).toEqual(jasmine.objectContaining({x: 4, y: 0, width: 8, height: 1}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('test isAreaEmpty', function() {
|
||||
var engine;
|
||||
|
||||
beforeAll(function() {
|
||||
engine = new GridStackUI.Engine(12, null, true);
|
||||
engine.nodes = [
|
||||
engine._prepareNode({x: 3, y: 2, width: 3, height: 2})
|
||||
];
|
||||
})
|
||||
|
||||
it('should be true', function() {
|
||||
expect(engine.isAreaEmpty(0, 0, 3, 2)).toEqual(true);
|
||||
expect(engine.isAreaEmpty(3, 4, 3, 2)).toEqual(true);
|
||||
});
|
||||
|
||||
it('should be false', function() {
|
||||
expect(engine.isAreaEmpty(1, 1, 3, 2)).toEqual(false);
|
||||
expect(engine.isAreaEmpty(2, 3, 3, 2)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('test cleanNodes/getDirtyNodes', function() {
|
||||
var engine;
|
||||
|
||||
beforeAll(function() {
|
||||
engine = new GridStackUI.Engine(12, null, true);
|
||||
engine.nodes = [
|
||||
engine._prepareNode({x: 0, y: 0, width: 1, height: 1, idx: 1, _dirty: true}),
|
||||
engine._prepareNode({x: 3, y: 2, width: 3, height: 2, idx: 2, _dirty: true}),
|
||||
engine._prepareNode({x: 3, y: 7, width: 3, height: 2, idx: 3})
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
engine._updateCounter = 0;
|
||||
});
|
||||
|
||||
it('should return all dirty nodes', function() {
|
||||
var nodes = engine.getDirtyNodes();
|
||||
|
||||
expect(nodes.length).toEqual(2);
|
||||
expect(nodes[0].idx).toEqual(1);
|
||||
expect(nodes[1].idx).toEqual(2);
|
||||
});
|
||||
|
||||
it('should\'n clean nodes if _updateCounter > 0', function() {
|
||||
engine._updateCounter = 1;
|
||||
engine.cleanNodes();
|
||||
|
||||
expect(engine.getDirtyNodes().length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should clean all dirty nodes', function() {
|
||||
engine.cleanNodes();
|
||||
|
||||
expect(engine.getDirtyNodes().length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('test _notify', function() {
|
||||
var engine;
|
||||
var spy;
|
||||
|
||||
beforeEach(function() {
|
||||
spy = {
|
||||
callback: function () {}
|
||||
}
|
||||
spyOn(spy, 'callback');
|
||||
|
||||
engine = new GridStackUI.Engine(12, spy.callback, true);
|
||||
|
||||
engine.nodes = [
|
||||
engine._prepareNode({x: 0, y: 0, width: 1, height: 1, idx: 1, _dirty: true}),
|
||||
engine._prepareNode({x: 3, y: 2, width: 3, height: 2, idx: 2, _dirty: true}),
|
||||
engine._prepareNode({x: 3, y: 7, width: 3, height: 2, idx: 3})
|
||||
];
|
||||
});
|
||||
|
||||
it('should\'n be called if _updateCounter > 0', function() {
|
||||
engine._updateCounter = 1;
|
||||
engine._notify();
|
||||
|
||||
expect(spy.callback).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should by called with dirty nodes', function() {
|
||||
engine._notify();
|
||||
|
||||
expect(spy.callback).toHaveBeenCalledWith([
|
||||
engine.nodes[0],
|
||||
engine.nodes[1]
|
||||
]);
|
||||
});
|
||||
|
||||
it('should by called with extra passed dirty nodes', function() {
|
||||
var n1 = {idx: -1},
|
||||
n2 = {idx: -2};
|
||||
|
||||
engine._notify(n1, n2);
|
||||
|
||||
expect(spy.callback).toHaveBeenCalledWith([
|
||||
n1,
|
||||
n2,
|
||||
engine.nodes[0],
|
||||
engine.nodes[1]
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue