-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solutions][Timeline] Added createFrom in action to hide #98144
Changes from 4 commits
3230b6a
006c81b
38d486c
588e1c8
854faab
e4d3f63
ed6e0a3
f3c3035
19bf8f4
99ec69f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,30 @@ | |
|
||
import { mount, ReactWrapper } from 'enzyme'; | ||
import React from 'react'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
import { AddTimelineButton } from './'; | ||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import { TimelineId } from '../../../../../common/types/timeline'; | ||
import { mockOpenTimelineQueryResults, TestProviders } from '../../../../common/mock'; | ||
import { mockHistory, Router } from '../../../../cases/components/__mock__/router'; | ||
import { getAllTimeline, useGetAllTimeline } from '../../../containers/all'; | ||
|
||
jest.mock('../../../../common/lib/kibana', () => { | ||
const originalModule = jest.requireActual('../../../../common/lib/kibana'); | ||
return { | ||
...originalModule, | ||
useKibana: jest.fn(), | ||
useUiSetting$: jest.fn().mockReturnValue([]), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../../common/lib/kibana', () => ({ | ||
useKibana: jest.fn(), | ||
useUiSetting$: jest.fn().mockReturnValue([]), | ||
})); | ||
jest.mock('../../../containers/all', () => { | ||
const originalModule = jest.requireActual('../../../containers/all'); | ||
return { | ||
...originalModule, | ||
useGetAllTimeline: jest.fn(), | ||
}; | ||
}); | ||
|
||
jest.mock('../../timeline/properties/new_template_timeline', () => ({ | ||
NewTemplateTimeline: jest.fn(() => <div data-test-subj="create-template-btn" />), | ||
|
@@ -35,8 +49,7 @@ jest.mock('../../../../common/components/inspect', () => ({ | |
InspectButtonContainer: jest.fn(({ children }) => <div>{children}</div>), | ||
})); | ||
|
||
// FLAKY: https://github.com/elastic/kibana/issues/96691 | ||
describe.skip('AddTimelineButton', () => { | ||
describe('AddTimelineButton', () => { | ||
let wrapper: ReactWrapper; | ||
const props = { | ||
timelineId: TimelineId.active, | ||
|
@@ -67,24 +80,18 @@ describe.skip('AddTimelineButton', () => { | |
}); | ||
|
||
test('it renders create timeline btn', async () => { | ||
await waitFor(() => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click'); | ||
expect(wrapper.find('[data-test-subj="create-default-btn"]').exists()).toBeTruthy(); | ||
}); | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing the tests!! Could we try putting back |
||
expect(wrapper.find('[data-test-subj="create-default-btn"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('it renders create timeline template btn', async () => { | ||
await waitFor(() => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click'); | ||
expect(wrapper.find('[data-test-subj="create-template-btn"]').exists()).toBeTruthy(); | ||
}); | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
expect(wrapper.find('[data-test-subj="create-template-btn"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('it renders Open timeline btn', async () => { | ||
await waitFor(() => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click'); | ||
expect(wrapper.find('[data-test-subj="open-timeline-button"]').exists()).toBeTruthy(); | ||
}); | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
expect(wrapper.find('[data-test-subj="open-timeline-button"]').exists()).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
|
@@ -112,25 +119,71 @@ describe.skip('AddTimelineButton', () => { | |
expect(wrapper.find('[data-test-subj="settings-plus-in-circle"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('it renders create timeline btn', async () => { | ||
await waitFor(() => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click'); | ||
expect(wrapper.find('[data-test-subj="create-default-btn"]').exists()).toBeTruthy(); | ||
}); | ||
test('it renders create timeline btn', () => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
expect(wrapper.find('[data-test-subj="create-default-btn"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('it renders create timeline template btn', async () => { | ||
await waitFor(() => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click'); | ||
expect(wrapper.find('[data-test-subj="create-template-btn"]').exists()).toBeTruthy(); | ||
}); | ||
test('it renders create timeline template btn', () => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
expect(wrapper.find('[data-test-subj="create-template-btn"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('it renders Open timeline btn', async () => { | ||
await waitFor(() => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click'); | ||
expect(wrapper.find('[data-test-subj="open-timeline-button"]').exists()).toBeTruthy(); | ||
test('it renders Open timeline btn', () => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
expect(wrapper.find('[data-test-subj="open-timeline-button"]').exists()).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('open modal', () => { | ||
beforeEach(() => { | ||
(useKibana as jest.Mock).mockReturnValue({ | ||
services: { | ||
application: { | ||
getUrlForApp: jest.fn(), | ||
capabilities: { | ||
siem: { | ||
crud: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
((useGetAllTimeline as unknown) as jest.Mock).mockReturnValue({ | ||
fetchAllTimeline: jest.fn(), | ||
timelines: getAllTimeline('', mockOpenTimelineQueryResults.timeline ?? []), | ||
loading: false, | ||
totalCount: mockOpenTimelineQueryResults.totalCount, | ||
refetch: jest.fn(), | ||
}); | ||
|
||
wrapper = mount( | ||
<TestProviders> | ||
<Router history={mockHistory}> | ||
<AddTimelineButton {...props} /> | ||
</Router> | ||
</TestProviders> | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
(useKibana as jest.Mock).mockReset(); | ||
}); | ||
|
||
it('should render timelines table', () => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
wrapper.find('[data-test-subj="open-timeline-button"]').first().simulate('click').update(); | ||
|
||
expect(wrapper.find('[data-test-subj="timelines-table"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should render correct actions', () => { | ||
wrapper.find('[data-test-subj="settings-plus-in-circle"]').last().simulate('click').update(); | ||
wrapper.find('[data-test-subj="open-timeline-button"]').first().simulate('click').update(); | ||
|
||
expect(wrapper.find('[data-test-subj="open-duplicate"]').exists()).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="create-from-template"]').exists()).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import React, { useCallback, useMemo, useState } from 'react'; | |
|
||
import { OpenTimelineModalButton } from '../../open_timeline/open_timeline_modal/open_timeline_modal_button'; | ||
import { OpenTimelineModal } from '../../open_timeline/open_timeline_modal'; | ||
import { ActionTimelineToShow } from '../../open_timeline/types'; | ||
import * as i18n from '../../timeline/properties/translations'; | ||
import { NewTimeline } from '../../timeline/properties/helpers'; | ||
import { NewTemplateTimeline } from '../../timeline/properties/new_template_timeline'; | ||
|
@@ -47,6 +48,8 @@ const AddTimelineButtonComponent: React.FC<AddTimelineButtonComponentProps> = ({ | |
[onButtonClick] | ||
); | ||
|
||
const actionTimelineToHide = useMemo<ActionTimelineToShow[]>(() => ['createFrom'], []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could put this as a constant and move out of the component as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes 👍 |
||
|
||
return ( | ||
<> | ||
<EuiFlexItem grow={false}> | ||
|
@@ -83,7 +86,9 @@ const AddTimelineButtonComponent: React.FC<AddTimelineButtonComponentProps> = ({ | |
</EuiPopover> | ||
</EuiFlexItem> | ||
|
||
{showTimelineModal ? <OpenTimelineModal onClose={onCloseTimelineModal} /> : null} | ||
{showTimelineModal ? ( | ||
<OpenTimelineModal onClose={onCloseTimelineModal} hideActions={actionTimelineToHide} /> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems doesn't change, please consider put this as a constant and move out of the component.