@@ -6,7 +6,7 @@ import TestUtils from 'react-addons-test-utils';
6
6
7
7
import { SLDSInput } from '../../components' ;
8
8
const {
9
- // Simulate,
9
+ Simulate,
10
10
findRenderedDOMComponentWithTag,
11
11
scryRenderedDOMComponentsWithTag,
12
12
findRenderedDOMComponentWithClass
@@ -146,27 +146,87 @@ describe('SLDS INPUT **************************************************', () =>
146
146
} ) ;
147
147
} ) ;
148
148
149
+ describe ( 'Input with Left Clickable Icon' , ( ) => {
150
+ let component ;
151
+ let elementControl ;
152
+ let leftButton ;
153
+
154
+ const clickCallback = sinon . spy ( ) ;
155
+
156
+ beforeEach ( ( ) => {
157
+ component = getInput ( { iconName : 'search' , iconCategory : 'utility' , iconPosition : 'left' , onIconClick : clickCallback } ) ;
158
+ leftButton = findRenderedDOMComponentWithTag ( component , 'button' ) ;
159
+ elementControl = findRenderedDOMComponentWithClass ( component , 'slds-form-element__control' ) ;
160
+ } ) ;
161
+
162
+ afterEach ( ( ) => {
163
+ removeInput ( ) ;
164
+ } ) ;
165
+
166
+ it ( 'element control has class "slds-input-has-icon"' , ( ) => {
167
+ expect ( elementControl . className ) . to . include ( 'slds-input-has-icon' ) ;
168
+ } ) ;
169
+
170
+ it ( 'icon renders button BEFORE input in DOM' , ( ) => {
171
+ const render = elementControl . innerHTML ;
172
+ expect ( render . indexOf ( '<button' ) ) . to . be . below ( render . indexOf ( '<input' ) ) ;
173
+ } ) ;
174
+
175
+ it ( 'icon can be clicked' , ( ) => {
176
+ TestUtils . Simulate . click ( leftButton ) ;
177
+
178
+ expect ( clickCallback . calledOnce ) . to . be . true ;
179
+ } ) ;
180
+ } ) ;
181
+
182
+ describe ( 'Input with Right Clickable Icon' , ( ) => {
183
+ let component ;
184
+ let elementControl ;
185
+ let leftButton ;
186
+
187
+ const clickCallback = sinon . spy ( ) ;
188
+
189
+ beforeEach ( ( ) => {
190
+ component = getInput ( { iconName : 'search' , iconCategory : 'utility' , iconPosition : 'right' , onIconClick : clickCallback } ) ;
191
+ leftButton = findRenderedDOMComponentWithTag ( component , 'button' ) ;
192
+ elementControl = findRenderedDOMComponentWithClass ( component , 'slds-form-element__control' ) ;
193
+ } ) ;
149
194
150
- // describe('Input with Clickable Icon', () => {
151
- // let component;
152
- // let input;
153
- // let label;
154
- // let icon;
155
-
156
- // beforeEach(() => {
157
- // component = getInput({ label: 'Input Label' });
158
- // input = findRenderedDOMComponentWithTag(component, 'input');
159
- // inputWrapper = findRenderedDOMComponentWithClass(component, 'slds-form-element__control');
160
- // label = findRenderedDOMComponentWithClass(component, 'slds-form-element__label');
161
- // icon = findRenderedDOMComponentWithTag(component, 'svg');
162
- // });
163
-
164
- // afterEach(() => {
165
- // removeInput();
166
- // });
167
-
168
- // // input wrapper has class "slds-input-has-icon"
169
- // // icon has class "slds-input__icon"
170
- // // icon can be clicked (Simulate)
171
- // });
195
+ afterEach ( ( ) => {
196
+ removeInput ( ) ;
197
+ } ) ;
198
+
199
+ it ( 'element control has class "slds-input-has-icon"' , ( ) => {
200
+ expect ( elementControl . className ) . to . include ( 'slds-input-has-icon' ) ;
201
+ } ) ;
202
+
203
+ it ( 'icon renders button AFTER input in DOM' , ( ) => {
204
+ const render = elementControl . innerHTML ;
205
+ expect ( render . indexOf ( '<button' ) ) . to . be . above ( render . indexOf ( '<input' ) ) ;
206
+ } ) ;
207
+
208
+ it ( 'icon can be clicked' , ( ) => {
209
+ TestUtils . Simulate . click ( leftButton ) ;
210
+
211
+ expect ( clickCallback . calledOnce ) . to . be . true ;
212
+ } ) ;
213
+ } ) ;
214
+
215
+ describe ( 'Input with Non-Clickable Icon' , ( ) => {
216
+ let component ;
217
+ let elementControl ;
218
+
219
+ beforeEach ( ( ) => {
220
+ component = getInput ( { iconName : 'search' , iconCategory : 'utility' , iconPosition : 'right' } ) ;
221
+ elementControl = findRenderedDOMComponentWithClass ( component , 'slds-form-element__control' ) ;
222
+ } ) ;
223
+
224
+ afterEach ( ( ) => {
225
+ removeInput ( ) ;
226
+ } ) ;
227
+
228
+ it ( 'button tag does not exist' , ( ) => {
229
+ expect ( elementControl . getElementsByTagName ( 'button' ) [ 0 ] ) . to . not . be . ok ;
230
+ } ) ;
231
+ } ) ;
172
232
} ) ;
0 commit comments