From 8b08ef1e869e2bcdb14d8dc171a2333645362793 Mon Sep 17 00:00:00 2001 From: Wendell Date: Tue, 24 Jul 2018 19:53:01 +0800 Subject: [PATCH] add test --- components/cascader/nz-cascader.component.ts | 3 ++- components/cascader/nz-cascader.spec.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/components/cascader/nz-cascader.component.ts b/components/cascader/nz-cascader.component.ts index 07c9a4b2d9a..e6521e3c640 100644 --- a/components/cascader/nz-cascader.component.ts +++ b/components/cascader/nz-cascader.component.ts @@ -643,7 +643,8 @@ export class NzCascaderComponent implements OnInit, OnDestroy, ControlValueAcces return; } - if (this.inSearch && (keyCode === BACKSPACE || + if (this.inSearch && ( + keyCode === BACKSPACE || keyCode === LEFT_ARROW || keyCode === RIGHT_ARROW )) { diff --git a/components/cascader/nz-cascader.spec.ts b/components/cascader/nz-cascader.spec.ts index d82ce035683..228da7ffe8c 100644 --- a/components/cascader/nz-cascader.spec.ts +++ b/components/cascader/nz-cascader.spec.ts @@ -13,7 +13,6 @@ import { dispatchMouseEvent } from '../core/testing'; -// import { NzDemoCascaderBasicComponent } from './demo/basic'; import { CascaderOption, NzCascaderComponent, NzShowSearchOptions } from './nz-cascader.component'; import { NzCascaderModule } from './nz-cascader.module'; @@ -1426,6 +1425,23 @@ describe('cascader', () => { done(); }); }); + // How can I test BACKSPACE? + it('should not preventDefault left/right arrow in search mode', () => { + const LEFT_ARROW = 37; + const RIGHT_ARROW = 39; + fixture.detectChanges(); + testComponent.nzShowSearch = true; + testComponent.cascader.inputValue = 'o'; + testComponent.cascader.setMenuVisible(true); + fixture.detectChanges(); + dispatchKeyboardEvent(cascader.nativeElement, 'keydown', LEFT_ARROW); + const itemEl1 = overlayContainerElement.querySelector('.ant-cascader-menu:nth-child(1) .ant-cascader-menu-item:nth-child(1)') as HTMLElement; + fixture.detectChanges(); + expect(itemEl1.classList).not.toContain('ant-cascader-menu-item-active'); + dispatchKeyboardEvent(cascader.nativeElement, 'keydown', RIGHT_ARROW); + fixture.detectChanges(); + expect(itemEl1.classList).not.toContain('ant-cascader-menu-item-active'); + }); }); describe('load data lazily', () => {