@@ -7,6 +7,10 @@ describe('regression >', function() {
77 let findEl = function ( id : string ) : GridItemHTMLElement {
88 return grid . engine . nodes . find ( n => n . id === id ) ! . el ! ;
99 } ;
10+ let findSubEl = function ( id : string , index = 0 ) : GridItemHTMLElement {
11+ return grid . engine . nodes [ index ] . subGrid ?. engine . nodes . find ( n => n . id === id ) ! . el ! ;
12+ } ;
13+
1014
1115 // empty grid
1216 let gridstackEmptyHTML =
@@ -55,4 +59,51 @@ describe('regression >', function() {
5559 expect ( parseInt ( el2 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
5660 } ) ;
5761 } ) ;
62+
63+ describe ( '2865 nested grid resize >' , function ( ) {
64+ beforeEach ( function ( ) {
65+ document . body . insertAdjacentHTML ( 'afterbegin' , gridstackEmptyHTML ) ;
66+ } ) ;
67+ afterEach ( function ( ) {
68+ document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
69+ } ) ;
70+ it ( '' , function ( ) {
71+ let children : GridStackWidget [ ] = [ { } , { } , { } ] ;
72+ let items : GridStackWidget [ ] = [
73+ { x : 0 , y : 0 , w :3 , h :3 , sizeToContent : true , subGridOpts : { children, column : 'auto' } }
74+ ] ;
75+ let count = 0 ;
76+ [ ...items , ...children ] . forEach ( n => n . id = String ( count ++ ) ) ;
77+ grid = GridStack . init ( { cellHeight : 70 , margin : 5 , children : items } ) ;
78+
79+ let nested = findEl ( '0' ) ;
80+ let el1 = findSubEl ( '1' ) ;
81+ let el2 = findSubEl ( '2' ) ;
82+ let el3 = findSubEl ( '3' ) ;
83+ expect ( parseInt ( nested . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 0 ) ;
84+ expect ( parseInt ( nested . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
85+ expect ( parseInt ( nested . getAttribute ( 'gs-w' ) , 10 ) ) . toBe ( 3 ) ;
86+ expect ( nested . getAttribute ( 'gs-h' ) ) . toBe ( null ) ; // sizeToContent 3 -> 1 which is null
87+ expect ( parseInt ( el1 . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 0 ) ;
88+ expect ( parseInt ( el1 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
89+ expect ( parseInt ( el2 . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 1 ) ;
90+ expect ( parseInt ( el2 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
91+ expect ( parseInt ( el3 . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 2 ) ;
92+ expect ( parseInt ( el3 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
93+
94+ // now resize the nested grid to 2 -> should reflow el3
95+ grid . update ( nested , { w :2 } ) ;
96+ expect ( parseInt ( nested . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 0 ) ;
97+ expect ( parseInt ( nested . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
98+ expect ( parseInt ( nested . getAttribute ( 'gs-w' ) , 10 ) ) . toBe ( 2 ) ;
99+ expect ( nested . getAttribute ( 'gs-h' ) ) . toBe ( null ) ; // sizeToContent not called until some delay
100+ expect ( parseInt ( el1 . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 0 ) ;
101+ expect ( parseInt ( el1 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
102+ expect ( parseInt ( el2 . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 1 ) ;
103+ expect ( parseInt ( el2 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 0 ) ;
104+ // 3rd item pushed to next row
105+ expect ( parseInt ( el3 . getAttribute ( 'gs-x' ) , 10 ) ) . toBe ( 0 ) ;
106+ expect ( parseInt ( el3 . getAttribute ( 'gs-y' ) , 10 ) ) . toBe ( 1 ) ;
107+ } ) ;
108+ } ) ;
58109} ) ;
0 commit comments