Merge commit 'd32092c1f0' as 'jquery-ui'

This commit is contained in:
Mark Schouten 2016-08-05 12:47:57 +02:00
commit b23131fdc2
717 changed files with 518330 additions and 0 deletions

View file

@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Button Test Suite</title>
<script src="../../../external/jquery/jquery.js"></script>
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
<link rel="stylesheet" href="../../../external/qunit-composite/qunit-composite.css">
<script src="../../../external/qunit/qunit.js"></script>
<script src="../../../external/qunit-composite/qunit-composite.js"></script>
<script src="../subsuite.js"></script>
<script>
testAllVersions( "button" );
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
</div>
</body>
</html>

View file

@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Button Test Suite</title>
<script src="../../../external/requirejs/require.js"></script>
<script src="../../lib/css.js" data-modules="core button"></script>
<script src="../../lib/bootstrap.js" data-widget="button" data-no-back-compat="true"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<form id="form1">
<div><button id="button">Label</button></div>
<div><button id="button2">label <span>with span</span></button></div>
<div><input id="submit" type="submit" value="Label"></div>
</form>
<form id="form2">
<button id="button-disabled" disabled>Button</button>
<a href="#" id="anchor-button">Anchor Button</a>
</form>
</div>
</body>
</html>

View file

@ -0,0 +1,27 @@
define( [
"lib/common",
"ui/widgets/button"
], function( common ) {
common.testWidget( "button", {
defaults: {
classes: {
"ui-button": "ui-corner-all"
},
disabled: null,
icon: null,
iconPosition: "beginning",
icons: {
primary: null,
secondary: null
},
label: null,
showLabel: true,
text: true,
// Callbacks
create: null
}
} );
} );

22
jquery-ui/tests/unit/button/common.js vendored Normal file
View file

@ -0,0 +1,22 @@
define( [
"lib/common",
"ui/widgets/button"
], function( common ) {
common.testWidget( "button", {
defaults: {
classes: {
"ui-button": "ui-corner-all"
},
disabled: null,
icon: null,
iconPosition: "beginning",
label: null,
showLabel: true,
// Callbacks
create: null
}
} );
} );

26
jquery-ui/tests/unit/button/core.js vendored Normal file
View file

@ -0,0 +1,26 @@
define( [
"qunit",
"jquery",
"ui/safe-active-element",
"ui/widgets/button"
], function( QUnit, $ ) {
QUnit.module( "Button: core" );
QUnit.test( "Disabled button loses focus", function( assert ) {
var ready = assert.async();
assert.expect( 2 );
var element = $( "#button" ).button();
element.focus();
setTimeout( function() {
assert.equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" );
element.button( "disable" );
assert.notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" );
ready();
} );
} );
} );

View file

@ -0,0 +1,61 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Button Deprecated Test Suite</title>
<script src="../../../external/requirejs/require.js"></script>
<script src="../../lib/css.js" data-modules="core button"></script>
<script src="../../lib/bootstrap.js" data-widget="button" data-deprecated="true"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<div class="buttonset"><button id="button">Label</button><button>button 2</button></div>
<div><button id="button2">label <span>with span</span></button></div>
<div id="radio0" style="margin-top: 2em;">
<input type="radio" id="radio01" name="radio" checked="checked"><label for="radio01">Choice 1</label>
<input type="radio" id="radio02" name="radio"><label for="radio02">Choice 2</label>
<input type="radio" id="radio03" name="radio"><label for="radio03">Choice 3</label>
</div>
<div id="checkbox0">
<input type="checkbox" id="checkbox01" name="checkbox"><label for="checkbox01">Choice 1</label>
<input type="checkbox" id="checkbox02" name="checkbox"><label for="checkbox02">Choice 2</label>
<input type="checkbox" id="checkbox03" name="checkbox"><label for="checkbox03">Choice 3</label>
</div>
<form>
<div id="radio1" style="margin-top: 2em;">
<input type="radio" id="radio11" name="radio"><label for="radio11">Choice 1</label>
<input type="radio" id="radio12" name="radio" checked="checked"><label for="radio12">Choice 2</label>
<input type="radio" id="radio13" name="radio"><label for="radio13">Choice 3</label>
</div>
</form>
<form>
<div id="radio2" style="margin-top: 2em;">
<input type="radio" id="radio21" name="radio"><label for="radio21">Choice 1</label>
<input type="radio" id="radio22" name="radio"><label for="radio22">Choice 2</label>
<input type="radio" id="radio23" name="radio" checked="checked"><label for="radio23">Choice 3</label>
</div>
</form>
<form>
<div id="radio3">
<input type="radio" id="radio31" name="data['Page']['parse']"><label for="radio31">Choice 1</label>
<input type="radio" id="radio32" name="data['Page']['parse']" checked="checked"><label for="radio32">Choice 2</label>
<input type="radio" id="radio33" name="data['Page']['parse']"><label for="radio33">Choice 3</label>
</div>
</form>
<input type="checkbox" id="check"><label for="check">Toggle</label>
<input type="checkbox" id="check2"><label for="check2">Checkbox</label>
<div><input id="submit" type="submit" value="Label"></div>
<button id="button-disabled" disabled>Button</button>
<button id="button1">Button</button>
<a href="#" id="anchor-button">Anchor Button</a>
</div>
</body>
</html>

