-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
98 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
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
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
59 changes: 59 additions & 0 deletions
59
...gins/endpoint/public/applications/endpoint/view/alerts/test_helpers/render_alert_page.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,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import * as reactTestingLibrary from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import { Router } from 'react-router-dom'; | ||
import { AlertIndex } from '../index'; | ||
import { appStoreFactory } from '../../../store'; | ||
import { KibanaContextProvider } from '../../../../../../../../../src/plugins/kibana_react/public'; | ||
import { RouteCapture } from '../../route_capture'; | ||
import { depsStartMock } from '../../../mocks'; | ||
|
||
/** | ||
* Create a 'history' instance that is only in-memory and causes no side effects to the testing environment. | ||
*/ | ||
const history = createMemoryHistory<never>(); | ||
/** | ||
* Create a store, with the middleware disabled. We don't want side effects being created by our code in this test. | ||
*/ | ||
const store = appStoreFactory(); | ||
|
||
const depsStart = depsStartMock(); | ||
depsStart.data.ui.SearchBar.mockImplementation(() => <div />); | ||
|
||
export const alertPageTestRender = { | ||
store, | ||
history, | ||
depsStart, | ||
|
||
/** | ||
* Render the test component, use this after setting up anything in `beforeEach`. | ||
*/ | ||
render: () => { | ||
/** | ||
* Provide the store via `Provider`, and i18n APIs via `I18nProvider`. | ||
* Use react-router via `Router`, passing our in-memory `history` instance. | ||
* Use `RouteCapture` to emit url-change actions when the URL is changed. | ||
* Finally, render the `AlertIndex` component which we are testing. | ||
*/ | ||
return reactTestingLibrary.render( | ||
<Provider store={store}> | ||
<KibanaContextProvider services={{ data: depsStart.data }}> | ||
<I18nProvider> | ||
<Router history={history}> | ||
<RouteCapture> | ||
<AlertIndex /> | ||
</RouteCapture> | ||
</Router> | ||
</I18nProvider> | ||
</KibanaContextProvider> | ||
</Provider> | ||
); | ||
}, | ||
}; |