@@ -66,25 +66,21 @@ describe('Button', () => {
66
66
67
67
describe ( 'attached' , ( ) => {
68
68
it ( 'renders a div' , ( ) => {
69
- shallow ( < Button attached /> )
70
- . should . have . tagName ( 'div' )
69
+ shallow ( < Button attached /> ) . should . have . tagName ( 'div' )
71
70
} )
72
71
} )
73
72
74
73
describe ( 'disabled' , ( ) => {
75
74
it ( 'is not set by default' , ( ) => {
76
- shallow ( < Button /> )
77
- . should . not . have . prop ( 'disabled' )
75
+ shallow ( < Button /> ) . should . not . have . prop ( 'disabled' )
78
76
} )
79
77
80
78
it ( 'applied when defined' , ( ) => {
81
- shallow ( < Button disabled /> )
82
- . should . have . prop ( 'disabled' , true )
79
+ shallow ( < Button disabled /> ) . should . have . prop ( 'disabled' , true )
83
80
} )
84
81
85
82
it ( "don't apply when the element's type isn't button" , ( ) => {
86
- shallow ( < Button as = 'div' disabled /> )
87
- . should . not . have . prop ( 'disabled' )
83
+ shallow ( < Button as = 'div' disabled /> ) . should . not . have . prop ( 'disabled' )
88
84
} )
89
85
90
86
it ( 'is not set by default when has a label' , ( ) => {
@@ -118,34 +114,27 @@ describe('Button', () => {
118
114
119
115
describe ( 'icon' , ( ) => {
120
116
it ( 'adds className icon' , ( ) => {
121
- shallow ( < Button icon = 'user' /> )
122
- . should . have . className ( 'icon' )
117
+ shallow ( < Button icon = 'user' /> ) . should . have . className ( 'icon' )
123
118
} )
124
119
125
120
it ( 'adds className icon when true' , ( ) => {
126
- shallow ( < Button icon /> )
127
- . should . have . className ( 'icon' )
121
+ shallow ( < Button icon /> ) . should . have . className ( 'icon' )
128
122
} )
129
123
130
124
it ( 'does not add className icon when there is content' , ( ) => {
131
- shallow ( < Button icon = 'user' content = { 0 } /> )
132
- . should . not . have . className ( 'icon' )
133
- shallow ( < Button icon = 'user' content = 'Yo' /> )
134
- . should . not . have . className ( 'icon' )
125
+ shallow ( < Button icon = 'user' content = { 0 } /> ) . should . not . have . className ( 'icon' )
126
+ shallow ( < Button icon = 'user' content = 'Yo' /> ) . should . not . have . className ( 'icon' )
135
127
} )
136
128
137
129
it ( 'adds className icon given labelPosition and content' , ( ) => {
138
- shallow ( < Button labelPosition = 'left' icon = 'user' content = 'My Account' /> )
139
- . should . have . className ( 'icon' )
140
- shallow ( < Button labelPosition = 'right' icon = 'user' content = 'My Account' /> )
141
- . should . have . className ( 'icon' )
130
+ shallow ( < Button labelPosition = 'left' icon = 'user' content = 'My Account' /> ) . should . have . className ( 'icon' )
131
+ shallow ( < Button labelPosition = 'right' icon = 'user' content = 'My Account' /> ) . should . have . className ( 'icon' )
142
132
} )
143
133
} )
144
134
145
135
describe ( 'label' , ( ) => {
146
136
it ( 'renders as a div' , ( ) => {
147
- shallow ( < Button label = 'http' /> )
148
- . should . have . tagName ( 'div' )
137
+ shallow ( < Button label = 'http' /> ) . should . have . tagName ( 'div' )
149
138
} )
150
139
it ( 'renders a div with a button and Label child' , ( ) => {
151
140
const wrapper = shallow ( < Button label = 'hi' /> )
@@ -155,8 +144,7 @@ describe('Button', () => {
155
144
wrapper . should . have . exactly ( 1 ) . descendants ( 'Label' )
156
145
} )
157
146
it ( 'adds the labeled className to the root element' , ( ) => {
158
- shallow ( < Button label = 'hi' /> )
159
- . should . have . className ( 'labeled' )
147
+ shallow ( < Button label = 'hi' /> ) . should . have . className ( 'labeled' )
160
148
} )
161
149
it ( 'contains children without disabled class when disabled attribute is set' , ( ) => {
162
150
const wrapper = shallow ( < Button label = 'hi' disabled /> )
@@ -174,80 +162,103 @@ describe('Button', () => {
174
162
} )
175
163
it ( 'creates a basic pointing label' , ( ) => {
176
164
shallow ( < Button label = 'foo' /> )
177
- . should . have . exactly ( 1 ) . descendants ( 'Label[basic][pointing]' )
165
+ . should . have . exactly ( 1 )
166
+ . descendants ( 'Label[basic][pointing]' )
178
167
} )
179
168
it ( 'is before the button and pointing="right" when labelPosition="left"' , ( ) => {
180
169
const wrapper = shallow ( < Button labelPosition = 'left' label = 'foo' /> )
181
170
wrapper . should . have . exactly ( 1 ) . descendants ( 'Label[pointing="right"]' )
182
171
183
- wrapper . children ( ) . at ( 0 ) . shallow ( ) . should . match ( '.ui.label' )
184
- wrapper . children ( ) . at ( 1 ) . should . match ( 'button' )
172
+ wrapper
173
+ . children ( )
174
+ . at ( 0 )
175
+ . shallow ( )
176
+ . should . match ( '.ui.label' )
177
+ wrapper
178
+ . children ( )
179
+ . at ( 1 )
180
+ . should . match ( 'button' )
185
181
} )
186
182
it ( 'is after the button and pointing="left" when labelPosition="right"' , ( ) => {
187
183
const wrapper = shallow ( < Button labelPosition = 'right' label = 'foo' /> )
188
184
wrapper . should . have . exactly ( 1 ) . descendants ( 'Label[pointing="left"]' )
189
185
190
- wrapper . children ( ) . at ( 0 ) . should . match ( 'button' )
191
- wrapper . children ( ) . at ( 1 ) . shallow ( ) . should . match ( '.ui.label' )
186
+ wrapper
187
+ . children ( )
188
+ . at ( 0 )
189
+ . should . match ( 'button' )
190
+ wrapper
191
+ . children ( )
192
+ . at ( 1 )
193
+ . shallow ( )
194
+ . should . match ( '.ui.label' )
192
195
} )
193
196
it ( 'is after the button and pointing="left" by default' , ( ) => {
194
197
const wrapper = shallow ( < Button label = 'foo' /> )
195
198
wrapper . should . have . exactly ( 1 ) . descendants ( 'Label[pointing="left"]' )
196
199
197
- wrapper . children ( ) . at ( 0 ) . should . match ( 'button' )
198
- wrapper . children ( ) . at ( 1 ) . shallow ( ) . should . match ( '.ui.label' )
200
+ wrapper
201
+ . children ( )
202
+ . at ( 0 )
203
+ . should . match ( 'button' )
204
+ wrapper
205
+ . children ( )
206
+ . at ( 1 )
207
+ . shallow ( )
208
+ . should . match ( '.ui.label' )
199
209
} )
200
210
} )
201
211
202
212
describe ( 'labelPosition' , ( ) => {
203
213
it ( 'renders as a button when given an icon' , ( ) => {
204
- shallow ( < Button labelPosition = 'left' icon = 'user' /> )
205
- . should . have . tagName ( 'button' )
206
- shallow ( < Button labelPosition = 'right' icon = 'user' /> )
207
- . should . have . tagName ( 'button' )
214
+ shallow ( < Button labelPosition = 'left' icon = 'user' /> ) . should . have . tagName ( 'button' )
215
+ shallow ( < Button labelPosition = 'right' icon = 'user' /> ) . should . have . tagName ( 'button' )
208
216
} )
209
217
} )
210
218
211
219
describe ( 'onClick' , ( ) => {
212
220
it ( 'is called with (e, data) when clicked' , ( ) => {
213
221
const onClick = sandbox . spy ( )
214
222
215
- shallow ( < Button onClick = { onClick } /> )
216
- . simulate ( 'click' , syntheticEvent )
223
+ shallow ( < Button onClick = { onClick } /> ) . simulate ( 'click' , syntheticEvent )
217
224
218
225
onClick . should . have . been . calledOnce ( )
219
- onClick . should . have . been . calledWithExactly ( syntheticEvent , { onClick, as : 'button' } )
226
+ onClick . should . have . been . calledWithExactly ( syntheticEvent , { onClick, ... Button . defaultProps } )
220
227
} )
221
228
222
229
it ( 'is not called when is disabled' , ( ) => {
223
230
const onClick = sandbox . spy ( )
224
231
225
- shallow ( < Button disabled onClick = { onClick } /> )
226
- . simulate ( 'click' , syntheticEvent )
232
+ shallow ( < Button disabled onClick = { onClick } /> ) . simulate ( 'click' , syntheticEvent )
227
233
onClick . should . have . callCount ( 0 )
228
234
} )
229
235
} )
230
236
237
+ describe ( 'role' , ( ) => {
238
+ it ( 'defaults to a button' , ( ) => {
239
+ Button . defaultProps . role . should . equal ( 'button' )
240
+ shallow ( < Button /> ) . should . have . prop ( 'role' , 'button' )
241
+ } )
242
+ it ( 'is configurable' , ( ) => {
243
+ shallow ( < Button role = 'link' /> ) . should . have . prop ( 'role' , 'link' )
244
+ } )
245
+ } )
246
+
231
247
describe ( 'tabIndex' , ( ) => {
232
248
it ( 'is not set by default' , ( ) => {
233
- shallow ( < Button /> )
234
- . should . not . have . prop ( 'tabIndex' )
249
+ shallow ( < Button /> ) . should . not . have . prop ( 'tabIndex' )
235
250
} )
236
251
it ( 'defaults to 0 as div' , ( ) => {
237
- shallow ( < Button as = 'div' /> )
238
- . should . have . prop ( 'tabIndex' , 0 )
252
+ shallow ( < Button as = 'div' /> ) . should . have . prop ( 'tabIndex' , 0 )
239
253
} )
240
254
it ( 'defaults to -1 when disabled' , ( ) => {
241
- shallow ( < Button disabled /> )
242
- . should . have . prop ( 'tabIndex' , - 1 )
255
+ shallow ( < Button disabled /> ) . should . have . prop ( 'tabIndex' , - 1 )
243
256
} )
244
257
it ( 'can be set explicitly' , ( ) => {
245
- shallow ( < Button tabIndex = { 123 } /> )
246
- . should . have . prop ( 'tabIndex' , 123 )
258
+ shallow ( < Button tabIndex = { 123 } /> ) . should . have . prop ( 'tabIndex' , 123 )
247
259
} )
248
260
it ( 'can be set explicitly when disabled' , ( ) => {
249
- shallow ( < Button tabIndex = { 123 } disabled /> )
250
- . should . have . prop ( 'tabIndex' , 123 )
261
+ shallow ( < Button tabIndex = { 123 } disabled /> ) . should . have . prop ( 'tabIndex' , 123 )
251
262
} )
252
263
} )
253
264
} )
0 commit comments