Skip to content

Commit

Permalink
[SIEM] - bugfix to stop making requests when index is undefined (elas…
Browse files Browse the repository at this point in the history
…tic#38666)

bugfix to stop making requests when index is undefined
  • Loading branch information
stephmilovic authored Jun 11, 2019
1 parent 5fcb13a commit 9c91d4d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
18 changes: 17 additions & 1 deletion x-pack/plugins/siem/public/containers/source/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MockedProvider } from 'react-apollo/test-utils';

import { wait } from '../../lib/helpers';

import { WithSource } from '.';
import { WithSource, indicesExistOrDataTemporarilyUnavailable } from '.';
import { mockBrowserFields, mockIndexFields, mocksSource } from './mock';

describe('Index Fields & Browser Fields', () => {
Expand Down Expand Up @@ -52,4 +52,20 @@ describe('Index Fields & Browser Fields', () => {
// Why => https://github.com/apollographql/react-apollo/issues/1711
await wait();
});

describe('indicesExistOrDataTemporarilyUnavailable', () => {
test('it returns false when undefined', () => {
let undefVar;
const result = indicesExistOrDataTemporarilyUnavailable(undefVar);
expect(result).toBeFalsy();
});
test('it returns true when true', () => {
const result = indicesExistOrDataTemporarilyUnavailable(true);
expect(result).toBeTruthy();
});
test('it returns false when false', () => {
const result = indicesExistOrDataTemporarilyUnavailable(false);
expect(result).toBeFalsy();
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/public/containers/source/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ export class WithSource extends React.PureComponent<WithSourceProps> {
}

export const indicesExistOrDataTemporarilyUnavailable = (indicesExist: boolean | undefined) =>
indicesExist || isUndefined(indicesExist);
isUndefined(indicesExist) ? false : indicesExist;
47 changes: 43 additions & 4 deletions x-pack/plugins/siem/public/pages/network/ip_details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,32 @@ import { mount, shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import * as React from 'react';
import { Router } from 'react-router-dom';
import { MockedProvider } from 'react-apollo/test-utils';

import '../../mock/match_media';
import { apolloClientObservable, mockGlobalState, TestProviders } from '../../mock';
import { IPDetailsComponent, IPDetails } from './ip_details';
import { FlowTarget } from '../../graphql/types';
import { createStore, State } from '../../store';
import { cloneDeep } from 'lodash/fp';
import { mocksSource } from '../../containers/source/mock';

type Action = 'PUSH' | 'POP' | 'REPLACE';
const pop: Action = 'POP';

let localSource: Array<{
request: {};
result: {
data: {
source: {
status: {
indicesExist: boolean;
};
};
};
};
}>;

const getMockHistory = (ip: string) => ({
length: 2,
location: {
Expand Down Expand Up @@ -50,13 +66,30 @@ const getMockProps = (ip: string) => ({
match: { params: { ip }, isExact: true, path: '', url: '' },
});

jest.mock('ui/documentation_links', () => ({
documentationLinks: {
siem: 'http://www.example.com',
},
}));
// Suppress warnings about "act" until async/await syntax is supported: https://github.com/facebook/react/issues/14769
/* eslint-disable no-console */
const originalError = console.error;

describe('Ip Details', () => {
beforeAll(() => {
console.error = jest.fn();
});

afterAll(() => {
console.error = originalError;
});
const state: State = mockGlobalState;

let store = createStore(state, apolloClientObservable);

beforeEach(() => {
store = createStore(state, apolloClientObservable);
localSource = cloneDeep(mocksSource);
});
test('it renders', () => {
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />);
Expand All @@ -73,15 +106,21 @@ describe('Ip Details', () => {
expect(toJson(wrapper)).toMatchSnapshot();
});

test('it renders ipv6 headline', () => {
test('it renders ipv6 headline', async () => {
localSource[0].result.data.source.status.indicesExist = true;
const ip = 'fe80--24ce-f7ff-fede-a571';
const wrapper = mount(
<TestProviders store={store}>
<Router history={getMockHistory(ip)}>
<IPDetails {...getMockProps(ip)} />
</Router>
<MockedProvider mocks={localSource} addTypename={false}>
<Router history={getMockHistory(ip)}>
<IPDetails {...getMockProps(ip)} />
</Router>
</MockedProvider>
</TestProviders>
);
// Why => https://github.com/apollographql/react-apollo/issues/1711
await new Promise(resolve => setTimeout(resolve));
wrapper.update();
expect(
wrapper
.find('[data-test-subj="ip-details-headline"] [data-test-subj="page_headline_title"]')
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/siem/public/pages/network/network.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ describe('rendering - rendering', () => {
beforeEach(() => {
localSource = cloneDeep(mocksSource);
});
beforeEach(() => {
localSource = cloneDeep(mocksSource);
});

test('it renders the Setup Instructions text when no index is available', async () => {
localSource[0].result.data.source.status.indicesExist = false;
Expand Down

0 comments on commit 9c91d4d

Please sign in to comment.