@@ -123,22 +123,38 @@ describe('gridstack', function() {
123
123
afterEach ( function ( ) {
124
124
document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
125
125
} ) ;
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
127
129
let options = {
128
- cellHeight : 80 ,
130
+ cellHeight : cellHeight ,
129
131
margin : 5
130
132
} ;
131
133
let grid = GridStack . init ( options ) ;
132
- let pixel = { top : 500 , left : 200 } ;
134
+ let pixel = { left : 4 * 800 / 12 + rectMargin , top : 5 * cellHeight + rectMargin } ;
133
135
let cell = grid . getCellFromPixel ( pixel ) ;
134
- expect ( cell . x ) . toBe ( 2 ) ;
136
+ expect ( cell . x ) . toBe ( 4 ) ;
135
137
expect ( cell . y ) . toBe ( 5 ) ;
136
138
cell = grid . getCellFromPixel ( pixel , false ) ;
137
- expect ( cell . x ) . toBe ( 2 ) ;
139
+ expect ( cell . x ) . toBe ( 4 ) ;
138
140
expect ( cell . y ) . toBe ( 5 ) ;
139
141
cell = grid . getCellFromPixel ( pixel , true ) ;
140
- expect ( cell . x ) . toBe ( 2 ) ;
142
+ expect ( cell . x ) . toBe ( 4 ) ;
141
143
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 ) ;
142
158
} ) ;
143
159
} ) ;
144
160
@@ -149,14 +165,14 @@ describe('gridstack', function() {
149
165
afterEach ( function ( ) {
150
166
document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
151
167
} ) ;
152
- it ( 'should return 1/12th of container width.' , function ( ) {
168
+ it ( 'should return 1/12th of container width (not rounded anymore) .' , function ( ) {
153
169
let options = {
154
170
cellHeight : 80 ,
155
171
margin : 5 ,
156
172
column : 12
157
173
} ;
158
174
let grid = GridStack . init ( options ) ;
159
- let res = Math . round ( $ ( '.grid-stack' ) . outerWidth ( ) / 12 ) ;
175
+ let res = $ ( '.grid-stack' ) . outerWidth ( ) / 12 ;
160
176
expect ( grid . cellWidth ( ) ) . toBe ( res ) ;
161
177
} ) ;
162
178
it ( 'should return 1/10th of container width.' , function ( ) {
@@ -193,21 +209,21 @@ describe('gridstack', function() {
193
209
expect ( grid . getRow ( ) ) . toBe ( rows ) ;
194
210
195
211
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 ) ;
197
213
198
214
grid . cellHeight ( grid . getCellHeight ( ) ) ; // should be no-op
199
215
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 ) ;
201
217
202
218
cellHeight = 120 ; // should change and CSS actual height
203
219
grid . cellHeight ( cellHeight ) ;
204
220
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 ) ;
206
222
207
223
cellHeight = 20 ; // should change and CSS actual height
208
224
grid . cellHeight ( cellHeight ) ;
209
225
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 ) ;
211
227
} ) ;
212
228
213
229
it ( 'should be square' , function ( ) {
0 commit comments