View file

@ -0,0 +1,197 @@
define( [
"qunit",
"jquery",
"ui/widgets/button"
], function( QUnit, $ ) {
QUnit.module( "Button (deprecated): core" );
QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) {
var checkbox = $( "#checkbox01" );
assert.expect( 2 );
checkbox.button();
assert.ok( !!checkbox.checkboxradio( "instance" ),
"Calling button on a checkbox creates checkboxradio instance" );
assert.ok( !checkbox.checkboxradio( "option", "icon" ),
"Calling button on a checkbox sets the checkboxradio icon option to false" );
} );
QUnit.test( "Calling buttonset calls controlgroup", function( assert ) {
var controlgroup = $( ".buttonset" );
assert.expect( 1 );
controlgroup.buttonset();
assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
} );
QUnit.module( "Button (deprecated): methods" );
QUnit.test( "destroy", function( assert ) {
assert.expect( 1 );
assert.domEqual( "#checkbox02", function() {
$( "#checkbox02" ).button().button( "destroy" );
} );
} );
QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
assert.expect( 5 );
var element = null;
element = $( "#checkbox02" );
element.button( { disabled: true } ).button( "refresh" );
assert.ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" );
assert.ok( element.prop( "disabled" ), "Input remains disabled after refresh" );
element = $( "#radio02" );
element.button( { disabled: true } ).button( "refresh" );
assert.ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" );
element = $( "#checkbox02" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
assert.ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." );
element = $( "#radio02" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
} );
QUnit.module( "button (deprecated): options" );
QUnit.test( "Setting items option on buttonset sets the button properties on the items option", function( assert ) {
assert.expect( 2 );
var controlgroup = $( ".buttonset" );
controlgroup.buttonset( { items: "bar" } );
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "bar",
"items.button set when setting items option on init on buttonset" );
controlgroup.buttonset( "option", "items", "foo" );
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
"items.button set when setting items option on buttonset" );
} );
QUnit.test( "disabled, null", function( assert ) {
assert.expect( 2 );
$( "#radio02" ).prop( "disabled", true ).button( { disabled: null } );
assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
"disabled option set to true" );
assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
} );
QUnit.test( "text / showLabel options proxied", function( assert ) {
assert.expect( 8 );
var button = $( "#button" );
button.button( {
text: false,
icon: "ui-icon-gear"
} );
assert.equal( button.button( "option", "showLabel" ), false,
"Setting the text option to false sets the showLabel option to false on init" );
button.button( "option", "showLabel", true );
assert.equal( button.button( "option", "text" ), true,
"Setting showLabel true with option method sets text option to true" );
button.button( "option", "text", false );
assert.equal( button.button( "option", "showLabel" ), false,
"Setting text false with option method sets showLabel option to false" );
button.button( "option", "text", true );
assert.equal( button.button( "option", "showLabel" ), true,
"Setting text true with option method sets showLabel option to true" );
button.button( "option", "showLabel", false );
assert.equal( button.button( "option", "text" ), false,
"Setting showLabel false with option method sets text option to false" );
button.button( "destroy" );
button.button( {
text: true,
icon: "ui-icon-gear"
} );
assert.equal( button.button( "option", "showLabel" ), true,
"Setting the text option to true sets the showLabel option to true on init" );
button.button( "destroy" );
button.button( {
showLabel: true,
icon: "ui-icon-gear"
} );
assert.equal( button.button( "option", "text" ), true,
"Setting the showLabel option to true sets the text option to true on init" );
button.button( "destroy" );
button.button( {
showLabel: false,
icon: "ui-icon-gear"
} );
assert.equal( button.button( "option", "text" ), false,
"Setting the showLabel option to false sets the text option to false on init" );
} );
QUnit.test( "icon / icons options properly proxied", function( assert ) {
assert.expect( 10 );
var button = $( "#button" );
button.button( {
icon: "foo"
} );
assert.equal( button.button( "option", "icons.primary" ), "foo",
"Icon option properly proxied on init" );
button.button( {
icon: "bar"
} );
assert.equal( button.button( "option", "icons.primary" ), "bar",
"Icon option properly proxied with option method" );
button.button( {
icons: {
primary: "foo"
}
} );
assert.equal( button.button( "option", "icon" ), "foo",
"Icons primary option properly proxied with option method" );
assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Icons primary option sets iconPosition option to beginning" );
button.button( {
icons: {
secondary: "bar"
}
} );
assert.equal( button.button( "option", "icon" ), "bar",
"Icons secondary option properly proxied with option method" );
assert.equal( button.button( "option", "iconPosition" ), "end",
"Icons secondary option sets iconPosition option to end" );
button.button( "destroy" );
button.button( {
icons: {
primary: "foo"
}
} );
assert.equal( button.button( "option", "icon" ), "foo",
"Icons primary option properly proxied on init" );
assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Icons primary option sets iconPosition option to beginning on init" );
button.button( {
icons: {
secondary: "bar"
}
} );
assert.equal( button.button( "option", "icon" ), "bar",
"Icons secondary option properly proxied on init" );
assert.equal( button.button( "option", "iconPosition" ), "end",
"Icons secondary option sets iconPosition option to end on init" );
} );
} );

