| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"ui/widgets/controlgroup", |
| 6 |
"ui/widgets/checkboxradio", |
| 7 |
"ui/widgets/selectmenu", |
| 8 |
"ui/widgets/button", |
| 9 |
"ui/widgets/spinner" |
| 10 |
], function( QUnit, $, helper ) { |
| 11 |
"use strict"; |
| 12 |
|
| 13 |
QUnit.module( "Controlgroup: options", { afterEach: helper.moduleAfterEach } ); |
| 14 |
|
| 15 |
QUnit.test( "disabled", function( assert ) { |
| 16 |
assert.expect( 4 ); |
| 17 |
var element = $( ".controlgroup" ).controlgroup().controlgroup( "option", "disabled", true ); |
| 18 |
assert.lacksClasses( element, "ui-state-disabled" ); |
| 19 |
assert.equal( element.find( ".ui-state-disabled" ).length, 9, "Child widgets are disabled" ); |
| 20 |
|
| 21 |
element.controlgroup( "option", "disabled", false ); |
| 22 |
assert.lacksClasses( element, "ui-state-disabled" ); |
| 23 |
assert.strictEqual( element.find( ".ui-state-disabled" ).length, 0, "Child widgets are not disabled" ); |
| 24 |
|
| 25 |
} ); |
| 26 |
|
| 27 |
QUnit.test( "items - null", function( assert ) { |
| 28 |
assert.expect( 2 ); |
| 29 |
var element = $( ".controlgroup" ).controlgroup( { |
| 30 |
items: { |
| 31 |
"button": null, |
| 32 |
"selectmenu": null, |
| 33 |
"checkboxradio": null |
| 34 |
} |
| 35 |
} ); |
| 36 |
|
| 37 |
assert.strictEqual( element.children( ".ui-button" ).length, 0, |
| 38 |
"Child widgets are not called when selector is null" ); |
| 39 |
|
| 40 |
element.controlgroup( "option", "items", { |
| 41 |
"button": "button" |
| 42 |
} ); |
| 43 |
assert.strictEqual( element.children( ".ui-button" ).length, 2, |
| 44 |
"Correct child widgets are called when selector is updated" ); |
| 45 |
} ); |
| 46 |
|
| 47 |
QUnit.test( "items: custom selector", function( assert ) { |
| 48 |
assert.expect( 1 ); |
| 49 |
var element = $( ".controlgroup" ).controlgroup( { |
| 50 |
items: { |
| 51 |
"button": ".button" |
| 52 |
} |
| 53 |
} ); |
| 54 |
assert.strictEqual( element.children( ".ui-button" ).length, 4, |
| 55 |
"Correct child widgets are called when custom selector used" ); |
| 56 |
} ); |
| 57 |
|
| 58 |
$.widget( "ui.test", { |
| 59 |
_create: function() { |
| 60 |
this.element.addClass( "ui-test ui-button" ); |
| 61 |
}, |
| 62 |
|
| 63 |
|
| 64 |
refresh: $.noop |
| 65 |
} ); |
| 66 |
|
| 67 |
QUnit.test( "items: custom widget", function( assert ) { |
| 68 |
assert.expect( 2 ); |
| 69 |
var element = $( ".controlgroup" ).controlgroup( { |
| 70 |
items: { |
| 71 |
"test": ".test" |
| 72 |
} |
| 73 |
} ); |
| 74 |
|
| 75 |
assert.strictEqual( element.children( ".ui-button" ).length, 7, |
| 76 |
"Correct child widgets are called when custom selector used" ); |
| 77 |
assert.strictEqual( element.children( ".ui-test" ).length, 1, |
| 78 |
"Custom widget called" ); |
| 79 |
} ); |
| 80 |
|
| 81 |
QUnit.test( "onlyVisible", function( assert ) { |
| 82 |
assert.expect( 4 ); |
| 83 |
var element = $( ".controlgroup" ).controlgroup( { |
| 84 |
onlyVisible: false |
| 85 |
} ), |
| 86 |
buttons = element.children( ".ui-button" ); |
| 87 |
|
| 88 |
assert.lacksClassStart( buttons.eq( 1 ), "ui-corner" ); |
| 89 |
assert.hasClasses( buttons.eq( 0 ), "ui-corner-left", |
| 90 |
"onlyVisible: false: First button hidden second button doesn't get a corner class" ); |
| 91 |
|
| 92 |
element.controlgroup( "option", "onlyVisible", true ); |
| 93 |
assert.lacksClassStart( buttons.eq( 0 ), "ui-corner" ); |
| 94 |
assert.hasClasses( buttons.eq( 1 ), "ui-corner-left", |
| 95 |
"onlyVisible: true: First button is hidden second button get corner class" ); |
| 96 |
} ); |
| 97 |
|
| 98 |
QUnit.test( "direction", function( assert ) { |
| 99 |
assert.expect( 6 ); |
| 100 |
var element = $( ".controlgroup" ).controlgroup(), |
| 101 |
buttons = element.children( ".ui-button" ).filter( ":visible" ); |
| 102 |
|
| 103 |
assert.hasClasses( element, "ui-controlgroup-horizontal" ); |
| 104 |
assert.hasClasses( buttons.first(), "ui-corner-left" ); |
| 105 |
assert.hasClasses( buttons.last(), "ui-corner-right" ); |
| 106 |
|
| 107 |
element.controlgroup( "option", "direction", "vertical" ); |
| 108 |
assert.hasClasses( element, "ui-controlgroup-vertical" ); |
| 109 |
assert.hasClasses( buttons.first(), "ui-corner-top" ); |
| 110 |
assert.hasClasses( buttons.last(), "ui-corner-bottom" ); |
| 111 |
} ); |
| 112 |
|
| 113 |
} ); |