Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should support keydown events to open and close select panel', fakeAsync(() => {
fixture.detectChanges();
dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', SPACE);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.open).toBe(true);
// #2201, space should not close select panel
dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', TAB);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.open).toBe(false);
dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', DOWN_ARROW);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.open).toBe(true);
dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', TAB);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.open).toBe(false);
testComponent.disabled = true;
fixture.detectChanges();
dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', TAB);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.open).toBe(false);
it('should select option when press ENTER', fakeAsync(() => {
fixture.detectChanges();
expect(testComponent.values).toBeNull();
testComponent.cascader.setMenuVisible(true);
fixture.detectChanges();
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', DOWN_ARROW); // active 1
fixture.detectChanges();
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.values).toBeNull(); // not select yet
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', RIGHT_ARROW); // active 2
fixture.detectChanges();
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.values).toBeNull(); // not select yet
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', RIGHT_ARROW); // active 3
fixture.detectChanges();
expect(testComponent.values).toBeNull(); // not select yet
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ENTER);
expect(testComponent.values).toBeNull();
testComponent.cascader.setMenuVisible(true);
fixture.detectChanges();
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', DOWN_ARROW); // active 1
fixture.detectChanges();
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.values).toBeNull(); // not select yet
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', RIGHT_ARROW); // active 2
fixture.detectChanges();
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.values).toBeNull(); // not select yet
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', RIGHT_ARROW); // active 3
fixture.detectChanges();
expect(testComponent.values).toBeNull(); // not select yet
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ENTER);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.values).toBeDefined();
expect(testComponent.values!.length).toBe(3);
expect(testComponent.values![0]).toBe('zhejiang');
expect(testComponent.values![1]).toBe('hangzhou');
expect(testComponent.values![2]).toBe('xihu');
flush();
fixture.detectChanges();
expect(testComponent.cascader.menuVisible).toBe(false);
it('should key down work', () => {
expect(testComponent.value).toBe(false);
switchElement.nativeElement.click();
fixture.detectChanges();
expect(testComponent.modelChange).toHaveBeenCalledTimes(1);
expect(testComponent.value).toBe(true);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(true);
expect(testComponent.modelChange).toHaveBeenCalledTimes(1);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(2);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(2);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', SPACE);
fixture.detectChanges();
expect(testComponent.value).toBe(true);
expect(testComponent.modelChange).toHaveBeenCalledTimes(3);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(4);
it('should close the dropdown when tabbing', fakeAsync(() => {
textarea.value = '@';
dispatchFakeEvent(textarea, 'click');
fixture.detectChanges();
expect(overlayContainerElement.querySelector('.ant-mention-dropdown')).toBeTruthy();
dispatchKeyboardEvent(textarea, 'keydown', TAB);
fixture.detectChanges();
tick(500);
expect(overlayContainerElement.querySelector('.ant-mention-dropdown')).toBeFalsy();
}));
it('should be openable after closed by "Escape" key', fakeAsync(() => {
fixture.detectChanges();
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(getPickerContainer()).not.toBeNull();
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(getPickerContainer()).toBeNull();
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(getPickerContainer()).not.toBeNull();
}));
expect(testComponent.modelChange).toHaveBeenCalledTimes(0);
dispatchKeyboardEvent(rate.nativeElement.firstElementChild, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(1);
expect(testComponent.modelChange).toHaveBeenCalledTimes(1);
dispatchKeyboardEvent(rate.nativeElement.firstElementChild, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(0);
expect(testComponent.modelChange).toHaveBeenCalledTimes(2);
testComponent.allowHalf = true;
fixture.detectChanges();
dispatchKeyboardEvent(rate.nativeElement.firstElementChild, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(0.5);
expect(testComponent.modelChange).toHaveBeenCalledTimes(3);
dispatchKeyboardEvent(rate.nativeElement.firstElementChild, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(0);
expect(testComponent.modelChange).toHaveBeenCalledTimes(4);
});
it('should right keydown not dispatch change reached limit', fakeAsync(() => {
it('should close the panel when pressing escape', fakeAsync(() => {
fixture.detectChanges();
input.focus();
flush();
expect(overlayContainerElement.querySelector('.ant-select-dropdown')).toBeTruthy();
dispatchKeyboardEvent(input, 'keydown', ESCAPE);
fixture.detectChanges();
tick(500);
expect(overlayContainerElement.querySelector('.ant-select-dropdown')).toBeFalsy();
}));
});
it('should close the dropdown when pressing escape', fakeAsync(() => {
textarea.value = '@';
dispatchFakeEvent(textarea, 'click');
fixture.detectChanges();
expect(overlayContainerElement.querySelector('.ant-mention-dropdown')).toBeTruthy();
dispatchKeyboardEvent(textarea, 'keydown', ESCAPE);
fixture.detectChanges();
tick(500);
expect(overlayContainerElement.querySelector('.ant-mention-dropdown')).toBeFalsy();
}));
});
expect(testComponent.value).toBe(true);
expect(testComponent.modelChange).toHaveBeenCalledTimes(1);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(2);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(2);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', SPACE);
fixture.detectChanges();
expect(testComponent.value).toBe(true);
expect(testComponent.modelChange).toHaveBeenCalledTimes(3);
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(4);
testComponent.control = true;
fixture.detectChanges();
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(4);
testComponent.control = false;
testComponent.loading = true;
fixture.detectChanges();
dispatchKeyboardEvent(switchElement.nativeElement.firstElementChild, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.value).toBe(false);
expect(testComponent.modelChange).toHaveBeenCalledTimes(4);