@@ -217,6 +217,58 @@ describe('<md-chips>', function() {
217
217
expect ( scope . appendChip ) . toHaveBeenCalled ( ) ;
218
218
expect ( scope . appendChip . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( 'Apple' ) ;
219
219
} ) ;
220
+
221
+ it ( 'should prevent the default when backspace is pressed' , inject ( function ( $mdConstant ) {
222
+ var element = buildChips ( BASIC_CHIP_TEMPLATE ) ;
223
+ var ctrl = element . controller ( 'mdChips' ) ;
224
+
225
+ var backspaceEvent = {
226
+ type : 'keydown' ,
227
+ keyCode : $mdConstant . KEY_CODE . BACKSPACE ,
228
+ which : $mdConstant . KEY_CODE . BACKSPACE ,
229
+ preventDefault : jasmine . createSpy ( 'preventDefault' )
230
+ } ;
231
+
232
+ element . find ( 'input' ) . triggerHandler ( backspaceEvent ) ;
233
+
234
+ expect ( backspaceEvent . preventDefault ) . toHaveBeenCalled ( ) ;
235
+ } ) ) ;
236
+
237
+ describe ( 'with input text' , function ( ) {
238
+
239
+ it ( 'should prevent the default when enter is pressed' , inject ( function ( $mdConstant ) {
240
+ var element = buildChips ( BASIC_CHIP_TEMPLATE ) ;
241
+ var ctrl = element . controller ( 'mdChips' ) ;
242
+
243
+ var enterEvent = {
244
+ type : 'keydown' ,
245
+ keyCode : $mdConstant . KEY_CODE . ENTER ,
246
+ which : $mdConstant . KEY_CODE . ENTER ,
247
+ preventDefault : jasmine . createSpy ( 'preventDefault' )
248
+ } ;
249
+
250
+ ctrl . chipBuffer = 'Test' ;
251
+ element . find ( 'input' ) . triggerHandler ( enterEvent ) ;
252
+
253
+ expect ( enterEvent . preventDefault ) . toHaveBeenCalled ( ) ;
254
+ } ) ) ;
255
+ } ) ;
256
+
257
+ it ( 'focuses/blurs the component when focusing/blurring the input' , inject ( function ( ) {
258
+ var element = buildChips ( BASIC_CHIP_TEMPLATE ) ;
259
+ var ctrl = element . controller ( 'mdChips' ) ;
260
+
261
+ // Focus the input and check
262
+ element . find ( 'input' ) . triggerHandler ( 'focus' ) ;
263
+ expect ( ctrl . inputHasFocus ) . toBe ( true ) ;
264
+ expect ( element . find ( 'md-chips-wrap' ) . hasClass ( 'md-focused' ) ) . toBe ( true ) ;
265
+
266
+ // Blur the input and check
267
+ element . find ( 'input' ) . triggerHandler ( 'blur' ) ;
268
+ expect ( ctrl . inputHasFocus ) . toBe ( false ) ;
269
+ expect ( element . find ( 'md-chips-wrap' ) . hasClass ( 'md-focused' ) ) . toBe ( false ) ;
270
+ } ) ) ;
271
+
220
272
} ) ;
221
273
222
274
describe ( 'custom inputs' , function ( ) {
@@ -264,6 +316,24 @@ describe('<md-chips>', function() {
264
316
<input type="text">\
265
317
</md-chips>' ;
266
318
319
+ it ( 'focuses/blurs the component when focusing/blurring the input' , inject ( function ( $timeout ) {
320
+ var element = buildChips ( INPUT_TEMPLATE ) ;
321
+ var ctrl = element . controller ( 'mdChips' ) ;
322
+ $timeout . flush ( ) ;
323
+
324
+ // Focus the input and check
325
+ element . find ( 'input' ) . triggerHandler ( 'focus' ) ;
326
+ $timeout . flush ( ) ;
327
+ expect ( ctrl . inputHasFocus ) . toBe ( true ) ;
328
+ expect ( element . find ( 'md-chips-wrap' ) . hasClass ( 'md-focused' ) ) . toBe ( true ) ;
329
+
330
+ // Blur the input and check
331
+ element . find ( 'input' ) . triggerHandler ( 'blur' ) ;
332
+ $timeout . flush ( ) ;
333
+ expect ( ctrl . inputHasFocus ) . toBe ( false ) ;
334
+ expect ( element . find ( 'md-chips-wrap' ) . hasClass ( 'md-focused' ) ) . toBe ( false ) ;
335
+ } ) ) ;
336
+
267
337
describe ( 'using ngModel' , function ( ) {
268
338
it ( 'should add the ngModelCtrl.$viewValue when <enter> is pressed' ,
269
339
inject ( function ( $timeout ) {
0 commit comments