@@ -16,7 +16,7 @@ describe('gridstack', function() {
16
16
' </div>' +
17
17
'</div>' ;
18
18
// 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>' ;
20
20
21
21
beforeEach ( function ( ) {
22
22
w = window ;
@@ -487,6 +487,38 @@ describe('gridstack', function() {
487
487
} ) ;
488
488
} ) ;
489
489
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
+
490
522
describe ( 'grid method obsolete warnings' , function ( ) {
491
523
beforeEach ( function ( ) {
492
524
document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
0 commit comments