diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx index 53f5e25530e98..5067cbbee9bf4 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx @@ -490,7 +490,7 @@ describe('alerts_list component with items', () => { it('does not render edit and delete button when rule type does not allow editing in rules management', async () => { await setup(false); expect(wrapper.find('[data-test-subj="alertSidebarEditAction"]').exists()).toBeFalsy(); - expect(wrapper.find('[data-test-subj="alertSidebarDeleteAction"]').exists()).toBeFalsy(); + expect(wrapper.find('[data-test-subj="alertSidebarDeleteAction"]').exists()).toBeTruthy(); }); }); @@ -540,7 +540,7 @@ describe('alerts_list component empty with show only capability', () => { describe('alerts_list with show only capability', () => { let wrapper: ReactWrapper; - async function setup() { + async function setup(editable: boolean = true) { loadAlerts.mockResolvedValue({ page: 1, perPage: 10000, @@ -606,7 +606,20 @@ describe('alerts_list with show only capability', () => { loadAlertTypes.mockResolvedValue([alertTypeFromApi]); loadAllActions.mockResolvedValue([]); - ruleTypeRegistry.has.mockReturnValue(false); + const ruleTypeMock: AlertTypeModel = { + id: 'test_alert_type', + iconClass: 'test', + description: 'Alert when testing', + documentationUrl: 'https://localhost.local/docs', + validate: () => { + return { errors: {} }; + }, + alertParamsExpression: jest.fn(), + requiresAppContext: !editable, + }; + + ruleTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.get.mockReturnValue(ruleTypeMock); // eslint-disable-next-line react-hooks/rules-of-hooks useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; @@ -621,18 +634,27 @@ describe('alerts_list with show only capability', () => { } it('renders table of alerts with edit button disabled', async () => { - await setup(); + await setup(false); expect(wrapper.find('EuiBasicTable')).toHaveLength(1); expect(wrapper.find('EuiTableRow')).toHaveLength(2); expect(wrapper.find('[data-test-subj="editActionHoverButton"]')).toHaveLength(0); }); it('renders table of alerts with delete button disabled', async () => { - await setup(); + const { hasAllPrivilege } = jest.requireMock('../../../lib/capabilities'); + hasAllPrivilege.mockReturnValue(false); + await setup(false); expect(wrapper.find('EuiBasicTable')).toHaveLength(1); expect(wrapper.find('EuiTableRow')).toHaveLength(2); expect(wrapper.find('[data-test-subj="deleteActionHoverButton"]')).toHaveLength(0); }); + + it('renders table of alerts with actions menu collapsedItemActions', async () => { + await setup(false); + expect(wrapper.find('EuiBasicTable')).toHaveLength(1); + expect(wrapper.find('EuiTableRow')).toHaveLength(2); + expect(wrapper.find('[data-test-subj="collapsedItemActions"]').length).toBeGreaterThan(0); + }); }); describe('alerts_list with disabled itmes', () => { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx index a7d54a896d7ef..b48d5a6a3629f 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx @@ -571,47 +571,50 @@ export const AlertsList: React.FunctionComponent = () => { name: '', width: '10%', render(item: AlertTableItem) { - return item.isEditable && isRuleTypeEditableInContext(item.alertTypeId) ? ( + return ( - - onRuleEdit(item)} - iconType={'pencil'} - aria-label={i18n.translate( - 'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.editAriaLabel', - { defaultMessage: 'Edit' } - )} - /> - - - setAlertsToDelete([item.id])} - iconType={'trash'} - aria-label={i18n.translate( - 'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.deleteAriaLabel', - { defaultMessage: 'Delete' } - )} - /> - + {item.isEditable && isRuleTypeEditableInContext(item.alertTypeId) ? ( + + onRuleEdit(item)} + iconType={'pencil'} + aria-label={i18n.translate( + 'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.editAriaLabel', + { defaultMessage: 'Edit' } + )} + /> + + ) : null} + {item.isEditable ? ( + + setAlertsToDelete([item.id])} + iconType={'trash'} + aria-label={i18n.translate( + 'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.deleteAriaLabel', + { defaultMessage: 'Delete' } + )} + /> + + ) : null} - { /> - ) : null; + ); }, }, ]; diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts_list.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts_list.ts index dede481669664..eb4c0fbe425c4 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts_list.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts_list.ts @@ -206,6 +206,22 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); }); + it('should be able to mute the rule with non "alerts" consumer from a non editable context', async () => { + const createdAlert = await createAlert({ consumer: 'siem' }); + await refreshAlertsList(); + await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name); + + await testSubjects.click('collapsedItemActions'); + + await testSubjects.click('muteButton'); + + await retry.tryForTime(30000, async () => { + await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name); + const muteBadge = await testSubjects.find('mutedActionsBadge'); + expect(await muteBadge.isDisplayed()).to.eql(true); + }); + }); + it('should unmute single alert', async () => { const createdAlert = await createAlert(); await muteAlert(createdAlert.id);