Debian Codegraph @

tests/unit/button/options.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: options", { afterEach: helper.moduleAfterEach } );
10
11 QUnit.test( "disabled, explicit value", function( assert ) {
12 assert.expect( 8 );
13
14 var element = $( "#button" ).button( { disabled: false } );
15
16 assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
17 assert.strictEqual( element.prop( "disabled" ), false, "Disabled property is false" );
18
19 assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" );
20
21 element = $( "#button" ).button( { disabled: true } );
22
23 assert.hasClasses( element.button( "widget" ), "ui-state-disabled" );
24 assert.strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined,
25 "element does not get aria-disabled" );
26 assert.hasClasses( element.button( "widget" ), "ui-button-disabled" );
27
28 assert.strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
29 assert.strictEqual( element.prop( "disabled" ), true, "Disabled property is set" );
30 } );
31
32 // We are testing the default here because the default null is a special value which means to check
33 // the DOM. We need to make sure this happens correctly. Checking the options should never return
34 // null, it should always be true or false.
35 QUnit.test( "disabled, null", function( assert ) {
36 assert.expect( 4 );
37 var element = $( "#button" ),
38 elementDisabled = $( "#button-disabled" );
39
40 element.add( elementDisabled ).button( { disabled: null } );
41 assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
42 assert.strictEqual( element.prop( "disabled" ), false, "element is disabled" );
43 assert.strictEqual( elementDisabled.button( "option", "disabled" ), true,
44 "disabled option set to true" );
45 assert.strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" );
46 } );
47
48 QUnit.test( "showLabel, false, without icon", function( assert ) {
49 assert.expect( 4 );
50
51 var button = $( "#button" ).button( {
52 showLabel: false
53 } );
54
55 assert.lacksClasses( button, "ui-button-icon-only" );
56 assert.strictEqual( button.button( "option", "showLabel" ), true,
57 "showLabel false only allowed if icon true" );
58
59 button.button( "option", "showLabel", false );
60 assert.lacksClasses( button, "ui-button-icon-only" );
61 assert.strictEqual( button.button( "option", "showLabel" ), true,
62 "showLabel false only allowed if icon true" );
63 } );
64
65 QUnit.test( "showLabel, false, with icon", function( assert ) {
66 assert.expect( 1 );
67 var button = $( "#button" ).button( {
68 showLabel: false,
69 icon: "iconclass"
70 } );
71 assert.hasClasses( button, "ui-button ui-corner-all ui-widget ui-button-icon-only" );
72 } );
73
74 QUnit.test( "label, default", function( assert ) {
75 assert.expect( 2 );
76 var button = $( "#button" ).button();
77
78 assert.deepEqual( button.text(), "Label" );
79 assert.deepEqual( button.button( "option", "label" ), "Label" );
80 } );
81
82 QUnit.test( "label, with html markup", function( assert ) {
83 assert.expect( 3 );
84 var button = $( "#button2" ).button();
85
86 assert.deepEqual( button.text(), "label with span" );
87 assert.deepEqual( button.html().toLowerCase(), "label <span>with span</span>" );
88 assert.deepEqual( button.button( "option", "label" ).toLowerCase(), "label <span>with span</span>" );
89 } );
90
91 QUnit.test( "label, explicit value", function( assert ) {
92 assert.expect( 2 );
93 var button = $( "#button" ).button( {
94 label: "xxx"
95 } );
96
97 assert.deepEqual( button.text(), "xxx" );
98 assert.deepEqual( button.button( "option", "label" ), "xxx" );
99 } );
100
101 QUnit.test( "label, default, with input type submit", function( assert ) {
102 assert.expect( 2 );
103 var button = $( "#submit" ).button();
104
105 assert.deepEqual( button.val(), "Label" );
106 assert.deepEqual( button.button( "option", "label" ), "Label" );
107 } );
108
109 QUnit.test( "label, explicit value, with input type submit", function( assert ) {
110 assert.expect( 2 );
111 var button = $( "#submit" ).button( {
112 label: "xxx"
113 } );
114
115 assert.deepEqual( button.val(), "xxx" );
116 assert.deepEqual( button.button( "option", "label" ), "xxx" );
117 } );
118
119 QUnit.test( "icon", function( assert ) {
120 assert.expect( 4 );
121 var button = $( "#button" ).button( {
122 showLabel: false,
123 icon: "iconclass"
124 } ),
125 icon = button.find( ".ui-icon" );
126
127 assert.hasClasses( icon, "iconclass" );
128 assert.equal( icon.length, 1, "button with icon option set has icon" );
129
130 button.button( "option", "icon", false );
131 assert.equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" );
132
133 button.button( "option", "icon", "iconclass" );
134 assert.ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" );
135
136 } );
137
138 QUnit.test( "icon position", function( assert ) {
139 assert.expect( 22 );
140
141 var button = $( "#button" ).button( {
142 icon: "ui-icon-gear"
143 } ),
144 icon = button.find( ".ui-icon" ),
145 space = button.find( ".ui-button-icon-space" );
146
147 assert.equal( icon.length, 1, "button with icon option set has icon" );
148 assert.equal( button.button( "option", "iconPosition" ), "beginning",
149 "Button has iconPosition beginning by default" );
150 assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" );
151 assert.equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" );
152 assert.equal( space.length, 1,
153 "ui-button-icon-space contains a breaking space iconPosition:beginning" );
154 assert.lacksClasses( icon, "ui-widget-icon-block" );
155
156 button.button( "option", "iconPosition", "end" );
157 icon = button.find( ".ui-icon" );
158 space = button.find( ".ui-button-icon-space" );
159 assert.equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" );
160 assert.equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" );
161 assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" );
162 assert.equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" );
163 assert.equal( space.length, 1,
164 "ui-button-icon-space contains a breaking space iconPosition:beginning" );
165 assert.lacksClasses( icon, "ui-widget-icon-block" );
166
167 button.button( "option", "iconPosition", "top" );
168 icon = button.find( ".ui-icon" );
169 assert.equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" );
170 assert.equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" );
171 assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" );
172 assert.ok( !button.find( "ui-button-icon-space" ).length,
173 "Button should not have an iconSpace with position: top" );
174 assert.hasClasses( icon, "ui-widget-icon-block" );
175
176 button.button( "option", "iconPosition", "bottom" );
177 icon = button.find( ".ui-icon" );
178 assert.equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" );
179 assert.equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" );
180 assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" );
181 assert.ok( !button.find( "ui-button-icon-space" ).length,
182 "Button should not have an iconSpace with position: bottom" );
183 assert.hasClasses( icon, "ui-widget-icon-block" );
184
185 } );
186
187 } );