23
jquery-ui/tests/unit/button/events.js vendored Normal file
View file

@ -0,0 +1,23 @@
define( [
"qunit",
"jquery",
"ui/widgets/button"
], function( QUnit, $ ) {
QUnit.module( "Button: events" );
QUnit.test( "Anchor recieves click event when spacebar is pressed", function( assert ) {
var ready = assert.async();
assert.expect( 1 );
var element = $( "#anchor-button" ).button();
element.on( "click", function( event ) {
event.preventDefault();
assert.ok( true, "click occcured as a result of spacebar" );
ready();
} );
element.trigger( $.Event( "keyup", { keyCode: $.ui.keyCode.SPACE } ) );
} );
} );

35
jquery-ui/tests/unit/button/methods.js vendored Normal file
View file

@ -0,0 +1,35 @@
define( [
"qunit",
"jquery",
"ui/widgets/button"
], function( QUnit, $ ) {
QUnit.module( "Button: methods" );
QUnit.test( "destroy", function( assert ) {
assert.expect( 1 );
assert.domEqual( "#button", function() {
$( "#button" ).button().button( "destroy" );
} );
} );
QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
assert.expect( 3 );
var element = $( "<a href='#'></a>" );
element.button( { disabled: true } ).button( "refresh" );
assert.ok( element.button( "option", "disabled" ),
"Anchor button should remain disabled after refresh" );
element = $( "<button></button>" );
element.button( { disabled: true } ).button( "refresh" );
assert.ok( element.button( "option", "disabled" ), "<button> should remain disabled after refresh" );
element = $( "<button></button>" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
assert.ok( !element.button( "option", "disabled" ),
"Changing a <button>'s disabled property should update the state after refresh." );
} );
} );

185
jquery-ui/tests/unit/button/options.js vendored Normal file
View file

