Skip to content

Commit

Permalink
Unskip flaky test and revert.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Oct 15, 2020
1 parent 4c68934 commit 42669cd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import { EuiSuperUpdateButton, OnRefreshProps } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { Toast } from 'src/core/public';
import { IDataPluginServices, IIndexPattern, TimeRange, TimeHistoryContract, Query } from '../..';
import { useKibana, toMountPoint } from '../../../../kibana_react/public';
import { QueryStringInput } from './';
import { useKibana, toMountPoint, withKibana } from '../../../../kibana_react/public';
import QueryStringInputUI from './query_string_input';
import { doesKueryExpressionHaveLuceneSyntaxError, UI_SETTINGS } from '../../../common';
import { PersistedLog, getQueryLog } from '../../query';
import { NoDataPopover } from './no_data_popover';

const QueryStringInput = withKibana(QueryStringInputUI);

// @internal
export interface QueryBarTopRowProps {
query?: Query;
Expand Down
104 changes: 42 additions & 62 deletions src/plugins/data/public/ui/search_bar/search_bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
*/

import React from 'react';
import { waitFor } from '@testing-library/dom';
import { render } from '@testing-library/react';

import { SearchBar } from './';
import SearchBar from './search_bar';

import { KibanaContextProvider } from 'src/plugins/kibana_react/public';
import { I18nProvider } from '@kbn/i18n/react';

import { coreMock } from '../../../../../core/public/mocks';
const startMock = coreMock.createStart();

import { mount } from 'enzyme';
import { IIndexPattern } from '../..';

const mockTimeHistory = {
Expand All @@ -37,16 +35,14 @@ const mockTimeHistory = {
},
};

jest.mock('..', () => {
jest.mock('../filter_bar/filter_bar', () => {
return {
FilterBar: () => <div className="filterBar" />,
};
});

jest.mock('../query_string_input', () => {
return {
QueryBarTopRow: () => <div className="queryBar" />,
};
jest.mock('../query_string_input/query_bar_top_row', () => {
return () => <div className="queryBar" />;
});

const noop = jest.fn();
Expand Down Expand Up @@ -117,48 +113,42 @@ function wrapSearchBarInContext(testProps: any) {
);
}

// FLAKY: https://github.com/elastic/kibana/issues/79910
describe.skip('SearchBar', () => {
const SEARCH_BAR_TEST_ID = 'globalQueryBar';
describe('SearchBar', () => {
const SEARCH_BAR_ROOT = '.globalQueryBar';
const FILTER_BAR = '.globalFilterBar';
const FILTER_BAR = '.filterBar';
const QUERY_BAR = '.queryBar';

beforeEach(() => {
jest.clearAllMocks();
});

it('Should render query bar when no options provided (in reality - timepicker)', async () => {
const { container, getByTestId } = render(
it('Should render query bar when no options provided (in reality - timepicker)', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(0);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(1);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(0);
expect(component.find(QUERY_BAR).length).toBe(1);
});

it('Should render empty when timepicker is off and no options provided', async () => {
const { container, getByTestId } = render(
it('Should render empty when timepicker is off and no options provided', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
showDatePicker: false,
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(0);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(0);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(0);
expect(component.find(QUERY_BAR).length).toBe(0);
});

it('Should render filter bar, when required fields are provided', async () => {
const { container, getByTestId } = render(
it('Should render filter bar, when required fields are provided', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
showDatePicker: false,
Expand All @@ -167,15 +157,13 @@ describe.skip('SearchBar', () => {
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(1);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(0);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(1);
expect(component.find(QUERY_BAR).length).toBe(0);
});

it('Should NOT render filter bar, if disabled', async () => {
const { container, getByTestId } = render(
it('Should NOT render filter bar, if disabled', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
showFilterBar: false,
Expand All @@ -185,15 +173,13 @@ describe.skip('SearchBar', () => {
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(0);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(0);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(0);
expect(component.find(QUERY_BAR).length).toBe(0);
});

it('Should render query bar, when required fields are provided', async () => {
const { container, getByTestId } = render(
it('Should render query bar, when required fields are provided', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
screenTitle: 'test screen',
Expand All @@ -202,15 +188,13 @@ describe.skip('SearchBar', () => {
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(0);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(1);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(0);
expect(component.find(QUERY_BAR).length).toBe(1);
});

it('Should NOT render query bar, if disabled', async () => {
const { container, getByTestId } = render(
it('Should NOT render query bar, if disabled', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
screenTitle: 'test screen',
Expand All @@ -220,15 +204,13 @@ describe.skip('SearchBar', () => {
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(0);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(0);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(0);
expect(component.find(QUERY_BAR).length).toBe(0);
});

it('Should render query bar and filter bar', async () => {
const { container, getByTestId } = render(
it('Should render query bar and filter bar', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
screenTitle: 'test screen',
Expand All @@ -239,10 +221,8 @@ describe.skip('SearchBar', () => {
})
);

await waitFor(() => getByTestId(SEARCH_BAR_TEST_ID));

expect(container.querySelectorAll(SEARCH_BAR_ROOT).length).toBe(1);
expect(container.querySelectorAll(FILTER_BAR).length).toBe(1);
expect(container.querySelectorAll(QUERY_BAR).length).toBe(1);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
expect(component.find(FILTER_BAR).length).toBe(1);
expect(component.find(QUERY_BAR).length).toBe(1);
});
});
2 changes: 1 addition & 1 deletion src/plugins/data/public/ui/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { get, isEqual } from 'lodash';

import { withKibana, KibanaReactContextValue } from '../../../../kibana_react/public';

import { QueryBarTopRow } from '../query_string_input';
import QueryBarTopRow from '../query_string_input/query_bar_top_row';
import { SavedQueryAttributes, TimeHistoryContract, SavedQuery } from '../../query';
import { IDataPluginServices } from '../../types';
import { TimeRange, Query, Filter, IIndexPattern } from '../../../common';
Expand Down

0 comments on commit 42669cd

Please sign in to comment.