From 9929c3e3d89ece2723a1b7a16046bfb6cb4a12d5 Mon Sep 17 00:00:00 2001 From: Lene Gadewoll Date: Fri, 3 May 2024 18:39:14 +0200 Subject: [PATCH] chore: cleanup -use const as type - revert newline changes --- src/components/combo_box/combo_box.stories.tsx | 3 +-- src/components/combo_box/combo_box.test.tsx | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/combo_box/combo_box.stories.tsx b/src/components/combo_box/combo_box.stories.tsx index 27827b45387..771f277889c 100644 --- a/src/components/combo_box/combo_box.stories.tsx +++ b/src/components/combo_box/combo_box.stories.tsx @@ -10,14 +10,13 @@ import React, { useCallback, useState } from 'react'; import type { Meta, StoryObj } from '@storybook/react'; import { action } from '@storybook/addon-actions'; -import { ToolTipPositions } from '../tool_tip'; import { EuiComboBox, EuiComboBoxProps } from './combo_box'; import { EuiComboBoxOptionMatcher } from './types'; import { EuiCode } from '../code'; const toolTipProps = { toolTipContent: 'This is a tooltip!', - toolTipProps: { position: 'left' as ToolTipPositions }, + toolTipProps: { position: 'left' as const }, value: 4, }; diff --git a/src/components/combo_box/combo_box.test.tsx b/src/components/combo_box/combo_box.test.tsx index 00533c38e36..251222921e6 100644 --- a/src/components/combo_box/combo_box.test.tsx +++ b/src/components/combo_box/combo_box.test.tsx @@ -525,21 +525,26 @@ describe('EuiComboBox', () => { describe('tabbing off the search input', () => { it("closes the options list if the user isn't navigating the options", async () => { const keyDownBubbled = jest.fn(); + const { getByTestSubject } = render(
); await showEuiComboBoxOptions(); + const mockEvent = { key: keys.TAB, shiftKey: true }; fireEvent.keyDown(getByTestSubject('comboBoxSearchInput'), mockEvent); + // If the TAB keydown bubbled up to the wrapper, then a browser DOM would shift the focus expect(keyDownBubbled).toHaveBeenCalledWith( expect.objectContaining(mockEvent) ); }); + it('calls onCreateOption', () => { const onCreateOptionHandler = jest.fn(); + const { getByTestSubject } = render( { /> ); const input = getByTestSubject('comboBoxSearchInput'); + fireEvent.change(input, { target: { value: 'foo' } }); fireEvent.blur(input); + expect(onCreateOptionHandler).toHaveBeenCalledTimes(1); expect(onCreateOptionHandler).toHaveBeenCalledWith('foo', options); }); + it('does nothing if the user is navigating the options', async () => { const keyDownBubbled = jest.fn(); + const { getByTestSubject } = render(
); await showEuiComboBoxOptions(); + // Navigate to an option then tab off const input = getByTestSubject('comboBoxSearchInput'); fireEvent.keyDown(input, { key: keys.ARROW_DOWN }); fireEvent.keyDown(input, { key: keys.TAB }); + // If the TAB keydown did not bubble to the wrapper, then the tab event was prevented expect(keyDownBubbled).not.toHaveBeenCalled(); });