mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[MX] Mute alert options with read only permission (#191283)
Issue: https://github.com/elastic/kibana/issues/191060 ### Checklist - [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.
This commit is contained in:
parent
7adda78d6b
commit
2d81ab694e
3 changed files with 87 additions and 3 deletions
|
@ -15,6 +15,20 @@ import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks
|
|||
import type { AlertActionsProps } from '@kbn/triggers-actions-ui-plugin/public/types';
|
||||
import { getAlertsTableDefaultAlertActionsLazy } from '@kbn/triggers-actions-ui-plugin/public/common/get_alerts_table_default_row_actions';
|
||||
import { lensPluginMock } from '@kbn/lens-plugin/public/mocks';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
logger: {
|
||||
log: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
},
|
||||
});
|
||||
|
||||
const triggersActionsUiStartMock = {
|
||||
createStart() {
|
||||
|
@ -29,7 +43,11 @@ const triggersActionsUiStartMock = {
|
|||
<div data-test-subj="alerts-state-table">mocked component</div>
|
||||
)),
|
||||
getAlertsTableDefaultAlertActions: (props: AlertActionsProps) => {
|
||||
return getAlertsTableDefaultAlertActionsLazy(props);
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{getAlertsTableDefaultAlertActionsLazy(props)}
|
||||
</QueryClientProvider>
|
||||
);
|
||||
},
|
||||
getAddRuleFlyout: jest.fn(() => <div data-test-subj="add-rule-flyout">mocked component</div>),
|
||||
getEditRuleFlyout: jest.fn(() => (
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 DefaultAlertActions from './default_alert_actions';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import type { AlertActionsProps } from '../../../../types';
|
||||
|
||||
jest.mock('../../../hooks/use_load_rule_types_query', () => ({
|
||||
useLoadRuleTypesQuery: jest.fn(),
|
||||
}));
|
||||
jest.mock('./view_rule_details_alert_action', () => {
|
||||
return {
|
||||
ViewRuleDetailsAlertAction: () => (
|
||||
<div data-test-subj="viewRuleDetailsAlertAction">{'ViewRuleDetailsAlertAction'}</div>
|
||||
),
|
||||
};
|
||||
});
|
||||
jest.mock('./view_alert_details_alert_action', () => {
|
||||
return {
|
||||
ViewAlertDetailsAlertAction: () => (
|
||||
<div data-test-subj="viewAlertDetailsAlertAction">{'ViewAlertDetailsAlertAction'}</div>
|
||||
),
|
||||
};
|
||||
});
|
||||
jest.mock('./mute_alert_action', () => {
|
||||
return { MuteAlertAction: () => <div data-test-subj="muteAlertAction">{'MuteAlertAction'}</div> };
|
||||
});
|
||||
jest.mock('./mark_as_untracked_alert_action', () => {
|
||||
return {
|
||||
MarkAsUntrackedAlertAction: () => (
|
||||
<div data-test-subj="markAsUntrackedAlertAction">{'MarkAsUntrackedAlertAction'}</div>
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
const { useLoadRuleTypesQuery } = jest.requireMock('../../../hooks/use_load_rule_types_query');
|
||||
const props = { alert: {}, refresh: jest.fn() } as unknown as AlertActionsProps;
|
||||
|
||||
describe('DefaultAlertActions component', () => {
|
||||
it('should show "Mute" and "Marked as untracted" option', async () => {
|
||||
useLoadRuleTypesQuery.mockReturnValue({ authorizedToCreateAnyRules: true });
|
||||
|
||||
render(<DefaultAlertActions {...props} />);
|
||||
|
||||
expect(await screen.findByText('MuteAlertAction')).toBeInTheDocument();
|
||||
expect(await screen.findByText('MarkAsUntrackedAlertAction')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should hide "Mute" and "Marked as untracted" option', async () => {
|
||||
useLoadRuleTypesQuery.mockReturnValue({ authorizedToCreateAnyRules: false });
|
||||
|
||||
render(<DefaultAlertActions {...props} />);
|
||||
|
||||
expect(screen.queryByText('MuteAlertAction')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('MarkAsUntrackedAlertAction')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
|
@ -11,17 +11,22 @@ import type { AlertActionsProps } from '../../../../types';
|
|||
import { ViewAlertDetailsAlertAction } from './view_alert_details_alert_action';
|
||||
import { MuteAlertAction } from './mute_alert_action';
|
||||
import { MarkAsUntrackedAlertAction } from './mark_as_untracked_alert_action';
|
||||
import { useLoadRuleTypesQuery } from '../../../hooks/use_load_rule_types_query';
|
||||
|
||||
/**
|
||||
* Common alerts table row actions
|
||||
*/
|
||||
export const DefaultAlertActions = (props: AlertActionsProps) => {
|
||||
const { authorizedToCreateAnyRules } = useLoadRuleTypesQuery({
|
||||
filteredRuleTypes: [],
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<ViewRuleDetailsAlertAction {...props} />
|
||||
<ViewAlertDetailsAlertAction {...props} />
|
||||
<MarkAsUntrackedAlertAction {...props} />
|
||||
<MuteAlertAction {...props} />
|
||||
{authorizedToCreateAnyRules && <MarkAsUntrackedAlertAction {...props} />}
|
||||
{authorizedToCreateAnyRules && <MuteAlertAction {...props} />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue