From d2c70519e2ed5b538108d4035c2c61e3bc3afb4b Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 21 Jan 2022 11:00:12 -0500 Subject: [PATCH] Add some tests Signed-off-by: Sebastian Malton --- .../+catalog/__tests__/custom-views.test.ts | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/renderer/components/+catalog/__tests__/custom-views.test.ts diff --git a/src/renderer/components/+catalog/__tests__/custom-views.test.ts b/src/renderer/components/+catalog/__tests__/custom-views.test.ts new file mode 100644 index 0000000000..af2dad0f55 --- /dev/null +++ b/src/renderer/components/+catalog/__tests__/custom-views.test.ts @@ -0,0 +1,96 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable"; +import { computed } from "mobx"; +import type React from "react"; +import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension"; +import rendererExtensionsInjectable from "../../../../extensions/renderer-extensions.injectable"; +import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; +import type { CustomCategoryViewRegistration } from "../custom-views"; +import customCategoryViewsInjectable from "../custom-views.injectable"; + +describe("Custom Category Views", () => { + let di: ConfigurableDependencyInjectionContainer; + + beforeEach(() => { + di = getDiForUnitTesting(); + }); + + it("should order items correctly over all extensions", () => { + const component1 = (): React.ReactElement => null; + const component2 = (): React.ReactElement => null; + + di.override(rendererExtensionsInjectable, () => computed(() => [ + { + customCategoryViews: [ + { + components: { + View: component1, + }, + group: "foo", + kind: "bar", + priority: 100, + } as CustomCategoryViewRegistration, + ], + }, + { + customCategoryViews: [ + { + components: { + View: component2, + }, + group: "foo", + kind: "bar", + priority: 95, + } as CustomCategoryViewRegistration, + ], + }, + ] as LensRendererExtension[])); + + const customCategoryViews = di.inject(customCategoryViewsInjectable); + const { after } = customCategoryViews.get().get("foo").get("bar"); + + expect(after[0].View).toBe(component2); + expect(after[1].View).toBe(component1); + }); + + it("should put put priority < 50 items in before", () => { + const component1 = (): React.ReactElement => null; + const component2 = (): React.ReactElement => null; + + di.override(rendererExtensionsInjectable, () => computed(() => [ + { + customCategoryViews: [ + { + components: { + View: component1, + }, + group: "foo", + kind: "bar", + priority: 40, + } as CustomCategoryViewRegistration, + ], + }, + { + customCategoryViews: [ + { + components: { + View: component2, + }, + group: "foo", + kind: "bar", + priority: 95, + } as CustomCategoryViewRegistration, + ], + }, + ] as LensRendererExtension[])); + + const customCategoryViews = di.inject(customCategoryViewsInjectable); + const { before } = customCategoryViews.get().get("foo").get("bar"); + + expect(before[0].View).toBe(component1); + }); +});