1
1
describe ( '<md-chips>' , function ( ) {
2
- var scope ;
3
-
2
+ var scope , $exceptionHandler , $timeout ;
4
3
var BASIC_CHIP_TEMPLATE =
5
4
'<md-chips ng-model="items"></md-chips>' ;
6
5
var CHIP_APPEND_TEMPLATE =
7
6
'<md-chips ng-model="items" md-on-append="appendChip($chip)"></md-chips>' ;
8
7
var CHIP_REMOVE_TEMPLATE =
9
8
'<md-chips ng-model="items" md-on-remove="removeChip($chip, $index)"></md-chips>' ;
9
+ var CHIP_READONLY_AUTOCOMPLETE_TEMPLATE =
10
+ '<md-chips ng-model="items" readonly="true">' +
11
+ ' <md-autocomplete md-items="item in [\'hi\', \'ho\', \'he\']"></md-autocomplete>' +
12
+ '</md-chips>' ;
10
13
11
14
describe ( 'with no overrides' , function ( ) {
12
-
13
15
beforeEach ( module ( 'material.components.chips' , 'material.components.autocomplete' ) ) ;
14
- beforeEach ( inject ( function ( $rootScope ) {
16
+ beforeEach ( inject ( function ( $rootScope , _$exceptionHandler_ , _$timeout_ ) {
15
17
scope = $rootScope . $new ( ) ;
16
18
scope . items = [ 'Apple' , 'Banana' , 'Orange' ] ;
19
+ $exceptionHandler = _$exceptionHandler_ ;
20
+ $timeout = _$timeout_ ;
17
21
} ) ) ;
18
22
19
23
describe ( 'basic functionality' , function ( ) {
@@ -155,6 +159,14 @@ describe('<md-chips>', function() {
155
159
expect ( scope . items [ 3 ] . uppername ) . toBe ( 'GRAPE' ) ;
156
160
} ) ;
157
161
162
+ it ( 'should not throw an error when using readonly with an autocomplete' , function ( ) {
163
+ var element = buildChips ( CHIP_READONLY_AUTOCOMPLETE_TEMPLATE ) ;
164
+
165
+ $timeout . flush ( ) ;
166
+
167
+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
168
+ } ) ;
169
+
158
170
it ( 'should disallow duplicate object chips' , function ( ) {
159
171
var element = buildChips ( CHIP_APPEND_TEMPLATE ) ;
160
172
var ctrl = element . controller ( 'mdChips' ) ;
@@ -270,6 +282,17 @@ describe('<md-chips>', function() {
270
282
<md-chip>Baseball</md-chip>\
271
283
<md-chip>{{chipItem}}</md-chip>\
272
284
</md-chips>' ;
285
+
286
+ var STATIC_CHIPS_NGREPEAT_TEMPLATE = '\
287
+ <div>\
288
+ <div ng-repeat="i in [1,2,3]">\
289
+ <md-chips>\
290
+ <md-chip>{{i}}</md-chip>\
291
+ </md-chips>\
292
+ </div>\
293
+ </div>\
294
+ ' ;
295
+
273
296
it ( 'should transclude static chips' , inject ( function ( $timeout ) {
274
297
scope . chipItem = 'Football' ;
275
298
var element = buildChips ( STATIC_CHIPS_TEMPLATE ) ;
@@ -283,6 +306,25 @@ describe('<md-chips>', function() {
283
306
expect ( chips [ 2 ] . innerHTML ) . toContain ( 'Baseball' ) ;
284
307
expect ( chips [ 3 ] . innerHTML ) . toContain ( 'Football' ) ;
285
308
} ) ) ;
309
+
310
+ it ( 'allows ng-repeat outside of md-chips' , function ( ) {
311
+ var element = buildChips ( STATIC_CHIPS_NGREPEAT_TEMPLATE ) ;
312
+ var ctrl = element . controller ( 'mdChips' ) ;
313
+
314
+ $timeout . flush ( ) ;
315
+
316
+ var chipsArray = getChipsElements ( element ) ;
317
+ var chipArray = getChipElements ( element ) ;
318
+
319
+ // Check the lengths
320
+ expect ( chipsArray . length ) . toBe ( 3 ) ;
321
+ expect ( chipArray . length ) . toBe ( 3 ) ;
322
+
323
+ // Check the chip's text
324
+ expect ( chipArray [ 0 ] . innerHTML ) . toContain ( '1' ) ;
325
+ expect ( chipArray [ 1 ] . innerHTML ) . toContain ( '2' ) ;
326
+ expect ( chipArray [ 2 ] . innerHTML ) . toContain ( '3' ) ;
327
+ } ) ;
286
328
} ) ;
287
329
288
330
describe ( '<md-chip-remove>' , function ( ) {
@@ -331,11 +373,11 @@ describe('<md-chips>', function() {
331
373
' <md-chip-template><div class="mychiptemplate">[[$chip]]</div></md-chip-template>' +
332
374
'</md-chips>' ;
333
375
var element = buildChips ( template ) ;
334
- var chips = element . find ( 'md-chip' ) ;
376
+ var chips = element [ 0 ] . querySelectorAll ( 'md-chip .mychiptemplate ' ) ;
335
377
336
- expect ( chips . eq ( 0 ) . text ( ) . trim ( ) ) . toEqual ( 'Apple' ) ;
337
- expect ( chips . eq ( 1 ) . text ( ) . trim ( ) ) . toEqual ( 'Banana' ) ;
338
- expect ( chips . eq ( 2 ) . text ( ) . trim ( ) ) . toEqual ( 'Orange' ) ;
378
+ expect ( angular . element ( chips [ 0 ] ) . text ( ) . trim ( ) ) . toEqual ( 'Apple' ) ;
379
+ expect ( angular . element ( chips [ 1 ] ) . text ( ) . trim ( ) ) . toEqual ( 'Banana' ) ;
380
+ expect ( angular . element ( chips [ 2 ] ) . text ( ) . trim ( ) ) . toEqual ( 'Orange' ) ;
339
381
} ) ;
340
382
341
383
it ( 'should not interpolate old-style tags in a user-provided chip template' , function ( ) {
@@ -385,6 +427,10 @@ describe('<md-chips>', function() {
385
427
ctrl . inputKeydown ( event ) ;
386
428
}
387
429
430
+ function getChipsElements ( root ) {
431
+ return angular . element ( root [ 0 ] . querySelectorAll ( 'md-chips' ) ) ;
432
+ }
433
+
388
434
function getChipElements ( root ) {
389
435
return angular . element ( root [ 0 ] . querySelectorAll ( 'md-chip' ) ) ;
390
436
}
0 commit comments