(function ($) {
  
  var grid;
  var el, offsetBefore, offsetAfter, dragged;
  
  var drag = function(handle, dx, dy) {
    offsetBefore = el.offset();
    $(handle).simulate("drag", {
      dx: dx || 0,
      dy: dy || 0
    });
    dragged = { dx: dx, dy: dy };
    offsetAfter = el.offset();
  }
  
  var moved = function (dx, dy, msg) {
    msg = msg ? msg + "." : "";
    var actual = { left: offsetAfter.left, top: offsetAfter.top };
    var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
    same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
  }
  
  var ROWS = 500, COLS = 10;
  var data = [], row;
  for (var i = 0; i < ROWS; i++) {
    row = { id: "id_" + i };
    for (var j = 0; j < COLS; j++) {
      row["col_" + j] = i + "." + j;
    }
    data.push(row);
  }
  
  var cols = [], col;
  for (var i = 0; i < COLS; i++) {
    cols.push({
      id: "col" + i,
      field: "col_" + i,
      name: "col_" + i
    });
  }
  
  cols[0].minWidth = 70;

  grid = new Slick.Grid("#container", data, cols);
  grid.render();

  module("grid - column resizing");
  
  test("minWidth is respected", function () {
    var firstCol = $("#container .slick-header-column:first");
    firstCol.find(".slick-resizable-handle:first").simulate("drag", { dx: 100,  dy: 0 });
    firstCol.find(".slick-resizable-handle:first").simulate("drag", { dx: -200, dy: 0 });
    equal(firstCol.outerWidth(), 70, "width set to minWidth");
  });
  
  test("onColumnsResized is fired on column resize", function () {
    expect(2);
    grid.onColumnsResized.subscribe(function() { ok(true,"onColumnsResized called") });
    var oldWidth = cols[0].width;
    $("#container .slick-resizable-handle:first").simulate("drag", { dx: 100, dy: 0 });
    equal(cols[0].width, oldWidth+100-1, "columns array is updated");
  });
  
  test("getData should return data", function () {
    equal(grid.getData(), data);
  });
  
})(jQuery);
@@ -9,25 +9,77 @@
 n ($) %7B%0A
+%0A
   
-%0A  var 
+const ROWS = 500, COLS = 10;%0A  var grid, data, cols, $test
 grid;%0A  
@@ -347,23 +347,26 @@
 %0A  %7D
+;
 %0A
-  
 %0A  var 
-moved
+setupData
  = f
@@ -378,347 +378,42 @@
 on (
-dx, dy, msg) %7B%0A    msg = msg ? msg + %22.%22 : %22%22;%0A    var actual = %7B left: offsetAfter.left, top: offsetAfter.top %7D;%0A    var expected = %7B left: offsetBefore.left + dx, top: offsetBefore.top + dy %7D;%0A    same(actual, expected, 'dragged%5B' + dragged.dx + ', ' + dragged.dy + '%5D ' + msg);%0A  %7D%0A  %0A  var ROWS = 500, COLS = 10;%0A  var data = %5B%5D,
+) %7B%0A    data = %5B%5D;%0A    var
  row;%0A
+  
   fo
@@ -447,16 +447,18 @@
 ) %7B%0A    
+  
 row = %7B 
@@ -474,24 +474,26 @@
  + i %7D;%0A    
+ 
+ 
 for (var j =
@@ -509,24 +509,26 @@
 OLS; j++) %7B%0A
+  
       row%5B%22c
@@ -560,14 +560,18 @@
     
+  
 %7D%0A    
+ 
+ 
 data
@@ -586,21 +586,19 @@
 w);%0A
+  
   %7D%0A
+%0A
   
-%0A
   
-var 
 cols
@@ -606,15 +606,25 @@
 = %5B%5D
-,
+;%0A    var
  col;%0A
+  
   fo
@@ -654,24 +654,26 @@
  i++) %7B%0A    
+ 
+ 
 cols.push(%7B%0A
@@ -672,16 +672,18 @@
 .push(%7B%0A
+  
       id
@@ -691,24 +691,26 @@
  %22col%22 + i,%0A
+  
       field:
@@ -728,16 +728,18 @@
 ,%0A      
+  
 name: %22c
@@ -755,19 +755,23 @@
     
+  
 %7D);%0A
+  
   %7D%0A
+%0A
   
-%0A
   co
@@ -791,17 +791,214 @@
 h = 70;%0A
-%0A
+  %7D;%0A%0A  var setupGrid = function() %7B%0A    setupData();%0A    $testgrid = $(%22%3Cdiv id='testgrid'%3E%3C/div%3E%22);%0A    $testgrid.height(200);%0A    $testgrid.width(200);%0A%0A    $(%22#container%22).append($testgrid);%0A%0A  
   grid =
@@ -1015,25 +1015,24 @@
 .Grid(%22#
-container
+testgrid
 %22, data,
@@ -1039,16 +1039,19 @@
  cols);%0A
+%0A  
   grid.r
@@ -1063,47 +1063,186 @@
 ();%0A
-%0A  module(%22grid - column resizing%22);%0A  
+  %7D;%0A%0A  var teardownGrid = function() %7B%0A    $(%22body%22).find($testgrid).remove();%0A  %7D;%0A%0A  module(%22grid - column resizing%22, %7B%0A    setup: setupGrid,%0A    teardown: teardownGrid%0A  %7D);%0A
 %0A  t

refactor grid test setup