Skip to content

Commit

Permalink
combine wrappers into one custom render function
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed Jan 7, 2021
1 parent 959c45e commit 48f1536
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import React from 'react';
import { renderTLWithRouter } from '../../../lib';
import { render } from '../../../lib';
import { MLJobLink } from './ml_job_link';

describe('ML JobLink', () => {
it('renders without errors', () => {
const { asFragment } = renderTLWithRouter(
const { asFragment } = render(
<MLJobLink dateRange={{ to: '', from: '' }} basePath="" monitorId="testMonitor" />,
{
coreOptions: { triggersActionsUi: { getEditAlertFlyout: jest.fn() } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { ExecutedStep } from './executed_step';
import { Ping } from '../../../../common/runtime_types';
import { mountWithRouter, renderTLWithRouter } from '../../../lib';
import { mountWithRouter, render } from '../../../lib';

// FLAKY: https://github.com/elastic/kibana/issues/85899
describe.skip('ExecutedStep', () => {
Expand Down Expand Up @@ -35,9 +35,7 @@ describe.skip('ExecutedStep', () => {
});

it('renders correct step heading', () => {
const { getByText } = renderTLWithRouter(
<ExecutedStep index={3} step={step} checkGroup={'fake-group'} />
);
const { getByText } = render(<ExecutedStep index={3} step={step} checkGroup={'fake-group'} />);

expect(getByText(`${step?.synthetics?.step?.index}. ${step?.synthetics?.step?.name}`));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ChromeBreadcrumb } from 'kibana/public';
import React from 'react';
import { Route } from 'react-router-dom';
import { of } from 'rxjs';
import { MountWithReduxProvider, renderTLWithRouter } from '../../../../lib';
import { render } from '../../../../lib';
import { useMonitorBreadcrumb } from './use_monitor_breadcrumb';
import { OVERVIEW_ROUTE } from '../../../../../common/constants';
import { Ping } from '../../../../../common/runtime_types/ping';
Expand All @@ -26,12 +26,10 @@ describe('useMonitorBreadcrumbs', () => {
return <>Step Water Fall</>;
};

renderTLWithRouter(
<MountWithReduxProvider>
<Route path={OVERVIEW_ROUTE}>
<Component />
</Route>
</MountWithReduxProvider>,
render(
<Route path={OVERVIEW_ROUTE}>
<Component />
</Route>,
{ kibanaProps: { services: { ...core } } }
);

Expand Down
49 changes: 21 additions & 28 deletions x-pack/plugins/uptime/public/lib/helper/component_test_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
*/

import React, { ReactElement } from 'react';
import { render } from '@testing-library/react';
import { render as reactRender } from '@testing-library/react';
import { Router } from 'react-router-dom';
import { MemoryHistory } from 'history/createMemoryHistory';
import { createMemoryHistory, History } from 'history';
import { I18nProvider } from '@kbn/i18n/react';
import { mountWithIntl, renderWithIntl, shallowWithIntl } from '@kbn/test/jest';
import { coreMock } from 'src/core/public/mocks';
import { ChromeBreadcrumb } from 'kibana/public';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import {
KibanaContextProvider,
KibanaServices,
} from '../../../../../../src/plugins/kibana_react/public';
import { MountWithReduxProvider } from './helper_with_redux';
import { AppState } from '../../state';

interface KibanaProps {
services?: KibanaServices;
}

interface KibanaProviderOptions {
coreOptions?: any;
kibanaProps?: { services: any };
kibanaProps?: KibanaProps;
}

interface MockKibanaProviderProps extends KibanaProviderOptions {
Expand All @@ -30,12 +36,10 @@ interface MockRouterProps extends MockKibanaProviderProps {
history?: History;
}

interface RenderKibanaOptions extends KibanaProviderOptions {
renderOptions?: any;
}

interface RenderRouterOptions extends RenderKibanaOptions {
interface RenderRouterOptions extends KibanaProviderOptions {
history?: History;
renderOptions?: any;
state?: any;
}

/* default mock core */
Expand Down Expand Up @@ -112,27 +116,16 @@ export function MockRouter({
);
}

/* React testing library custom render functions */
export const renderTLWithKibana = (
ui: ReactElement,
{ coreOptions, kibanaProps, renderOptions }: RenderKibanaOptions = {}
) => {
return render(
<MockKibanaProvider coreOptions={coreOptions} kibanaProps={kibanaProps}>
{ui}
</MockKibanaProvider>,
renderOptions
);
};

export const renderTLWithRouter = (
export const render = (
ui: ReactElement,
{ history, coreOptions, kibanaProps, renderOptions }: RenderRouterOptions = {}
{ history, coreOptions, kibanaProps, renderOptions, state }: RenderRouterOptions = {}
) => {
return render(
<MockRouter history={history} kibanaProps={kibanaProps} coreOptions={coreOptions}>
{ui}
</MockRouter>,
return reactRender(
<MountWithReduxProvider store={state}>
<MockRouter history={history} kibanaProps={kibanaProps} coreOptions={coreOptions}>
{ui}
</MockRouter>
</MountWithReduxProvider>,
renderOptions
);
};
Expand Down

0 comments on commit 48f1536

Please sign in to comment.