Skip to content

Commit 0b94492

Browse files
committed
More tests (including all obsolete options), clean up unnecessary code.
1 parent eedf6d5 commit 0b94492

File tree

2 files changed

+272
-5
lines changed

2 files changed

+272
-5
lines changed

spec/gridstack-spec.js

Lines changed: 272 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ describe('gridstack', function() {
361361
});
362362
});
363363

364-
describe('grid obsolete warnings', function() {
364+
describe('grid method obsolete warnings', function() {
365365
beforeEach(function() {
366366
document.body.insertAdjacentHTML(
367367
'afterbegin', gridstackHTML);
@@ -631,4 +631,275 @@ describe('gridstack', function() {
631631
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Function `_trigger_change_event` is deprecated as of v0.2.5 and has been replaced with `_triggerChangeEvent`. It will be **completely** removed in v1.0.');
632632
});
633633
});
634+
635+
describe('grid opts obsolete warnings', function() {
636+
beforeEach(function() {
637+
document.body.insertAdjacentHTML(
638+
'afterbegin', gridstackHTML);
639+
});
640+
afterEach(function() {
641+
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
642+
});
643+
it('should log a warning if handle_class is set.', function() {
644+
console.warn = jasmine.createSpy('log');
645+
var options = {
646+
cellHeight: 80,
647+
verticalMargin: 10,
648+
handle_class: 'grid-stack-header'
649+
650+
};
651+
$('.grid-stack').gridstack(options);
652+
var grid = $('.grid-stack').data('gridstack');
653+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `handle_class` is deprecated as of v0.2.5 and has been replaced with `handleClass`. It will be **completely** removed in v1.0.');
654+
});
655+
it('should log a warning if item_class is set.', function() {
656+
console.warn = jasmine.createSpy('log');
657+
var options = {
658+
cellHeight: 80,
659+
verticalMargin: 10,
660+
item_class: 'grid-stack-item'
661+
662+
};
663+
$('.grid-stack').gridstack(options);
664+
var grid = $('.grid-stack').data('gridstack');
665+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `item_class` is deprecated as of v0.2.5 and has been replaced with `itemClass`. It will be **completely** removed in v1.0.');
666+
});
667+
it('should log a warning if placeholder_class is set.', function() {
668+
console.warn = jasmine.createSpy('log');
669+
var options = {
670+
cellHeight: 80,
671+
verticalMargin: 10,
672+
placeholder_class: 'grid-stack-placeholder'
673+
674+
};
675+
$('.grid-stack').gridstack(options);
676+
var grid = $('.grid-stack').data('gridstack');
677+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `placeholder_class` is deprecated as of v0.2.5 and has been replaced with `placeholderClass`. It will be **completely** removed in v1.0.');
678+
});
679+
it('should log a warning if placeholder_text is set.', function() {
680+
console.warn = jasmine.createSpy('log');
681+
var options = {
682+
cellHeight: 80,
683+
verticalMargin: 10,
684+
placeholder_text: 'placeholder'
685+
686+
};
687+
$('.grid-stack').gridstack(options);
688+
var grid = $('.grid-stack').data('gridstack');
689+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `placeholder_text` is deprecated as of v0.2.5 and has been replaced with `placeholderText`. It will be **completely** removed in v1.0.');
690+
});
691+
it('should log a warning if cell_height is set.', function() {
692+
console.warn = jasmine.createSpy('log');
693+
var options = {
694+
cell_height: 80,
695+
verticalMargin: 10
696+
697+
};
698+
$('.grid-stack').gridstack(options);
699+
var grid = $('.grid-stack').data('gridstack');
700+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `cell_height` is deprecated as of v0.2.5 and has been replaced with `cellHeight`. It will be **completely** removed in v1.0.');
701+
});
702+
it('should log a warning if vertical_margin is set.', function() {
703+
console.warn = jasmine.createSpy('log');
704+
var options = {
705+
cellHeight: 80,
706+
vertical_margin: 10
707+
708+
};
709+
$('.grid-stack').gridstack(options);
710+
var grid = $('.grid-stack').data('gridstack');
711+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `vertical_margin` is deprecated as of v0.2.5 and has been replaced with `verticalMargin`. It will be **completely** removed in v1.0.');
712+
});
713+
it('should log a warning if min_width is set.', function() {
714+
console.warn = jasmine.createSpy('log');
715+
var options = {
716+
cellHeight: 80,
717+
verticalMargin: 10,
718+
min_width: 2
719+
720+
};
721+
$('.grid-stack').gridstack(options);
722+
var grid = $('.grid-stack').data('gridstack');
723+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `min_width` is deprecated as of v0.2.5 and has been replaced with `minWidth`. It will be **completely** removed in v1.0.');
724+
});
725+
it('should log a warning if static_grid is set.', function() {
726+
console.warn = jasmine.createSpy('log');
727+
var options = {
728+
cellHeight: 80,
729+
verticalMargin: 10,
730+
static_grid: false
731+
732+
};
733+
$('.grid-stack').gridstack(options);
734+
var grid = $('.grid-stack').data('gridstack');
735+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `static_grid` is deprecated as of v0.2.5 and has been replaced with `staticGrid`. It will be **completely** removed in v1.0.');
736+
});
737+
it('should log a warning if is_nested is set.', function() {
738+
console.warn = jasmine.createSpy('log');
739+
var options = {
740+
cellHeight: 80,
741+
verticalMargin: 10,
742+
is_nested: false
743+
744+
};
745+
$('.grid-stack').gridstack(options);
746+
var grid = $('.grid-stack').data('gridstack');
747+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `is_nested` is deprecated as of v0.2.5 and has been replaced with `isNested`. It will be **completely** removed in v1.0.');
748+
});
749+
it('should log a warning if always_show_resize_handle is set.', function() {
750+
console.warn = jasmine.createSpy('log');
751+
var options = {
752+
cellHeight: 80,
753+
verticalMargin: 10,
754+
always_show_resize_handle: false
755+
756+
};
757+
$('.grid-stack').gridstack(options);
758+
var grid = $('.grid-stack').data('gridstack');
759+
expect(console.warn).toHaveBeenCalledWith('gridstack.js: Option `always_show_resize_handle` is deprecated as of v0.2.5 and has been replaced with `alwaysShowResizeHandle`. It will be **completely** removed in v1.0.');
760+
});
761+
});
762+
763+
describe('grid method _packNodes with float', function() {
764+
beforeEach(function() {
765+
document.body.insertAdjacentHTML(
766+
'afterbegin', gridstackHTML);
767+
});
768+
afterEach(function() {
769+
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
770+
});
771+
it('should allow same x, y coordinates for widgets.', function() {
772+
var options = {
773+
cellHeight: 80,
774+
verticalMargin: 10,
775+
float: true
776+
};
777+
$('.grid-stack').gridstack(options);
778+
var grid = $('.grid-stack').data('gridstack');
779+
var items = $('.grid-stack-item');
780+
var $el;
781+
var $oldEl;
782+
for (var i = 0; i < items.length; i++) {
783+
$el = $(grid.addWidget(items[i]));
784+
$oldEl = $(items[i]);
785+
expect(parseInt($oldEl.attr('data-gs-x'), 10)).toBe(parseInt($el.attr('data-gs-x'), 10));
786+
expect(parseInt($oldEl.attr('data-gs-y'), 10)).toBe(parseInt($el.attr('data-gs-y'), 10));
787+
}
788+
});
789+
it('should not allow same x, y coordinates for widgets.', function() {
790+
var options = {
791+
cellHeight: 80,
792+
verticalMargin: 10
793+
};
794+
$('.grid-stack').gridstack(options);
795+
var grid = $('.grid-stack').data('gridstack');
796+
var items = $('.grid-stack-item');
797+
var $el;
798+
var $oldEl;
799+
var newY;
800+
var oldY;
801+
for (var i = 0; i < items.length; i++) {
802+
$oldEl = $.extend(true, {}, $(items[i]));
803+
newY = parseInt($oldEl.attr('data-gs-y'), 10) + 5;
804+
$oldEl.attr('data-gs-y', newY);
805+
$el = $(grid.addWidget($oldEl));
806+
expect(parseInt($el.attr('data-gs-y'), 10)).not.toBe(newY);
807+
}
808+
});
809+
});
810+
811+
describe('grid method addWidget with all parameters', function() {
812+
beforeEach(function() {
813+
document.body.insertAdjacentHTML(
814+
'afterbegin', gridstackHTML);
815+
});
816+
afterEach(function() {
817+
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
818+
});
819+
it('should allow same x, y coordinates for widgets.', function() {
820+
var options = {
821+
cellHeight: 80,
822+
verticalMargin: 10,
823+
float: true
824+
};
825+
$('.grid-stack').gridstack(options);
826+
var grid = $('.grid-stack').data('gridstack');
827+
var widgetHTML =
828+
' <div class="grid-stack-item">' +
829+
' <div class="grid-stack-item-content"></div>' +
830+
' </div>';
831+
var widget = grid.addWidget(widgetHTML, 6, 7, 2, 3, false, 1, 4, 2, 5, 'coolWidget');
832+
var $widget = $(widget);
833+
expect(parseInt($widget.attr('data-gs-x'), 10)).toBe(6);
834+
expect(parseInt($widget.attr('data-gs-y'), 10)).toBe(7);
835+
expect(parseInt($widget.attr('data-gs-width'), 10)).toBe(2);
836+
expect(parseInt($widget.attr('data-gs-height'), 10)).toBe(3);
837+
expect($widget.attr('data-gs-auto-position')).toBe(undefined);
838+
expect(parseInt($widget.attr('data-gs-min-width'), 10)).toBe(1);
839+
expect(parseInt($widget.attr('data-gs-max-width'), 10)).toBe(4);
840+
expect(parseInt($widget.attr('data-gs-min-height'), 10)).toBe(2);
841+
expect(parseInt($widget.attr('data-gs-max-height'), 10)).toBe(5);
842+
expect($widget.attr('data-gs-id')).toBe('coolWidget');
843+
});
844+
});
845+
846+
describe('grid method addWidget with autoPosition true', function() {
847+
beforeEach(function() {
848+
document.body.insertAdjacentHTML(
849+
'afterbegin', gridstackHTML);
850+
});
851+
afterEach(function() {
852+
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
853+
});
854+
it('should change x, y coordinates for widgets.', function() {
855+
var options = {
856+
cellHeight: 80,
857+
verticalMargin: 10
858+
};
859+
$('.grid-stack').gridstack(options);
860+
var grid = $('.grid-stack').data('gridstack');
861+
var widgetHTML =
862+
' <div class="grid-stack-item">' +
863+
' <div class="grid-stack-item-content"></div>' +
864+
' </div>';
865+
var widget = grid.addWidget(widgetHTML, 9, 7, 2, 3, true);
866+
var $widget = $(widget);
867+
expect(parseInt($widget.attr('data-gs-x'), 10)).not.toBe(6);
868+
expect(parseInt($widget.attr('data-gs-y'), 10)).not.toBe(7);
869+
});
870+
});
871+
872+
describe('grid.destroy()', function() {
873+
beforeEach(function() {
874+
document.body.insertAdjacentHTML(
875+
'afterbegin', gridstackHTML);
876+
});
877+
afterEach(function() {
878+
//document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
879+
});
880+
it('should cleanup gridstack', function() {
881+
var options = {
882+
cellHeight: 80,
883+
verticalMargin: 10
884+
};
885+
$('.grid-stack').gridstack(options);
886+
var grid = $('.grid-stack').data('gridstack');
887+
grid.destroy();
888+
expect($('.grid-stack').length).toBe(0);
889+
expect(grid.grid).toBe(null);
890+
});
891+
it('should cleanup gridstack but leave elements', function() {
892+
var options = {
893+
cellHeight: 80,
894+
verticalMargin: 10
895+
};
896+
$('.grid-stack').gridstack(options);
897+
var grid = $('.grid-stack').data('gridstack');
898+
grid.destroy(false);
899+
//console.log(grid.grid.nodes);
900+
expect($('.grid-stack').length).toBe(1);
901+
expect($('.grid-stack-item').length).toBe(2);
902+
expect(grid.grid).toBe(null);
903+
});
904+
});
634905
});

src/gridstack.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,6 @@
477477
opts.placeholderText = opts.placeholder_text;
478478
obsoleteOpts('placeholder_text', 'placeholderText');
479479
}
480-
if (typeof opts.item_class !== 'undefined') {
481-
opts.itemClass = opts.item_class;
482-
obsoleteOpts('item_class', 'itemClass');
483-
}
484480
if (typeof opts.cell_height !== 'undefined') {
485481
opts.cellHeight = opts.cell_height;
486482
obsoleteOpts('cell_height', 'cellHeight');

0 commit comments

Comments
 (0)