@@ -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
@@ -535,8 +536,8 @@ describe('MdAutocomplete', () => {
535
536
fixture . detectChanges ( ) ;
536
537
537
538
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
538
- DOWN_ARROW_EVENT = new MockKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
539
- ENTER_EVENT = new MockKeyboardEvent ( ENTER ) as KeyboardEvent ;
539
+ DOWN_ARROW_EVENT = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
540
+ ENTER_EVENT = createKeyboardEvent ( 'keydown' , ENTER ) ;
540
541
541
542
fixture . componentInstance . trigger . openPanel ( ) ;
542
543
fixture . detectChanges ( ) ;
@@ -594,7 +595,7 @@ describe('MdAutocomplete', () => {
594
595
const optionEls =
595
596
overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
596
597
597
- const UP_ARROW_EVENT = new MockKeyboardEvent ( UP_ARROW ) as KeyboardEvent ;
598
+ const UP_ARROW_EVENT = createKeyboardEvent ( 'keydown' , UP_ARROW ) ;
598
599
fixture . componentInstance . trigger . _handleKeydown ( UP_ARROW_EVENT ) ;
599
600
tick ( ) ;
600
601
fixture . detectChanges ( ) ;
@@ -668,7 +669,7 @@ describe('MdAutocomplete', () => {
668
669
typeInElement ( 'New' , input ) ;
669
670
fixture . detectChanges ( ) ;
670
671
671
- const SPACE_EVENT = new MockKeyboardEvent ( SPACE ) as KeyboardEvent ;
672
+ const SPACE_EVENT = createKeyboardEvent ( 'keydown' , SPACE ) ;
672
673
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
673
674
674
675
fixture . whenStable ( ) . then ( ( ) => {
@@ -748,7 +749,7 @@ describe('MdAutocomplete', () => {
748
749
const scrollContainer =
749
750
document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
750
751
751
- const UP_ARROW_EVENT = new MockKeyboardEvent ( UP_ARROW ) as KeyboardEvent ;
752
+ const UP_ARROW_EVENT = createKeyboardEvent ( 'keydown' , UP_ARROW ) ;
752
753
fixture . componentInstance . trigger . _handleKeydown ( UP_ARROW_EVENT ) ;
753
754
tick ( ) ;
754
755
fixture . detectChanges ( ) ;
@@ -757,36 +758,6 @@ describe('MdAutocomplete', () => {
757
758
expect ( scrollContainer . scrollTop ) . toEqual ( 272 , `Expected panel to reveal last option.` ) ;
758
759
} ) ) ;
759
760
760
- it ( 'should scroll the active option into view when pressing END' , fakeAsync ( ( ) => {
761
- tick ( ) ;
762
- const scrollContainer =
763
- document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
764
-
765
- const END_EVENT = new MockKeyboardEvent ( END ) as KeyboardEvent ;
766
- fixture . componentInstance . trigger . _handleKeydown ( END_EVENT ) ;
767
- tick ( ) ;
768
- fixture . detectChanges ( ) ;
769
-
770
- // Expect option bottom minus the panel height (528 - 256 = 272)
771
- expect ( scrollContainer . scrollTop ) . toEqual ( 272 , 'Expected panel to reveal the last option.' ) ;
772
- } ) ) ;
773
-
774
- it ( 'should scroll the active option into view when pressing HOME' , fakeAsync ( ( ) => {
775
- tick ( ) ;
776
- const scrollContainer =
777
- document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
778
-
779
- scrollContainer . scrollTop = 100 ;
780
- fixture . detectChanges ( ) ;
781
-
782
- const HOME_EVENT = new MockKeyboardEvent ( HOME ) as KeyboardEvent ;
783
- fixture . componentInstance . trigger . _handleKeydown ( HOME_EVENT ) ;
784
- tick ( ) ;
785
- fixture . detectChanges ( ) ;
786
-
787
- expect ( scrollContainer . scrollTop ) . toEqual ( 0 , 'Expected panel to reveal the first option.' ) ;
788
- } ) ) ;
789
-
790
761
} ) ;
791
762
792
763
describe ( 'aria' , ( ) => {
@@ -832,7 +803,7 @@ describe('MdAutocomplete', () => {
832
803
expect ( input . hasAttribute ( 'aria-activedescendant' ) )
833
804
. toBe ( false , 'Expected aria-activedescendant to be absent if no active item.' ) ;
834
805
835
- const DOWN_ARROW_EVENT = new MockKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
806
+ const DOWN_ARROW_EVENT = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
836
807
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
837
808
838
809
fixture . whenStable ( ) . then ( ( ) => {
@@ -1140,7 +1111,7 @@ describe('MdAutocomplete', () => {
1140
1111
tick ( ) ;
1141
1112
fixture . detectChanges ( ) ;
1142
1113
1143
- const DOWN_ARROW_EVENT = new MockKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
1114
+ const DOWN_ARROW_EVENT = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
1144
1115
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
1145
1116
tick ( ) ;
1146
1117
fixture . detectChanges ( ) ;
@@ -1418,10 +1389,3 @@ class AutocompleteWithNativeInput {
1418
1389
} ) ;
1419
1390
}
1420
1391
}
1421
-
1422
-
1423
- /** This is a mock keyboard event to test keyboard events in the autocomplete. */
1424
- class MockKeyboardEvent {
1425
- constructor ( public keyCode : number ) { }
1426
- preventDefault ( ) { }
1427
- }
0 commit comments