1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
define( [
"qunit",
"jquery",
"./helper",
"ui/widgets/resizable"
], function( QUnit, $, testHelper ) {
QUnit.module( "resizable: events" );
QUnit.test( "start", function( assert ) {
assert.expect( 5 );
var count = 0,
handle = ".ui-resizable-se";
$( "#resizable1" ).resizable( {
handles: "all",
start: function( event, ui ) {
assert.equal( ui.size.width, 100, "compare width" );
assert.equal( ui.size.height, 100, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
count++;
}
} );
testHelper.drag( handle, 50, 50 );
assert.equal( count, 1, "start callback should happen exactly once" );
} );
QUnit.test( "resize", function( assert ) {
assert.expect( 9 );
var count = 0,
handle = ".ui-resizable-se";
$( "#resizable1" ).resizable( {
handles: "all",
resize: function( event, ui ) {
if ( count === 0 ) {
assert.equal( ui.size.width, 125, "compare width" );
assert.equal( ui.size.height, 125, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
} else {
assert.equal( ui.size.width, 150, "compare width" );
assert.equal( ui.size.height, 150, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
}
count++;
}
} );
testHelper.drag( handle, 50, 50 );
assert.equal( count, 2, "resize callback should happen exactly once per size adjustment" );
} );
QUnit.test( "resize (min/max dimensions)", function( assert ) {
assert.expect( 5 );
var count = 0,
handle = ".ui-resizable-se";
$( "#resizable1" ).resizable( {
handles: "all",
minWidth: 60,
minHeight: 60,
maxWidth: 100,
maxHeight: 100,
resize: function( event, ui ) {
assert.equal( ui.size.width, 60, "compare width" );
assert.equal( ui.size.height, 60, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
count++;
}
} );
testHelper.drag( handle, -200, -200 );
assert.equal( count, 1, "resize callback should happen exactly once per size adjustment" );
} );
QUnit.test( "resize (containment)", function( assert ) {
assert.expect( 5 );
var count = 0,
handle = ".ui-resizable-se",
container = $( "#resizable1" ).wrap( "<div>" ).parent().css( {
height: "100px",
width: "100px"
} );
$( "#resizable1" ).resizable( {
handles: "all",
containment: container,
resize: function( event, ui ) {
assert.equal( ui.size.width, 10, "compare width" );
assert.equal( ui.size.height, 10, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
count++;
}
} );
// Prove you can't resize outside containment by dragging southeast corner southeast
testHelper.drag( handle, 100, 100 );
// Prove you can't resize outside containment by dragging southeast corner northwest
testHelper.drag( handle, -200, -200 );
assert.equal( count, 1, "resize callback should happen exactly once per size adjustment" );
} );
QUnit.test( "resize (grid)", function( assert ) {
assert.expect( 5 );
var count = 0,
handle = ".ui-resizable-se";
$( "#resizable1" ).resizable( {
handles: "all",
grid: 50,
resize: function( event, ui ) {
assert.equal( ui.size.width, 150, "compare width" );
assert.equal( ui.size.height, 150, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
count++;
}
} );
testHelper.drag( handle, 50, 50 );
assert.equal( count, 1, "resize callback should happen exactly once per grid-unit size adjustment" );
} );
QUnit.test( "resize, custom adjustment", function( assert ) {
assert.expect( 4 );
var handle = ".ui-resizable-se",
element = $( "#resizable1" ).resizable( {
resize: function( event, ui ) {
ui.size.width = 100;
ui.size.height = 200;
ui.position.left = 300;
ui.position.top = 400;
}
} );
testHelper.drag( handle, 50, 50 );
assert.equal( element.width(), 100, "resize event can control width" );
assert.equal( element.height(), 200, "resize event can control height" );
assert.equal( element.position().left, 300, "resize event can control left" );
assert.equal( element.position().top, 400, "resize event can control top" );
} );
QUnit.test( "stop", function( assert ) {
assert.expect( 5 );
var count = 0,
handle = ".ui-resizable-se";
$( "#resizable1" ).resizable( {
handles: "all",
stop: function( event, ui ) {
assert.equal( ui.size.width, 150, "compare width" );
assert.equal( ui.size.height, 150, "compare height" );
assert.equal( ui.originalSize.width, 100, "compare original width" );
assert.equal( ui.originalSize.height, 100, "compare original height" );
count++;
}
} );
testHelper.drag( handle, 50, 50 );
assert.equal( count, 1, "stop callback should happen exactly once" );
} );
QUnit.test( "resize (containment) works with parent with negative offset", function( assert ) {
assert.expect( 1 );
var widthBefore, widthAfter,
handle = ".ui-resizable-e",
target = $( "#resizable1" ),
absoluteContainer = target.wrap( "<div />" ).parent(),
fixedContainer = absoluteContainer.wrap( "<div />" ).parent(),
increaseWidthBy = 50;
// Position fixed container in window top left
fixedContainer.css( {
width: 400,
height: 100,
position: "fixed",
top: 0,
left: 0
} );
// Position absolute container within fixed on slightly outside window
absoluteContainer.css( {
width: 400,
height: 100,
position: "absolute",
top: 0,
left: -50
} );
// Set up resizable to be contained within absolute container
target.resizable( {
handles: "all",
containment: "parent"
} ).css( {
width: 300
} );
widthBefore = target.width();
testHelper.drag( handle, increaseWidthBy, 0 );
widthAfter = target.width();
assert.equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" );
} );
} );
|