-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Update open timeline filters and add unit tests (#…
…89852) (#90773) * update filter and add unit tests * styling * fix i18n error * fix unit test * fix lint error Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
c8b1485
commit 3162365
Showing
8 changed files
with
228 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
...s/security_solution/public/timelines/components/open_timeline/use_timeline_types.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import { | ||
useTimelineTypes, | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult, | ||
} from './use_timeline_types'; | ||
|
||
jest.mock('react-router-dom', () => { | ||
return { | ||
useParams: jest.fn().mockReturnValue('default'), | ||
useHistory: jest.fn().mockReturnValue([]), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../common/components/link_to', () => { | ||
return { | ||
getTimelineTabsUrl: jest.fn(), | ||
useFormatUrl: jest.fn().mockReturnValue({ | ||
formatUrl: jest.fn(), | ||
search: '', | ||
}), | ||
}; | ||
}); | ||
|
||
describe('useTimelineTypes', () => { | ||
it('init', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
expect(result.current).toEqual({ | ||
timelineType: 'default', | ||
timelineTabs: result.current.timelineTabs, | ||
timelineFilters: result.current.timelineFilters, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('timelineTabs', () => { | ||
it('render timelineTabs', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
|
||
const { container } = render(result.current.timelineTabs); | ||
expect( | ||
container.querySelector('[data-test-subj="timeline-tab-default"]') | ||
).toHaveTextContent('Timelines'); | ||
expect( | ||
container.querySelector('[data-test-subj="timeline-tab-template"]') | ||
).toHaveTextContent('Templates'); | ||
}); | ||
}); | ||
|
||
it('set timelineTypes correctly', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
|
||
const { container } = render(result.current.timelineTabs); | ||
|
||
fireEvent( | ||
container.querySelector('[data-test-subj="timeline-tab-template"]')!, | ||
new MouseEvent('click', { | ||
bubbles: true, | ||
cancelable: true, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual({ | ||
timelineType: 'template', | ||
timelineTabs: result.current.timelineTabs, | ||
timelineFilters: result.current.timelineFilters, | ||
}); | ||
}); | ||
}); | ||
|
||
it('stays in the same tab if clicking again on current tab', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
|
||
const { container } = render(result.current.timelineTabs); | ||
|
||
fireEvent( | ||
container.querySelector('[data-test-subj="timeline-tab-default"]')!, | ||
new MouseEvent('click', { | ||
bubbles: true, | ||
cancelable: true, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual({ | ||
timelineType: 'default', | ||
timelineTabs: result.current.timelineTabs, | ||
timelineFilters: result.current.timelineFilters, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('timelineFilters', () => { | ||
it('render timelineFilters', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
|
||
const { container } = render(<>{result.current.timelineFilters}</>); | ||
expect( | ||
container.querySelector('[data-test-subj="open-timeline-modal-body-filter-default"]') | ||
).toHaveTextContent('Timelines'); | ||
expect( | ||
container.querySelector('[data-test-subj="open-timeline-modal-body-filter-template"]') | ||
).toHaveTextContent('Templates'); | ||
}); | ||
}); | ||
|
||
it('set timelineTypes correctly', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
|
||
const { container } = render(<>{result.current.timelineFilters}</>); | ||
|
||
fireEvent( | ||
container.querySelector('[data-test-subj="open-timeline-modal-body-filter-template"]')!, | ||
new MouseEvent('click', { | ||
bubbles: true, | ||
cancelable: true, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual({ | ||
timelineType: 'template', | ||
timelineTabs: result.current.timelineTabs, | ||
timelineFilters: result.current.timelineFilters, | ||
}); | ||
}); | ||
}); | ||
|
||
it('stays in the same tab if clicking again on current tab', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
UseTimelineTypesArgs, | ||
UseTimelineTypesResult | ||
>(() => useTimelineTypes({ defaultTimelineCount: 0, templateTimelineCount: 3 })); | ||
await waitForNextUpdate(); | ||
|
||
const { container } = render(<>{result.current.timelineFilters}</>); | ||
|
||
fireEvent( | ||
container.querySelector('[data-test-subj="open-timeline-modal-body-filter-default"]')!, | ||
new MouseEvent('click', { | ||
bubbles: true, | ||
cancelable: true, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual({ | ||
timelineType: 'default', | ||
timelineTabs: result.current.timelineTabs, | ||
timelineFilters: result.current.timelineFilters, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.