mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[SIEM] bugfix to stop making requests when index is undefined
This commit is contained in:
parent
2703180ac6
commit
7b6ec6588d
4 changed files with 61 additions and 10 deletions
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -115,4 +115,4 @@ export class WithSource extends React.PureComponent<WithSourceProps> {
|
|||
}
|
||||
|
||||
export const indicesExistOrDataTemporarilyUnavailable = (indicesExist: boolean | undefined) =>
|
||||
indicesExist || isUndefined(indicesExist);
|
||||
isUndefined(indicesExist) ? false : indicesExist;
|
||||
|
|
|
@ -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"]')
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue