@@ -16,13 +16,14 @@ import {MdInputModule} from '../input/index';
16
16
import { Dir , LayoutDirection } from '../core/rtl/dir' ;
17
17
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
18
18
import { Subscription } from 'rxjs/Subscription' ;
19
- import { ENTER , DOWN_ARROW , SPACE , UP_ARROW , HOME , END } from '../core/keyboard/keycodes' ;
19
+ import { ENTER , DOWN_ARROW , SPACE , UP_ARROW } from '../core/keyboard/keycodes' ;
20
20
import { MdOption } from '../core/option/option' ;
21
21
import { MdAutocomplete } from './autocomplete' ;
22
22
import { MdInputContainer } from '../input/input-container' ;
23
23
import { Observable } from 'rxjs/Observable' ;
24
24
import { Subject } from 'rxjs/Subject' ;
25
25
import { dispatchFakeEvent } from '../core/testing/dispatch-events' ;
26
+ import { createKeyboardEvent } from '../core/testing/event-objects' ;
26
27
import { typeInElement } from '../core/testing/type-in-element' ;
27
28
import { ScrollDispatcher } from '../core/overlay/scroll/scroll-dispatcher' ;
28
29
@@ -534,8 +535,8 @@ describe('MdAutocomplete', () => {
534
535
fixture . detectChanges ( ) ;
535
536
536
537
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
537
- DOWN_ARROW_EVENT = new MockKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
538
- ENTER_EVENT = new MockKeyboardEvent ( ENTER ) as KeyboardEvent ;
538
+ DOWN_ARROW_EVENT = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
539
+ ENTER_EVENT = createKeyboardEvent ( 'keydown' , ENTER ) ;
539
540
540
541
fixture . componentInstance . trigger . openPanel ( ) ;
541
542
fixture . detectChanges ( ) ;
@@ -593,7 +594,7 @@ describe('MdAutocomplete', () => {
593
594
const optionEls =
594
595
overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
595
596
596
- const UP_ARROW_EVENT = new MockKeyboardEvent ( UP_ARROW ) as KeyboardEvent ;
597
+ const UP_ARROW_EVENT = createKeyboardEvent ( 'keydown' , UP_ARROW ) ;
597
598
fixture . componentInstance . trigger . _handleKeydown ( UP_ARROW_EVENT ) ;
598
599
tick ( ) ;
599
600
fixture . detectChanges ( ) ;
@@ -667,7 +668,7 @@ describe('MdAutocomplete', () => {
667
668
typeInElement ( 'New' , input ) ;
668
669
fixture . detectChanges ( ) ;
669
670
670
- const SPACE_EVENT = new MockKeyboardEvent ( SPACE ) as KeyboardEvent ;
671
+ const SPACE_EVENT = createKeyboardEvent ( 'keydown' , SPACE ) ;
671
672
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
672
673
673
674
fixture . whenStable ( ) . then ( ( ) => {
@@ -747,7 +748,7 @@ describe('MdAutocomplete', () => {
747
748
const scrollContainer =
748
749
document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
749
750
750
- const UP_ARROW_EVENT = new MockKeyboardEvent ( UP_ARROW ) as KeyboardEvent ;
751
+ const UP_ARROW_EVENT = createKeyboardEvent ( 'keydown' , UP_ARROW ) ;
751
752
fixture . componentInstance . trigger . _handleKeydown ( UP_ARROW_EVENT ) ;
752
753
tick ( ) ;
753
754
fixture . detectChanges ( ) ;
@@ -756,36 +757,6 @@ describe('MdAutocomplete', () => {
756
757
expect ( scrollContainer . scrollTop ) . toEqual ( 272 , `Expected panel to reveal last option.` ) ;
757
758
} ) ) ;
758
759
759
- it ( 'should scroll the active option into view when pressing END' , fakeAsync ( ( ) => {
760
- tick ( ) ;
761
- const scrollContainer =
762
- document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
763
-
764
- const END_EVENT = new MockKeyboardEvent ( END ) as KeyboardEvent ;
765
- fixture . componentInstance . trigger . _handleKeydown ( END_EVENT ) ;
766
- tick ( ) ;
767
- fixture . detectChanges ( ) ;
768
-
769
- // Expect option bottom minus the panel height (528 - 256 = 272)
770
- expect ( scrollContainer . scrollTop ) . toEqual ( 272 , 'Expected panel to reveal the last option.' ) ;
771
- } ) ) ;
772
-
773
- it ( 'should scroll the active option into view when pressing HOME' , fakeAsync ( ( ) => {
774
- tick ( ) ;
775
- const scrollContainer =
776
- document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
777
-
778
- scrollContainer . scrollTop = 100 ;
779
- fixture . detectChanges ( ) ;
780
-
781
- const HOME_EVENT = new MockKeyboardEvent ( HOME ) as KeyboardEvent ;
782
- fixture . componentInstance . trigger . _handleKeydown ( HOME_EVENT ) ;
783
- tick ( ) ;
784
- fixture . detectChanges ( ) ;
785
-
786
- expect ( scrollContainer . scrollTop ) . toEqual ( 0 , 'Expected panel to reveal the first option.' ) ;
787
- } ) ) ;
788
-
789
760
} ) ;
790
761
791
762
describe ( 'aria' , ( ) => {
@@ -831,7 +802,7 @@ describe('MdAutocomplete', () => {
831
802
expect ( input . hasAttribute ( 'aria-activedescendant' ) )
832
803
. toBe ( false , 'Expected aria-activedescendant to be absent if no active item.' ) ;
833
804
834
- const DOWN_ARROW_EVENT = new MockKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
805
+ const DOWN_ARROW_EVENT = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
835
806
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
836
807
837
808
fixture . whenStable ( ) . then ( ( ) => {
@@ -1121,7 +1092,7 @@ describe('MdAutocomplete', () => {
1121
1092
tick ( ) ;
1122
1093
fixture . detectChanges ( ) ;
1123
1094
1124
- const DOWN_ARROW_EVENT = new MockKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
1095
+ const DOWN_ARROW_EVENT = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
1125
1096
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
1126
1097
tick ( ) ;
1127
1098
fixture . detectChanges ( ) ;
@@ -1372,10 +1343,3 @@ class AutocompleteWithOnPushDelay implements OnInit {
1372
1343
} , 1000 ) ;
1373
1344
}
1374
1345
}
1375
-
1376
-
1377
- /** This is a mock keyboard event to test keyboard events in the autocomplete. */
1378
- class MockKeyboardEvent {
1379
- constructor ( public keyCode : number ) { }
1380
- preventDefault ( ) { }
1381
- }
0 commit comments