|
1 | | -import {DOWN_ARROW, SPACE, UP_ARROW} from '@angular/cdk/keycodes'; |
| 1 | +import {DOWN_ARROW, END, HOME, SPACE, UP_ARROW} 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 | +import {FormControl, FormsModule, NgModel, ReactiveFormsModule} from '@angular/forms'; |
6 | 7 | import {By} from '@angular/platform-browser'; |
7 | 8 | import { |
8 | 9 | MatListModule, |
9 | 10 | MatListOption, |
10 | 11 | MatListOptionChange, |
11 | 12 | MatSelectionList, |
12 | | - MatSelectionListChange |
| 13 | + MatSelectionListChange, |
13 | 14 | } from './index'; |
14 | | -import {FormControl, FormsModule, NgModel, ReactiveFormsModule} from '@angular/forms'; |
15 | 15 |
|
16 | 16 | describe('MatSelectionList without forms', () => { |
17 | 17 | describe('with list option', () => { |
@@ -248,6 +248,29 @@ describe('MatSelectionList without forms', () => { |
248 | 248 | expect(manager.activeItemIndex).toEqual(3); |
249 | 249 | }); |
250 | 250 |
|
| 251 | + it('should focus the first non-disabled item when pressing HOME', () => { |
| 252 | + const manager = selectionList.componentInstance._keyManager; |
| 253 | + expect(manager.activeItemIndex).toBe(-1); |
| 254 | + |
| 255 | + const event = dispatchKeyboardEvent(selectionList.nativeElement, 'keydown', HOME); |
| 256 | + fixture.detectChanges(); |
| 257 | + |
| 258 | + // Note that the first item is disabled so we expect the second one to be focused. |
| 259 | + expect(manager.activeItemIndex).toBe(1); |
| 260 | + expect(event.defaultPrevented).toBe(true); |
| 261 | + }); |
| 262 | + |
| 263 | + it('should focus the last item when pressing END', () => { |
| 264 | + const manager = selectionList.componentInstance._keyManager; |
| 265 | + expect(manager.activeItemIndex).toBe(-1); |
| 266 | + |
| 267 | + const event = dispatchKeyboardEvent(selectionList.nativeElement, 'keydown', END); |
| 268 | + fixture.detectChanges(); |
| 269 | + |
| 270 | + expect(manager.activeItemIndex).toBe(3); |
| 271 | + expect(event.defaultPrevented).toBe(true); |
| 272 | + }); |
| 273 | + |
251 | 274 | it('should be able to select all options', () => { |
252 | 275 | const list: MatSelectionList = selectionList.componentInstance; |
253 | 276 |
|
|
0 commit comments