@@ -276,6 +276,13 @@ describe('typeahead tests', function () {
276
276
277
277
expect ( findMatches ( element ) . eq ( 0 ) . find ( 'p' ) . text ( ) ) . toEqual ( '0 Alaska' ) ;
278
278
} ) ) ;
279
+
280
+ it ( 'should throw error on invalid expression' , function ( ) {
281
+ var prepareInvalidDir = function ( ) {
282
+ prepareInputEl ( "<div><input ng-model='result' typeahead='an invalid expression'></div>" ) ;
283
+ } ;
284
+ expect ( prepareInvalidDir ) . toThrow ( ) ;
285
+ } ) ;
279
286
} ) ;
280
287
281
288
describe ( 'selecting a match' , function ( ) {
@@ -354,6 +361,84 @@ describe('typeahead tests', function () {
354
361
} ) ;
355
362
} ) ;
356
363
364
+ describe ( 'pop-up interaction' , function ( ) {
365
+ var element ;
366
+
367
+ beforeEach ( function ( ) {
368
+ element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>" ) ;
369
+ } ) ;
370
+
371
+ it ( 'should activate prev/next matches on up/down keys' , function ( ) {
372
+ changeInputValueTo ( element , 'b' ) ;
373
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
374
+
375
+ // Down arrow key
376
+ triggerKeyDown ( element , 40 ) ;
377
+ expect ( element ) . toBeOpenWithActive ( 2 , 1 ) ;
378
+
379
+ // Down arrow key goes back to first element
380
+ triggerKeyDown ( element , 40 ) ;
381
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
382
+
383
+ // Up arrow key goes back to last element
384
+ triggerKeyDown ( element , 38 ) ;
385
+ expect ( element ) . toBeOpenWithActive ( 2 , 1 ) ;
386
+
387
+ // Up arrow key goes back to last element
388
+ triggerKeyDown ( element , 38 ) ;
389
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
390
+ } ) ;
391
+
392
+ it ( 'should close popup on escape key' , function ( ) {
393
+ changeInputValueTo ( element , 'b' ) ;
394
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
395
+
396
+ // Escape key
397
+ triggerKeyDown ( element , 27 ) ;
398
+ expect ( element ) . toBeClosed ( ) ;
399
+ } ) ;
400
+
401
+ it ( 'should highlight match on mouseenter' , function ( ) {
402
+ changeInputValueTo ( element , 'b' ) ;
403
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
404
+
405
+ findMatches ( element ) . eq ( 1 ) . trigger ( 'mouseenter' ) ;
406
+ expect ( element ) . toBeOpenWithActive ( 2 , 1 ) ;
407
+ } ) ;
408
+
409
+ } ) ;
410
+
411
+ describe ( 'promises' , function ( ) {
412
+ var element , deferred ;
413
+
414
+ beforeEach ( inject ( function ( $q ) {
415
+ deferred = $q . defer ( ) ;
416
+ $scope . source = function ( ) {
417
+ return deferred . promise ;
418
+ } ;
419
+ element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source()'></div>" ) ;
420
+ } ) ) ;
421
+
422
+ it ( 'should display matches from promise' , function ( ) {
423
+ changeInputValueTo ( element , 'c' ) ;
424
+ expect ( element ) . toBeClosed ( ) ;
425
+
426
+ deferred . resolve ( [ 'good' , 'stuff' ] ) ;
427
+ $scope . $digest ( ) ;
428
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
429
+ } ) ;
430
+
431
+ it ( 'should not display anything when promise is rejected' , function ( ) {
432
+ changeInputValueTo ( element , 'c' ) ;
433
+ expect ( element ) . toBeClosed ( ) ;
434
+
435
+ deferred . reject ( 'fail' ) ;
436
+ $scope . $digest ( ) ;
437
+ expect ( element ) . toBeClosed ( ) ;
438
+ } ) ;
439
+
440
+ } ) ;
441
+
357
442
describe ( 'non-regressions tests' , function ( ) {
358
443
359
444
it ( 'issue 231 - closes matches popup on click outside typeahead' , function ( ) {
0 commit comments