Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendell committed Jul 24, 2018
1 parent 6961b66 commit 8b08ef1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion components/cascader/nz-cascader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)) {
Expand Down
18 changes: 17 additions & 1 deletion components/cascader/nz-cascader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 8b08ef1

Please sign in to comment.