Skip to content

Commit f7e46c5

Browse files
author
Alain Dumesny
committed
added removeWidget() test cases
1 parent 1c77147 commit f7e46c5

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

spec/gridstack-spec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('gridstack', function() {
1616
' </div>' +
1717
'</div>';
1818
// generic widget with no param
19-
var widgetHTML = '<div class="grid-stack-item"><div class="grid-stack-item-content"> hello </div></div>';
19+
var widgetHTML = '<div class="grid-stack-item" id="item3"><div class="grid-stack-item-content"> hello </div></div>';
2020

2121
beforeEach(function() {
2222
w = window;
@@ -487,6 +487,38 @@ describe('gridstack', function() {
487487
});
488488
});
489489

490+
describe('grid.removeWidget', function() {
491+
beforeEach(function() {
492+
document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
493+
});
494+
afterEach(function() {
495+
document.body.removeChild(document.getElementById('gs-cont'));
496+
});
497+
it('should remove first item (default), then second (true), then third (false)', function() {
498+
$('.grid-stack').gridstack();
499+
var grid = $('.grid-stack').data('gridstack');
500+
expect(grid.grid.nodes.length).toEqual(2);
501+
502+
var el1 = document.getElementById('item1');
503+
expect(el1).not.toBe(null);
504+
grid.removeWidget(el1);
505+
expect(grid.grid.nodes.length).toEqual(1);
506+
expect(document.getElementById('item1')).toBe(null);
507+
expect(document.getElementById('item2')).not.toBe(null);
508+
509+
var el2 = document.getElementById('item2');
510+
grid.removeWidget(el2, true);
511+
expect(grid.grid.nodes.length).toEqual(0);
512+
expect(document.getElementById('item2')).toBe(null);
513+
514+
var el3 = grid.addWidget(widgetHTML);
515+
expect(el3).not.toBe(null);
516+
grid.removeWidget(el3, false);
517+
expect(grid.grid.nodes.length).toEqual(0);
518+
expect(document.getElementById('item3')).not.toBe(null);
519+
});
520+
});
521+
490522
describe('grid method obsolete warnings', function() {
491523
beforeEach(function() {
492524
document.body.insertAdjacentHTML('afterbegin', gridstackHTML);

0 commit comments

Comments
 (0)