[SIEM] Fix mocks for kibana context (#54996)
* Use our internal uiSettings mock in all context mocks We were previously only using our internal uiSettings mock (which returns real values) in our TestProviders component, as all tests either needed: * specific mocks, in which case we'd call jest.mock() ourselves * broad mocks, for which platform's kibana_react mocks were usually sufficient However, a recent addition in the Timeline component added a usage of uiSettings that could not use the default mock. With this change, one can either jest.mock('lib/kibana') or use the TestProviders wrapper to get real values for UI settings in test. * Remove production code guarding against tests This coalescence was due to the service not being properly mocked in test, which is now fixed.
This commit is contained in:
parent
92c4604b5d
commit
27103bd4a5
|
@ -81,8 +81,7 @@ class TimelineQueryComponent extends QueryTemplate<
|
||||||
sourceId,
|
sourceId,
|
||||||
sortField,
|
sortField,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
// I needed to do that to avoid test to yell at me since there is no good way yet to mock withKibana
|
const defaultKibanaIndex = kibana.services.uiSettings.get<string[]>(DEFAULT_INDEX_KEY);
|
||||||
const defaultKibanaIndex = kibana.services.uiSettings.get<string[]>(DEFAULT_INDEX_KEY) ?? [];
|
|
||||||
const defaultIndex = isEmpty(indexPattern)
|
const defaultIndex = isEmpty(indexPattern)
|
||||||
? [...defaultKibanaIndex, ...indexToAdd]
|
? [...defaultKibanaIndex, ...indexToAdd]
|
||||||
: indexPattern?.title.split(',') ?? [];
|
: indexPattern?.title.split(',') ?? [];
|
||||||
|
|
|
@ -71,7 +71,18 @@ export const createUseUiSetting$Mock = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createUseKibanaMock = () => {
|
export const createUseKibanaMock = () => {
|
||||||
const services = { ...createKibanaCoreStartMock(), ...createKibanaPluginsStartMock() };
|
const core = createKibanaCoreStartMock();
|
||||||
|
const plugins = createKibanaPluginsStartMock();
|
||||||
|
const useUiSetting = createUseUiSettingMock();
|
||||||
|
|
||||||
|
const services = {
|
||||||
|
...core,
|
||||||
|
...plugins,
|
||||||
|
uiSettings: {
|
||||||
|
...core.uiSettings,
|
||||||
|
get: useUiSetting,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
return () => ({ services });
|
return () => ({ services });
|
||||||
};
|
};
|
||||||
|
@ -87,15 +98,11 @@ export const createWithKibanaMock = () => {
|
||||||
|
|
||||||
export const createKibanaContextProviderMock = () => {
|
export const createKibanaContextProviderMock = () => {
|
||||||
const kibana = createUseKibanaMock()();
|
const kibana = createUseKibanaMock()();
|
||||||
const uiSettings = {
|
|
||||||
...kibana.services.uiSettings,
|
|
||||||
get: createUseUiSettingMock(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
return ({ services, ...rest }: any) =>
|
return ({ services, ...rest }: any) =>
|
||||||
React.createElement(KibanaContextProvider, {
|
React.createElement(KibanaContextProvider, {
|
||||||
...rest,
|
...rest,
|
||||||
services: { ...kibana.services, uiSettings, ...services },
|
services: { ...kibana.services, ...services },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue