diff --git a/x-pack/plugins/observability_solution/observability/public/plugin.mock.tsx b/x-pack/plugins/observability_solution/observability/public/plugin.mock.tsx
index 9bef3e98ddf84..93892427c01f9 100644
--- a/x-pack/plugins/observability_solution/observability/public/plugin.mock.tsx
+++ b/x-pack/plugins/observability_solution/observability/public/plugin.mock.tsx
@@ -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 = {
mocked component
)),
getAlertsTableDefaultAlertActions: (props: AlertActionsProps) => {
- return getAlertsTableDefaultAlertActionsLazy(props);
+ return (
+
+ {getAlertsTableDefaultAlertActionsLazy(props)}
+
+ );
},
getAddRuleFlyout: jest.fn(() => mocked component
),
getEditRuleFlyout: jest.fn(() => (
diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.test.tsx
new file mode 100644
index 0000000000000..cedc0eccfd68e
--- /dev/null
+++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.test.tsx
@@ -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: () => (
+ {'ViewRuleDetailsAlertAction'}
+ ),
+ };
+});
+jest.mock('./view_alert_details_alert_action', () => {
+ return {
+ ViewAlertDetailsAlertAction: () => (
+ {'ViewAlertDetailsAlertAction'}
+ ),
+ };
+});
+jest.mock('./mute_alert_action', () => {
+ return { MuteAlertAction: () => {'MuteAlertAction'}
};
+});
+jest.mock('./mark_as_untracked_alert_action', () => {
+ return {
+ MarkAsUntrackedAlertAction: () => (
+ {'MarkAsUntrackedAlertAction'}
+ ),
+ };
+});
+
+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();
+
+ 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();
+
+ expect(screen.queryByText('MuteAlertAction')).not.toBeInTheDocument();
+ expect(screen.queryByText('MarkAsUntrackedAlertAction')).not.toBeInTheDocument();
+ });
+});
diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.tsx
index e2bcec4a2b6d2..791eca7b2489a 100644
--- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.tsx
+++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/row_actions/default_alert_actions.tsx
@@ -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 (
<>
-
-
+ {authorizedToCreateAnyRules && }
+ {authorizedToCreateAnyRules && }
>
);
};