@@ -15,6 +15,8 @@ describe('gridstack', function() {
1515 ' </div>' +
1616 ' </div>' +
1717 '</div>' ;
18+ // generic widget with no param
19+ var widgetHTML = '<div class="grid-stack-item"><div class="grid-stack-item-content"> hello </div></div>' ;
1820
1921 beforeEach ( function ( ) {
2022 w = window ;
@@ -31,13 +33,12 @@ describe('gridstack', function() {
3133
3234 it ( 'should set default params correctly.' , function ( ) {
3335 e . call ( w ) ;
34- expect ( w . column ) . toBeUndefined ( ) ;
36+ expect ( w . column ) . toEqual ( 12 ) ;
3537 expect ( w . float ) . toBe ( false ) ;
3638 expect ( w . maxRow ) . toEqual ( 0 ) ;
3739 expect ( w . nodes ) . toEqual ( [ ] ) ;
3840 expect ( typeof w . onchange ) . toBe ( 'function' ) ;
39- expect ( w . _updateCounter ) . toEqual ( 0 ) ;
40- expect ( w . _float ) . toEqual ( w . float ) ;
41+ expect ( w . _batchMode ) . toBeFalse ( ) ;
4142 } ) ;
4243
4344 it ( 'should set params correctly.' , function ( ) {
@@ -50,23 +51,19 @@ describe('gridstack', function() {
5051 expect ( w . maxRow ) . toEqual ( 2 ) ;
5152 expect ( w . nodes ) . toEqual ( arr ) ;
5253 expect ( w . onchange ) . toEqual ( fkt ) ;
53- expect ( w . _updateCounter ) . toEqual ( 0 ) ;
54- expect ( w . _float ) . toEqual ( w . float ) ;
54+ expect ( w . _batchMode ) . toBeFalse ( ) ;
5555 } ) ;
56-
57-
5856 } ) ;
5957
6058 describe ( 'batch update' , function ( ) {
6159
62- it ( 'should set float and counter when calling batchUpdate.' , function ( ) {
60+ it ( 'should set float and batchMode when calling batchUpdate.' , function ( ) {
6361 e . prototype . batchUpdate . call ( w ) ;
6462 expect ( w . float ) . toBe ( true ) ;
65- expect ( w . _updateCounter ) . toEqual ( 1 ) ;
63+ expect ( w . _batchMode ) . toBeTrue ( ) ;
6664 } ) ;
6765
6866 //test commit function
69-
7067 } ) ;
7168
7269 describe ( 'sorting of nodes' , function ( ) {
@@ -914,7 +911,6 @@ describe('gridstack', function() {
914911 it ( 'should keep all widget options the same (autoPosition off' , function ( ) {
915912 $ ( '.grid-stack' ) . gridstack ( { float : true } ) ;
916913 var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
917- var widgetHTML = '<div class="grid-stack-item"><div class="grid-stack-item-content"></div></div>' ;
918914 var widget = grid . addWidget ( widgetHTML , 6 , 7 , 2 , 3 , false , 1 , 4 , 2 , 5 , 'coolWidget' ) ;
919915 var $widget = $ ( widget ) ;
920916 expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 6 ) ;
@@ -927,6 +923,35 @@ describe('gridstack', function() {
927923 expect ( parseInt ( $widget . attr ( 'data-gs-min-height' ) , 10 ) ) . toBe ( 2 ) ;
928924 expect ( parseInt ( $widget . attr ( 'data-gs-max-height' ) , 10 ) ) . toBe ( 5 ) ;
929925 expect ( $widget . attr ( 'data-gs-id' ) ) . toBe ( 'coolWidget' ) ;
926+
927+ // should move widget to top with float=false
928+ expect ( grid . float ( ) ) . toBe ( true ) ;
929+ grid . float ( false ) ;
930+ expect ( grid . float ( ) ) . toBe ( false ) ;
931+ expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 6 ) ;
932+ expect ( parseInt ( $widget . attr ( 'data-gs-y' ) , 10 ) ) . toBe ( 4 ) ; // <--- from 7 to 4 below second original widget
933+ expect ( parseInt ( $widget . attr ( 'data-gs-width' ) , 10 ) ) . toBe ( 2 ) ;
934+ expect ( parseInt ( $widget . attr ( 'data-gs-height' ) , 10 ) ) . toBe ( 3 ) ;
935+ expect ( $widget . attr ( 'data-gs-auto-position' ) ) . toBe ( undefined ) ;
936+ expect ( parseInt ( $widget . attr ( 'data-gs-min-width' ) , 10 ) ) . toBe ( 1 ) ;
937+ expect ( parseInt ( $widget . attr ( 'data-gs-max-width' ) , 10 ) ) . toBe ( 4 ) ;
938+ expect ( parseInt ( $widget . attr ( 'data-gs-min-height' ) , 10 ) ) . toBe ( 2 ) ;
939+ expect ( parseInt ( $widget . attr ( 'data-gs-max-height' ) , 10 ) ) . toBe ( 5 ) ;
940+ expect ( $widget . attr ( 'data-gs-id' ) ) . toBe ( 'coolWidget' ) ;
941+
942+ // should not move again (no-op)
943+ grid . float ( true ) ;
944+ expect ( grid . float ( ) ) . toBe ( true ) ;
945+ expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 6 ) ;
946+ expect ( parseInt ( $widget . attr ( 'data-gs-y' ) , 10 ) ) . toBe ( 4 ) ;
947+ expect ( parseInt ( $widget . attr ( 'data-gs-width' ) , 10 ) ) . toBe ( 2 ) ;
948+ expect ( parseInt ( $widget . attr ( 'data-gs-height' ) , 10 ) ) . toBe ( 3 ) ;
949+ expect ( $widget . attr ( 'data-gs-auto-position' ) ) . toBe ( undefined ) ;
950+ expect ( parseInt ( $widget . attr ( 'data-gs-min-width' ) , 10 ) ) . toBe ( 1 ) ;
951+ expect ( parseInt ( $widget . attr ( 'data-gs-max-width' ) , 10 ) ) . toBe ( 4 ) ;
952+ expect ( parseInt ( $widget . attr ( 'data-gs-min-height' ) , 10 ) ) . toBe ( 2 ) ;
953+ expect ( parseInt ( $widget . attr ( 'data-gs-max-height' ) , 10 ) ) . toBe ( 5 ) ;
954+ expect ( $widget . attr ( 'data-gs-id' ) ) . toBe ( 'coolWidget' ) ;
930955 } ) ;
931956 } ) ;
932957
@@ -940,7 +965,6 @@ describe('gridstack', function() {
940965 it ( 'should change x, y coordinates for widgets.' , function ( ) {
941966 $ ( '.grid-stack' ) . gridstack ( { float : true } ) ;
942967 var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
943- var widgetHTML = '<div class="grid-stack-item"><div class="grid-stack-item-content"></div></div>' ;
944968 var widget = grid . addWidget ( widgetHTML , 9 , 7 , 2 , 3 , true ) ;
945969 var $widget = $ ( widget ) ;
946970 expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . not . toBe ( 9 ) ;
@@ -958,7 +982,6 @@ describe('gridstack', function() {
958982 it ( 'should keep all widget options the same (autoPosition off)' , function ( ) {
959983 $ ( '.grid-stack' ) . gridstack ( ) ;
960984 var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
961- var widgetHTML = '<div class="grid-stack-item"><div class="grid-stack-item-content"></div></div>' ;
962985 var widget = grid . addWidget ( widgetHTML , { x : 8 , height : 2 , id : 'optionWidget' } ) ;
963986 var $widget = $ ( widget ) ;
964987 expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 8 ) ;
@@ -983,7 +1006,6 @@ describe('gridstack', function() {
9831006 it ( 'should use default' , function ( ) {
9841007 $ ( '.grid-stack' ) . gridstack ( ) ;
9851008 var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
986- var widgetHTML = '<div class="grid-stack-item"><div class="grid-stack-item-content"></div></div>' ;
9871009 var widget = grid . addWidget ( widgetHTML , { x : 'foo' , height : null , width : 'bar' , height : '' } ) ;
9881010 var $widget = $ ( widget ) ;
9891011 expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 8 ) ;
@@ -1011,6 +1033,28 @@ describe('gridstack', function() {
10111033 } ) ;
10121034 } ) ;
10131035
1036+ describe ( 'method float()' , function ( ) {
1037+ beforeEach ( function ( ) {
1038+ document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
1039+ } ) ;
1040+ afterEach ( function ( ) {
1041+ document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
1042+ } ) ;
1043+ it ( 'should match true/false only' , function ( ) {
1044+ $ ( '.grid-stack' ) . gridstack ( { float : true } ) ;
1045+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
1046+ expect ( grid . float ( ) ) . toBe ( true ) ;
1047+ grid . float ( 0 ) ;
1048+ expect ( grid . float ( ) ) . toBe ( false ) ;
1049+ grid . float ( null ) ;
1050+ expect ( grid . float ( ) ) . toBe ( false ) ;
1051+ grid . float ( undefined ) ;
1052+ expect ( grid . float ( ) ) . toBe ( false ) ;
1053+ grid . float ( false ) ;
1054+ expect ( grid . float ( ) ) . toBe ( false ) ;
1055+ } ) ;
1056+ } ) ;
1057+
10141058 describe ( 'grid.destroy' , function ( ) {
10151059 beforeEach ( function ( ) {
10161060 document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
0 commit comments