Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph: fix flaky unit test #52395

Merged
merged 2 commits into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions x-pack/legacy/plugins/graph/public/components/search_bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function wrapSearchBarInContext(testProps: OuterSearchBarProps) {
query: {
savedQueries: {},
},
autocomplete: {
getProvider: () => undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not just use jest.fn() here? seems a bit cleaner?

},
},
};

Expand All @@ -63,8 +66,7 @@ function wrapSearchBarInContext(testProps: OuterSearchBarProps) {
);
}

// FLAKY: https://github.com/elastic/kibana/issues/52246
describe.skip('search_bar', () => {
describe('search_bar', () => {
const defaultProps = {
isLoading: false,
onQuerySubmit: jest.fn(),
Expand All @@ -89,21 +91,23 @@ describe.skip('search_bar', () => {
);
});

function mountSearchBar() {
async function mountSearchBar() {
jest.clearAllMocks();
const wrappedSearchBar = wrapSearchBarInContext({ ...defaultProps });

instance = mountWithIntl(<Provider store={store}>{wrappedSearchBar}</Provider>);
await act(async () => {
instance = mountWithIntl(<Provider store={store}>{wrappedSearchBar}</Provider>);
});
}

it('should render search bar and fetch index pattern', () => {
mountSearchBar();
it('should render search bar and fetch index pattern', async () => {
await mountSearchBar();

expect(defaultProps.indexPatternProvider.get).toHaveBeenCalledWith('123');
});

it('should render search bar and submit queries', async () => {
mountSearchBar();
await mountSearchBar();

await waitForIndexPatternFetch();

Expand All @@ -119,7 +123,7 @@ describe.skip('search_bar', () => {
});

it('should translate kql query into JSON dsl', async () => {
mountSearchBar();
await mountSearchBar();

await waitForIndexPatternFetch();

Expand All @@ -137,8 +141,8 @@ describe.skip('search_bar', () => {
});
});

it('should open index pattern picker', () => {
mountSearchBar();
it('should open index pattern picker', async () => {
await mountSearchBar();

// pick the button component out of the tree because
// it's part of a popover and thus not covered by enzyme
Expand Down