Skip to content

Commit

Permalink
[Uptime] Jest test adjust to use relative date (#70411)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
shahzad31 and elasticmachine authored Jul 9, 2020
1 parent 69ff09e commit 1b4804b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.

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 @@ -16,6 +16,7 @@ import {
import { MonitorListComponent, noItemsMessage } from '../monitor_list';
import { renderWithRouter, shallowWithRouter } from '../../../../lib';
import * as redux from 'react-redux';
import moment from 'moment';

const testFooPings: Ping[] = [
makePing({
Expand Down Expand Up @@ -96,11 +97,25 @@ const testBarSummary: MonitorSummary = {
},
};

// Failing: See https://github.com/elastic/kibana/issues/70386
describe.skip('MonitorList component', () => {
let result: MonitorSummariesResult;
describe('MonitorList component', () => {
let localStorageMock: any;

const getMonitorList = (timestamp?: string): MonitorSummariesResult => {
if (timestamp) {
testBarSummary.state.timestamp = timestamp;
testFooSummary.state.timestamp = timestamp;
} else {
testBarSummary.state.timestamp = '125';
testFooSummary.state.timestamp = '123';
}
return {
nextPagePagination: null,
prevPagePagination: null,
summaries: [testFooSummary, testBarSummary],
totalSummaryCount: 2,
};
};

beforeEach(() => {
const useDispatchSpy = jest.spyOn(redux, 'useDispatch');
useDispatchSpy.mockReturnValue(jest.fn());
Expand All @@ -113,20 +128,14 @@ describe.skip('MonitorList component', () => {
setItem: jest.fn(),
};

// @ts-ignore replacing a call to localStorage we use for monitor list size
// @ts-expect-error replacing a call to localStorage we use for monitor list size
global.localStorage = localStorageMock;
result = {
nextPagePagination: null,
prevPagePagination: null,
summaries: [testFooSummary, testBarSummary],
totalSummaryCount: 2,
};
});

it('shallow renders the monitor list', () => {
const component = shallowWithRouter(
<MonitorListComponent
monitorList={{ list: result, loading: false }}
monitorList={{ list: getMonitorList(), loading: false }}
pageSize={10}
setPageSize={jest.fn()}
/>
Expand Down Expand Up @@ -157,7 +166,10 @@ describe.skip('MonitorList component', () => {
it('renders the monitor list', () => {
const component = renderWithRouter(
<MonitorListComponent
monitorList={{ list: result, loading: false }}
monitorList={{
list: getMonitorList(moment().subtract(5, 'minute').toISOString()),
loading: false,
}}
pageSize={10}
setPageSize={jest.fn()}
/>
Expand All @@ -169,7 +181,7 @@ describe.skip('MonitorList component', () => {
it('renders error list', () => {
const component = shallowWithRouter(
<MonitorListComponent
monitorList={{ list: result, error: new Error('foo message'), loading: false }}
monitorList={{ list: getMonitorList(), error: new Error('foo message'), loading: false }}
pageSize={10}
setPageSize={jest.fn()}
/>
Expand All @@ -181,7 +193,7 @@ describe.skip('MonitorList component', () => {
it('renders loading state', () => {
const component = shallowWithRouter(
<MonitorListComponent
monitorList={{ list: result, loading: true }}
monitorList={{ list: getMonitorList(), loading: true }}
pageSize={10}
setPageSize={jest.fn()}
/>
Expand Down

0 comments on commit 1b4804b

Please sign in to comment.