@@ -8,10 +8,10 @@ describe('gridstack', function() {
88 let gridHTML =
99 '<div class="grid-stack">' +
1010 ' <div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="4" data-gs-height="2" id="item1">' +
11- ' <div class="grid-stack-item-content"></div>' +
11+ ' <div class="grid-stack-item-content">item 1 </div>' +
1212 ' </div>' +
1313 ' <div class="grid-stack-item" data-gs-x="4" data-gs-y="0" data-gs-width="4" data-gs-height="4" id="item2">' +
14- ' <div class="grid-stack-item-content"></div>' +
14+ ' <div class="grid-stack-item-content">item 2 </div>' +
1515 ' </div>' +
1616 '</div>' ;
1717 let gridstackHTML =
@@ -1386,6 +1386,42 @@ describe('gridstack', function() {
13861386 } ) ;
13871387 } ) ;
13881388
1389+ describe ( 'two grids' , function ( ) {
1390+ beforeEach ( function ( ) {
1391+ document . body . insertAdjacentHTML ( 'afterbegin' , gridHTML ) ;
1392+ document . body . insertAdjacentHTML ( 'afterbegin' , gridHTML ) ;
1393+ } ) ;
1394+ afterEach ( function ( ) {
1395+ document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
1396+ } ) ;
1397+ it ( 'should not remove incorrect child' , function ( ) {
1398+ let grids = GridStack . initAll ( ) ;
1399+ expect ( grids . length ) . toBe ( 2 ) ;
1400+ expect ( grids [ 0 ] . engine . nodes . length ) . toBe ( 2 ) ;
1401+ expect ( grids [ 1 ] . engine . nodes . length ) . toBe ( 2 ) ;
1402+ // should do nothing
1403+ grids [ 0 ] . removeWidget ( grids [ 1 ] . engine . nodes [ 0 ] . el ) ;
1404+ expect ( grids [ 0 ] . engine . nodes . length ) . toBe ( 2 ) ;
1405+ expect ( grids [ 0 ] . el . children . length ) . toBe ( 2 ) ;
1406+ expect ( grids [ 1 ] . engine . nodes . length ) . toBe ( 2 ) ;
1407+ expect ( grids [ 1 ] . el . children . length ) . toBe ( 2 ) ;
1408+ // should empty with no errors
1409+ grids [ 1 ] . removeAll ( ) ;
1410+ expect ( grids [ 0 ] . engine . nodes . length ) . toBe ( 2 ) ;
1411+ expect ( grids [ 0 ] . el . children . length ) . toBe ( 2 ) ;
1412+ expect ( grids [ 1 ] . engine . nodes . length ) . toBe ( 0 ) ;
1413+ expect ( grids [ 1 ] . el . children . length ) . toBe ( 0 ) ;
1414+ } ) ;
1415+ it ( 'should remove 1 child' , function ( ) {
1416+ let grids = GridStack . initAll ( ) ;
1417+ grids [ 1 ] . removeWidget ( grids [ 1 ] . engine . nodes [ 0 ] . el ) ;
1418+ expect ( grids [ 0 ] . engine . nodes . length ) . toBe ( 2 ) ;
1419+ expect ( grids [ 0 ] . el . children . length ) . toBe ( 2 ) ;
1420+ expect ( grids [ 1 ] . engine . nodes . length ) . toBe ( 1 ) ;
1421+ expect ( grids [ 1 ] . el . children . length ) . toBe ( 1 ) ;
1422+ } ) ;
1423+ } ) ;
1424+
13891425 describe ( 'ddPlugin option' , function ( ) {
13901426 beforeEach ( function ( ) {
13911427 document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
0 commit comments