-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fdd100
commit bfb6b58
Showing
23 changed files
with
570 additions
and
440 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
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
102 changes: 102 additions & 0 deletions
102
x-pack/plugins/observability/public/pages/alert_details/components/header_actions.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,102 @@ | ||
/* | ||
* 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 } from '@testing-library/react'; | ||
import { triggersActionsUiMock } from '@kbn/triggers-actions-ui-plugin/public/mocks'; | ||
import { casesPluginMock, openAddToExistingCaseModalMock } from '@kbn/cases-plugin/public/mocks'; | ||
|
||
import { render } from '../../../utils/test_helper'; | ||
import { useKibana } from '../../../utils/kibana_react'; | ||
import { kibanaStartMock } from '../../../utils/kibana_react.mock'; | ||
import { alertWithTags, mockAlertUuid } from '../mock/alert'; | ||
|
||
import { HeaderActions } from './header_actions'; | ||
|
||
jest.mock('../../../utils/kibana_react'); | ||
|
||
const useKibanaMock = useKibana as jest.Mock; | ||
|
||
const mockKibana = () => { | ||
useKibanaMock.mockReturnValue({ | ||
services: { | ||
...kibanaStartMock.startContract(), | ||
triggersActionsUi: triggersActionsUiMock.createStart(), | ||
cases: casesPluginMock.createStartContract(), | ||
}, | ||
}); | ||
}; | ||
|
||
const ruleId = '123'; | ||
const ruleName = '456'; | ||
|
||
jest.mock('../../../hooks/use_fetch_rule', () => { | ||
return { | ||
useFetchRule: () => ({ | ||
reloadRule: jest.fn(), | ||
rule: { | ||
id: ruleId, | ||
name: ruleName, | ||
}, | ||
}), | ||
}; | ||
}); | ||
|
||
describe('Header Actions', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockKibana(); | ||
}); | ||
|
||
const mockViewInExternalApp = jest.fn(); | ||
|
||
it('should display an actions button', () => { | ||
const { queryByTestId } = render(<HeaderActions alert={alertWithTags} />); | ||
expect(queryByTestId('alert-details-header-actions-menu-button')).toBeTruthy(); | ||
}); | ||
|
||
describe('when clicking the actions button', () => { | ||
it('should offer an "add to case" button which opens the add to case modal', async () => { | ||
const { getByTestId, findByRole } = render(<HeaderActions alert={alertWithTags} />); | ||
|
||
fireEvent.click(await findByRole('button', { name: 'Actions' })); | ||
|
||
fireEvent.click(getByTestId('add-to-case-button')); | ||
|
||
expect(openAddToExistingCaseModalMock).toBeCalledWith({ | ||
attachments: [ | ||
{ | ||
alertId: mockAlertUuid, | ||
index: '.internal.alerts-observability.metrics.alerts-*', | ||
rule: { | ||
id: ruleId, | ||
name: ruleName, | ||
}, | ||
type: 'alert', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
it('should show a connector action if passed an externalConnector prop', async () => { | ||
const { findByRole, getByTestId } = render( | ||
<HeaderActions | ||
alert={alertWithTags} | ||
externalConnector={{ name: 'foo', onViewInExternalApp: mockViewInExternalApp }} | ||
/> | ||
); | ||
|
||
fireEvent.click(await findByRole('button', { name: 'Actions' })); | ||
const button = getByTestId('view-in-external-app-button'); | ||
expect(button).toBeTruthy(); | ||
|
||
fireEvent.click(button); | ||
|
||
expect(mockViewInExternalApp).toBeCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.