Skip to content

Commit

Permalink
Merge pull request #6 from Dmitriynj/field-types-help
Browse files Browse the repository at this point in the history
[Discover] Improve field types docs popover unit tests
  • Loading branch information
andreadelrio authored Apr 1, 2022
2 parents ef05603 + 71c38d8 commit 0faad6d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ import { findTestSubject } from '@elastic/eui/lib/test';
import { DiscoverFieldSearch, Props } from './discover_field_search';
import { EuiButtonGroupProps, EuiPopover } from '@elastic/eui';
import { ReactWrapper } from 'enzyme';
import { KibanaContextProvider } from '../../../../../../kibana_react/public';

describe('DiscoverFieldSearch', () => {
const defaultProps = {
onChange: jest.fn(),
value: 'test',
types: ['any', 'string', '_source'],
presentFieldTypes: ['string', 'date', 'boolean', 'number'],
};

function mountComponent(props?: Props) {
const compProps = props || defaultProps;
return mountWithIntl(<DiscoverFieldSearch {...compProps} />);
return mountWithIntl(
<KibanaContextProvider
services={{ docLinks: { links: { discover: { fieldTypeHelp: '' } } } }}
>
<DiscoverFieldSearch {...compProps} />
</KibanaContextProvider>
);
}

function findButtonGroup(component: ReactWrapper, id: string) {
Expand Down Expand Up @@ -131,9 +139,25 @@ describe('DiscoverFieldSearch', () => {
const btn = findTestSubject(component, 'toggleFieldFilterButton');
btn.simulate('click');
let popover = component.find(EuiPopover);
expect(popover.prop('isOpen')).toBe(true);
expect(popover.get(0).props.isOpen).toBe(true);
btn.simulate('click');
popover = component.find(EuiPopover);
expect(popover.prop('isOpen')).toBe(false);
expect(popover.get(0).props.isOpen).toBe(false);
});

test('click help button should open popover with types of field docs', () => {
const component = mountComponent();

const btn = findTestSubject(component, 'fieldTypesHelpButton');
btn.simulate('click');
let popover = component.find(EuiPopover);
expect(popover.get(1).props.isOpen).toBe(true);

const rows = component.find('.euiTableRow');
expect(rows.length).toBe(4);

btn.simulate('click');
popover = component.find(EuiPopover);
expect(popover.get(1).props.isOpen).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export function DiscoverFieldSearch({ onChange, value, types, presentFieldTypes
<EuiFilterButton
grow={false}
onClick={onHelpClick}
data-test-subj="fieldTypesHelpButton"
className="dscFieldTypesHelp__button"
aria-label="Filter type help"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const mockServices = {
}
},
},
docLinks: { links: { discover: { fieldTypeHelp: '' } } },
} as unknown as DiscoverServices;

const mockfieldCounts: Record<string, number> = {};
Expand Down

0 comments on commit 0faad6d

Please sign in to comment.