1
- import { DOWN_ARROW , LEFT_ARROW , RIGHT_ARROW , TAB , UP_ARROW } from '@angular/cdk/keycodes' ;
1
+ import { DOWN_ARROW , END , HOME , LEFT_ARROW , RIGHT_ARROW , TAB , UP_ARROW } from '@angular/cdk/keycodes' ;
2
2
import { createKeyboardEvent } from '@angular/cdk/testing/private' ;
3
3
import { QueryList } from '@angular/core' ;
4
4
import { fakeAsync , tick } from '@angular/core/testing' ;
@@ -51,6 +51,8 @@ describe('Key managers', () => {
51
51
leftArrow : KeyboardEvent ,
52
52
rightArrow : KeyboardEvent ,
53
53
tab : KeyboardEvent ,
54
+ home : KeyboardEvent ,
55
+ end : KeyboardEvent ,
54
56
unsupported : KeyboardEvent
55
57
} ;
56
58
@@ -62,6 +64,8 @@ describe('Key managers', () => {
62
64
leftArrow : createKeyboardEvent ( 'keydown' , LEFT_ARROW ) ,
63
65
rightArrow : createKeyboardEvent ( 'keydown' , RIGHT_ARROW ) ,
64
66
tab : createKeyboardEvent ( 'keydown' , TAB ) ,
67
+ home : createKeyboardEvent ( 'keydown' , HOME ) ,
68
+ end : createKeyboardEvent ( 'keydown' , END ) ,
65
69
unsupported : createKeyboardEvent ( 'keydown' , 192 ) // corresponds to the tilde character (~)
66
70
} ;
67
71
} ) ;
@@ -195,6 +199,30 @@ describe('Key managers', () => {
195
199
expect ( fakeKeyEvents . downArrow . defaultPrevented ) . toBe ( false ) ;
196
200
} ) ;
197
201
202
+ describe ( 'withHomeAndEnd' , ( ) => {
203
+ beforeEach ( ( ) => {
204
+ keyManager . withHomeAndEnd ( ) ;
205
+ } ) ;
206
+
207
+ it ( 'should focus the first item when Home is pressed' , ( ) => {
208
+ keyManager . setActiveItem ( 1 ) ;
209
+ expect ( keyManager . activeItemIndex ) . toBe ( 1 ) ;
210
+
211
+ keyManager . onKeydown ( fakeKeyEvents . home ) ;
212
+
213
+ expect ( keyManager . activeItemIndex ) . toBe ( 0 ) ;
214
+ } ) ;
215
+
216
+ it ( 'should focus the last item when End is pressed' , ( ) => {
217
+ keyManager . setActiveItem ( 0 ) ;
218
+ expect ( keyManager . activeItemIndex ) . toBe ( 0 ) ;
219
+
220
+ keyManager . onKeydown ( fakeKeyEvents . end ) ;
221
+
222
+ expect ( keyManager . activeItemIndex ) . toBe ( itemList . items . length - 1 ) ;
223
+ } )
224
+ } ) ;
225
+
198
226
describe ( 'with `vertical` direction' , function ( this : KeyEventTestContext ) {
199
227
beforeEach ( ( ) => {
200
228
keyManager . withVerticalOrientation ( ) ;
0 commit comments