From 43e8319ebfd4d8f4e47313aae896bfc86f7cd78e Mon Sep 17 00:00:00 2001 From: Matt Jacobson Date: Wed, 7 Jan 2026 12:24:23 -0500 Subject: [PATCH] Add back removed test --- .../useNotificationPolicyRoute.test.tsx | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/public/app/features/alerting/unified/components/notification-policies/useNotificationPolicyRoute.test.tsx b/public/app/features/alerting/unified/components/notification-policies/useNotificationPolicyRoute.test.tsx index 25a5ca0cafd..da6060f63a3 100644 --- a/public/app/features/alerting/unified/components/notification-policies/useNotificationPolicyRoute.test.tsx +++ b/public/app/features/alerting/unified/components/notification-policies/useNotificationPolicyRoute.test.tsx @@ -1,8 +1,93 @@ import { MatcherOperator, ROUTES_META_SYMBOL, Route } from 'app/plugins/datasource/alertmanager/types'; +import { ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Route } from '../../openapi/routesApi.gen'; import { ROOT_ROUTE_NAME } from '../../utils/k8s/constants'; -import { createKubernetesRoutingTreeSpec } from './useNotificationPolicyRoute'; +import { createKubernetesRoutingTreeSpec, k8sSubRouteToRoute, routeToK8sSubRoute } from './useNotificationPolicyRoute'; + +test('k8sSubRouteToRoute', () => { + const input: ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Route = { + continue: false, + group_by: ['label1'], + group_interval: '5m', + group_wait: '30s', + matchers: [{ label: 'label1', type: '=', value: 'value1' }], + mute_time_intervals: ['mt-1'], + receiver: 'my-receiver', + repeat_interval: '4h', + routes: [ + { + receiver: 'receiver2', + matchers: [{ label: 'label2', type: '!=', value: 'value2' }], + }, + ], + }; + + const expected: Route = { + name: 'test-name', + continue: false, + group_by: ['label1'], + group_interval: '5m', + group_wait: '30s', + matchers: undefined, // matchers -> object_matchers + object_matchers: [['label1', MatcherOperator.equal, 'value1']], + mute_time_intervals: ['mt-1'], + receiver: 'my-receiver', + repeat_interval: '4h', + routes: [ + { + name: 'test-name', + receiver: 'receiver2', + matchers: undefined, + object_matchers: [['label2', MatcherOperator.notEqual, 'value2']], + routes: undefined, + }, + ], + }; + + expect(k8sSubRouteToRoute(input, 'test-name')).toStrictEqual(expected); +}); + +test('routeToK8sSubRoute', () => { + const input: Route = { + continue: false, + group_by: ['label1'], + group_interval: '5m', + group_wait: '30s', + matchers: undefined, // matchers -> object_matchers + object_matchers: [['label1', MatcherOperator.equal, 'value1']], + mute_time_intervals: ['mt-1'], + receiver: 'my-receiver', + repeat_interval: '4h', + routes: [ + { + receiver: 'receiver2', + matchers: undefined, + object_matchers: [['label2', MatcherOperator.notEqual, 'value2']], + }, + ], + }; + + const expected: ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Route = { + continue: false, + group_by: ['label1'], + group_interval: '5m', + group_wait: '30s', + matchers: [{ label: 'label1', type: '=', value: 'value1' }], + mute_time_intervals: ['mt-1'], + receiver: 'my-receiver', + repeat_interval: '4h', + routes: [ + { + receiver: 'receiver2', + matchers: [{ label: 'label2', type: '!=', value: 'value2' }], + routes: undefined, + }, + ], + }; + + expect(routeToK8sSubRoute(input)).toStrictEqual(expected); +}); test('createKubernetesRoutingTreeSpec', () => { const route: Route = {