forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Cases] Improve jest tests on connector switcher …
…feature (elastic#79922) (elastic#80169)
- Loading branch information
1 parent
296ced8
commit d8070bd
Showing
10 changed files
with
362 additions
and
20 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
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
79 changes: 79 additions & 0 deletions
79
...k/plugins/security_solution/public/cases/components/settings/jira/use_get_issues.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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import { connector as actionConnector, issues } from '../mock'; | ||
import { useGetIssues, UseGetIssues } from './use_get_issues'; | ||
import * as api from './api'; | ||
|
||
jest.mock('../../../../common/lib/kibana'); | ||
jest.mock('./api'); | ||
|
||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>; | ||
|
||
describe('useGetIssues', () => { | ||
const { http, notifications } = useKibanaMock().services; | ||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
test('init', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseGetIssues>(() => | ||
useGetIssues({ | ||
http, | ||
toastNotifications: notifications.toasts, | ||
actionConnector, | ||
query: null, | ||
}) | ||
); | ||
await waitForNextUpdate(); | ||
expect(result.current).toEqual({ isLoading: false, issues: [] }); | ||
}); | ||
}); | ||
|
||
test('fetch issues', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseGetIssues>(() => | ||
useGetIssues({ | ||
http, | ||
toastNotifications: notifications.toasts, | ||
actionConnector, | ||
query: 'Task', | ||
}) | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
expect(result.current).toEqual({ | ||
isLoading: false, | ||
issues, | ||
}); | ||
}); | ||
}); | ||
|
||
test('unhappy path', async () => { | ||
const spyOnGetCaseConfigure = jest.spyOn(api, 'getIssues'); | ||
spyOnGetCaseConfigure.mockImplementation(() => { | ||
throw new Error('Something went wrong'); | ||
}); | ||
|
||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseGetIssues>(() => | ||
useGetIssues({ | ||
http, | ||
toastNotifications: notifications.toasts, | ||
actionConnector, | ||
query: 'oh no', | ||
}) | ||
); | ||
|
||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
|
||
expect(result.current).toEqual({ isLoading: false, issues: [] }); | ||
}); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
...ins/security_solution/public/cases/components/settings/jira/use_get_single_issue.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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import { connector as actionConnector, issues } from '../mock'; | ||
import { useGetSingleIssue, UseGetSingleIssue } from './use_get_single_issue'; | ||
import * as api from './api'; | ||
|
||
jest.mock('../../../../common/lib/kibana'); | ||
jest.mock('./api'); | ||
|
||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>; | ||
|
||
describe('useGetSingleIssue', () => { | ||
const { http, notifications } = useKibanaMock().services; | ||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
test('init', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseGetSingleIssue>(() => | ||
useGetSingleIssue({ | ||
http, | ||
toastNotifications: notifications.toasts, | ||
actionConnector, | ||
id: null, | ||
}) | ||
); | ||
await waitForNextUpdate(); | ||
expect(result.current).toEqual({ isLoading: false, issue: null }); | ||
}); | ||
}); | ||
|
||
test('fetch issues', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseGetSingleIssue>(() => | ||
useGetSingleIssue({ | ||
http, | ||
toastNotifications: notifications.toasts, | ||
actionConnector, | ||
id: '123', | ||
}) | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
expect(result.current).toEqual({ | ||
isLoading: false, | ||
issue: issues[0], | ||
}); | ||
}); | ||
}); | ||
|
||
test('unhappy path', async () => { | ||
const spyOnGetCaseConfigure = jest.spyOn(api, 'getIssue'); | ||
spyOnGetCaseConfigure.mockImplementation(() => { | ||
throw new Error('Something went wrong'); | ||
}); | ||
|
||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseGetSingleIssue>(() => | ||
useGetSingleIssue({ | ||
http, | ||
toastNotifications: notifications.toasts, | ||
actionConnector, | ||
id: '123', | ||
}) | ||
); | ||
|
||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
|
||
expect(result.current).toEqual({ isLoading: false, issue: null }); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.