From 9fff736549707052d64a67df76a7f5db8e06b45e Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Wed, 2 Oct 2024 17:14:54 +0200 Subject: [PATCH] Alerting: Support k8s templates API (#92112) Co-authored-by: Tom Ratcliffe Co-authored-by: Sonia Aguilar Co-authored-by: Gilles De Mey --- .betterer.results | 6 - .../alerting/unified/Templates.test.tsx | 117 +++++- .../alerting/unified/api/templateApi.ts | 17 +- .../app/features/alerting/unified/api/util.ts | 6 +- .../DuplicateMessageTemplate.tsx | 65 ++- .../contact-points/EditMessageTemplate.tsx | 48 ++- .../contact-points/NewMessageTemplate.tsx | 24 +- .../NotificationTemplates.test.tsx | 46 ++- .../__mocks__/alertmanager.config.mock.json | 8 +- .../useNotificationTemplates.ts | 264 ++++++++++-- .../receivers/DuplicateTemplateView.tsx | 35 -- .../components/receivers/EditTemplateView.tsx | 31 -- .../components/receivers/NewTemplateView.tsx | 12 - .../components/receivers/TemplateForm.tsx | 70 ++-- .../components/receivers/TemplatesTable.tsx | 204 +++++---- .../NewReceiverView.test.tsx.snap | 8 +- .../form/fields/TemplateSelector.test.tsx | 70 +++- .../form/fields/TemplateSelector.tsx | 26 +- .../unified/mocks/server/all-handlers.ts | 3 +- .../server/handlers/k8s/templates.k8s.ts | 100 +++++ .../unified/openapi/templatesApi.gen.ts | 387 ++++++++++++++++++ scripts/generate-alerting-rtk-apis.ts | 13 + 22 files changed, 1225 insertions(+), 335 deletions(-) delete mode 100644 public/app/features/alerting/unified/components/receivers/DuplicateTemplateView.tsx delete mode 100644 public/app/features/alerting/unified/components/receivers/EditTemplateView.tsx delete mode 100644 public/app/features/alerting/unified/components/receivers/NewTemplateView.tsx create mode 100644 public/app/features/alerting/unified/mocks/server/handlers/k8s/templates.k8s.ts create mode 100644 public/app/features/alerting/unified/openapi/templatesApi.gen.ts diff --git a/.betterer.results b/.betterer.results index 7f27fd80d8f..12d1729d2e1 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1765,12 +1765,6 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "1"], [0, 0, 0, "No untranslated strings. Wrap text with ", "2"] ], - "public/app/features/alerting/unified/components/receivers/DuplicateTemplateView.tsx:5381": [ - [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] - ], - "public/app/features/alerting/unified/components/receivers/EditTemplateView.tsx:5381": [ - [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] - ], "public/app/features/alerting/unified/components/receivers/GlobalConfigForm.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"], [0, 0, 0, "No untranslated strings. Wrap text with ", "1"], diff --git a/public/app/features/alerting/unified/Templates.test.tsx b/public/app/features/alerting/unified/Templates.test.tsx index a18a74475b7..6d695af5826 100644 --- a/public/app/features/alerting/unified/Templates.test.tsx +++ b/public/app/features/alerting/unified/Templates.test.tsx @@ -1,7 +1,12 @@ import * as React from 'react'; -import { render, screen } from 'test/test-utils'; +import { Props } from 'react-virtualized-auto-sizer'; +import { render, screen, within } from 'test/test-utils'; +import { byRole } from 'testing-library-selector'; +import { CodeEditorProps } from '@grafana/ui/src/components/Monaco/types'; +import { AppNotificationList } from 'app/core/components/AppNotifications/AppNotificationList'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; +import { testWithFeatureToggles } from 'app/features/alerting/unified/test/test-utils'; import { AccessControlAction } from 'app/types'; import Templates from './Templates'; @@ -11,6 +16,38 @@ jest.mock('app/core/components/AppChrome/AppChromeUpdate', () => ({ AppChromeUpdate: ({ actions }: { actions: React.ReactNode }) =>
{actions}
, })); +//mock updateDefinesWithUniqueValue +jest.mock('app/features/alerting/unified/utils/templates', () => ({ + ...jest.requireActual('app/features/alerting/unified/utils/templates'), + updateDefinesWithUniqueValue: (templateContent: string) => { + return templateContent.replace(/custom-email/g, 'custom-email_NEW'); + }, +})); + +jest.mock( + 'react-virtualized-auto-sizer', + () => + ({ children }: Props) => + children({ width: 1000, height: 1000, scaledWidth: 1, scaledHeight: 1 }) +); + +jest.mock('@grafana/ui', () => ({ + ...jest.requireActual('@grafana/ui'), + CodeEditor: ({ value, onChange }: CodeEditorProps) => ( +