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.
[ML] Transforms: Support wildcards in the alerting rule flyout (elast…
…ic#204226) ## Summary Closes elastic#166810 - Adds wildcards support for the tranform health alerting rule. - Populates transforms with alerting rules based on wildcard expressions. - Excludes `alerting_rules` from the JSON tab. ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
6 changed files
with
344 additions
and
68 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
.../transform/public/alerting/transform_health_rule_type/transform_selector_control.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,62 @@ | ||
/* | ||
* 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 { render, fireEvent } from '@testing-library/react'; | ||
import type { TransformSelectorControlProps } from './transform_selector_control'; | ||
import { TransformSelectorControl } from './transform_selector_control'; | ||
|
||
describe('TransformSelectorControl', () => { | ||
const defaultProps: TransformSelectorControlProps = { | ||
label: 'Select Transforms', | ||
errors: [], | ||
onChange: jest.fn(), | ||
selectedOptions: [], | ||
options: ['transform1', 'transform2'], | ||
allowSelectAll: true, | ||
}; | ||
|
||
it('renders without crashing', () => { | ||
const { getByLabelText } = render(<TransformSelectorControl {...defaultProps} />); | ||
expect(getByLabelText('Select Transforms')).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays options correctly', () => { | ||
const { getByText } = render(<TransformSelectorControl {...defaultProps} />); | ||
fireEvent.click(getByText('Select Transforms')); | ||
expect(getByText('transform1')).toBeInTheDocument(); | ||
expect(getByText('transform2')).toBeInTheDocument(); | ||
expect(getByText('*')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onChange with selected options', () => { | ||
const { getByText } = render(<TransformSelectorControl {...defaultProps} />); | ||
fireEvent.click(getByText('Select Transforms')); | ||
fireEvent.click(getByText('transform1')); | ||
expect(defaultProps.onChange).toHaveBeenCalledWith(['transform1']); | ||
}); | ||
|
||
it('only allows wildcards as custom options', () => { | ||
const { getByText, getByTestId } = render(<TransformSelectorControl {...defaultProps} />); | ||
fireEvent.click(getByText('Select Transforms')); | ||
const input = getByTestId('comboBoxSearchInput'); | ||
|
||
fireEvent.change(input, { target: { value: 'custom' } }); | ||
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' }); | ||
expect(defaultProps.onChange).not.toHaveBeenCalledWith(['custom']); | ||
|
||
fireEvent.change(input, { target: { value: 'custom*' } }); | ||
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' }); | ||
expect(defaultProps.onChange).toHaveBeenCalledWith(['custom*']); | ||
}); | ||
|
||
it('displays errors correctly', () => { | ||
const errorProps = { ...defaultProps, errors: ['Error message'] }; | ||
const { getByText } = render(<TransformSelectorControl {...errorProps} />); | ||
expect(getByText('Error message')).toBeInTheDocument(); | ||
}); | ||
}); |
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
Oops, something went wrong.