|
1 |
| -import {DOWN_ARROW, SPACE, ENTER, UP_ARROW, HOME, END} from '@angular/cdk/keycodes'; |
| 1 | +import {DOWN_ARROW, SPACE, ENTER, UP_ARROW, HOME, END, A} from '@angular/cdk/keycodes'; |
2 | 2 | import {
|
3 | 3 | createKeyboardEvent,
|
4 | 4 | dispatchFakeEvent,
|
@@ -321,6 +321,48 @@ describe('MatSelectionList without forms', () => {
|
321 | 321 | expect(event.defaultPrevented).toBe(true);
|
322 | 322 | });
|
323 | 323 |
|
| 324 | + it('should select all items using ctrl + a', () => { |
| 325 | + const event = createKeyboardEvent('keydown', A, selectionList.nativeElement); |
| 326 | + Object.defineProperty(event, 'ctrlKey', {get: () => true}); |
| 327 | + |
| 328 | + expect(listOptions.some(option => option.componentInstance.selected)).toBe(false); |
| 329 | + |
| 330 | + dispatchEvent(selectionList.nativeElement, event); |
| 331 | + fixture.detectChanges(); |
| 332 | + |
| 333 | + expect(listOptions.every(option => option.componentInstance.selected)).toBe(true); |
| 334 | + }); |
| 335 | + |
| 336 | + it('should select all items using ctrl + a if some items are selected', () => { |
| 337 | + const event = createKeyboardEvent('keydown', A, selectionList.nativeElement); |
| 338 | + Object.defineProperty(event, 'ctrlKey', {get: () => true}); |
| 339 | + |
| 340 | + listOptions.slice(0, 2).forEach(option => option.componentInstance.selected = true); |
| 341 | + fixture.detectChanges(); |
| 342 | + |
| 343 | + expect(listOptions.some(option => option.componentInstance.selected)).toBe(true); |
| 344 | + |
| 345 | + dispatchEvent(selectionList.nativeElement, event); |
| 346 | + fixture.detectChanges(); |
| 347 | + |
| 348 | + expect(listOptions.every(option => option.componentInstance.selected)).toBe(true); |
| 349 | + }); |
| 350 | + |
| 351 | + it('should deselect all with ctrl + a if all options are selected', () => { |
| 352 | + const event = createKeyboardEvent('keydown', A, selectionList.nativeElement); |
| 353 | + Object.defineProperty(event, 'ctrlKey', {get: () => true}); |
| 354 | + |
| 355 | + listOptions.forEach(option => option.componentInstance.selected = true); |
| 356 | + fixture.detectChanges(); |
| 357 | + |
| 358 | + expect(listOptions.every(option => option.componentInstance.selected)).toBe(true); |
| 359 | + |
| 360 | + dispatchEvent(selectionList.nativeElement, event); |
| 361 | + fixture.detectChanges(); |
| 362 | + |
| 363 | + expect(listOptions.every(option => option.componentInstance.selected)).toBe(false); |
| 364 | + }); |
| 365 | + |
324 | 366 | it('should be able to jump focus down to an item by typing', fakeAsync(() => {
|
325 | 367 | const listEl = selectionList.nativeElement;
|
326 | 368 | const manager = selectionList.componentInstance._keyManager;
|
|
0 commit comments