Skip to content

Commit 6dd4bf7

Browse files
committed
Changed test cases to use a generic function.
1 parent daee00b commit 6dd4bf7

File tree

2 files changed

+25
-120
lines changed

2 files changed

+25
-120
lines changed

tests/unit/resizable/core.js

Lines changed: 13 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -246,107 +246,28 @@ QUnit.test( "nested resizable", function( assert ) {
246246

247247
QUnit.test( "Resizable with scrollbars and box-sizing: border-box", function( assert ) {
248248
assert.expect( 4 );
249-
250-
$( "<style> * { box-sizing: border-box; } </style>" ).appendTo( "#qunit-fixture" );
251-
252-
// Both scrollbars
253-
var elementContent = $( "<div>" )
254-
.css( {
255-
width: "200px",
256-
height: "200px",
257-
padding: "10px",
258-
border: "5px",
259-
borderStyle: "solid",
260-
margin: "20px"
261-
} )
262-
.appendTo( "#resizable1" ),
263-
element = $( "#resizable1" ).css( "overflow", "auto" ).resizable(),
264-
handle = ".ui-resizable-se";
265-
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)" );
269-
270-
// Single (vertical) scrollbar.
271-
elementContent.css( "width", "50px" );
272-
testHelper.drag( handle, 10, 10 );
273-
assert.equal( element.width(), 120, "element width (only vertical scrollbar)" );
274-
assert.equal( element.height(), 120, "element height (only vertical scrollbar)" );
249+
testResizableWithBoxSizing( assert, true, false );
275250
} );
276251

277252
QUnit.test( "Resizable with scrollbars and box-sizing: content-box", function( assert ) {
278253
assert.expect( 4 );
279-
280-
$( "<style> * { box-sizing: content-box; } </style>" ).appendTo( "#qunit-fixture" );
281-
282-
// Both scrollbars
283-
var widthBefore, heightBefore,
284-
elementContent = $( "<div>" )
285-
.css( {
286-
width: "200px",
287-
height: "200px",
288-
padding: "10px",
289-
border: "5px",
290-
borderStyle: "solid",
291-
margin: "20px"
292-
} )
293-
.appendTo( "#resizable1" ),
294-
element = $( "#resizable1" ).css( "overflow", "auto" ).resizable(),
295-
handle = ".ui-resizable-se";
296-
297-
// In some browsers scrollbar may change element size (when "box-sizing: content-box")
298-
widthBefore = element.innerWidth();
299-
heightBefore = element.innerHeight();
300-
301-
testHelper.drag( handle, 10, 10 );
302-
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 10, "element width (both scrollbars)" );
303-
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 10, "element height (both scrollbars)" );
304-
305-
// Single (vertical) scrollbar.
306-
elementContent.css( "width", "50px" );
307-
308-
testHelper.drag( handle, 10, 10 );
309-
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 20, "element width (only vertical scrollbar)" );
310-
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 20, "element height (only vertical scrollbar)" );
254+
testResizableWithBoxSizing( assert, false, false );
311255
} );
312256

313257
QUnit.test( "Resizable with scrollbars, a transform and box-sizing: border-box", function( assert ) {
314258
assert.expect( 4 );
315-
316-
$( "<style> * { box-sizing: border-box; } </style>" ).appendTo( "#qunit-fixture" );
317-
318-
// Both scrollbars
319-
var elementContent = $( "<div>" )
320-
.css( {
321-
width: "200px",
322-
height: "200px",
323-
padding: "10px",
324-
border: "5px",
325-
borderStyle: "solid",
326-
margin: "20px"
327-
} )
328-
.appendTo( "#resizable1" ),
329-
element = $( "#resizable1" ).css( { overflow: "auto", transform: "scale(1.5)" } ).resizable(),
330-
handle = ".ui-resizable-se";
331-
332-
testHelper.drag( handle, 10, 10 );
333-
assert.equal( element.width(), 110, "element width (both scrollbars)" );
334-
assert.equal( element.height(), 110, "element height (both scrollbars)" );
335-
336-
// Single (vertical) scrollbar.
337-
elementContent.css( "width", "50px" );
338-
testHelper.drag( handle, 10, 10 );
339-
assert.equal( element.width(), 120, "element width (only vertical scrollbar)" );
340-
assert.equal( element.height(), 120, "element height (only vertical scrollbar)" );
259+
testResizableWithBoxSizing( assert, true, true );
341260
} );
342261

343262
QUnit.test( "Resizable with scrollbars, a transform and box-sizing: content-box", function( assert ) {
344263
assert.expect( 4 );
264+
testResizableWithBoxSizing( assert, false, true );
265+
} );
345266

