-
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.
split enzyme helpers and rtl helpers into different files and adjust …
…types
- Loading branch information
1 parent
48f1536
commit 8f8af46
Showing
10 changed files
with
199 additions
and
218 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
x-pack/plugins/uptime/public/components/monitor/ml/__snapshots__/ml_job_link.test.tsx.snap
This file was deleted.
Oops, something went wrong.
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
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
187 changes: 0 additions & 187 deletions
187
x-pack/plugins/uptime/public/lib/helper/component_test_helpers.tsx
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
x-pack/plugins/uptime/public/lib/helper/enzyme_helpers.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,68 @@ | ||
/* | ||
* 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, { ReactElement } from 'react'; | ||
import { Router } from 'react-router-dom'; | ||
import { MemoryHistory } from 'history/createMemoryHistory'; | ||
import { createMemoryHistory } from 'history'; | ||
import { mountWithIntl, renderWithIntl, shallowWithIntl } from '@kbn/test/jest'; | ||
import { MountWithReduxProvider } from './helper_with_redux'; | ||
import { AppState } from '../../state'; | ||
|
||
const helperWithRouter: <R>( | ||
helper: (node: ReactElement) => R, | ||
component: ReactElement, | ||
customHistory?: MemoryHistory, | ||
wrapReduxStore?: boolean, | ||
storeState?: AppState | ||
) => R = (helper, component, customHistory, wrapReduxStore, storeState) => { | ||
const history = customHistory ?? createMemoryHistory(); | ||
|
||
history.location.key = 'TestKeyForTesting'; | ||
|
||
const routerWrapper = <Router history={history}>{component}</Router>; | ||
|
||
if (wrapReduxStore) { | ||
return helper( | ||
<MountWithReduxProvider state={storeState}>{routerWrapper}</MountWithReduxProvider> | ||
); | ||
} | ||
|
||
return helper(routerWrapper); | ||
}; | ||
|
||
export const renderWithRouter = (component: ReactElement, customHistory?: MemoryHistory) => { | ||
return helperWithRouter(renderWithIntl, component, customHistory); | ||
}; | ||
|
||
export const shallowWithRouter = (component: ReactElement, customHistory?: MemoryHistory) => { | ||
return helperWithRouter(shallowWithIntl, component, customHistory); | ||
}; | ||
|
||
export const mountWithRouter = (component: ReactElement, customHistory?: MemoryHistory) => { | ||
return helperWithRouter(mountWithIntl, component, customHistory); | ||
}; | ||
|
||
export const renderWithRouterRedux = (component: ReactElement, customHistory?: MemoryHistory) => { | ||
return helperWithRouter(renderWithIntl, component, customHistory, true); | ||
}; | ||
|
||
export const shallowWithRouterRedux = (component: ReactElement, customHistory?: MemoryHistory) => { | ||
return helperWithRouter(shallowWithIntl, component, customHistory, true); | ||
}; | ||
|
||
export const mountWithRouterRedux = ( | ||
component: ReactElement, | ||
options?: { customHistory?: MemoryHistory; storeState?: AppState } | ||
) => { | ||
return helperWithRouter( | ||
mountWithIntl, | ||
component, | ||
options?.customHistory, | ||
true, | ||
options?.storeState | ||
); | ||
}; |
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
Oops, something went wrong.