Debian Codegraph @

tests/unit/button/deprecated.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "lib/helper",
5 "ui/widgets/button"
6 ], function( QUnit, $, helper ) {
7 "use strict";
8
9 QUnit.module( "Button (deprecated): core", { afterEach: helper.moduleAfterEach } );
10
11 QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) {
12 var checkbox = $( "#checkbox01" );
13
14 assert.expect( 2 );
15 checkbox.button();
16
17 assert.ok( !!checkbox.checkboxradio( "instance" ),
18 "Calling button on a checkbox creates checkboxradio instance" );
19 assert.ok( !checkbox.checkboxradio( "option", "icon" ),
20 "Calling button on a checkbox sets the checkboxradio icon option to false" );
21 } );
22
23 QUnit.test( "Calling buttonset calls controlgroup", function( assert ) {
24 var controlgroup = $( ".buttonset" );
25
26 assert.expect( 1 );
27 controlgroup.buttonset();
28
29 assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
30 } );
31
32 QUnit.module( "Button (deprecated): methods", { afterEach: helper.moduleAfterEach } );
33
34 QUnit.test( "destroy", function( assert ) {
35 assert.expect( 1 );
36 assert.domEqual( "#checkbox02", function() {
37 $( "#checkbox02" ).button().button( "destroy" );
38 } );
39 } );
40
41 QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
42 assert.expect( 5 );
43 var element = null;
44
45 element = $( "#checkbox02" );
46 element.button( { disabled: true } ).button( "refresh" );
47 assert.ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" );
48 assert.ok( element.prop( "disabled" ), "Input remains disabled after refresh" );
49
50 element = $( "#radio02" );
51 element.button( { disabled: true } ).button( "refresh" );
52 assert.ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" );
53
54 element = $( "#checkbox02" );
55 element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
56 assert.ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." );
57
58 element = $( "#radio02" );
59 element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
60 assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
61
62 } );
63
64 QUnit.module( "button (deprecated): options", { afterEach: helper.moduleAfterEach } );
65
66 QUnit.test( "Setting items option on buttonset sets the button properties on the items option", function( assert ) {
67 assert.expect( 2 );
68
69 var controlgroup = $( ".buttonset" );
70
71 controlgroup.buttonset( { items: "bar" } );
72 assert.equal( controlgroup.controlgroup( "option", "items.button" ), "bar",
73 "items.button set when setting items option on init on buttonset" );
74
75 controlgroup.buttonset( "option", "items", "foo" );
76 assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
77 "items.button set when setting items option on buttonset" );
78 } );
79
80 QUnit.test( "disabled, null", function( assert ) {
81 assert.expect( 2 );
82
83 $( "#radio02" ).prop( "disabled", true ).button( { disabled: null } );
84 assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
85 "disabled option set to true" );
86 assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
87 } );
88
89 QUnit.test( "text / showLabel options proxied", function( assert ) {
90 assert.expect( 8 );
91 var button = $( "#button" );
92 button.button( {
93 text: false,
94 icon: "ui-icon-gear"
95 } );
96 assert.equal( button.button( "option", "showLabel" ), false,
97 "Setting the text option to false sets the showLabel option to false on init" );
98 button.button( "option", "showLabel", true );
99 assert.equal( button.button( "option", "text" ), true,
100 "Setting showLabel true with option method sets text option to true" );
101 button.button( "option", "text", false );
102 assert.equal( button.button( "option", "showLabel" ), false,
103 "Setting text false with option method sets showLabel option to false" );
104 button.button( "option", "text", true );
105 assert.equal( button.button( "option", "showLabel" ), true,
106 "Setting text true with option method sets showLabel option to true" );
107 button.button( "option", "showLabel", false );
108 assert.equal( button.button( "option", "text" ), false,
109 "Setting showLabel false with option method sets text option to false" );
110 button.button( "destroy" );
111 button.button( {
112 text: true,
113 icon: "ui-icon-gear"
114 } );
115 assert.equal( button.button( "option", "showLabel" ), true,
116 "Setting the text option to true sets the showLabel option to true on init" );
117 button.button( "destroy" );
118 button.button( {
119 showLabel: true,
120 icon: "ui-icon-gear"
121 } );
122 assert.equal( button.button( "option", "text" ), true,
123 "Setting the showLabel option to true sets the text option to true on init" );
124 button.button( "destroy" );
125 button.button( {
126 showLabel: false,
127 icon: "ui-icon-gear"
128 } );
129 assert.equal( button.button( "option", "text" ), false,
130 "Setting the showLabel option to false sets the text option to false on init" );
131 } );
132
133 QUnit.test( "icon / icons options properly proxied", function( assert ) {
134 assert.expect( 10 );
135
136 var button = $( "#button" );
137
138 button.button( {
139 icon: "foo"
140 } );
141
142 assert.equal( button.button( "option", "icons.primary" ), "foo",
143 "Icon option properly proxied on init" );
144
145 button.button( {
146 icon: "bar"
147 } );
148
149 assert.equal( button.button( "option", "icons.primary" ), "bar",
150 "Icon option properly proxied with option method" );
151
152 button.button( {
153 icons: {
154 primary: "foo"
155 }
156 } );
157
158 assert.equal( button.button( "option", "icon" ), "foo",
159 "Icons primary option properly proxied with option method" );
160 assert.equal( button.button( "option", "iconPosition" ), "beginning",
161 "Icons primary option sets iconPosition option to beginning" );
162
163 button.button( {
164 icons: {
165 secondary: "bar"
166 }
167 } );
168
169 assert.equal( button.button( "option", "icon" ), "bar",
170 "Icons secondary option properly proxied with option method" );
171 assert.equal( button.button( "option", "iconPosition" ), "end",
172 "Icons secondary option sets iconPosition option to end" );
173
174 button.button( "destroy" );
175
176 button.button( {
177 icons: {
178 primary: "foo"
179 }
180 } );
181
182 assert.equal( button.button( "option", "icon" ), "foo",
183 "Icons primary option properly proxied on init" );
184 assert.equal( button.button( "option", "iconPosition" ), "beginning",
185 "Icons primary option sets iconPosition option to beginning on init" );
186
187 button.button( {
188 icons: {
189 secondary: "bar"
190 }
191 } );
192
193 assert.equal( button.button( "option", "icon" ), "bar",
194 "Icons secondary option properly proxied on init" );
195 assert.equal( button.button( "option", "iconPosition" ), "end",
196 "Icons secondary option sets iconPosition option to end on init" );
197 } );
198
199 QUnit.test( "Calling button on a collection of mixed types works correctly", function( assert ) {
200 assert.expect( 5 );
201
202 var group = $( ".mixed" ).children();
203
204 group.button();
205
206 $.each( {
207 anchor: "button",
208 button: "button",
209 check: "checkboxradio",
210 input: "button",
211 radio: "checkboxradio"
212 }, function( type, widget ) {
213 assert.ok( $( "#mixed-" + type )[ widget ]( "instance" ), type + " is a " + widget );
214 } );
215 } );
216
217 } );