346-
$( "<style> * { box-sizing: content-box; } </style>" ).appendTo( "#qunit-fixture" );
347-
348-
// Both scrollbars
267+
function testResizableWithBoxSizing( assert, isBorderBox, applyScaleTransform ) {
349268
var widthBefore, heightBefore,
269+
cssBoxSizing = isBorderBox ? "border-box" : "content-box",
270+
cssTrasform = applyScaleTransform ? "scale(1.5)" : "",
350271
elementContent = $( "<div>" )
351272
.css( {
352273
width: "200px",
@@ -357,13 +278,16 @@ QUnit.test( "Resizable with scrollbars, a transform and box-sizing: content-box"
357278
margin: "20px"
358279
} )
359280
.appendTo( "#resizable1" ),
360-
element = $( "#resizable1" ).css( { overflow: "auto", transform: "scale(1.5)" } ).resizable(),
281+
element = $( "#resizable1" ).css( { overflow: "auto", transform: cssTrasform } ).resizable(),
361282
handle = ".ui-resizable-se";
362283

284+
$( "<style> * { box-sizing: " + cssBoxSizing + "; } </style>" ).appendTo( "#qunit-fixture" );
285+
363286
// In some browsers scrollbar may change element size (when "box-sizing: content-box")
364287
widthBefore = element.innerWidth();
365288
heightBefore = element.innerHeight();
366289

290+
// Both scrollbars
367291
testHelper.drag( handle, 10, 10 );
368292
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 10, "element width (both scrollbars)" );
369293
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 10, "element height (both scrollbars)" );
@@ -374,6 +298,6 @@ QUnit.test( "Resizable with scrollbars, a transform and box-sizing: content-box"
374298
testHelper.drag( handle, 10, 10 );
375299
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 20, "element width (only vertical scrollbar)" );
376300
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 20, "element height (only vertical scrollbar)" );
377-
} );
301+
}
378302

379303
} );

tests/unit/resizable/options.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -568,39 +568,18 @@ QUnit.test( "alsoResize with box-sizing: border-box", function( assert ) {
568568

569569
QUnit.test( "alsoResize with scrollbars and box-sizing: border-box", function( assert ) {
570570
assert.expect( 4 );
571-
572-
$( "<style> * { box-sizing: border-box; } </style>" ).appendTo( "#qunit-fixture" );
573-
574-
var other = $( "<div>" )
575-
.css( {
576-
width: "150px",
577-
height: "150px",
578-
padding: "10px",
579-
border: "5px",
580-
borderStyle: "solid",
581-
margin: "25px",
582-
overflow: "scroll"
583-
} )
584-
.appendTo( "#qunit-fixture" ),
585-
element = $( "#resizable1" ).resizable( {
586-
alsoResize: other
587-
} ),
588-
handle = ".ui-resizable-se";
589-
590-
testHelper.drag( handle, 80, 80 );
591-
592-
assert.equal( element.width(), 180, "resizable width" );
593-
assert.equal( parseFloat( other.css( "width" ) ), 230, "alsoResize width" );
594-
assert.equal( element.height(), 180, "resizable height" );
595-
assert.equal( parseFloat( other.css( "height" ) ), 230, "alsoResize height" );
571+
testAlsoResizeWithBoxSizing( assert, true );
596572
} );
597573

598574
QUnit.test( "alsoResize with scrollbars and box-sizing: content-box", function( assert ) {
599575
assert.expect( 4 );
576+
testAlsoResizeWithBoxSizing( assert, false );
577+
} );
600578

601-
$( "<style> * { box-sizing: content-box; } </style>" ).appendTo( "#qunit-fixture" );
602-
603-
var other = $( "<div>" )
579+
function testAlsoResizeWithBoxSizing( assert, isBorderBox ) {
580+
var widthBefore, heightBefore,
581+
cssBoxSizing = isBorderBox ? "border-box" : "content-box",
582+
other = $( "<div>" )
604583
.css( {
605584
width: "150px",
606585
height: "150px",
@@ -616,16 +595,18 @@ QUnit.test( "alsoResize with scrollbars and box-sizing: content-box", function(
616595
} ),
617596
handle = ".ui-resizable-se";
618597

598+
$( "<style> * { box-sizing: " + cssBoxSizing + "; } </style>" ).appendTo( "#qunit-fixture" );
599+
619600
// In some browsers scrollbar may change element computed size.
620-
var widthBefore = other.innerWidth();
621-
var heightBefore = other.innerHeight();
601+
widthBefore = other.innerWidth();
602+
heightBefore = other.innerHeight();
622603

623604
testHelper.drag( handle, 80, 80 );
624605

625606
assert.equal( element.width(), 180, "resizable width" );
626607
assert.equal( parseFloat( other.innerWidth() ), widthBefore + 80, "alsoResize width" );
627608
assert.equal( element.height(), 180, "resizable height" );
628609
assert.equal( parseFloat( other.innerHeight() ), heightBefore + 80, "alsoResize height" );
629-
} );
610+
}
630611

631612
} );

0 commit comments

Comments
 (0)