Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Flapping] Update rule specific flapping tooltip UI #194086

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ jest.mock('../../lib/action_connector_api', () => ({
loadAllActions: jest.fn(),
}));

jest.mock('../../lib/rule_api/get_flapping_settings', () => ({
getFlappingSettings: jest.fn().mockResolvedValue({
lookBackWindow: 20,
statusChangeThreshold: 20,
}),
}));

const actionTypeRegistry = actionTypeRegistryMock.create();
const ruleTypeRegistry = ruleTypeRegistryMock.create();

Expand Down Expand Up @@ -149,6 +156,9 @@ describe('rule_add', () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useKibanaMock().services.application.capabilities = {
...capabilities,
rulesSettings: {
writeFlappingSettingsUI: true,
},
rules: {
show: true,
save: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ jest.mock('@kbn/alerts-ui-shared/src/common/apis/fetch_ui_health_status', () =>
fetchUiHealthStatus: jest.fn(() => ({ isRulesAvailable: true })),
}));

jest.mock('../../lib/rule_api/get_flapping_settings', () => ({
getFlappingSettings: jest.fn().mockResolvedValue({
lookBackWindow: 20,
statusChangeThreshold: 20,
}),
}));

describe('rule_edit', () => {
let wrapper: ReactWrapper<any>;
let mockedCoreSetup: ReturnType<typeof coreMock.createSetup>;
Expand All @@ -80,6 +87,9 @@ describe('rule_edit', () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useKibanaMock().services.application.capabilities = {
...capabilities,
rulesSettings: {
writeFlappingSettingsUI: true,
},
rules: {
show: true,
save: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ jest.mock('../../lib/capabilities', () => ({
hasShowActionsCapability: jest.fn(() => true),
hasExecuteActionsCapability: jest.fn(() => true),
}));
jest.mock('../../lib/rule_api/get_flapping_settings', () => ({
getFlappingSettings: jest.fn().mockResolvedValue({
lookBackWindow: 20,
statusChangeThreshold: 20,
}),
}));

describe('rule_form', () => {
const ruleType = {
Expand Down Expand Up @@ -203,6 +209,9 @@ describe('rule_form', () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useKibanaMock().services.application.capabilities = {
...capabilities,
rulesSettings: {
writeFlappingSettingsUI: true,
},
rules: {
show: true,
save: true,
Expand Down Expand Up @@ -358,6 +367,9 @@ describe('rule_form', () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useKibanaMock().services.application.capabilities = {
...capabilities,
rulesSettings: {
writeFlappingSettingsUI: true,
},
rules: {
show: true,
save: true,
Expand Down Expand Up @@ -1071,6 +1083,9 @@ describe('rule_form', () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useKibanaMock().services.application.capabilities = {
...capabilities,
rulesSettings: {
writeFlappingSettingsUI: true,
},
rules: {
show: true,
save: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
import { RuleFormAdvancedOptions } from './rule_form_advanced_options';
import { useKibana } from '../../../common/lib/kibana';
import userEvent from '@testing-library/user-event';
import { ApplicationStart } from '@kbn/core-application-browser';

jest.mock('../../../common/lib/kibana');

Expand All @@ -38,6 +39,11 @@ describe('ruleFormAdvancedOptions', () => {
enabled: true,
});
useKibanaMock().services.http = http;
useKibanaMock().services.application.capabilities = {
rulesSettings: {
writeFlappingSettingsUI: true,
},
} as unknown as ApplicationStart['capabilities'];
});

afterEach(() => {
Expand Down Expand Up @@ -80,7 +86,7 @@ describe('ruleFormAdvancedOptions', () => {

expect(await screen.findByText('ON')).toBeInTheDocument();
expect(screen.getByTestId('ruleFormAdvancedOptionsOverrideSwitch')).not.toBeChecked();
expect(screen.queryByText('Override')).not.toBeInTheDocument();
expect(screen.queryByText('Custom')).not.toBeInTheDocument();
expect(screen.getByTestId('ruleSettingsFlappingMessage')).toHaveTextContent(
'An alert is flapping if it changes status at least 3 times in the last 10 rule runs.'
);
Expand Down Expand Up @@ -111,7 +117,7 @@ describe('ruleFormAdvancedOptions', () => {
);

expect(await screen.findByTestId('ruleFormAdvancedOptionsOverrideSwitch')).toBeChecked();
expect(screen.getByText('Override')).toBeInTheDocument();
expect(screen.getByText('Custom')).toBeInTheDocument();
expect(screen.getByTestId('lookBackWindowRangeInput')).toHaveValue('6');
expect(screen.getByTestId('statusChangeThresholdRangeInput')).toHaveValue('4');
expect(screen.getByTestId('ruleSettingsFlappingMessage')).toHaveTextContent(
Expand Down Expand Up @@ -148,7 +154,7 @@ describe('ruleFormAdvancedOptions', () => {
);

expect(await screen.findByText('OFF')).toBeInTheDocument();
expect(screen.queryByText('Override')).not.toBeInTheDocument();
expect(screen.queryByText('Custom')).not.toBeInTheDocument();
expect(screen.queryByTestId('ruleFormAdvancedOptionsOverrideSwitch')).not.toBeInTheDocument();
expect(screen.queryByTestId('ruleSettingsFlappingMessage')).not.toBeInTheDocument();
});
Expand Down
Loading