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