Skip to content

Commit 673b069

Browse files
committed
Fixed and improved tests
1 parent 37bcb36 commit 673b069

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

tests/unit/resizable/core.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -245,56 +245,72 @@ QUnit.test( "nested resizable", function( assert ) {
245245
} );
246246

247247
QUnit.test( "Resizable with scrollbars and box-sizing: border-box", function( assert ) {
248-
assert.expect( 2 );
248+
assert.expect( 4 );
249+
250+
var style = $( "<style> * { box-sizing: border-box; } </style>" ).appendTo( "head" );
249251

252+
//Both scrollbars
250253
var elementContent = $( "<div>" )
251254
.css( {
252-
width: 50,
253-
height: 200,
254-
padding: 10,
255-
border: 5,
256-
borderStyle: "solid"
255+
width: "200px",
256+
height: "200px",
257+
padding: "10px",
258+
border: "5px",
259+
borderStyle: "solid",
260+
margin: "20px"
257261
} )
258262
.appendTo( "#resizable1" ),
259-
element = $( "#resizable1" ).css( { overflow: "auto" } ).resizable(),
263+
element = $( "#resizable1" ).css( "overflow", "auto" ).resizable(),
260264
handle = ".ui-resizable-se";
261265

262-
$( "*" ).css( "box-sizing", "border-box" );
266+
testHelper.drag( handle, 10, 10 );
267+
assert.equal( element.width(), 110, "element width (both scrollbars)" );
268+
assert.equal( element.height(), 110, "element height (both scrollbars)" );
263269

270+
//Single (vertical) scrollbar.
271+
elementContent.css( "width", "50px" );
264272
testHelper.drag( handle, 10, 10 );
265-
assert.equal( element.width(), 110, "element width" );
266-
assert.equal( element.height(), 110, "element height" );
273+
assert.equal( element.width(), 120, "element width (only vertical scrollbar)" );
274+
assert.equal( element.height(), 120, "element height (only vertical scrollbar)" );
267275

268-
elementContent.remove();
276+
style.remove();
269277
} );
270278

271279
QUnit.test( "Resizable with scrollbars and box-sizing: content-box", function( assert ) {
272-
assert.expect( 2 );
280+
assert.expect( 4 );
281+
282+
var style = $( "<style> * { box-sizing: content-box; } </style>" ).appendTo( "head" );
273283

284+
//Both scrollbars
274285
var elementContent = $( "<div>" )
275286
.css( {
276-
width: 50,
277-
height: 200,
278-
padding: 10,
279-
border: 5,
280-
borderStyle: "solid"
287+
width: "200px",
288+
height: "200px",
289+
padding: "10px",
290+
border: "5px",
291+
borderStyle: "solid",
292+
margin: "20px"
281293
} )
282294
.appendTo( "#resizable1" ),
283-
element = $( "#resizable1" ).css( { overflow: "auto" } ).resizable(),
295+
element = $( "#resizable1" ).css( "overflow", "auto" ).resizable(),
284296
handle = ".ui-resizable-se";
285297

286-
$( "*" ).css( "box-sizing", "content-box" );
287-
288298
// In some browsers scrollbar may change element size (when "box-sizing: content-box")
289299
var widthBefore = element.innerWidth();
290300
var heightBefore = element.innerHeight();
291301

292302
testHelper.drag( handle, 10, 10 );
303+
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 10, "element width (both scrollbars)" );
304+
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 10, "element height (both scrollbars)" );
293305

294-
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 10, "element width" );
295-
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 10, "element height" );
306+
//Single (vertical) scrollbar.
307+
elementContent.css( "width", "50px" );
308+
309+
testHelper.drag( handle, 10, 10 );
310+
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 20, "element width (only vertical scrollbar)" );
311+
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 20, "element height (only vertical scrollbar)" );
296312

297-
elementContent.remove();
313+
style.remove();
298314
} );
299315

300316
} );

tests/unit/resizable/options.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,49 +568,56 @@ QUnit.test( "alsoResize with box-sizing: border-box", function( assert ) {
568568
QUnit.test( "alsoResize with scrollbars and box-sizing: border-box", function( assert ) {
569569
assert.expect( 4 );
570570

571+
var style = $( "<style> * { box-sizing: border-box; } </style>" ).appendTo( "head" );
572+
571573
var other = $( "<div>" )
572574
.css( {
573-
width: 150,
574-
height: 150,
575-
padding: 10,
576-
border: 5,
575+
width: "150px",
576+
height: "150px",
577+
padding: "10px",
578+
border: "5px",
577579
borderStyle: "solid",
580+
margin: "25px",
578581
overflow: "scroll"
579582
} )
580-
.appendTo( "body" ),
583+
.appendTo( "#qunit-fixture" ),
581584
element = $( "#resizable1" ).resizable( {
582585
alsoResize: other
583586
} ),
584587
handle = ".ui-resizable-se";
585588

586-
587-
$( "*" ).css( "box-sizing", "border-box" );
588589
testHelper.drag( handle, 80, 80 );
589590

590591
assert.equal( element.width(), 180, "resizable width" );
591592
assert.equal( parseFloat( other.css( "width" ) ), 230, "alsoResize width" );
592593
assert.equal( element.height(), 180, "resizable height" );
593594
assert.equal( parseFloat( other.css( "height" ) ), 230, "alsoResize height" );
595+
596+
style.remove();
594597
} );
595598

596599
QUnit.test( "alsoResize with scrollbars and box-sizing: content-box", function( assert ) {
597600
assert.expect( 4 );
598601

602+
var style = $( "<style> * { box-sizing: content-box; } </style>" ).appendTo( "head" );
603+
599604
var other = $( "<div>" )
600605
.css( {
601-
width: 150,
602-
height: 150,
606+
width: "150px",
607+
height: "150px",
608+
padding: "10px",
609+
border: "5px",
610+
borderStyle: "solid",
611+
margin: "20px",
603612
overflow: "scroll"
604613
} )
605-
.appendTo( "body" ),
614+
.appendTo( "#qunit-fixture" ),
606615
element = $( "#resizable1" ).resizable( {
607616
alsoResize: other
608617
} ),
609618
handle = ".ui-resizable-se";
610619

611-
$( "*" ).css( "box-sizing", "content-box" );
612-
613-
// In some browsers scrollbar may change element size.
620+
// In some browsers scrollbar may change element computed size.
614621
var widthBefore = other.innerWidth();
615622
var heightBefore = other.innerHeight();
616623

@@ -620,6 +627,8 @@ QUnit.test( "alsoResize with scrollbars and box-sizing: content-box", function(
620627
assert.equal( parseFloat( other.innerWidth() ), widthBefore + 80, "alsoResize width" );
621628
assert.equal( element.height(), 180, "resizable height" );
622629
assert.equal( parseFloat( other.innerHeight() ), heightBefore + 80, "alsoResize height" );
630+
631+
style.remove();
623632
} );
624633

625634

0 commit comments

Comments
 (0)