|
1 |
| -import {DOWN_ARROW, SPACE, ENTER, UP_ARROW, HOME, END, A} from '@angular/cdk/keycodes'; |
| 1 | +import {DOWN_ARROW, SPACE, ENTER, UP_ARROW, HOME, END, A, D} from '@angular/cdk/keycodes'; |
2 | 2 | import {
|
3 | 3 | createKeyboardEvent,
|
4 | 4 | dispatchFakeEvent,
|
@@ -501,6 +501,44 @@ describe('MatSelectionList without forms', () => {
|
501 | 501 | expect(manager.activeItemIndex).toBe(3);
|
502 | 502 | }));
|
503 | 503 |
|
| 504 | + it('should be able to skip to an item by typing', fakeAsync(() => { |
| 505 | + const manager = selectionList.componentInstance._keyManager; |
| 506 | + |
| 507 | + expect(manager.activeItemIndex).not.toBe(3); |
| 508 | + |
| 509 | + const event = createKeyboardEvent('keydown', D, 'd'); |
| 510 | + selectionList.componentInstance._keydown(event); |
| 511 | + fixture.detectChanges(); |
| 512 | + tick(200); |
| 513 | + |
| 514 | + expect(manager.activeItemIndex).toBe(3); |
| 515 | + })); |
| 516 | + |
| 517 | + it('should not select items while using the typeahead', fakeAsync(() => { |
| 518 | + const manager = selectionList.componentInstance._keyManager; |
| 519 | + const testListItem = listOptions[1].nativeElement as HTMLElement; |
| 520 | + const model = |
| 521 | + selectionList.injector.get<MatSelectionList>(MatSelectionList).selectedOptions; |
| 522 | + |
| 523 | + dispatchFakeEvent(testListItem, 'focus'); |
| 524 | + fixture.detectChanges(); |
| 525 | + |
| 526 | + expect(manager.activeItemIndex).toBe(1); |
| 527 | + expect(model.isEmpty()).toBe(true); |
| 528 | + |
| 529 | + selectionList.componentInstance._keydown(createKeyboardEvent('keydown', D, 'd')); |
| 530 | + fixture.detectChanges(); |
| 531 | + tick(100); // Tick only half the typeahead timeout. |
| 532 | + |
| 533 | + selectionList.componentInstance._keydown( |
| 534 | + createKeyboardEvent('keydown', SPACE, undefined, testListItem)); |
| 535 | + fixture.detectChanges(); |
| 536 | + tick(100); // Tick the rest of the timeout. |
| 537 | + |
| 538 | + expect(manager.activeItemIndex).toBe(3); |
| 539 | + expect(model.isEmpty()).toBe(true); |
| 540 | + })); |
| 541 | + |
504 | 542 | it('should be able to select all options', () => {
|
505 | 543 | const list: MatSelectionList = selectionList.componentInstance;
|
506 | 544 |
|
|
0 commit comments