[Security Solution] Adds getMockTheme function (#92840)

Closes elastic/security-team#866.
This commit is contained in:
Ece Özalp 2021-03-04 10:31:39 -05:00 committed by GitHub
parent 00bad90676
commit 3d374e2686
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 258 additions and 243 deletions

View file

@ -6,15 +6,12 @@
*/
import { History } from 'history';
import React, { memo, useMemo, FC } from 'react';
import React, { memo, FC } from 'react';
import { ApolloProvider } from 'react-apollo';
import { Store, Action } from 'redux';
import { Provider as ReduxStoreProvider } from 'react-redux';
import { ThemeProvider } from 'styled-components';
import { EuiErrorBoundary } from '@elastic/eui';
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
import { AppLeaveHandler } from '../../../../../src/core/public';
import { ManageUserInfo } from '../detections/components/user_info';
@ -30,6 +27,7 @@ import { ApolloClientContext } from '../common/utils/apollo_context';
import { ManageGlobalTimeline } from '../timelines/components/manage_timeline';
import { StartServices } from '../types';
import { PageRouter } from './routes';
import { EuiThemeProvider } from '../../../../../src/plugins/kibana_react/common';
interface StartAppComponent extends AppFrontendLibs {
children: React.ReactNode;
@ -46,15 +44,7 @@ const StartAppComponent: FC<StartAppComponent> = ({
store,
}) => {
const { i18n } = useKibana().services;
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
const theme = useMemo(
() => ({
eui: darkMode ? euiDarkVars : euiLightVars,
darkMode,
}),
[darkMode]
);
return (
<EuiErrorBoundary>
@ -64,7 +54,7 @@ const StartAppComponent: FC<StartAppComponent> = ({
<ReduxStoreProvider store={store}>
<ApolloProvider client={apolloClient}>
<ApolloClientContext.Provider value={apolloClient}>
<ThemeProvider theme={theme}>
<EuiThemeProvider darkMode={darkMode}>
<MlCapabilitiesProvider>
<ManageUserInfo>
<PageRouter history={history} onAppLeave={onAppLeave}>
@ -72,7 +62,7 @@ const StartAppComponent: FC<StartAppComponent> = ({
</PageRouter>
</ManageUserInfo>
</MlCapabilitiesProvider>
</ThemeProvider>
</EuiThemeProvider>
<ErrorToastDispatcher />
<GlobalToaster />
</ApolloClientContext.Provider>

View file

@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';
import { AndOrBadge } from './';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorLightShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });
describe('AndOrBadge', () => {
test('it renders top and bottom antenna bars when "includeAntennas" is true', () => {

View file

@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';
import { RoundedBadgeAntenna } from './rounded_badge_antenna';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorLightShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });
describe('RoundedBadgeAntenna', () => {
test('it renders top and bottom antenna bars', () => {

View file

@ -18,9 +18,10 @@ import {
getEmptyValue,
getOrEmptyTag,
} from '.';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
describe('EmptyValue', () => {
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
test('it renders against snapshot', () => {
const wrapper = shallow(<p>{getEmptyString()}</p>);

View file

@ -30,8 +30,9 @@ import {
} from '../../../../../common/detection_engine/schemas/response/rules_schema.mocks';
import { useRuleAsync } from '../../../../detections/containers/detection_engine/rules/use_rule_async';
import { AlertData } from '../types';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiBreakpoints: {
l: '1200px',
@ -40,7 +41,7 @@ const mockTheme = {
m: '10px',
},
},
};
});
jest.mock('../../../../detections/containers/detection_engine/alerts/use_signal_index');
jest.mock('../../../../common/lib/kibana');

View file

@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';
import { BuilderAndBadgeComponent } from './and_badge';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorLightShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });
describe('BuilderAndBadgeComponent', () => {
test('it renders exceptionItemEntryFirstRowAndBadge for very first exception item in builder', () => {

View file

@ -16,12 +16,13 @@ import { getEntryMatchMock } from '../../../../../../lists/common/schemas/types/
import { getEntryMatchAnyMock } from '../../../../../../lists/common/schemas/types/entry_match_any.mock';
import { BuilderExceptionListItemComponent } from './exception_item';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightShade: '#ece',
},
};
});
jest.mock('../../../../common/lib/kibana');

View file

@ -21,12 +21,13 @@ import { useKibana } from '../../../../common/lib/kibana';
import { getEmptyValue } from '../../empty_value';
import { ExceptionBuilderComponent } from './';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightShade: '#ece',
},
};
});
jest.mock('../../../../common/lib/kibana');

View file

@ -27,8 +27,9 @@ import {
getRulesSchemaMock,
} from '../../../../../common/detection_engine/schemas/response/rules_schema.mocks';
import { useRuleAsync } from '../../../../detections/containers/detection_engine/rules/use_rule_async';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiBreakpoints: {
l: '1200px',
@ -37,7 +38,7 @@ const mockTheme = {
m: '10px',
},
},
};
});
jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../detections/containers/detection_engine/rules');

View file

@ -129,4 +129,4 @@
"user.hash",
"user.id",
"Ransomware.feature"
]
]

View file

@ -13,12 +13,13 @@ import moment from 'moment-timezone';
import { ExceptionDetails } from './exception_details';
import { getExceptionListItemSchemaMock } from '../../../../../../../lists/common/schemas/response/exception_list_item_schema.mock';
import { getCommentsArrayMock } from '../../../../../../../lists/common/schemas/types/comment.mock';
import { getMockTheme } from '../../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightestShade: '#ece',
},
};
});
describe('ExceptionDetails', () => {
beforeEach(() => {

View file

@ -12,8 +12,11 @@ import { mount } from 'enzyme';
import { ExceptionEntries } from './exception_entries';
import { getFormattedEntryMock } from '../../exceptions.mock';
import { getEmptyValue } from '../../../empty_value';
import { getMockTheme } from '../../../../lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiSize: '10px', euiColorPrimary: '#ece', euiColorDanger: '#ece' } };
const mockTheme = getMockTheme({
eui: { euiSize: '10px', euiColorPrimary: '#ece', euiColorDanger: '#ece' },
});
describe('ExceptionEntries', () => {
test('it does NOT render the and badge if only one exception item entry exists', () => {

View file

@ -12,17 +12,18 @@ import { mount } from 'enzyme';
import { ExceptionItem } from './';
import { getExceptionListItemSchemaMock } from '../../../../../../../lists/common/schemas/response/exception_list_item_schema.mock';
import { getCommentsArrayMock } from '../../../../../../../lists/common/schemas/types/comment.mock';
import { getMockTheme } from '../../../../lib/kibana/kibana_react.mock';
jest.mock('../../../../lib/kibana');
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorDanger: '#ece',
euiColorLightestShade: '#ece',
euiColorPrimary: '#ece',
euiFontWeightSemiBold: 'bold',
euiFontWeightSemiBold: 1,
},
};
});
describe('ExceptionItem', () => {
it('it renders ExceptionDetails and ExceptionEntries', () => {

View file

@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
import { mountWithIntl } from '@kbn/test/jest';
import { ExceptionsViewerUtility } from './exceptions_utility';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiBreakpoints: {
l: '1200px',
@ -21,7 +22,7 @@ const mockTheme = {
},
euiBorderThin: '1px solid #ece',
},
};
});
describe('ExceptionsViewerUtility', () => {
it('it renders correct pluralized text when more than one exception exists', () => {

View file

@ -12,14 +12,15 @@ import { mount } from 'enzyme';
import * as i18n from '../translations';
import { getExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_item_schema.mock';
import { ExceptionsViewerItems } from './exceptions_viewer_items';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiSize: '10px',
euiColorPrimary: '#ece',
euiColorDanger: '#ece',
},
};
});
describe('ExceptionsViewerItems', () => {
it('it renders empty prompt if "showEmpty" is "true"', () => {

View file

@ -18,8 +18,9 @@ import {
} from '../../../../../public/lists_plugin_deps';
import { getExceptionListSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_schema.mock';
import { getFoundExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/found_exception_list_item_schema.mock';
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorEmptyShade: '#ece',
euiBreakpoints: {
@ -29,7 +30,7 @@ const mockTheme = {
m: '10px',
},
},
};
});
jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../../public/lists_plugin_deps');

View file

@ -11,14 +11,15 @@ import { ThemeProvider } from 'styled-components';
import { NO_ALERT_INDEX } from '../../../../common/constants';
import { ModalInspectQuery, formatIndexPatternRequested } from './modal';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiBreakpoints: {
l: '1200px',
},
},
};
});
const request =
'{"index": ["auditbeat-*","filebeat-*","packetbeat-*","winlogbeat-*"],"allowNoIndices": true, "ignoreUnavailable": true, "body": { "aggregations": {"hosts": {"cardinality": {"field": "host.name" } }, "hosts_histogram": {"auto_date_histogram": {"field": "@timestamp","buckets": "6"},"aggs": { "count": {"cardinality": {"field": "host.name" }}}}}, "query": {"bool": {"filter": [{"range": { "@timestamp": {"gte": 1562290224506,"lte": 1562376624506 }}}]}}, "size": 0, "track_total_hits": false}}';

View file

@ -14,6 +14,7 @@ import { Direction } from '../../../graphql/types';
import { BasicTableProps, PaginatedTable } from './index';
import { getHostsColumns, mockData, rowItems, sortedHosts } from './index.mock';
import { ThemeProvider } from 'styled-components';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
jest.mock('react', () => {
const r = jest.requireActual('react');
@ -21,7 +22,7 @@ jest.mock('react', () => {
return { ...r, memo: (x: any) => x };
});
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorEmptyShade: '#ece',
euiSizeL: '10px',
@ -32,7 +33,7 @@ const mockTheme = {
m: '10px',
},
},
};
});
describe('Paginated Table Component', () => {
let loadPage: jest.Mock<number>;

View file

@ -31,11 +31,11 @@ import {
mockNarrowDateRange,
} from '../../../network/components/kpi_network/mock';
import {
mockGlobalState,
apolloClientObservable,
SUB_PLUGINS_REDUCER,
kibanaObservable,
createSecuritySolutionStorageMock,
kibanaObservable,
mockGlobalState,
SUB_PLUGINS_REDUCER,
} from '../../mock';
import { State, createStore } from '../../store';
import { Provider as ReduxStoreProvider } from 'react-redux';
@ -43,6 +43,7 @@ import {
HostsKpiStrategyResponse,
NetworkKpiStrategyResponse,
} from '../../../../common/search_strategy';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const from = '2019-06-15T06:00:00.000Z';
const to = '2019-06-18T06:00:00.000Z';
@ -56,7 +57,7 @@ jest.mock('../charts/barchart', () => {
});
describe('Stat Items Component', () => {
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
const state: State = mockGlobalState;
const { storage } = createSecuritySolutionStorageMock();
const store = createStore(

View file

@ -10,12 +10,13 @@ import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';
import { AndBadgeComponent } from './and_badge';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightShade: '#ece',
},
};
});
describe('AndBadgeComponent', () => {
test('it renders entryItemIndexItemEntryFirstRowAndBadge for very first item', () => {

View file

@ -17,12 +17,13 @@ import { useKibana } from '../../../common/lib/kibana';
import { ThreatMatchComponent } from './';
import { ThreatMapEntries } from './types';
import { IndexPattern } from 'src/plugins/data/public';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightShade: '#ece',
},
};
});
jest.mock('../../../common/lib/kibana');

View file

@ -15,12 +15,13 @@ import { fields } from '../../../../../../../src/plugins/data/common/index_patte
import { ListItemComponent } from './list_item';
import { ThreatMapEntries } from './types';
import { IndexPattern } from 'src/plugins/data/public';
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightShade: '#ece',
},
};
});
jest.mock('../../../common/lib/kibana');

