-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented edit alert functionality * Added unit tests * Added functional test for edit alert * Fixed failed tests * Fixed edit api * Fixed due to comments * Fixed functional test * Fixed tests * Fixed add alert * Small type fix * Fixed jest test * Fixed type check * Fixed bugs with interval and throttle + index threshold expression
- Loading branch information
1 parent
ac4f8f4
commit daf6226
Showing
21 changed files
with
508 additions
and
99 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
...ublic/application/components/builtin_alert_types/threshold/constants/aggregation_types.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...s_ui/public/application/components/builtin_alert_types/threshold/constants/comparators.ts
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...actions_ui/public/application/components/builtin_alert_types/threshold/constants/index.ts
This file was deleted.
Oops, something went wrong.
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
131 changes: 131 additions & 0 deletions
131
...ck/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.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,131 @@ | ||
/* | ||
* 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 * as React from 'react'; | ||
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { coreMock } from '../../../../../../../src/core/public/mocks'; | ||
import { actionTypeRegistryMock } from '../../action_type_registry.mock'; | ||
import { ValidationResult } from '../../../types'; | ||
import { AlertsContextProvider } from '../../context/alerts_context'; | ||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; | ||
import { ReactWrapper } from 'enzyme'; | ||
import { AlertEdit } from './alert_edit'; | ||
const actionTypeRegistry = actionTypeRegistryMock.create(); | ||
const alertTypeRegistry = alertTypeRegistryMock.create(); | ||
|
||
describe('alert_edit', () => { | ||
let deps: any; | ||
let wrapper: ReactWrapper<any>; | ||
|
||
beforeAll(async () => { | ||
const mockes = coreMock.createSetup(); | ||
deps = { | ||
toastNotifications: mockes.notifications.toasts, | ||
http: mockes.http, | ||
uiSettings: mockes.uiSettings, | ||
actionTypeRegistry: actionTypeRegistry as any, | ||
alertTypeRegistry: alertTypeRegistry as any, | ||
}; | ||
const alertType = { | ||
id: 'my-alert-type', | ||
iconClass: 'test', | ||
name: 'test-alert', | ||
validate: (): ValidationResult => { | ||
return { errors: {} }; | ||
}, | ||
alertParamsExpression: () => <React.Fragment />, | ||
}; | ||
|
||
const actionTypeModel = { | ||
id: 'my-action-type', | ||
iconClass: 'test', | ||
selectMessage: 'test', | ||
validateConnector: (): ValidationResult => { | ||
return { errors: {} }; | ||
}, | ||
validateParams: (): ValidationResult => { | ||
const validationResult = { errors: {} }; | ||
return validationResult; | ||
}, | ||
actionConnectorFields: null, | ||
actionParamsFields: null, | ||
}; | ||
|
||
const alert = { | ||
id: 'ab5661e0-197e-45ee-b477-302d89193b5e', | ||
params: { | ||
aggType: 'average', | ||
threshold: [1000, 5000], | ||
index: 'kibana_sample_data_flights', | ||
timeField: 'timestamp', | ||
aggField: 'DistanceMiles', | ||
window: '1s', | ||
comparator: 'between', | ||
}, | ||
consumer: 'alerting', | ||
alertTypeId: 'my-alert-type', | ||
enabled: false, | ||
schedule: { interval: '1m' }, | ||
actions: [ | ||
{ | ||
actionTypeId: 'my-action-type', | ||
group: 'threshold met', | ||
params: { message: 'Alert [{{ctx.metadata.name}}] has exceeded the threshold' }, | ||
message: 'Alert [{{ctx.metadata.name}}] has exceeded the threshold', | ||
id: '917f5d41-fbc4-4056-a8ad-ac592f7dcee2', | ||
}, | ||
], | ||
tags: [], | ||
name: 'test alert', | ||
throttle: null, | ||
apiKeyOwner: null, | ||
createdBy: 'elastic', | ||
updatedBy: 'elastic', | ||
createdAt: new Date(), | ||
muteAll: false, | ||
mutedInstanceIds: [], | ||
updatedAt: new Date(), | ||
}; | ||
actionTypeRegistry.get.mockReturnValueOnce(actionTypeModel); | ||
actionTypeRegistry.has.mockReturnValue(true); | ||
alertTypeRegistry.list.mockReturnValue([alertType]); | ||
alertTypeRegistry.get.mockReturnValue(alertType); | ||
alertTypeRegistry.has.mockReturnValue(true); | ||
actionTypeRegistry.list.mockReturnValue([actionTypeModel]); | ||
actionTypeRegistry.has.mockReturnValue(true); | ||
|
||
wrapper = mountWithIntl( | ||
<AlertsContextProvider | ||
value={{ | ||
reloadAlerts: () => { | ||
return new Promise<void>(() => {}); | ||
}, | ||
http: deps!.http, | ||
actionTypeRegistry: deps!.actionTypeRegistry, | ||
alertTypeRegistry: deps!.alertTypeRegistry, | ||
toastNotifications: deps!.toastNotifications, | ||
uiSettings: deps!.uiSettings, | ||
}} | ||
> | ||
<AlertEdit | ||
editFlyoutVisible={true} | ||
setEditFlyoutVisibility={() => {}} | ||
initialAlert={alert} | ||
/> | ||
</AlertsContextProvider> | ||
); | ||
// Wait for active space to resolve before requesting the component to update | ||
await act(async () => { | ||
await nextTick(); | ||
wrapper.update(); | ||
}); | ||
}); | ||
|
||
it('renders alert add flyout', () => { | ||
expect(wrapper.find('[data-test-subj="editAlertFlyoutTitle"]').exists()).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="saveEditedAlertButton"]').exists()).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.