mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce first unit test made possible because of recently demonstrated changes
Key changes were: - Introduction of dependencies as interfaces to permit stubbing in general (Dependency Inversion Principle) - Introduction of segregated interfaces to only require stubbing of minimal stuff (Interface Segregation Principle) Signed-off-by: Janne Savolainen <janne.savolainen@houston-inc.com>
This commit is contained in:
parent
94d3f6b5fb
commit
350f07b457
@ -0,0 +1,18 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`kube-object-menu given no kube object, renders 1`] = `
|
||||||
|
<div>
|
||||||
|
<i
|
||||||
|
class="Icon material interactive focusable"
|
||||||
|
id="menu_actions_1"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="icon"
|
||||||
|
data-icon-name="more_vert"
|
||||||
|
>
|
||||||
|
more_vert
|
||||||
|
</span>
|
||||||
|
</i>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { render } from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
|
import { KubeObjectMenu } from "./kube-object-menu";
|
||||||
|
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||||
|
import type { KubeApi } from "../../../common/k8s-api/kube-api";
|
||||||
|
import type { IHasGettableItemsForKind } from "../../../extensions/registries";
|
||||||
|
import type { IGettableStore } from "../../../common/k8s-api/api-manager";
|
||||||
|
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||||
|
import type { IHasName } from "../../../main/cluster";
|
||||||
|
|
||||||
|
describe("kube-object-menu", () => {
|
||||||
|
let hideDetailsStub: () => void;
|
||||||
|
let editResourceTabStub: () => void;
|
||||||
|
let apiManagerStub: IGettableStore;
|
||||||
|
let clusterStub : IHasName;
|
||||||
|
let kubeObjectMenuRegistryStub: IHasGettableItemsForKind;
|
||||||
|
let objectStub: any;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// TODO: Remove illegal global overwrites for what should be a dependency somewhere.
|
||||||
|
window.requestIdleCallback = () => 42;
|
||||||
|
|
||||||
|
window.cancelIdleCallback = () => {};
|
||||||
|
|
||||||
|
apiManagerStub = {
|
||||||
|
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||||
|
getStore: <TKubeObjectStore extends KubeObjectStore<KubeObject>>(api: string | KubeApi<KubeObject>): TKubeObjectStore | undefined => undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
clusterStub = { name: "Some cluster name" };
|
||||||
|
|
||||||
|
kubeObjectMenuRegistryStub = {
|
||||||
|
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||||
|
getItemsForKind: (kind: string, apiVersion: string): any => undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
hideDetailsStub = () => {};
|
||||||
|
|
||||||
|
editResourceTabStub = () => {};
|
||||||
|
});
|
||||||
|
|
||||||
|
it("given no kube object, renders", () => {
|
||||||
|
objectStub = null;
|
||||||
|
|
||||||
|
const { container } = render(<KubeObjectMenu object={objectStub}
|
||||||
|
apiManager={apiManagerStub}
|
||||||
|
cluster={clusterStub}
|
||||||
|
kubeObjectMenuRegistry={kubeObjectMenuRegistryStub}
|
||||||
|
hideDetails={hideDetailsStub}
|
||||||
|
editResourceTab={editResourceTabStub}
|
||||||
|
/>);
|
||||||
|
|
||||||
|
expect(container).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user