View file

@ -9,6 +9,7 @@
import React from 'react';
import { RecursivePartial } from '@elastic/eui/src/components/common';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { dataPluginMock } from '../../../../../../../src/plugins/data/public/mocks';
@ -36,6 +37,7 @@ import {
import { StartServices } from '../../../types';
import { createSecuritySolutionStorageMock } from '../../mock/mock_local_storage';
import { MlUrlGenerator } from '../../../../../ml/public';
import { EuiTheme } from '../../../../../../../src/plugins/kibana_react/common';
const mockUiSettings: Record<string, unknown> = {
[DEFAULT_TIME_RANGE]: { from: 'now-15m', to: 'now', mode: 'quick' },
@ -148,3 +150,6 @@ export const createKibanaContextProviderMock = () => {
return ({ children }: { children: React.ReactNode }) =>
React.createElement(KibanaContextProvider, { services }, children);
};
export const getMockTheme = (partialTheme: RecursivePartial<EuiTheme>): EuiTheme =>
partialTheme as EuiTheme;

View file

@ -9,11 +9,11 @@ export * from './global_state';
export * from './header';
export * from './hook_wrapper';
export * from './index_pattern';
export * from './mock_timeline_data';
export * from './mock_detail_item';
export * from './mock_ecs';
export * from './mock_local_storage';
export * from './mock_timeline_data';
export * from './netflow';
export * from './test_providers';
export * from './utils';
export * from './mock_ecs';
export * from './timeline_results';
export * from './utils';

View file

@ -16,12 +16,13 @@ import { PreviewQuery } from './';
import { getMockEqlResponse } from '../../../../common/hooks/eql/eql_search_response.mock';
import { useMatrixHistogram } from '../../../../common/containers/matrix_histogram';
import { useEqlPreview } from '../../../../common/hooks/eql/';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiSuperDatePickerWidth: '180px',
},
};
});
jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../common/containers/matrix_histogram');
@ -132,19 +133,17 @@ describe('PreviewQuery', () => {
test('it renders query histogram when rule type is query and preview button clicked', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'host.name:*', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'host.name:*', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
);
wrapper.find('[data-test-subj="queryPreviewButton"] button').at(0).simulate('click');
@ -159,19 +158,17 @@ describe('PreviewQuery', () => {
test('it renders noise warning when rule type is query, timeframe is last hour and hit average is greater than 1/hour', async () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'host.name:*', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'host.name:*', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
);
(useMatrixHistogram as jest.Mock).mockReturnValue([
@ -195,19 +192,17 @@ describe('PreviewQuery', () => {
test('it renders query histogram when rule type is saved_query and preview button clicked', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="saved_query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'host.name:*', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="saved_query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'host.name:*', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
);
wrapper.find('[data-test-subj="queryPreviewButton"] button').at(0).simulate('click');
@ -222,19 +217,17 @@ describe('PreviewQuery', () => {
test('it renders eql histogram when preview button clicked and rule type is eql', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="eql"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="eql"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
);
wrapper.find('[data-test-subj="queryPreviewButton"] button').at(0).simulate('click');
@ -249,19 +242,17 @@ describe('PreviewQuery', () => {
test('it renders noise warning when rule type is eql, timeframe is last hour and hit average is greater than 1/hour', async () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="eql"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="eql"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
);
(useEqlPreview as jest.Mock).mockReturnValue([
@ -285,26 +276,24 @@ describe('PreviewQuery', () => {
test('it renders threshold histogram when preview button clicked, rule type is threshold, and threshold field is defined', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: 'agent.hostname',
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: 'agent.hostname',
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
);
(useMatrixHistogram as jest.Mock).mockReturnValue([
@ -334,26 +323,24 @@ describe('PreviewQuery', () => {
test('it renders noise warning when rule type is threshold, and threshold field is defined, timeframe is last hour and hit average is greater than 1/hour', async () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: 'agent.hostname',
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="query"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: 'agent.hostname',
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
);
(useMatrixHistogram as jest.Mock).mockReturnValue([
@ -380,26 +367,24 @@ describe('PreviewQuery', () => {
test('it renders query histogram when preview button clicked, rule type is threshold, and threshold field is not defined', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: undefined,
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: undefined,
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
);
wrapper.find('[data-test-subj="queryPreviewButton"] button').at(0).simulate('click');
@ -414,26 +399,24 @@ describe('PreviewQuery', () => {
test('it renders query histogram when preview button clicked, rule type is threshold, and threshold field is empty string', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: ' ',
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={{
field: ' ',
value: 200,
cardinality: {
field: ['user.name'],
value: 2,
},
}}
isDisabled={false}
/>
</TestProviders>
);
wrapper.find('[data-test-subj="queryPreviewButton"] button').at(0).simulate('click');
@ -448,19 +431,17 @@ describe('PreviewQuery', () => {
test('it hides histogram when timeframe changes', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
</ThemeProvider>
<TestProviders>
<PreviewQuery
ruleType="threshold"
dataTestSubj="queryPreviewSelect"
idAria="queryPreview"
query={{ query: { query: 'file where true', language: 'kuery' }, filters: [] }}
index={['foo-*']}
threshold={undefined}
isDisabled={false}
/>
</TestProviders>
);
wrapper.find('[data-test-subj="queryPreviewButton"] button').at(0).simulate('click');

View file

@ -22,12 +22,13 @@ import {
RuleStep,
} from '../../../pages/detection_engine/rules/types';
import { fillEmptySeverityMappings } from '../../../pages/detection_engine/rules/helpers';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorLightestShade: '#ece',
},
};
});
jest.mock('../../../../common/containers/source');
jest.mock('@elastic/eui', () => {

View file

@ -15,12 +15,13 @@ import { mockAboutStepRule } from '../../../pages/detection_engine/rules/all/__m
import { HeaderSection } from '../../../../common/components/header_section';
import { StepAboutRule } from '../step_about_rule';
import { AboutStepRule } from '../../../pages/detection_engine/rules/types';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
jest.mock('../../../../common/lib/kibana');
const mockTheme = {
const mockTheme = getMockTheme({
eui: { euiSizeL: '10px', euiBreakpoints: { s: '450px' }, paddingSizes: { m: '10px' } },
};
});
describe('StepAboutRuleToggleDetails', () => {
let mockRule: AboutStepRule;

View file

@ -11,8 +11,11 @@ import { ThemeProvider } from 'styled-components';
import { waitFor } from '@testing-library/react';
import { AllRulesUtilityBar } from './utility_bar';
import { getMockTheme } from '../../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiBreakpoints: { l: '1200px' }, paddingSizes: { m: '10px' } } };
const mockTheme = getMockTheme({
eui: { euiBreakpoints: { l: '1200px' }, paddingSizes: { m: '10px' } },
});
describe('AllRules', () => {
it('renders AllRulesUtilityBar total rules and selected rules', () => {

View file

@ -21,12 +21,13 @@ import {
} from '../../../test_utils';
import { TrustedAppsGrid } from '.';
import { getMockTheme } from '../../../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiSize: '16px',
},
};
});
jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
htmlIdGenerator: () => () => 'mockId',

View file

@ -20,13 +20,14 @@ import {
createGlobalNoMiddlewareStore,
} from '../../../test_utils';
const mockTheme = {
import { TrustedAppsList } from '.';
import { getMockTheme } from '../../../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = getMockTheme({
eui: {
euiColorLightestShade: '#ece',
},
};
import { TrustedAppsList } from '.';
});
jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
htmlIdGenerator: () => () => 'mockId',

View file

@ -19,6 +19,7 @@ import { mockTimelineResults } from '../../../common/mock/timeline_results';
import { OpenTimeline } from './open_timeline';
import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from './constants';
import { TimelineType, TimelineStatus } from '../../../../common/types/timeline';
import { getMockTheme } from '../../../common/lib/kibana/kibana_react.mock';
jest.mock('../../../common/lib/kibana');
@ -31,7 +32,7 @@ jest.mock('react-router-dom', () => {
};
});
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiSizeL: '10px',
paddingSizes: {
@ -41,7 +42,7 @@ const mockTheme = {
l: '1200px',
},
},
};
});
describe('OpenTimeline', () => {
const title = 'All Timelines / Open Timelines';

View file

@ -18,18 +18,19 @@ import { mockTimelineResults } from '../../../../common/mock/timeline_results';
import { OpenTimelineModalBody } from './open_timeline_modal_body';
import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants';
import { TimelineType, TimelineStatus } from '../../../../../common/types/timeline';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
jest.mock('../../../../common/lib/kibana');
describe('OpenTimelineModal', () => {
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorMediumShade: '#ece',
euiBreakpoints: {
s: '500px',
},
},
};
});
const title = 'All Timelines / Open Timelines';
let mockResults: OpenTimelineResult[];

View file

@ -15,12 +15,13 @@ import { TimelineType } from '../../../../../common/types/timeline';
import { SearchRow } from '.';
import * as i18n from '../translations';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiSizeL: '10px',
},
};
});
describe('SearchRow', () => {
test('it renders a search input with the expected placeholder when the query is empty', () => {

View file

@ -17,8 +17,9 @@ import { mockTimelineResults } from '../../../../common/mock/timeline_results';
import { OpenTimelineResult } from '../types';
import { TimelinesTableProps } from '.';
import { getMockTimelinesTableProps } from './mocks';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
jest.mock('../../../../common/lib/kibana');

View file

@ -21,8 +21,9 @@ import { TimelinesTable, TimelinesTableProps } from '.';
import * as i18n from '../translations';
import { getMockTimelinesTableProps } from './mocks';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
jest.mock('../../../../common/lib/kibana');

View file

@ -19,8 +19,9 @@ import { TimelinesTable, TimelinesTableProps } from '.';
import * as i18n from '../translations';
import { getMockTimelinesTableProps } from './mocks';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
jest.mock('../../../../common/lib/kibana');

View file

@ -15,8 +15,9 @@ import { mockTimelineResults } from '../../../../common/mock/timeline_results';
import { TimelinesTable, TimelinesTableProps } from '.';
import { OpenTimelineResult } from '../types';
import { getMockTimelinesTableProps } from './mocks';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
jest.mock('../../../../common/lib/kibana');

View file

@ -17,8 +17,9 @@ import { TimelinesTable, TimelinesTableProps } from '.';
import { getMockTimelinesTableProps } from './mocks';
import * as i18n from '../translations';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
jest.mock('../../../../common/lib/kibana');

View file

@ -11,10 +11,11 @@ import React from 'react';
import { ThemeProvider } from 'styled-components';
import { TitleRow } from '.';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = {
eui: { euiSizeS: '10px', euiLineHeight: '20px', euiBreakpoints: { s: '10px' }, euiSize: '10px' },
};
const mockTheme = getMockTheme({
eui: { euiSizeS: '10px', euiLineHeight: 10, euiBreakpoints: { s: '10px' }, euiSize: '10px' },
});
describe('TitleRow', () => {
const title = 'All Timelines / Open Timelines';

View file

@ -15,12 +15,13 @@ import { defaultHeaders, mockTimelineData } from '../../../../../common/mock';
import { getEmptyValue } from '../../../../../common/components/empty_value';
import { unknownColumnRenderer } from './unknown_column_renderer';
import { getValues } from './helpers';
import { getMockTheme } from '../../../../../common/lib/kibana/kibana_react.mock';
const mockTheme = {
const mockTheme = getMockTheme({
eui: {
euiColorMediumShade: '#ece',
},
};
});
describe('unknown_column_renderer', () => {
let mockDatum: TimelineNonEcsData[];