|
1 |
| -import {DOWN_ARROW, SPACE, ENTER, UP_ARROW} from '@angular/cdk/keycodes'; |
| 1 | +import {DOWN_ARROW, SPACE, ENTER, UP_ARROW, HOME, END} from '@angular/cdk/keycodes'; |
2 | 2 | import {Platform} from '@angular/cdk/platform';
|
3 |
| -import {createKeyboardEvent, dispatchFakeEvent} from '@angular/cdk/testing'; |
| 3 | +import {createKeyboardEvent, dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing'; |
4 | 4 | import {Component, DebugElement} from '@angular/core';
|
5 | 5 | import {async, ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
|
6 | 6 | import {By} from '@angular/platform-browser';
|
@@ -264,6 +264,29 @@ describe('MatSelectionList without forms', () => {
|
264 | 264 | expect(manager.activeItemIndex).toEqual(3);
|
265 | 265 | });
|
266 | 266 |
|
| 267 | + it('should focus the first non-disabled item when pressing HOME', () => { |
| 268 | + const manager = selectionList.componentInstance._keyManager; |
| 269 | + expect(manager.activeItemIndex).toBe(-1); |
| 270 | + |
| 271 | + const event = dispatchKeyboardEvent(selectionList.nativeElement, 'keydown', HOME); |
| 272 | + fixture.detectChanges(); |
| 273 | + |
| 274 | + // Note that the first item is disabled so we expect the second one to be focused. |
| 275 | + expect(manager.activeItemIndex).toBe(1); |
| 276 | + expect(event.defaultPrevented).toBe(true); |
| 277 | + }); |
| 278 | + |
| 279 | + it('should focus the last item when pressing END', () => { |
| 280 | + const manager = selectionList.componentInstance._keyManager; |
| 281 | + expect(manager.activeItemIndex).toBe(-1); |
| 282 | + |
| 283 | + const event = dispatchKeyboardEvent(selectionList.nativeElement, 'keydown', END); |
| 284 | + fixture.detectChanges(); |
| 285 | + |
| 286 | + expect(manager.activeItemIndex).toBe(3); |
| 287 | + expect(event.defaultPrevented).toBe(true); |
| 288 | + }); |
| 289 | + |
267 | 290 | it('should be able to select all options', () => {
|
268 | 291 | const list: MatSelectionList = selectionList.componentInstance;
|
269 | 292 |
|
|
0 commit comments