Skip to content

Commit

Permalink
Update unit tests with mock provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Jun 5, 2020
1 parent 63bf9ec commit b6c5e04
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { UptimeDatePicker } from '../uptime_date_picker';
import { renderWithRouter, shallowWithRouter } from '../../../lib';
import { renderWithRouter, shallowWithRouter, MountWithReduxProvider } from '../../../lib';

describe('UptimeDatePicker component', () => {
it('validates props with shallow render', () => {
Expand All @@ -15,7 +15,11 @@ describe('UptimeDatePicker component', () => {
});

it('renders properly with mock data', () => {
const component = renderWithRouter(<UptimeDatePicker />);
const component = renderWithRouter(
<MountWithReduxProvider>
<UptimeDatePicker />
</MountWithReduxProvider>
);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { MonitorBarSeries, MonitorBarSeriesProps } from '../monitor_bar_series';
import { renderWithRouter, shallowWithRouter } from '../../../../lib';
import { renderWithRouter, shallowWithRouter, MountWithReduxProvider } from '../../../../lib';
import { HistogramPoint } from '../../../../../common/runtime_types';

describe('MonitorBarSeries component', () => {
Expand Down Expand Up @@ -197,7 +197,11 @@ describe('MonitorBarSeries component', () => {
});

it('renders if the data series is present', () => {
const component = renderWithRouter(<MonitorBarSeries histogramSeries={histogramSeries} />);
const component = renderWithRouter(
<MountWithReduxProvider>
<MonitorBarSeries histogramSeries={histogramSeries} />
</MountWithReduxProvider>
);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { PingHistogramComponent, PingHistogramComponentProps } from '../ping_histogram';
import { renderWithRouter, shallowWithRouter } from '../../../../lib';
import { renderWithRouter, shallowWithRouter, MountWithReduxProvider } from '../../../../lib';

describe('PingHistogram component', () => {
const props: PingHistogramComponentProps = {
Expand Down Expand Up @@ -49,7 +49,12 @@ describe('PingHistogram component', () => {
});

it('renders the component without errors', () => {
const component = renderWithRouter(<PingHistogramComponent {...props} />);
const component = renderWithRouter(
<MountWithReduxProvider>
<PingHistogramComponent {...props} />
</MountWithReduxProvider>
);

expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { FilterStatusButton, FilterStatusButtonProps } from '../filter_status_button';
import { renderWithRouter, shallowWithRouter } from '../../../../lib';
import { renderWithRouter, shallowWithRouter, MountWithReduxProvider } from '../../../../lib';

describe('FilterStatusButton', () => {
let props: FilterStatusButtonProps;
Expand All @@ -26,7 +26,11 @@ describe('FilterStatusButton', () => {
});

it('renders without errors for valid props', () => {
const wrapper = renderWithRouter(<FilterStatusButton {...props} />);
const wrapper = renderWithRouter(
<MountWithReduxProvider>
<FilterStatusButton {...props} />
</MountWithReduxProvider>
);
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
*/

import React from 'react';
import { mountWithRouter, renderWithRouter, shallowWithRouter } from '../../../../lib';
import {
mountWithRouter,
renderWithRouter,
shallowWithRouter,
MountWithReduxProvider,
} from '../../../../lib';
import { createMemoryHistory } from 'history';
import { StatusFilter } from '../status_filter';
import { FilterStatusButton } from '../filter_status_button';
Expand All @@ -18,7 +23,12 @@ describe('StatusFilterComponent', () => {
initialEntries: [`/?g=%22%22&statusFilter=${status}`],
});

const wrapper = mountWithRouter(<StatusFilter />, history);
const wrapper = mountWithRouter(
<MountWithReduxProvider>
<StatusFilter />
</MountWithReduxProvider>,
history
);
const filterBtns = wrapper.find(FilterStatusButton);

const allBtn = filterBtns.at(0);
Expand All @@ -34,7 +44,11 @@ describe('StatusFilterComponent', () => {
});

it('renders without errors for valid props', () => {
const wrapper = renderWithRouter(<StatusFilter />);
const wrapper = renderWithRouter(
<MountWithReduxProvider>
<StatusFilter />
</MountWithReduxProvider>
);
expect(wrapper).toMatchSnapshot();
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Route } from 'react-router-dom';
import { mountWithRouter } from '../../lib';
import { OVERVIEW_ROUTE } from '../../../common/constants';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { UptimeUrlParams, getSupportedUrlParams } from '../../lib/helper';
import { UptimeUrlParams, getSupportedUrlParams, MountWithReduxProvider } from '../../lib/helper';
import { makeBaseBreadcrumb, useBreadcrumbs } from '../use_breadcrumbs';

describe('useBreadcrumbs', () => {
Expand All @@ -34,11 +34,13 @@ describe('useBreadcrumbs', () => {
};

mountWithRouter(
<KibanaContextProvider services={{ ...core }}>
<Route path={OVERVIEW_ROUTE}>
<Component />
</Route>
</KibanaContextProvider>
<MountWithReduxProvider>
<KibanaContextProvider services={{ ...core }}>
<Route path={OVERVIEW_ROUTE}>
<Component />
</Route>
</KibanaContextProvider>
</MountWithReduxProvider>
);

const urlParams: UptimeUrlParams = getSupportedUrlParams({});
Expand Down
Loading

0 comments on commit b6c5e04

Please sign in to comment.