From 56795e079838ee555884b119ff0c7d2f4b5b9a08 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 17 Apr 2023 15:10:45 +0300 Subject: [PATCH] Adding validatingwebhookconfigs tests Signed-off-by: Alex Andreev --- .../details.test.tsx | 82 ++++++++++++++++++ .../details.test.tsx | 83 +++++++++++++++++++ .../__tests__/cluster-pages.tests.ts | 12 +++ 3 files changed, 177 insertions(+) create mode 100644 packages/core/src/renderer/components/+config-mutating-webhook-configurations/details.test.tsx create mode 100644 packages/core/src/renderer/components/+config-validating-webhook-configurations/details.test.tsx diff --git a/packages/core/src/renderer/components/+config-mutating-webhook-configurations/details.test.tsx b/packages/core/src/renderer/components/+config-mutating-webhook-configurations/details.test.tsx new file mode 100644 index 0000000000..c02b3047a7 --- /dev/null +++ b/packages/core/src/renderer/components/+config-mutating-webhook-configurations/details.test.tsx @@ -0,0 +1,82 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import type { RenderResult } from "@testing-library/react"; +import React from "react"; +import { + MutatingWebhookConfiguration, +} from "../../../common/k8s-api/endpoints"; +import { getDiForUnitTesting } from "../../getDiForUnitTesting"; +import type { DiRender } from "../test-utils/renderFor"; +import { renderFor } from "../test-utils/renderFor"; +import { MutatingWebhookDetails } from "./mutating-webhook-configurations-details"; + +const mutatingWebhookConfig = { + apiVersion: "admissionregistration.k8s.io/v1", + kind: "MutatingWebhookConfiguration", + metadata: { + name: "pod-policy.example.com", + resourceVersion: "1", + uid: "pod-policy.example.com", + namespace: "default", + selfLink: "/apis/admissionregistration.k8s.io/v1/pod-policy.example.com", + }, + webhooks: [ + { + name: "pod-policy.example.com", + rules: [ + { + apiGroups: ["", "apps", "extensions"], + apiVersions: ["v1", "v1beta1"], + operations: ["CREATE", "UPDATE"], + resources: ["pods", "deployments"], + }, + ], + failurePolicy: "Fail", + admissionReviewVersions: ["v1", "v1beta1"], + sideEffects: "None", + clientConfig: { + service: { + namespace: "service-namespace", + name: "service-name", + }, + caBundle: "Cg==", + }, + }, + ], +}; + +describe("MutatingWebhookConfigsDetails", () => { + let result: RenderResult; + let render: DiRender; + + beforeEach(async () => { + const di = getDiForUnitTesting(); + + render = renderFor(di); + }); + + it("renders", () => { + const webhookConfig = new MutatingWebhookConfiguration(mutatingWebhookConfig); + + result = render( + , + ); + + expect(result.baseElement).toMatchSnapshot(); + }); + + it("renders with no webhooks", () => { + const webhookConfig = new MutatingWebhookConfiguration({ + ...mutatingWebhookConfig, + webhooks: [], + }); + + result = render( + , + ); + + expect(result.baseElement).toMatchSnapshot(); + }); +}); diff --git a/packages/core/src/renderer/components/+config-validating-webhook-configurations/details.test.tsx b/packages/core/src/renderer/components/+config-validating-webhook-configurations/details.test.tsx new file mode 100644 index 0000000000..3ccb7e0725 --- /dev/null +++ b/packages/core/src/renderer/components/+config-validating-webhook-configurations/details.test.tsx @@ -0,0 +1,83 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import type { RenderResult } from "@testing-library/react"; +import React from "react"; +import { + ValidatingWebhookConfiguration, +} from "../../../common/k8s-api/endpoints"; +import { getDiForUnitTesting } from "../../getDiForUnitTesting"; +import type { DiRender } from "../test-utils/renderFor"; +import { renderFor } from "../test-utils/renderFor"; +import { ValidatingWebhookDetails } from "./validating-webhook-configurations-details"; + +const validatingWebhookConfig = { + apiVersion: "admissionregistration.k8s.io/v1", + kind: "ValidatingWebhookConfiguration", + metadata: { + name: "pod-policy.example.com", + resourceVersion: "1", + uid: "pod-policy.example.com", + namespace: "default", + selfLink: "/apis/admissionregistration.k8s.io/v1/pod-policy.example.com", + }, + webhooks: [ + { + name: "pod-policy.example.com", + rules: [ + { + apiGroups: ["", "apps", "extensions"], + apiVersions: ["v1", "v1beta1"], + operations: ["CREATE", "UPDATE"], + resources: ["pods", "deployments"], + }, + ], + failurePolicy: "Fail", + admissionReviewVersions: ["v1", "v1beta1"], + sideEffects: "None", + timeoutSeconds: 5, + clientConfig: { + service: { + namespace: "service-namespace", + name: "service-name", + }, + caBundle: "Cg==", + }, + }, + ], +}; + +describe("ValidatingWebhookConfigsDetails", () => { + let result: RenderResult; + let render: DiRender; + + beforeEach(async () => { + const di = getDiForUnitTesting(); + + render = renderFor(di); + }); + + it("renders", () => { + const webhookConfig = new ValidatingWebhookConfiguration(validatingWebhookConfig); + + result = render( + , + ); + + expect(result.baseElement).toMatchSnapshot(); + }); + + it("renders with no webhooks", () => { + const webhookConfig = new ValidatingWebhookConfiguration({ + ...validatingWebhookConfig, + webhooks: [], + }); + + result = render( + , + ); + + expect(result.baseElement).toMatchSnapshot(); + }); +}); diff --git a/packages/open-lens/integration/__tests__/cluster-pages.tests.ts b/packages/open-lens/integration/__tests__/cluster-pages.tests.ts index c9130c4f59..68e50474c4 100644 --- a/packages/open-lens/integration/__tests__/cluster-pages.tests.ts +++ b/packages/open-lens/integration/__tests__/cluster-pages.tests.ts @@ -366,6 +366,18 @@ const scenarios = [ parentSidebarItemTestId: null, sidebarItemTestId: "sidebar-item-link-for-custom-resources", }, + + { + expectedSelector: "h5.title", + parentSidebarItemTestId: "sidebar-item-link-for-config", + sidebarItemTestId: "sidebar-item-link-for-validating-webhook-configurations", + }, + + { + expectedSelector: "h5.title", + parentSidebarItemTestId: "sidebar-item-link-for-config", + sidebarItemTestId: "sidebar-item-link-for-mutating-webhook-configurations", + }, ]; const navigateToPods = async (frame: Frame) => {