@@ -123,22 +123,38 @@ describe('gridstack', function() {
123123 afterEach ( function ( ) {
124124 document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
125125 } ) ;
126- it ( 'should return {x: 2, y: 5}.' , function ( ) {
126+ it ( 'should return {x: 4, y: 5}.' , function ( ) {
127+ let cellHeight = 80 ;
128+ let rectMargin = 8 ; // ??? top/left margin of 8 when calling getBoundingClientRect
127129 let options = {
128- cellHeight : 80 ,
130+ cellHeight : cellHeight ,
129131 margin : 5
130132 } ;
131133 let grid = GridStack . init ( options ) ;
132- let pixel = { top : 500 , left : 200 } ;
134+ let pixel = { left : 4 * 800 / 12 + rectMargin , top : 5 * cellHeight + rectMargin } ;
133135 let cell = grid . getCellFromPixel ( pixel ) ;
134- expect ( cell . x ) . toBe ( 2 ) ;
136+ expect ( cell . x ) . toBe ( 4 ) ;
135137 expect ( cell . y ) . toBe ( 5 ) ;
136138 cell = grid . getCellFromPixel ( pixel , false ) ;
137- expect ( cell . x ) . toBe ( 2 ) ;
139+ expect ( cell . x ) . toBe ( 4 ) ;
138140 expect ( cell . y ) . toBe ( 5 ) ;
139141 cell = grid . getCellFromPixel ( pixel , true ) ;
140- expect ( cell . x ) . toBe ( 2 ) ;
142+ expect ( cell . x ) . toBe ( 4 ) ;
141143 expect ( cell . y ) . toBe ( 5 ) ;
144+ pixel = { left : 4 * 800 / 12 + rectMargin , top : 5 * cellHeight + rectMargin } ;
145+
146+ // now move 1 pixel in and get prev cell (we were on the edge)
147+ pixel . left -- ;
148+ pixel . top -- ;
149+ cell = grid . getCellFromPixel ( pixel ) ;
150+ expect ( cell . x ) . toBe ( 3 ) ;
151+ expect ( cell . y ) . toBe ( 4 ) ;
152+ cell = grid . getCellFromPixel ( pixel , false ) ;
153+ expect ( cell . x ) . toBe ( 3 ) ;
154+ expect ( cell . y ) . toBe ( 4 ) ;
155+ cell = grid . getCellFromPixel ( pixel , true ) ;
156+ expect ( cell . x ) . toBe ( 3 ) ;
157+ expect ( cell . y ) . toBe ( 4 ) ;
142158 } ) ;
143159 } ) ;
144160
@@ -149,14 +165,14 @@ describe('gridstack', function() {
149165 afterEach ( function ( ) {
150166 document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
151167 } ) ;
152- it ( 'should return 1/12th of container width.' , function ( ) {
168+ it ( 'should return 1/12th of container width (not rounded anymore) .' , function ( ) {
153169 let options = {
154170 cellHeight : 80 ,
155171 margin : 5 ,
156172 column : 12
157173 } ;
158174 let grid = GridStack . init ( options ) ;
159- let res = Math . round ( $ ( '.grid-stack' ) . outerWidth ( ) / 12 ) ;
175+ let res = $ ( '.grid-stack' ) . outerWidth ( ) / 12 ;
160176 expect ( grid . cellWidth ( ) ) . toBe ( res ) ;
161177 } ) ;
162178 it ( 'should return 1/10th of container width.' , function ( ) {
@@ -193,21 +209,21 @@ describe('gridstack', function() {
193209 expect ( grid . getRow ( ) ) . toBe ( rows ) ;
194210
195211 expect ( grid . getCellHeight ( ) ) . toBe ( cellHeight ) ;
196- expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight + ( rows - 1 ) * margin ) ;
212+ expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight ) ;
197213
198214 grid . cellHeight ( grid . getCellHeight ( ) ) ; // should be no-op
199215 expect ( grid . getCellHeight ( ) ) . toBe ( cellHeight ) ;
200- expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight + ( rows - 1 ) * margin ) ;
216+ expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight ) ;
201217
202218 cellHeight = 120 ; // should change and CSS actual height
203219 grid . cellHeight ( cellHeight ) ;
204220 expect ( grid . getCellHeight ( ) ) . toBe ( cellHeight ) ;
205- expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight + ( rows - 1 ) * margin ) ;
221+ expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight ) ;
206222
207223 cellHeight = 20 ; // should change and CSS actual height
208224 grid . cellHeight ( cellHeight ) ;
209225 expect ( grid . getCellHeight ( ) ) . toBe ( cellHeight ) ;
210- expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight + ( rows - 1 ) * margin ) ;
226+ expect ( parseInt ( container . css ( 'height' ) ) ) . toBe ( rows * cellHeight ) ;
211227 } ) ;
212228
213229 it ( 'should be square' , function ( ) {
0 commit comments