diff --git a/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx b/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx index 5b78e5f5ac1..9726a8e7cea 100644 --- a/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx +++ b/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx @@ -59,6 +59,17 @@ describe('Redirect to Rule viewer', () => { expect(screen.getAllByText('Cloud test alert')).toHaveLength(2); }); + it('should show no rules if empty response', () => { + jest.mocked(combinedRuleHooks.useCloudCombinedRulesMatching).mockReturnValue({ + rules: [], + loading: false, + error: undefined, + }); + mockRuleSourceByName(); + renderRedirectToRuleViewer('/alerting/test prom/prom alert/find'); + expect(screen.getByTestId('no-rules')).toBeInTheDocument(); + }); + it('should redirect to view rule page if only one match', () => { jest.mocked(combinedRuleHooks.useCloudCombinedRulesMatching).mockReturnValue({ rules: [mockedRules[0]], diff --git a/public/app/features/alerting/unified/RedirectToRuleViewer.tsx b/public/app/features/alerting/unified/RedirectToRuleViewer.tsx index 3805cbbbcd0..2bc0fc71f53 100644 --- a/public/app/features/alerting/unified/RedirectToRuleViewer.tsx +++ b/public/app/features/alerting/unified/RedirectToRuleViewer.tsx @@ -98,6 +98,17 @@ export function RedirectToRuleViewer(): JSX.Element | null { return ; } + if (rules.length === 0) { + return ( + +
+ No rules in {sourceName} matched the name{' '} + {name} +
+
+ ); + } + return (