[SIEM] bugfix to stop making requests when index is undefined

This commit is contained in:
Steph Milovic 2019-06-11 16:04:21 -06:00 committed by GitHub
parent 2703180ac6
commit 7b6ec6588d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 10 deletions

View file

@ -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', () => {
@ -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();
});
});
});

View file

@ -115,4 +115,4 @@ export class WithSource extends React.PureComponent<WithSourceProps> {
}
export const indicesExistOrDataTemporarilyUnavailable = (indicesExist: boolean | undefined) =>
indicesExist || isUndefined(indicesExist);
isUndefined(indicesExist) ? false : indicesExist;

View file

@ -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: {
@ -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')} />);
@ -72,16 +105,21 @@ describe('Ip Details', () => {
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />);
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"]')

View file

@ -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;