Merge pull request #363 from radiolips/tests/frontend-1
Tests/frontend 1
This commit is contained in:
commit
6aae19b80d
2
dist/gridstack.js
vendored
2
dist/gridstack.js
vendored
|
@ -1360,7 +1360,7 @@
|
||||||
|
|
||||||
GridStack.prototype.cellWidth = function() {
|
GridStack.prototype.cellWidth = function() {
|
||||||
var o = this.container.children('.' + this.opts.itemClass).first();
|
var o = this.container.children('.' + this.opts.itemClass).first();
|
||||||
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
|
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
|
||||||
};
|
};
|
||||||
|
|
||||||
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
|
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
|
||||||
|
|
2
dist/gridstack.min.js
vendored
2
dist/gridstack.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/gridstack.min.map
vendored
2
dist/gridstack.min.map
vendored
File diff suppressed because one or more lines are too long
|
@ -3,6 +3,19 @@ describe('gridstack', function() {
|
||||||
|
|
||||||
var e;
|
var e;
|
||||||
var w;
|
var w;
|
||||||
|
var gridstackHTML =
|
||||||
|
'<div class="grid-stack">' +
|
||||||
|
' <div class="grid-stack-item"' +
|
||||||
|
' data-gs-x="0" data-gs-y="0"' +
|
||||||
|
' data-gs-width="4" data-gs-height="2">' +
|
||||||
|
' <div class="grid-stack-item-content"></div>' +
|
||||||
|
' </div>' +
|
||||||
|
' <div class="grid-stack-item"' +
|
||||||
|
' data-gs-x="4" data-gs-y="0"' +
|
||||||
|
' data-gs-width="4" data-gs-height="4">' +
|
||||||
|
' <div class="grid-stack-item-content"></div>' +
|
||||||
|
' </div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
w = window;
|
w = window;
|
||||||
|
@ -87,6 +100,234 @@ describe('gridstack', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('grid.setAnimation', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should add class grid-stack-animate to the container.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
$('.grid-stack').removeClass('grid-stack-animate');
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
grid.setAnimation(true);
|
||||||
|
expect($('.grid-stack').hasClass('grid-stack-animate')).toBe(true);
|
||||||
|
});
|
||||||
|
it('should remove class grid-stack-animate from the container.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
$('.grid-stack').addClass('grid-stack-animate');
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
grid.setAnimation(false);
|
||||||
|
expect($('.grid-stack').hasClass('grid-stack-animate')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('grid._setStaticClass', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should add class grid-stack-static to the container.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10,
|
||||||
|
staticGrid: true
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
$('.grid-stack').removeClass('grid-stack-static');
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
grid._setStaticClass();
|
||||||
|
expect($('.grid-stack').hasClass('grid-stack-static')).toBe(true);
|
||||||
|
});
|
||||||
|
it('should remove class grid-stack-static from the container.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10,
|
||||||
|
staticGrid: false
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
$('.grid-stack').addClass('grid-stack-static');
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
grid._setStaticClass();
|
||||||
|
expect($('.grid-stack').hasClass('grid-stack-static')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
describe('grid.getCellFromPixel', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should return {x: 2, y: 1}.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var pixel = {top: 100, left: 72};
|
||||||
|
var cell = grid.getCellFromPixel(pixel);
|
||||||
|
expect(cell.x).toBe(2);
|
||||||
|
expect(cell.y).toBe(1);
|
||||||
|
});
|
||||||
|
it('should return {x: 2, y: 1}.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var pixel = {top: 100, left: 72};
|
||||||
|
var cell = grid.getCellFromPixel(pixel, false);
|
||||||
|
expect(cell.x).toBe(2);
|
||||||
|
expect(cell.y).toBe(1);
|
||||||
|
});
|
||||||
|
it('should return {x: 2, y: 1}.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var pixel = {top: 100, left: 72};
|
||||||
|
var cell = grid.getCellFromPixel(pixel, true);
|
||||||
|
expect(cell.x).toBe(2);
|
||||||
|
expect(cell.y).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('grid.cellWidth', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should return 96.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
expect(grid.cellWidth()).toBe(96);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('grid.minWidth', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should set data-gs-min-width to 2.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var items = $('.grid-stack-item');
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
grid.minWidth(items[i], 2);
|
||||||
|
}
|
||||||
|
for (var j = 0; j < items.length; j++) {
|
||||||
|
expect(parseInt($(items[j]).attr('data-gs-min-width'), 10)).toBe(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('grid.maxWidth', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should set data-gs-min-width to 2.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var items = $('.grid-stack-item');
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
grid.maxWidth(items[i], 2);
|
||||||
|
}
|
||||||
|
for (var j = 0; j < items.length; j++) {
|
||||||
|
expect(parseInt($(items[j]).attr('data-gs-max-width'), 10)).toBe(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('grid.minHeight', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should set data-gs-min-height to 2.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var items = $('.grid-stack-item');
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
grid.minHeight(items[i], 2);
|
||||||
|
}
|
||||||
|
for (var j = 0; j < items.length; j++) {
|
||||||
|
expect(parseInt($(items[j]).attr('data-gs-min-height'), 10)).toBe(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('grid.maxHeight', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
document.body.insertAdjacentHTML(
|
||||||
|
'afterbegin', gridstackHTML);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
|
||||||
|
});
|
||||||
|
it('should set data-gs-min-height to 2.', function() {
|
||||||
|
var options = {
|
||||||
|
cellHeight: 80,
|
||||||
|
verticalMargin: 10
|
||||||
|
};
|
||||||
|
$('.grid-stack').gridstack(options);
|
||||||
|
var grid = $('.grid-stack').data('gridstack');
|
||||||
|
var items = $('.grid-stack-item');
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
grid.maxHeight(items[i], 2);
|
||||||
|
}
|
||||||
|
for (var j = 0; j < items.length; j++) {
|
||||||
|
expect(parseInt($(items[j]).attr('data-gs-max-height'), 10)).toBe(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1360,7 +1360,7 @@
|
||||||
|
|
||||||
GridStack.prototype.cellWidth = function() {
|
GridStack.prototype.cellWidth = function() {
|
||||||
var o = this.container.children('.' + this.opts.itemClass).first();
|
var o = this.container.children('.' + this.opts.itemClass).first();
|
||||||
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
|
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
|
||||||
};
|
};
|
||||||
|
|
||||||
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
|
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
|
||||||
|
|
Loading…
Reference in a new issue