[Security Solution] Load prepackage timelines by default (#74209)
* load prepackage timelines by default * fix unit tests
This commit is contained in:
parent
8e0ae5ffd1
commit
b42f64d1a2
|
@ -25,11 +25,10 @@ import { getTimelineTabsUrl } from '../../../common/components/link_to';
|
|||
import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../pages/timelines_page';
|
||||
import { useGetAllTimeline, getAllTimeline } from '../../containers/all';
|
||||
|
||||
import { useTimelineStatus } from './use_timeline_status';
|
||||
import { NotePreviews } from './note_previews';
|
||||
import { OPEN_TIMELINE_CLASS_NAME } from './helpers';
|
||||
|
||||
import { StatefulOpenTimeline } from '.';
|
||||
|
||||
import { TimelineTabsStyle } from './types';
|
||||
import {
|
||||
useTimelineTypes,
|
||||
|
@ -75,9 +74,17 @@ jest.mock('../../../common/components/link_to', () => {
|
|||
};
|
||||
});
|
||||
|
||||
jest.mock('./use_timeline_status', () => {
|
||||
return {
|
||||
useTimelineStatus: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('StatefulOpenTimeline', () => {
|
||||
const title = 'All Timelines / Open Timelines';
|
||||
let mockHistory: History[];
|
||||
const mockInstallPrepackagedTimelines = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
(useParams as jest.Mock).mockReturnValue({
|
||||
tabName: TimelineType.default,
|
||||
|
@ -95,6 +102,13 @@ describe('StatefulOpenTimeline', () => {
|
|||
totalCount: mockOpenTimelineQueryResults[0].result.data.getAllTimeline.totalCount,
|
||||
refetch: jest.fn(),
|
||||
});
|
||||
((useTimelineStatus as unknown) as jest.Mock).mockReturnValue({
|
||||
timelineStatus: null,
|
||||
templateTimelineType: null,
|
||||
templateTimelineFilter: <div />,
|
||||
installPrepackagedTimelines: mockInstallPrepackagedTimelines,
|
||||
});
|
||||
mockInstallPrepackagedTimelines.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -12,10 +12,11 @@ import { ThemeProvider } from 'styled-components';
|
|||
|
||||
// we don't have the types for waitFor just yet, so using "as waitFor" until when we do
|
||||
import { wait as waitFor } from '@testing-library/react';
|
||||
|
||||
import { TestProviderWithoutDragAndDrop } from '../../../../common/mock/test_providers';
|
||||
import { mockOpenTimelineQueryResults } from '../../../../common/mock/timeline_results';
|
||||
import { useGetAllTimeline, getAllTimeline } from '../../../containers/all';
|
||||
|
||||
import { useTimelineStatus } from '../use_timeline_status';
|
||||
import { OpenTimelineModal } from '.';
|
||||
|
||||
jest.mock('../../../../common/lib/kibana');
|
||||
|
@ -39,8 +40,15 @@ jest.mock('../use_timeline_types', () => {
|
|||
};
|
||||
});
|
||||
|
||||
jest.mock('../use_timeline_status', () => {
|
||||
return {
|
||||
useTimelineStatus: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('OpenTimelineModal', () => {
|
||||
const theme = () => ({ eui: euiDarkVars, darkMode: true });
|
||||
const mockInstallPrepackagedTimelines = jest.fn();
|
||||
beforeEach(() => {
|
||||
((useGetAllTimeline as unknown) as jest.Mock).mockReturnValue({
|
||||
fetchAllTimeline: jest.fn(),
|
||||
|
@ -52,6 +60,16 @@ describe('OpenTimelineModal', () => {
|
|||
totalCount: mockOpenTimelineQueryResults[0].result.data.getAllTimeline.totalCount,
|
||||
refetch: jest.fn(),
|
||||
});
|
||||
((useTimelineStatus as unknown) as jest.Mock).mockReturnValue({
|
||||
timelineStatus: null,
|
||||
templateTimelineType: null,
|
||||
templateTimelineFilter: <div />,
|
||||
installPrepackagedTimelines: mockInstallPrepackagedTimelines,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockInstallPrepackagedTimelines.mockClear();
|
||||
});
|
||||
|
||||
test('it renders the expected modal', async () => {
|
||||
|
@ -76,4 +94,25 @@ describe('OpenTimelineModal', () => {
|
|||
{ timeout: 10000 }
|
||||
);
|
||||
}, 20000);
|
||||
|
||||
test('it installs elastic prebuilt templates', async () => {
|
||||
const wrapper = mount(
|
||||
<ThemeProvider theme={theme}>
|
||||
<TestProviderWithoutDragAndDrop>
|
||||
<MockedProvider mocks={mockOpenTimelineQueryResults} addTypename={false}>
|
||||
<OpenTimelineModal onClose={jest.fn()} />
|
||||
</MockedProvider>
|
||||
</TestProviderWithoutDragAndDrop>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
||||
await waitFor(
|
||||
() => {
|
||||
wrapper.update();
|
||||
|
||||
expect(mockInstallPrepackagedTimelines).toHaveBeenCalled();
|
||||
},
|
||||
{ timeout: 10000 }
|
||||
);
|
||||
}, 20000);
|
||||
});
|
||||
|
|
|
@ -102,7 +102,7 @@ export const useTimelineStatus = ({
|
|||
}, [templateTimelineType, filters, isTemplateFilterEnabled, onFilterClicked]);
|
||||
|
||||
const installPrepackagedTimelines = useCallback(async () => {
|
||||
if (templateTimelineType === TemplateTimelineType.elastic) {
|
||||
if (templateTimelineType !== TemplateTimelineType.custom) {
|
||||
await installPrepackedTimelines();
|
||||
}
|
||||
}, [templateTimelineType]);
|
||||
|
|
Loading…
Reference in a new issue