mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix unit tests
- Remove prettier as snapShot testing is too tight of a bound Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
599a517ddd
commit
99eac44479
@ -357,7 +357,6 @@
|
|||||||
"postcss": "^8.3.6",
|
"postcss": "^8.3.6",
|
||||||
"postcss-loader": "4.3.0",
|
"postcss-loader": "4.3.0",
|
||||||
"postinstall-postinstall": "^2.1.0",
|
"postinstall-postinstall": "^2.1.0",
|
||||||
"prettier": "^2.4.1",
|
|
||||||
"progress-bar-webpack-plugin": "^2.1.0",
|
"progress-bar-webpack-plugin": "^2.1.0",
|
||||||
"randomcolor": "^0.6.2",
|
"randomcolor": "^0.6.2",
|
||||||
"raw-loader": "^4.0.2",
|
"raw-loader": "^4.0.2",
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import { Catalog } from "./catalog";
|
|||||||
import { createMemoryHistory } from "history";
|
import { createMemoryHistory } from "history";
|
||||||
import { mockWindow } from "../../../../__mocks__/windowMock";
|
import { mockWindow } from "../../../../__mocks__/windowMock";
|
||||||
import { kubernetesClusterCategory } from "../../../common/catalog-entities/kubernetes-cluster";
|
import { kubernetesClusterCategory } from "../../../common/catalog-entities/kubernetes-cluster";
|
||||||
import { catalogCategoryRegistry, CatalogCategoryRegistry } from "../../../common/catalog";
|
import { catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntity, CatalogEntityActionContext, CatalogEntityData } from "../../../common/catalog";
|
||||||
import { CatalogEntityRegistry } from "../../../renderer/api/catalog-entity-registry";
|
import { CatalogEntityRegistry } from "../../../renderer/api/catalog-entity-registry";
|
||||||
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
||||||
import { CatalogEntityItem } from "./catalog-entity-item";
|
import { CatalogEntityItem } from "./catalog-entity-item";
|
||||||
@ -46,6 +46,18 @@ jest.mock("@electron/remote", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
class MockCatalogEntity extends CatalogEntity {
|
||||||
|
public apiVersion = "api";
|
||||||
|
public kind = "kind";
|
||||||
|
|
||||||
|
constructor(data: CatalogEntityData, public onRun: (context: CatalogEntityActionContext) => void | Promise<void>) {
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onContextMenuOpen(): void | Promise<void> {}
|
||||||
|
public onSettingsOpen(): void | Promise<void> {}
|
||||||
|
}
|
||||||
|
|
||||||
describe("<Catalog />", () => {
|
describe("<Catalog />", () => {
|
||||||
const history = createMemoryHistory();
|
const history = createMemoryHistory();
|
||||||
const mockLocation = {
|
const mockLocation = {
|
||||||
@ -66,13 +78,10 @@ describe("<Catalog />", () => {
|
|||||||
url: "",
|
url: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const catalogEntityUid = "a_catalogEntity_uid";
|
function createMockCatalogEntity(onRun: (context: CatalogEntityActionContext) => void | Promise<void>) {
|
||||||
const catalogEntity = {
|
return new MockCatalogEntity({
|
||||||
enabled: true,
|
|
||||||
apiVersion: "api",
|
|
||||||
kind: "kind",
|
|
||||||
metadata: {
|
metadata: {
|
||||||
uid: catalogEntityUid,
|
uid: "a_catalogEntity_uid",
|
||||||
name: "a catalog entity",
|
name: "a catalog entity",
|
||||||
labels: {
|
labels: {
|
||||||
test: "label",
|
test: "label",
|
||||||
@ -82,14 +91,8 @@ describe("<Catalog />", () => {
|
|||||||
phase: "",
|
phase: "",
|
||||||
},
|
},
|
||||||
spec: {},
|
spec: {},
|
||||||
};
|
}, onRun);
|
||||||
const catalogEntityItemMethods = {
|
}
|
||||||
getId: () => catalogEntity.metadata.uid,
|
|
||||||
getName: () => catalogEntity.metadata.name,
|
|
||||||
onContextMenuOpen: () => {},
|
|
||||||
onSettingsOpen: () => {},
|
|
||||||
onRun: () => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
CatalogEntityDetailRegistry.createInstance();
|
CatalogEntityDetailRegistry.createInstance();
|
||||||
@ -117,11 +120,7 @@ describe("<Catalog />", () => {
|
|||||||
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||||
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
||||||
const onRun = jest.fn();
|
const onRun = jest.fn();
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem(createMockCatalogEntity(onRun), catalogEntityRegistry);
|
||||||
...catalogEntity,
|
|
||||||
...catalogEntityItemMethods,
|
|
||||||
onRun,
|
|
||||||
}, catalogEntityRegistry);
|
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
@ -130,29 +129,8 @@ describe("<Catalog />", () => {
|
|||||||
|
|
||||||
catalogEntityRegistry.addOnBeforeRun(
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
(event) => {
|
(event) => {
|
||||||
expect(event.target).toMatchInlineSnapshot(`
|
expect(event.target.getId()).toBe("a_catalogEntity_uid");
|
||||||
Object {
|
expect(event.target.getName()).toBe("a catalog entity");
|
||||||
"apiVersion": "api",
|
|
||||||
"enabled": true,
|
|
||||||
"getId": [Function],
|
|
||||||
"getName": [Function],
|
|
||||||
"kind": "kind",
|
|
||||||
"metadata": Object {
|
|
||||||
"labels": Object {
|
|
||||||
"test": "label",
|
|
||||||
},
|
|
||||||
"name": "a catalog entity",
|
|
||||||
"uid": "a_catalogEntity_uid",
|
|
||||||
},
|
|
||||||
"onContextMenuOpen": [Function],
|
|
||||||
"onRun": [MockFunction],
|
|
||||||
"onSettingsOpen": [Function],
|
|
||||||
"spec": Object {},
|
|
||||||
"status": Object {
|
|
||||||
"phase": "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(onRun).toHaveBeenCalled();
|
expect(onRun).toHaveBeenCalled();
|
||||||
@ -178,11 +156,7 @@ describe("<Catalog />", () => {
|
|||||||
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||||
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
||||||
const onRun = jest.fn();
|
const onRun = jest.fn();
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem(createMockCatalogEntity(onRun), catalogEntityRegistry);
|
||||||
...catalogEntity,
|
|
||||||
...catalogEntityItemMethods,
|
|
||||||
onRun,
|
|
||||||
}, catalogEntityRegistry);
|
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
@ -216,11 +190,7 @@ describe("<Catalog />", () => {
|
|||||||
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||||
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
||||||
const onRun = jest.fn();
|
const onRun = jest.fn();
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem(createMockCatalogEntity(onRun), catalogEntityRegistry);
|
||||||
...catalogEntity,
|
|
||||||
...catalogEntityItemMethods,
|
|
||||||
onRun,
|
|
||||||
}, catalogEntityRegistry);
|
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
@ -255,11 +225,7 @@ describe("<Catalog />", () => {
|
|||||||
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||||
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
||||||
const onRun = jest.fn(() => done());
|
const onRun = jest.fn(() => done());
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem(createMockCatalogEntity(onRun), catalogEntityRegistry);
|
||||||
...catalogEntity,
|
|
||||||
...catalogEntityItemMethods,
|
|
||||||
onRun,
|
|
||||||
}, catalogEntityRegistry);
|
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
@ -289,11 +255,7 @@ describe("<Catalog />", () => {
|
|||||||
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||||
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
||||||
const onRun = jest.fn();
|
const onRun = jest.fn();
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem(createMockCatalogEntity(onRun), catalogEntityRegistry);
|
||||||
...catalogEntity,
|
|
||||||
...catalogEntityItemMethods,
|
|
||||||
onRun,
|
|
||||||
}, catalogEntityRegistry);
|
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
@ -330,11 +292,7 @@ describe("<Catalog />", () => {
|
|||||||
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||||
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
|
||||||
const onRun = jest.fn();
|
const onRun = jest.fn();
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem(createMockCatalogEntity(onRun), catalogEntityRegistry);
|
||||||
...catalogEntity,
|
|
||||||
...catalogEntityItemMethods,
|
|
||||||
onRun,
|
|
||||||
}, catalogEntityRegistry);
|
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
|
|||||||
@ -11220,11 +11220,6 @@ prepend-http@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
|
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
|
||||||
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
|
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
|
||||||
|
|
||||||
prettier@^2.4.1:
|
|
||||||
version "2.4.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.1.tgz#671e11c89c14a4cfc876ce564106c4a6726c9f5c"
|
|
||||||
integrity sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==
|
|
||||||
|
|
||||||
pretty-error@^2.1.1:
|
pretty-error@^2.1.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3"
|
resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user