@@ -157,4 +157,76 @@ describe('gridstack engine', function() {
157157 ] ) ;
158158 } ) ;
159159 } ) ;
160+
161+ describe ( 'test _packNodes' , function ( ) {
162+ describe ( 'using not float mode' , function ( ) {
163+ var engine ;
164+
165+ var findNode = function ( engine , id ) {
166+ return _ . find ( engine . nodes , function ( i ) { return i . _id === id } ) ;
167+ }
168+
169+ beforeEach ( function ( ) {
170+ engine = new GridStackUI . Engine ( 12 , null , false ) ;
171+ } ) ;
172+
173+ it ( 'shouldn\'t pack one node with y coord eq 0' , function ( ) {
174+ engine . nodes = [
175+ { x : 0 , y : 0 , width : 1 , height : 1 , _id : 1 } ,
176+ ] ;
177+
178+ engine . _packNodes ( ) ;
179+
180+ expect ( findNode ( engine , 1 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 0 , width : 1 , height : 1 } ) ) ;
181+ expect ( findNode ( engine , 1 ) . _dirty ) . toBeFalsy ( ) ;
182+ } ) ;
183+
184+ it ( 'should pack one node correctly' , function ( ) {
185+ engine . nodes = [
186+ { x : 0 , y : 1 , width : 1 , height : 1 , _id : 1 } ,
187+ ] ;
188+
189+ engine . _packNodes ( ) ;
190+
191+ expect ( findNode ( engine , 1 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 0 , width : 1 , height : 1 , _dirty : true } ) ) ;
192+ } ) ;
193+
194+ it ( 'should pack nodes correctly' , function ( ) {
195+ engine . nodes = [
196+ { x : 0 , y : 1 , width : 1 , height : 1 , _id : 1 } ,
197+ { x : 0 , y : 5 , width : 1 , height : 1 , _id : 2 } ,
198+ ] ;
199+
200+ engine . _packNodes ( ) ;
201+
202+ expect ( findNode ( engine , 1 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 0 , width : 1 , height : 1 , _dirty : true } ) ) ;
203+ expect ( findNode ( engine , 2 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 1 , width : 1 , height : 1 , _dirty : true } ) ) ;
204+ } ) ;
205+
206+ it ( 'should pack nodes correctly' , function ( ) {
207+ engine . nodes = [
208+ { x : 0 , y : 5 , width : 1 , height : 1 , _id : 1 } ,
209+ { x : 0 , y : 1 , width : 1 , height : 1 , _id : 2 } ,
210+ ] ;
211+
212+ engine . _packNodes ( ) ;
213+
214+ expect ( findNode ( engine , 2 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 0 , width : 1 , height : 1 , _dirty : true } ) ) ;
215+ expect ( findNode ( engine , 1 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 1 , width : 1 , height : 1 , _dirty : true } ) ) ;
216+ } ) ;
217+
218+ it ( 'should respect locked nodes' , function ( ) {
219+ engine . nodes = [
220+ { x : 0 , y : 1 , width : 1 , height : 1 , _id : 1 , locked : true } ,
221+ { x : 0 , y : 5 , width : 1 , height : 1 , _id : 2 } ,
222+ ] ;
223+
224+ engine . _packNodes ( ) ;
225+
226+ expect ( findNode ( engine , 1 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 1 , width : 1 , height : 1 } ) ) ;
227+ expect ( findNode ( engine , 1 ) . _dirty ) . toBeFalsy ( ) ;
228+ expect ( findNode ( engine , 2 ) ) . toEqual ( jasmine . objectContaining ( { x : 0 , y : 2 , width : 1 , height : 1 , _dirty : true } ) ) ;
229+ } ) ;
230+ } ) ;
231+ } ) ;
160232} ) ;
0 commit comments