@ -0,0 +1,185 @@
define( [
"qunit",
"jquery",
"ui/widgets/button"
], function( QUnit, $ ) {
QUnit.module( "button: options" );
QUnit.test( "disabled, explicit value", function( assert ) {
assert.expect( 8 );
var element = $( "#button" ).button( { disabled: false } );
assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
assert.strictEqual( element.prop( "disabled" ), false, "Disabled property is false" );
assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" );
element = $( "#button" ).button( { disabled: true } );
assert.hasClasses( element.button( "widget" ), "ui-state-disabled" );
assert.strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined,
"element does not get aria-disabled" );
assert.hasClasses( element.button( "widget" ), "ui-button-disabled" );
assert.strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
assert.strictEqual( element.prop( "disabled" ), true, "Disabled property is set" );
} );
// We are testing the default here because the default null is a special value which means to check
// the DOM. We need to make sure this happens correctly. Checking the options should never return
// null, it should always be true or false.
QUnit.test( "disabled, null", function( assert ) {
assert.expect( 4 );
var element = $( "#button" ),
elementDisabled = $( "#button-disabled" );
element.add( elementDisabled ).button( { disabled: null } );
assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
assert.strictEqual( element.prop( "disabled" ), false, "element is disabled" );
assert.strictEqual( elementDisabled.button( "option", "disabled" ), true,
"disabled option set to true" );
assert.strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" );
} );
QUnit.test( "showLabel, false, without icon", function( assert ) {
assert.expect( 4 );
var button = $( "#button" ).button( {
showLabel: false
} );
assert.lacksClasses( button, "ui-button-icon-only" );
assert.strictEqual( button.button( "option", "showLabel" ), true,
"showLabel false only allowed if icon true" );
button.button( "option", "showLabel", false );
assert.lacksClasses( button, "ui-button-icon-only" );
assert.strictEqual( button.button( "option", "showLabel" ), true,
"showLabel false only allowed if icon true" );
} );
QUnit.test( "showLabel, false, with icon", function( assert ) {
assert.expect( 1 );
var button = $( "#button" ).button( {
showLabel: false,
icon: "iconclass"
} );
assert.hasClasses( button, "ui-button ui-corner-all ui-widget ui-button-icon-only" );
} );
QUnit.test( "label, default", function( assert ) {
assert.expect( 2 );
var button = $( "#button" ).button();
assert.deepEqual( button.text(), "Label" );
assert.deepEqual( button.button( "option", "label" ), "Label" );
} );
QUnit.test( "label, with html markup", function( assert ) {
assert.expect( 3 );
var button = $( "#button2" ).button();
assert.deepEqual( button.text(), "label with span" );
assert.deepEqual( button.html().toLowerCase(), "label <span>with span</span>" );
assert.deepEqual( button.button( "option", "label" ).toLowerCase(), "label <span>with span</span>" );
} );
QUnit.test( "label, explicit value", function( assert ) {
assert.expect( 2 );
var button = $( "#button" ).button( {
label: "xxx"
} );
assert.deepEqual( button.text(), "xxx" );
assert.deepEqual( button.button( "option", "label" ), "xxx" );
} );
QUnit.test( "label, default, with input type submit", function( assert ) {
assert.expect( 2 );
var button = $( "#submit" ).button();
assert.deepEqual( button.val(), "Label" );
assert.deepEqual( button.button( "option", "label" ), "Label" );
} );
QUnit.test( "label, explicit value, with input type submit", function( assert ) {
assert.expect( 2 );
var button = $( "#submit" ).button( {
label: "xxx"
} );
assert.deepEqual( button.val(), "xxx" );
assert.deepEqual( button.button( "option", "label" ), "xxx" );
} );
QUnit.test( "icon", function( assert ) {
assert.expect( 4 );
var button = $( "#button" ).button( {
showLabel: false,
icon: "iconclass"
} ),
icon = button.find( ".ui-icon" );
assert.hasClasses( icon, "iconclass" );
assert.equal( icon.length, 1, "button with icon option set has icon" );
button.button( "option", "icon", false );
assert.equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" );
button.button( "option", "icon", "iconclass" );
assert.ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" );
} );
QUnit.test( "icon position", function( assert ) {
assert.expect( 22 );
var button = $( "#button" ).button( {
icon: "ui-icon-gear"
} ),
icon = button.find( ".ui-icon" ),
space = button.find( ".ui-button-icon-space" );
assert.equal( icon.length, 1, "button with icon option set has icon" );
assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Button has iconPosition beginning by default" );
assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" );
assert.equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" );
assert.equal( space.length, 1,
"ui-button-icon-space contains a breaking space iconPosition:beginning" );
assert.lacksClasses( icon, "ui-widget-icon-block" );
button.button( "option", "iconPosition", "end" );
icon = button.find( ".ui-icon" );
space = button.find( ".ui-button-icon-space" );
assert.equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" );
assert.equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" );
assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" );
assert.equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" );
assert.equal( space.length, 1,
"ui-button-icon-space contains a breaking space iconPosition:beginning" );
assert.lacksClasses( icon, "ui-widget-icon-block" );
button.button( "option", "iconPosition", "top" );
icon = button.find( ".ui-icon" );
assert.equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" );
assert.equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" );
assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" );
assert.ok( !button.find( "ui-button-icon-space" ).length,
"Button should not have an iconSpace with position: top" );
assert.hasClasses( icon, "ui-widget-icon-block" );
button.button( "option", "iconPosition", "bottom" );
icon = button.find( ".ui-icon" );
assert.equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" );
assert.equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" );
assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" );
assert.ok( !button.find( "ui-button-icon-space" ).length,
"Button should not have an iconSpace with position: bottom" );
assert.hasClasses( icon, "ui-widget-icon-block" );
} );
} );