Skip to content

Commit

Permalink
[Security Solution] Load prepackage timelines by default (#74209) (#7…
Browse files Browse the repository at this point in the history
…4266)

* load prepackage timelines by default

* fix unit tests
  • Loading branch information
angorayc authored Aug 4, 2020
1 parent 435ca3d commit 28f1110
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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(),
Expand All @@ -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 () => {
Expand All @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 28f1110

Please sign in to comment.