-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serverless Search] Expanded unit testing (#161356)
## Summary Sets up unit testing for react components. Unit testing of server-side components already implemented. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Sloane
authored
Jul 10, 2023
1 parent
79b5754
commit 9f2a75b
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
TZ="Etc/UTC" yarn test:jest -c "$(dirname "${BASH_SOURCE[0]}")/jest.config.js" |
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/serverless_search/public/application/components/overview.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { render, core } from '../../test/test_utils'; | ||
import { ElasticsearchOverview as Overview } from './overview'; | ||
|
||
describe('<Overview />', () => { | ||
beforeEach(() => { | ||
core.http.fetch.mockResolvedValueOnce({ apiKeys: [] }); | ||
}); | ||
|
||
test('renders without throwing an error', () => { | ||
const wrapper = render(<Overview />); | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
|
||
test('getting started', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Get started with Elasticsearch' })).toBeDefined(); | ||
}); | ||
|
||
test('select client', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Select your client' })).toBeDefined(); | ||
}); | ||
test('install client', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Install a client' })).toBeDefined(); | ||
}); | ||
test('api key', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Store your API key and Cloud ID' })).toBeDefined(); | ||
}); | ||
test('configure client', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Configure your client' })).toBeDefined(); | ||
}); | ||
test('test connection', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Test your connection' })).toBeDefined(); | ||
}); | ||
test('ingest data', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Ingest data' })).toBeDefined(); | ||
}); | ||
test('build query', () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: 'Build your first search query' })).toBeDefined(); | ||
}); | ||
test("what's next?", () => { | ||
const { getByRole } = render(<Overview />); | ||
expect(getByRole('heading', { name: "What's next?" })).toBeDefined(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/serverless_search/public/test/test_utils.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { ReactElement } from 'react'; | ||
import { render, RenderOptions } from '@testing-library/react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
|
||
import { coreMock } from '@kbn/core/public/mocks'; | ||
import { cloudMock } from '@kbn/cloud-plugin/public/mocks'; | ||
import { sharePluginMock } from '@kbn/share-plugin/public/mocks'; | ||
import { userProfileMock } from '@kbn/security-plugin/common/model/user_profile.mock'; | ||
|
||
export const core = coreMock.createStart(); | ||
export const services = { | ||
cloud: cloudMock.createStart(), | ||
share: sharePluginMock.createStartContract(), | ||
userProfile: userProfileMock.createWithSecurity(), | ||
}; | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { cacheTime: Infinity, retry: false }, | ||
}, | ||
}); | ||
|
||
const AllTheProviders: React.FC = ({ children }) => { | ||
return ( | ||
<KibanaThemeProvider theme$={core.theme.theme$}> | ||
<KibanaContextProvider services={{ ...core, ...services }}> | ||
<QueryClientProvider client={queryClient}> | ||
<I18nProvider>{children}</I18nProvider> | ||
</QueryClientProvider> | ||
</KibanaContextProvider> | ||
</KibanaThemeProvider> | ||
); | ||
}; | ||
|
||
const customRender = (ui: ReactElement, options: Omit<RenderOptions, 'wrapper'> = {}) => | ||
render(ui, { wrapper: AllTheProviders, ...options }); | ||
|
||
export * from '@testing-library/react'; | ||
export { customRender as render }; |