Skip to content

Commit 28e2731

Browse files
authored
[Security Solution] Adds getMockTheme function (#92840) (#94326)
Closes elastic/security-team#866. # Conflicts: # x-pack/plugins/security_solution/public/detections/components/rules/query_preview/index.test.tsx
1 parent 6708f1b commit 28e2731

File tree

40 files changed

+258
-243
lines changed

40 files changed

+258
-243
lines changed

x-pack/plugins/security_solution/public/app/app.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
*/
77

88
import { History } from 'history';
9-
import React, { memo, useMemo, FC } from 'react';
9+
import React, { memo, FC } from 'react';
1010
import { ApolloProvider } from 'react-apollo';
1111
import { Store, Action } from 'redux';
1212
import { Provider as ReduxStoreProvider } from 'react-redux';
13-
import { ThemeProvider } from 'styled-components';
1413

1514
import { EuiErrorBoundary } from '@elastic/eui';
16-
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
17-
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
1815
import { AppLeaveHandler } from '../../../../../src/core/public';
1916

2017
import { ManageUserInfo } from '../detections/components/user_info';
@@ -30,6 +27,7 @@ import { ApolloClientContext } from '../common/utils/apollo_context';
3027
import { ManageGlobalTimeline } from '../timelines/components/manage_timeline';
3128
import { StartServices } from '../types';
3229
import { PageRouter } from './routes';
30+
import { EuiThemeProvider } from '../../../../../src/plugins/kibana_react/common';
3331

3432
interface StartAppComponent extends AppFrontendLibs {
3533
children: React.ReactNode;
@@ -46,15 +44,7 @@ const StartAppComponent: FC<StartAppComponent> = ({
4644
store,
4745
}) => {
4846
const { i18n } = useKibana().services;
49-
5047
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
51-
const theme = useMemo(
52-
() => ({
53-
eui: darkMode ? euiDarkVars : euiLightVars,
54-
darkMode,
55-
}),
56-
[darkMode]
57-
);
5848

5949
return (
6050
<EuiErrorBoundary>
@@ -64,15 +54,15 @@ const StartAppComponent: FC<StartAppComponent> = ({
6454
<ReduxStoreProvider store={store}>
6555
<ApolloProvider client={apolloClient}>
6656
<ApolloClientContext.Provider value={apolloClient}>
67-
<ThemeProvider theme={theme}>
57+
<EuiThemeProvider darkMode={darkMode}>
6858
<MlCapabilitiesProvider>
6959
<ManageUserInfo>
7060
<PageRouter history={history} onAppLeave={onAppLeave}>
7161
{children}
7262
</PageRouter>
7363
</ManageUserInfo>
7464
</MlCapabilitiesProvider>
75-
</ThemeProvider>
65+
</EuiThemeProvider>
7666
<ErrorToastDispatcher />
7767
<GlobalToaster />
7868
</ApolloClientContext.Provider>

x-pack/plugins/security_solution/public/common/components/and_or_badge/index.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
1010
import { mount } from 'enzyme';
1111

1212
import { AndOrBadge } from './';
13+
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
1314

14-
const mockTheme = { eui: { euiColorLightShade: '#ece' } };
15+
const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });
1516

1617
describe('AndOrBadge', () => {
1718
test('it renders top and bottom antenna bars when "includeAntennas" is true', () => {

x-pack/plugins/security_solution/public/common/components/and_or_badge/rounded_badge_antenna.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
1010
import { mount } from 'enzyme';
1111

1212
import { RoundedBadgeAntenna } from './rounded_badge_antenna';
13+
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
1314

14-
const mockTheme = { eui: { euiColorLightShade: '#ece' } };
15+
const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });
1516

1617
describe('RoundedBadgeAntenna', () => {
1718
test('it renders top and bottom antenna bars', () => {

x-pack/plugins/security_solution/public/common/components/empty_value/empty_value.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import {
1818
getEmptyValue,
1919
getOrEmptyTag,
2020
} from '.';
21+
import { getMockTheme } from '../../lib/kibana/kibana_react.mock';
2122

2223
describe('EmptyValue', () => {
23-
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
24+
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
2425

2526
test('it renders against snapshot', () => {
2627
const wrapper = shallow(<p>{getEmptyString()}</p>);

x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import {
3030
} from '../../../../../common/detection_engine/schemas/response/rules_schema.mocks';
3131
import { useRuleAsync } from '../../../../detections/containers/detection_engine/rules/use_rule_async';
3232
import { AlertData } from '../types';
33+
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
3334

34-
const mockTheme = {
35+
const mockTheme = getMockTheme({
3536
eui: {
3637
euiBreakpoints: {
3738
l: '1200px',
@@ -40,7 +41,7 @@ const mockTheme = {
4041
m: '10px',
4142
},
4243
},
43-
};
44+
});
4445

4546
jest.mock('../../../../detections/containers/detection_engine/alerts/use_signal_index');
4647
jest.mock('../../../../common/lib/kibana');

x-pack/plugins/security_solution/public/common/components/exceptions/builder/and_badge.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { ThemeProvider } from 'styled-components';
1010
import { mount } from 'enzyme';
1111

1212
import { BuilderAndBadgeComponent } from './and_badge';
13+
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
1314

14-
const mockTheme = { eui: { euiColorLightShade: '#ece' } };
15+
const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });
1516

1617
describe('BuilderAndBadgeComponent', () => {
1718
test('it renders exceptionItemEntryFirstRowAndBadge for very first exception item in builder', () => {

x-pack/plugins/security_solution/public/common/components/exceptions/builder/exception_item.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import { getEntryMatchMock } from '../../../../../../lists/common/schemas/types/
1616
import { getEntryMatchAnyMock } from '../../../../../../lists/common/schemas/types/entry_match_any.mock';
1717

1818
import { BuilderExceptionListItemComponent } from './exception_item';
19+
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
1920

20-
const mockTheme = {
21+
const mockTheme = getMockTheme({
2122
eui: {
2223
euiColorLightShade: '#ece',
2324
},
24-
};
25+
});
2526

2627
jest.mock('../../../../common/lib/kibana');
2728

x-pack/plugins/security_solution/public/common/components/exceptions/builder/index.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import { useKibana } from '../../../../common/lib/kibana';
2121
import { getEmptyValue } from '../../empty_value';
2222

2323
import { ExceptionBuilderComponent } from './';
24+
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
2425

25-
const mockTheme = {
26+
const mockTheme = getMockTheme({
2627
eui: {
2728
euiColorLightShade: '#ece',
2829
},
29-
};
30+
});
3031

3132
jest.mock('../../../../common/lib/kibana');
3233

x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import {
2727
getRulesSchemaMock,
2828
} from '../../../../../common/detection_engine/schemas/response/rules_schema.mocks';
2929
import { useRuleAsync } from '../../../../detections/containers/detection_engine/rules/use_rule_async';
30+
import { getMockTheme } from '../../../lib/kibana/kibana_react.mock';
3031

31-
const mockTheme = {
32+
const mockTheme = getMockTheme({
3233
eui: {
3334
euiBreakpoints: {
3435
l: '1200px',
@@ -37,7 +38,7 @@ const mockTheme = {
3738
m: '10px',
3839
},
3940
},
40-
};
41+
});
4142

4243
jest.mock('../../../../common/lib/kibana');
4344
jest.mock('../../../../detections/containers/detection_engine/rules');

x-pack/plugins/security_solution/public/common/components/exceptions/exceptionable_fields.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@
129129
"user.hash",
130130
"user.id",
131131
"Ransomware.feature"
132-
]
132+
]

0 commit comments

Comments
 (0)