From 1721b4114f14dbe502dd80b7f88b29a163df10c5 Mon Sep 17 00:00:00 2001 From: Steph Milovic Date: Tue, 23 Jul 2019 11:13:59 -0600 Subject: [PATCH] [SIEM] - Fix Jest test errors and warnings (#41712) --- .../autocomplete_field/suggestion_item.tsx | 8 +- .../components/event_details/columns.tsx | 3 +- .../components/event_details/translations.ts | 4 + .../add_entities_to_kql.test.ts | 10 + ...e_kql_query_location_for_host_page.test.ts | 10 + ...ql_query_location_for_network_page.test.ts | 11 +- .../conditional_links/rison_helpers.test.ts | 10 + .../timelines_table/actions_columns.tsx | 22 +- .../__snapshots__/index.test.tsx.snap | 302 +++++++++++++++--- .../components/stat_items/index.test.tsx | 2 - 10 files changed, 326 insertions(+), 56 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx index 0c175b1fe07b4..53be16ed2843c 100644 --- a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx +++ b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx @@ -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 { diff --git a/x-pack/legacy/plugins/siem/public/components/event_details/columns.tsx b/x-pack/legacy/plugins/siem/public/components/event_details/columns.tsx index e0accfc964337..a8f8b6bc1365d 100644 --- a/x-pack/legacy/plugins/siem/public/components/event_details/columns.tsx +++ b/x-pack/legacy/plugins/siem/public/components/event_details/columns.tsx @@ -183,9 +183,10 @@ export const getColumns = ({ }, { field: 'valuesConcatenated', + name: i18n.BLANK, + render: () => null, sortable: false, truncateText: true, - render: () => null, width: '1px', }, ]; diff --git a/x-pack/legacy/plugins/siem/public/components/event_details/translations.ts b/x-pack/legacy/plugins/siem/public/components/event_details/translations.ts index c38778f2dc3c3..c5e37b2cd7451 100644 --- a/x-pack/legacy/plugins/siem/public/components/event_details/translations.ts +++ b/x-pack/legacy/plugins/siem/public/components/event_details/translations.ts @@ -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...', }); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/add_entities_to_kql.test.ts b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/add_entities_to_kql.test.ts index a666a3280c496..c039cc2f88646 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/add_entities_to_kql.test.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/add_entities_to_kql.test.ts @@ -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([], ''); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_host_page.test.ts b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_host_page.test.ts index 6b304cb8b6a46..48e6e1c942cc4 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_host_page.test.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_host_page.test.ts @@ -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)' diff --git a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_network_page.test.ts b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_network_page.test.ts index a79d827dd82f7..5a31bbf2cb676 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_network_page.test.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/replace_kql_query_location_for_network_page.test.ts @@ -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)' diff --git a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/rison_helpers.test.ts b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/rison_helpers.test.ts index 14241a2578837..60d876fab2bf9 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/rison_helpers.test.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/rison_helpers.test.ts @@ -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); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx index 5cb5c9ddae233..6b576cca24b1e 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx @@ -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: ( + + + + ), field: 'savedObjectId', render: (savedObjectId: string, { title }: OpenTimelineResult) => ( @@ -42,7 +53,12 @@ export const getActionsColumns = ({ }; const openAsDuplicateColumn = { - align: 'center', + align: 'right', + name: ( + + + + ), field: 'savedObjectId', render: (savedObjectId: string, timelineResult: OpenTimelineResult) => ( diff --git a/x-pack/legacy/plugins/siem/public/components/stat_items/__snapshots__/index.test.tsx.snap b/x-pack/legacy/plugins/siem/public/components/stat_items/__snapshots__/index.test.tsx.snap index d34a2b346fbff..fb0e584d032bc 100644 --- a/x-pack/legacy/plugins/siem/public/components/stat_items/__snapshots__/index.test.tsx.snap +++ b/x-pack/legacy/plugins/siem/public/components/stat_items/__snapshots__/index.test.tsx.snap @@ -32,10 +32,10 @@ exports[`Stat Items Component disable charts it renders the default widget 1`] = >

-- @@ -275,10 +275,10 @@ exports[`Stat Items Component disable charts it renders the default widget 2`] = >

-- @@ -591,10 +591,10 @@ exports[`Stat Items Component rendering kpis with charts it renders the default >

1,714 @@ -834,10 +834,10 @@ exports[`Stat Items Component rendering kpis with charts it renders the default key="stat-items-field-uniqueDestinationIps" >

2,359 @@ -934,12 +934,12 @@ exports[`Stat Items Component rendering kpis with charts it renders the default >

- + > + + +
+ + + +
+
+
+
- + > + + +
+ + + +
+
+
+
diff --git a/x-pack/legacy/plugins/siem/public/components/stat_items/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/stat_items/index.test.tsx index 8b4739e76766d..e171e1d853c00 100644 --- a/x-pack/legacy/plugins/siem/public/components/stat_items/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/stat_items/index.test.tsx @@ -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();