@@ -7,16 +7,16 @@ describe('gridstack', function() {
7
7
var gridstackHTML =
8
8
'<div style="width: 992px; height: 800px" id="gs-cont">' +
9
9
' <div class="grid-stack">' +
10
- ' <div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="4" data-gs-height="2">' +
10
+ ' <div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="4" data-gs-height="2" id="item1" >' +
11
11
' <div class="grid-stack-item-content"></div>' +
12
12
' </div>' +
13
- ' <div class="grid-stack-item" data-gs-x="4" data-gs-y="0" data-gs-width="4" data-gs-height="4">' +
13
+ ' <div class="grid-stack-item" data-gs-x="4" data-gs-y="0" data-gs-width="4" data-gs-height="4" id="item2" >' +
14
14
' <div class="grid-stack-item-content"></div>' +
15
15
' </div>' +
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 ;
@@ -457,6 +457,68 @@ describe('gridstack', function() {
457
457
} ) ;
458
458
} ) ;
459
459
460
+ describe ( 'grid.removeAll' , function ( ) {
461
+ beforeEach ( function ( ) {
462
+ document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
463
+ } ) ;
464
+ afterEach ( function ( ) {
465
+ document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
466
+ } ) ;
467
+ it ( 'should remove all children by default' , function ( ) {
468
+ $ ( '.grid-stack' ) . gridstack ( ) ;
469
+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
470
+ grid . removeAll ( ) ;
471
+ expect ( grid . grid . nodes ) . toEqual ( [ ] ) ;
472
+ expect ( document . getElementById ( 'item1' ) ) . toBe ( null ) ;
473
+ } ) ;
474
+ it ( 'should remove all children' , function ( ) {
475
+ $ ( '.grid-stack' ) . gridstack ( ) ;
476
+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
477
+ grid . removeAll ( true ) ;
478
+ expect ( grid . grid . nodes ) . toEqual ( [ ] ) ;
479
+ expect ( document . getElementById ( 'item1' ) ) . toBe ( null ) ;
480
+ } ) ;
481
+ it ( 'should remove gridstack part, leave DOM behind' , function ( ) {
482
+ $ ( '.grid-stack' ) . gridstack ( ) ;
483
+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
484
+ grid . removeAll ( false ) ;
485
+ expect ( grid . grid . nodes ) . toEqual ( [ ] ) ;
486
+ expect ( document . getElementById ( 'item1' ) ) . not . toBe ( null ) ;
487
+ } ) ;
488
+ } ) ;
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
+
460
522
describe ( 'grid method obsolete warnings' , function ( ) {
461
523
beforeEach ( function ( ) {
462
524
document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
0 commit comments