[SIEM] - Fix Jest test errors and warnings (#41712) (#41800)

This commit is contained in:
Steph Milovic 2019-07-25 11:08:49 -06:00 committed by GitHub
parent 337d34fe85
commit f57a2a774e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 326 additions and 56 deletions

View file

@ -8,7 +8,7 @@ import { EuiIcon } from '@elastic/eui';
import { transparentize } from 'polished';
import React from 'react';
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import styled from 'styled-components';
import euiStyled from '../../../../../common/eui_styled_components';
interface SuggestionItemProps {
@ -64,7 +64,7 @@ const SuggestionItemField = euiStyled.div`
padding: ${props => props.theme.eui.euiSizeXS};
`;
const SuggestionItemIconField = SuggestionItemField.extend<{ suggestionType: string }>`
const SuggestionItemIconField = styled(SuggestionItemField)<{ suggestionType: string }>`
background-color: ${props =>
transparentize(0.9, getEuiIconColor(props.theme, props.suggestionType))};
color: ${props => getEuiIconColor(props.theme, props.suggestionType)};
@ -73,12 +73,12 @@ const SuggestionItemIconField = SuggestionItemField.extend<{ suggestionType: str
width: ${props => props.theme.eui.euiSizeXL};
`;
const SuggestionItemTextField = SuggestionItemField.extend`
const SuggestionItemTextField = styled(SuggestionItemField)`
flex: 2 0 0;
font-family: ${props => props.theme.eui.euiCodeFontFamily};
`;
const SuggestionItemDescriptionField = SuggestionItemField.extend`
const SuggestionItemDescriptionField = styled(SuggestionItemField)`
flex: 3 0 0;
p {

View file

@ -184,9 +184,10 @@ export const getColumns = ({
},
{
field: 'valuesConcatenated',
name: i18n.BLANK,
render: () => null,
sortable: false,
truncateText: true,
render: () => null,
width: '1px',
},
];

View file

@ -26,6 +26,10 @@ export const DESCRIPTION = i18n.translate('xpack.siem.eventDetails.description',
defaultMessage: 'Description',
});
export const BLANK = i18n.translate('xpack.siem.eventDetails.blank', {
defaultMessage: ' ',
});
export const PLACEHOLDER = i18n.translate('xpack.siem.eventDetails.filter.placeholder', {
defaultMessage: 'Filter by Field, Value, or Description...',
});

View file

@ -7,6 +7,16 @@
import { entityToKql, entitiesToKql, addEntitiesToKql } from './add_entities_to_kql';
describe('add_entities_to_kql', () => {
// Suppress warnings about invalid RISON as this is what we are testing
/* eslint-disable no-console */
const originalError = console.log;
beforeAll(() => {
console.log = jest.fn();
});
afterAll(() => {
console.log = originalError;
});
describe('#entityToKql', () => {
test('returns empty string with no entity names defined and an empty entity string', () => {
const entity = entityToKql([], '');

View file

@ -6,7 +6,17 @@
import { replaceKqlQueryLocationForHostPage } from './replace_kql_query_location_for_host_page';
// Suppress warnings about invalid RISON as this is what we are testing
/* eslint-disable no-console */
const originalError = console.log;
describe('replace_kql_query_location_for_host_page', () => {
beforeAll(() => {
console.log = jest.fn();
});
afterAll(() => {
console.log = originalError;
});
test('replaces host details and type details for a page', () => {
const replacement = replaceKqlQueryLocationForHostPage(
'(filterQuery:(expression:\'process.name: "some-name"\',kind:kuery),queryLocation:hosts.details,type:details)'

View file

@ -5,8 +5,17 @@
*/
import { replaceKqlQueryLocationForNetworkPage } from './replace_kql_query_location_for_network_page';
// Suppress warnings about invalid RISON as this is what we are testing
/* eslint-disable no-console */
const originalError = console.log;
describe('replace_kql_query_location_for_host_page', () => {
beforeAll(() => {
console.log = jest.fn();
});
afterAll(() => {
console.log = originalError;
});
test('replaces host details and type details for a page', () => {
const replacement = replaceKqlQueryLocationForNetworkPage(
'(filterQuery:(expression:\'process.name: "some-name"\',kind:kuery),queryLocation:network.details,type:details)'

View file

@ -7,7 +7,17 @@
import { decodeRison, isRisonObject, isRegularString } from './rison_helpers';
describe('rison_helpers', () => {
// Suppress warnings about invalid RISON as this is what we are testing
/* eslint-disable no-console */
const originalError = console.log;
describe('#decodeRison', () => {
beforeAll(() => {
console.log = jest.fn();
});
afterAll(() => {
console.log = originalError;
});
test('returns null if given a bad value for RISON', () => {
const expected = decodeRison('some invalid value');
expect(expected).toEqual(null);

View file

@ -4,8 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import { EuiButtonIcon, EuiToolTip, EuiIcon } from '@elastic/eui';
import * as React from 'react';
import styled from 'styled-components';
import { ACTION_COLUMN_WIDTH, PositionedIcon } from './common_styles';
import { DeleteTimelines, OnOpenTimeline, OpenTimelineResult } from '../types';
@ -13,6 +14,11 @@ import { DeleteTimelineModalButton } from '../delete_timeline_modal';
import * as i18n from '../translations';
const HeaderIcon = styled(EuiIcon)`
position: relative;
left: 9px;
`;
/**
* Returns the action columns (e.g. delete, open duplicate timeline)
*/
@ -26,7 +32,12 @@ export const getActionsColumns = ({
showDeleteAction: boolean;
}) => {
const deleteTimelineColumn = {
align: 'center',
align: 'right',
name: (
<EuiToolTip content={i18n.DELETE}>
<HeaderIcon data-test-subj="delete-header-icon" size="s" color="subdued" type="trash" />
</EuiToolTip>
),
field: 'savedObjectId',
render: (savedObjectId: string, { title }: OpenTimelineResult) => (
<PositionedIcon>
@ -42,7 +53,12 @@ export const getActionsColumns = ({
};
const openAsDuplicateColumn = {
align: 'center',
align: 'right',
name: (
<EuiToolTip content={i18n.OPEN_AS_DUPLICATE}>
<HeaderIcon data-test-subj="duplicate-header-icon" size="s" color="subdued" type="copy" />
</EuiToolTip>
),
field: 'savedObjectId',
render: (savedObjectId: string, timelineResult: OpenTimelineResult) => (
<PositionedIcon>

View file

@ -32,10 +32,10 @@ exports[`Stat Items Component disable charts it renders the default widget 1`] =
>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiPanel
grow={true}
@ -112,7 +112,7 @@ exports[`Stat Items Component disable charts it renders the default widget 1`] =
showInspect={false}
>
<div
className="sc-bxivhb fGGQew"
className="sc-EHOje dUUqHB"
>
<EuiButtonIcon
aria-label="Inspect"
@ -184,10 +184,10 @@ exports[`Stat Items Component disable charts it renders the default widget 1`] =
key="stat-items-field-hosts"
>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiFlexGroup
alignItems="center"
@ -199,17 +199,17 @@ exports[`Stat Items Component disable charts it renders the default widget 1`] =
>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<Styled(EuiTitle)>
<EuiTitle
className="sc-EHOje koezUx"
className="sc-gzVnrw dJnFxB"
>
<p
className="euiTitle euiTitle--medium sc-EHOje koezUx"
className="euiTitle euiTitle--medium sc-gzVnrw dJnFxB"
data-test-subj="stat-title"
>
--
@ -275,10 +275,10 @@ exports[`Stat Items Component disable charts it renders the default widget 2`] =
>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiPanel
grow={true}
@ -355,7 +355,7 @@ exports[`Stat Items Component disable charts it renders the default widget 2`] =
showInspect={false}
>
<div
className="sc-bxivhb fGGQew"
className="sc-EHOje dUUqHB"
>
<EuiButtonIcon
aria-label="Inspect"
@ -427,10 +427,10 @@ exports[`Stat Items Component disable charts it renders the default widget 2`] =
key="stat-items-field-hosts"
>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiFlexGroup
alignItems="center"
@ -443,17 +443,17 @@ exports[`Stat Items Component disable charts it renders the default widget 2`] =
0
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<Styled(EuiTitle)>
<EuiTitle
className="sc-EHOje koezUx"
className="sc-gzVnrw dJnFxB"
>
<p
className="euiTitle euiTitle--medium sc-EHOje koezUx"
className="euiTitle euiTitle--medium sc-gzVnrw dJnFxB"
data-test-subj="stat-title"
>
--
@ -591,10 +591,10 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiPanel
grow={true}
@ -671,7 +671,7 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
showInspect={false}
>
<div
className="sc-bxivhb fGGQew"
className="sc-EHOje dUUqHB"
>
<EuiButtonIcon
aria-label="Inspect"
@ -743,10 +743,10 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
key="stat-items-field-uniqueSourceIps"
>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiFlexGroup
alignItems="center"
@ -760,11 +760,11 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
grow={false}
>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
grow={false}
>
<div
className="euiFlexItem euiFlexItem--flexGrowZero sc-ifAKCX cFdETZ"
className="euiFlexItem euiFlexItem--flexGrowZero sc-bZQynM kpuYFd"
>
<EuiIcon
color="#DB1374"
@ -803,17 +803,17 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
</Styled(EuiFlexItem)>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<Styled(EuiTitle)>
<EuiTitle
className="sc-EHOje koezUx"
className="sc-gzVnrw dJnFxB"
>
<p
className="euiTitle euiTitle--medium sc-EHOje koezUx"
className="euiTitle euiTitle--medium sc-gzVnrw dJnFxB"
data-test-subj="stat-title"
>
1,714
@ -834,10 +834,10 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
key="stat-items-field-uniqueDestinationIps"
>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<EuiFlexGroup
alignItems="center"
@ -851,11 +851,11 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
grow={false}
>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
grow={false}
>
<div
className="euiFlexItem euiFlexItem--flexGrowZero sc-ifAKCX cFdETZ"
className="euiFlexItem euiFlexItem--flexGrowZero sc-bZQynM kpuYFd"
>
<EuiIcon
color="#490092"
@ -894,17 +894,17 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
</Styled(EuiFlexItem)>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<Styled(EuiTitle)>
<EuiTitle
className="sc-EHOje koezUx"
className="sc-gzVnrw dJnFxB"
>
<p
className="euiTitle euiTitle--medium sc-EHOje koezUx"
className="euiTitle euiTitle--medium sc-gzVnrw dJnFxB"
data-test-subj="stat-title"
>
2,359
@ -934,12 +934,12 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<Memo(mockConstructor)
<Memo()
barChart={
Array [
Object {
@ -975,18 +975,107 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
},
}
}
/>
>
<AutoSizer
content={true}
detectAnyWindowResize={false}
>
<styled.div
innerRef={[Function]}
>
<div
className="sc-bwzfXH ffMqh"
>
<Memo()
configs={
Object {
"axis": Object {
"xTickFormatter": [Function],
},
"series": Object {
"xScaleType": "ordinal",
"yScaleType": "linear",
},
}
}
data={
Array [
Object {
"color": "#DB1374",
"key": "uniqueSourceIps",
"value": Array [
Object {
"x": "uniqueSourceIps",
"y": "1714",
},
],
},
Object {
"color": "#490092",
"key": "uniqueDestinationIps",
"value": Array [
Object {
"x": "uniqueDestinationIps",
"y": 2354,
},
],
},
]
}
>
<Memo()
configs={
Object {
"axis": Object {
"xTickFormatter": [Function],
},
"series": Object {
"xScaleType": "ordinal",
"yScaleType": "linear",
},
}
}
data={
Array [
Object {
"color": "#DB1374",
"key": "uniqueSourceIps",
"value": Array [
Object {
"x": "uniqueSourceIps",
"y": "1714",
},
],
},
Object {
"color": "#490092",
"key": "uniqueDestinationIps",
"value": Array [
Object {
"x": "uniqueDestinationIps",
"y": 2354,
},
],
},
]
}
/>
</Memo()>
</div>
</styled.div>
</AutoSizer>
</Memo()>
</div>
</EuiFlexItem>
</Styled(EuiFlexItem)>
<Styled(EuiFlexItem)>
<EuiFlexItem
className="sc-ifAKCX cFdETZ"
className="sc-bZQynM kpuYFd"
>
<div
className="euiFlexItem sc-ifAKCX cFdETZ"
className="euiFlexItem sc-bZQynM kpuYFd"
>
<Memo(mockConstructor)
<Memo()
areaChart={
Array [
Object {
@ -1039,7 +1128,130 @@ exports[`Stat Items Component rendering kpis with charts it renders the default
},
}
}
/>
>
<AutoSizer
content={true}
detectAnyWindowResize={false}
>
<styled.div
innerRef={[Function]}
>
<div
className="sc-bwzfXH ffMqh"
>
<Memo()
configs={
Object {
"axis": Object {
"xTickFormatter": [Function],
"yTickFormatter": [Function],
},
"series": Object {
"xScaleType": "time",
"yScaleType": "linear",
},
}
}
data={
Array [
Object {
"color": "#DB1374",
"key": "uniqueSourceIpsHistogram",
"value": Array [
Object {
"x": 1556888400000,
"y": 565975,
},
Object {
"x": 1556931600000,
"y": 1084366,
},
Object {
"x": 1556974800000,
"y": 12280,
},
],
},
Object {
"color": "#490092",
"key": "uniqueDestinationIpsHistogram",
"value": Array [
Object {
"x": 1556888400000,
"y": 565975,
},
Object {
"x": 1556931600000,
"y": 1084366,
},
Object {
"x": 1556974800000,
"y": 12280,
},
],
},
]
}
>
<Memo()
configs={
Object {
"axis": Object {
"xTickFormatter": [Function],
"yTickFormatter": [Function],
},
"series": Object {
"xScaleType": "time",
"yScaleType": "linear",
},
}
}
data={
Array [
Object {
"color": "#DB1374",
"key": "uniqueSourceIpsHistogram",
"value": Array [
Object {
"x": 1556888400000,
"y": 565975,
},
Object {
"x": 1556931600000,
"y": 1084366,
},
Object {
"x": 1556974800000,
"y": 12280,
},
],
},
Object {
"color": "#490092",
"key": "uniqueDestinationIpsHistogram",
"value": Array [
Object {
"x": 1556888400000,
"y": 565975,
},
Object {
"x": 1556931600000,
"y": 1084366,
},
Object {
"x": 1556974800000,
"y": 12280,
},
],
},
]
}
/>
</Memo()>
</div>
</styled.div>
</AutoSizer>
</Memo()>
</div>
</EuiFlexItem>
</Styled(EuiFlexItem)>

View file

@ -30,8 +30,6 @@ import { mockGlobalState, apolloClientObservable } from '../../mock';
import { State, createStore } from '../../store';
import { Provider as ReduxStoreProvider } from 'react-redux';
import { KpiNetworkData, KpiHostsData } from '../../graphql/types';
jest.mock('../charts/barchart');
jest.mock('../charts/areachart');
const from = new Date('2019-06-15T06:00:00.000Z').valueOf();
const to = new Date('2019-06-18T06:00:00.000Z').valueOf();