Skip to content
Snippets Groups Projects
Commit 1ba90279 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6129 improve test

parent d030b458
No related branches found
No related tags found
No related merge requests found
...@@ -146,11 +146,12 @@ describe('InstantSearchComponent', () => { ...@@ -146,11 +146,12 @@ describe('InstantSearchComponent', () => {
}); });
describe('handleArrowNavigation', () => { describe('handleArrowNavigation', () => {
const event: KeyboardEvent = new KeyboardEvent('arrow');
beforeEach(() => { beforeEach(() => {
component.setFocusOnResultItem = jest.fn();
component.getResultIndexForKey = jest.fn(); component.getResultIndexForKey = jest.fn();
component.setFocusOnResultItem = jest.fn();
}); });
const event: KeyboardEvent = new KeyboardEvent('arrow');
it('should call prevent default', () => { it('should call prevent default', () => {
event.preventDefault = jest.fn(); event.preventDefault = jest.fn();
...@@ -160,13 +161,13 @@ describe('InstantSearchComponent', () => { ...@@ -160,13 +161,13 @@ describe('InstantSearchComponent', () => {
expect(event.preventDefault).toHaveBeenCalled(); expect(event.preventDefault).toHaveBeenCalled();
}); });
it('should call getResultIndexForKey with key of event', () => { it('should call getResultIndexForKey', () => {
component.handleArrowNavigation(event); component.handleArrowNavigation(event);
expect(component.getResultIndexForKey).toHaveBeenCalledWith(event.key); expect(component.getResultIndexForKey).toHaveBeenCalledWith(event.key);
}); });
it('should call setFocusOnResultItem new index', () => { it('should call setFocusOnResultItem', () => {
component.getResultIndexForKey = jest.fn().mockReturnValue(0); component.getResultIndexForKey = jest.fn().mockReturnValue(0);
component.handleArrowNavigation(event); component.handleArrowNavigation(event);
...@@ -422,20 +423,12 @@ describe('InstantSearchComponent', () => { ...@@ -422,20 +423,12 @@ describe('InstantSearchComponent', () => {
}); });
describe('isArrowNavigationKey', () => { describe('isArrowNavigationKey', () => {
it('should return true if key is ArrowDown', () => { it.each(['ArrowUp', 'ArrowDown'])('should return true for key %s', (key: string) => {
const arrowDownEvent = { ...new KeyboardEvent('key'), key: 'ArrowDown' }; const keyboardEvent: KeyboardEvent = { ...new KeyboardEvent('key'), key };
const result: boolean = component.isArrowNavigationKey(arrowDownEvent); const result: boolean = component.isArrowNavigationKey(keyboardEvent);
expect(result).toBe(true); expect(result).toBeTruthy();
});
it('should return true if key is ArrowUp', () => {
const arrowUpEvent = { ...new KeyboardEvent('navigation'), key: 'ArrowUp' };
const result: boolean = component.isArrowNavigationKey(arrowUpEvent);
expect(result).toBe(true);
}); });
it('should return false', () => { it('should return false', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment