[Discover Index Pattern management] Add more unit tests (#97749)
* [Discover Index Pattern management] Add more unit tests * [Discover Index Pattern management] Fix typo * Fix failing unit test
This commit is contained in:
parent
a8a8289b20
commit
55f3b8975e
3 changed files with 116 additions and 19 deletions
|
@ -634,21 +634,16 @@ exports[`Discover IndexPattern Management renders correctly 1`] = `
|
|||
"show": true,
|
||||
},
|
||||
},
|
||||
"core": Object {
|
||||
"application": Object {
|
||||
"navigateToApp": [MockFunction],
|
||||
},
|
||||
},
|
||||
"history": [Function],
|
||||
"indexPatternFieldEditor": Object {
|
||||
"openEditor": [MockFunction],
|
||||
"userPermissions": Object {
|
||||
"editIndexPattern": [MockFunction] {
|
||||
"calls": Array [
|
||||
Array [],
|
||||
],
|
||||
"results": Array [
|
||||
Object {
|
||||
"type": "return",
|
||||
"value": undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
"editIndexPattern": [Function],
|
||||
},
|
||||
},
|
||||
"uiSettings": Object {
|
||||
|
@ -657,5 +652,65 @@ exports[`Discover IndexPattern Management renders correctly 1`] = `
|
|||
}
|
||||
}
|
||||
useNewFieldsApi={true}
|
||||
/>
|
||||
>
|
||||
<EuiPopover
|
||||
anchorPosition="downCenter"
|
||||
button={
|
||||
<EuiButtonIcon
|
||||
aria-label="Index pattern settings"
|
||||
color="text"
|
||||
data-test-subj="discoverIndexPatternActions"
|
||||
iconType="boxesHorizontal"
|
||||
onClick={[Function]}
|
||||
/>
|
||||
}
|
||||
closePopover={[Function]}
|
||||
data-test-subj="discover-addRuntimeField-popover"
|
||||
display="inlineBlock"
|
||||
hasArrow={true}
|
||||
isOpen={false}
|
||||
ownFocus={true}
|
||||
panelPaddingSize="s"
|
||||
>
|
||||
<div
|
||||
className="euiPopover euiPopover--anchorDownCenter"
|
||||
data-test-subj="discover-addRuntimeField-popover"
|
||||
>
|
||||
<div
|
||||
className="euiPopover__anchor"
|
||||
>
|
||||
<EuiButtonIcon
|
||||
aria-label="Index pattern settings"
|
||||
color="text"
|
||||
data-test-subj="discoverIndexPatternActions"
|
||||
iconType="boxesHorizontal"
|
||||
onClick={[Function]}
|
||||
>
|
||||
<button
|
||||
aria-label="Index pattern settings"
|
||||
className="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall"
|
||||
data-test-subj="discoverIndexPatternActions"
|
||||
disabled={false}
|
||||
onClick={[Function]}
|
||||
type="button"
|
||||
>
|
||||
<EuiIcon
|
||||
aria-hidden="true"
|
||||
className="euiButtonIcon__icon"
|
||||
size="m"
|
||||
type="boxesHorizontal"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="euiButtonIcon__icon"
|
||||
data-euiicon-type="boxesHorizontal"
|
||||
size="m"
|
||||
/>
|
||||
</EuiIcon>
|
||||
</button>
|
||||
</EuiButtonIcon>
|
||||
</div>
|
||||
</div>
|
||||
</EuiPopover>
|
||||
</DiscoverIndexPatternManagement>
|
||||
`;
|
||||
|
|
|
@ -14,6 +14,8 @@ import stubbedLogstashFields from '../../../__fixtures__/logstash_fields';
|
|||
import { mountWithIntl } from '@kbn/test/jest';
|
||||
import React from 'react';
|
||||
import { DiscoverIndexPatternManagement } from './discover_index_pattern_management';
|
||||
import { EuiContextMenuPanel, EuiPopover, EuiContextMenuItem } from '@elastic/eui';
|
||||
import { findTestSubject } from '@kbn/test/jest';
|
||||
|
||||
const mockServices = ({
|
||||
history: () => ({
|
||||
|
@ -29,6 +31,11 @@ const mockServices = ({
|
|||
save: false,
|
||||
},
|
||||
},
|
||||
core: {
|
||||
application: {
|
||||
navigateToApp: jest.fn(),
|
||||
},
|
||||
},
|
||||
uiSettings: {
|
||||
get: (key: string) => {
|
||||
if (key === 'fields:popularLimit') {
|
||||
|
@ -39,15 +46,13 @@ const mockServices = ({
|
|||
indexPatternFieldEditor: {
|
||||
openEditor: jest.fn(),
|
||||
userPermissions: {
|
||||
editIndexPattern: jest.fn(),
|
||||
editIndexPattern: () => {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown) as DiscoverServices;
|
||||
|
||||
jest.mock('../../../kibana_services', () => ({
|
||||
getServices: () => mockServices,
|
||||
}));
|
||||
|
||||
describe('Discover IndexPattern Management', () => {
|
||||
const indexPattern = getStubIndexPattern(
|
||||
'logstash-*',
|
||||
|
@ -59,8 +64,8 @@ describe('Discover IndexPattern Management', () => {
|
|||
|
||||
const editField = jest.fn();
|
||||
|
||||
test('renders correctly', () => {
|
||||
const component = mountWithIntl(
|
||||
const mountComponent = () => {
|
||||
return mountWithIntl(
|
||||
<DiscoverIndexPatternManagement
|
||||
services={mockServices}
|
||||
editField={editField}
|
||||
|
@ -68,6 +73,42 @@ describe('Discover IndexPattern Management', () => {
|
|||
useNewFieldsApi={true}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
test('renders correctly', () => {
|
||||
const component = mountComponent();
|
||||
expect(component).toMatchSnapshot();
|
||||
expect(component.find(EuiPopover).length).toBe(1);
|
||||
});
|
||||
|
||||
test('click on a button opens popover', () => {
|
||||
const component = mountComponent();
|
||||
expect(component.find(EuiContextMenuPanel).length).toBe(0);
|
||||
|
||||
const button = findTestSubject(component, 'discoverIndexPatternActions');
|
||||
button.simulate('click');
|
||||
|
||||
expect(component.find(EuiContextMenuPanel).length).toBe(1);
|
||||
expect(component.find(EuiContextMenuItem).length).toBe(2);
|
||||
});
|
||||
|
||||
test('click on an add button executes editField callback', () => {
|
||||
const component = mountComponent();
|
||||
const button = findTestSubject(component, 'discoverIndexPatternActions');
|
||||
button.simulate('click');
|
||||
|
||||
const addButton = findTestSubject(component, 'indexPattern-add-field');
|
||||
addButton.simulate('click');
|
||||
expect(editField).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
|
||||
test('click on a manage button navigates away from discover', () => {
|
||||
const component = mountComponent();
|
||||
const button = findTestSubject(component, 'discoverIndexPatternActions');
|
||||
button.simulate('click');
|
||||
|
||||
const manageButton = findTestSubject(component, 'indexPattern-manage-field');
|
||||
manageButton.simulate('click');
|
||||
expect(mockServices.core.application.navigateToApp).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -89,6 +89,7 @@ export function DiscoverIndexPatternManagement(props: DiscoverIndexPatternManage
|
|||
<EuiContextMenuItem
|
||||
key="manage"
|
||||
icon="indexSettings"
|
||||
data-test-subj="indexPattern-manage-field"
|
||||
onClick={() => {
|
||||
setIsAddIndexPatternFieldPopoverOpen(false);
|
||||
core.application.navigateToApp('management', {
|
||||
|
|
Loading…
Reference in a new issue