Skip to content

Commit 71d9806

Browse files
committed
test(listbox): added test for selection via shift key.
1 parent 83db6b5 commit 71d9806

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/cdk-experimental/listbox/listbox.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
CdkOption,
1010
CdkListboxModule, ListboxSelectionChangeEvent, CdkListbox
1111
} from './index';
12-
import {dispatchKeyboardEvent, dispatchMouseEvent} from '@angular/cdk/testing/private';
12+
import {
13+
createKeyboardEvent,
14+
dispatchKeyboardEvent,
15+
dispatchMouseEvent
16+
} from '@angular/cdk/testing/private';
1317
import {A, DOWN_ARROW, END, HOME, SPACE} from '@angular/cdk/keycodes';
1418

1519
describe('CdkOption', () => {
@@ -327,6 +331,28 @@ describe('CdkOption', () => {
327331
expect(fixture.componentInstance.changedOption).toBeDefined();
328332
expect(fixture.componentInstance.changedOption.id).toBe(optionInstances[0].id);
329333
});
334+
335+
it('should focus and toggle the next item when pressing SHIFT + DOWN_ARROW', () => {
336+
let selectedOptions = optionInstances.filter(option => option.selected);
337+
const downKeyEvent = createKeyboardEvent('keydown', DOWN_ARROW);
338+
Object.defineProperty(downKeyEvent, 'shiftKey', {get: () => true});
339+
340+
expect(selectedOptions.length).toBe(0);
341+
expect(optionElements[0].hasAttribute('aria-selected')).toBeFalse();
342+
expect(optionInstances[0].selected).toBeFalse();
343+
expect(fixture.componentInstance.changedOption).toBeUndefined();
344+
345+
listboxInstance.setActiveOption(optionInstances[0]);
346+
listboxInstance._keydown(downKeyEvent);
347+
fixture.detectChanges();
348+
349+
selectedOptions = optionInstances.filter(option => option.selected);
350+
expect(selectedOptions.length).toBe(1);
351+
expect(optionElements[1].getAttribute('aria-selected')).toBe('true');
352+
expect(optionInstances[1].selected).toBeTrue();
353+
expect(fixture.componentInstance.changedOption).toBeDefined();
354+
expect(fixture.componentInstance.changedOption.id).toBe(optionInstances[1].id);
355+
});
330356
});
331357

332358
describe('with multiple selection', () => {

0 commit comments

Comments
 (0)