mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix unit tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
911e2d1bc4
commit
dd40bfee99
@ -3,12 +3,12 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { appEventBus } from "./event-bus";
|
import { EventEmitter } from "../event-emitter";
|
||||||
|
import type { AppEvent } from "./event-bus";
|
||||||
|
|
||||||
const appEventBusInjectable = getInjectable({
|
const appEventBusInjectable = getInjectable({
|
||||||
id: "app-event-bus",
|
id: "app-event-bus",
|
||||||
instantiate: () => appEventBus,
|
instantiate: () => new EventEmitter<[AppEvent]>(),
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default appEventBusInjectable;
|
export default appEventBusInjectable;
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { EventEmitter } from "../event-emitter";
|
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||||
|
import appEventBusInjectable from "./app-event-bus.injectable";
|
||||||
|
|
||||||
export interface AppEvent {
|
export interface AppEvent {
|
||||||
name: string;
|
name: string;
|
||||||
@ -12,4 +13,7 @@ export interface AppEvent {
|
|||||||
params?: Record<string, any>;
|
params?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const appEventBus = new EventEmitter<[AppEvent]>();
|
/**
|
||||||
|
* @deprecated Switch to using appEventBusInjectable instead
|
||||||
|
*/
|
||||||
|
export const appEventBus = asLegacyGlobalForExtensionApi(appEventBusInjectable);
|
||||||
|
|||||||
@ -3,5 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { appEventBus } from "../../common/app-event-bus/event-bus";
|
import { appEventBus as bus } from "../../common/app-event-bus/event-bus";
|
||||||
export type { AppEvent } from "../../common/app-event-bus/event-bus";
|
export type { AppEvent } from "../../common/app-event-bus/event-bus";
|
||||||
|
|
||||||
|
export const appEventBus = bus;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ exports[`cluster connection status renders 1`] = `
|
|||||||
style="width: 320px;"
|
style="width: 320px;"
|
||||||
>
|
>
|
||||||
<h2>
|
<h2>
|
||||||
Welcome to OpenLens 5!
|
Welcome to OpenLens!
|
||||||
</h2>
|
</h2>
|
||||||
<p>
|
<p>
|
||||||
To get you started we have auto-detected your clusters in your
|
To get you started we have auto-detected your clusters in your
|
||||||
|
|||||||
@ -18,6 +18,8 @@ import createKubectlInjectable from "../../main/kubectl/create-kubectl.injectabl
|
|||||||
import type { KubeconfigManager } from "../../main/kubeconfig-manager/kubeconfig-manager";
|
import type { KubeconfigManager } from "../../main/kubeconfig-manager/kubeconfig-manager";
|
||||||
import type { Kubectl } from "../../main/kubectl/kubectl";
|
import type { Kubectl } from "../../main/kubectl/kubectl";
|
||||||
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
||||||
|
import catalogEntityRegistryInjectable from "../../renderer/api/catalog/entity/registry.injectable";
|
||||||
|
import { KubernetesCluster } from "../../common/catalog-entities";
|
||||||
|
|
||||||
describe("cluster connection status", () => {
|
describe("cluster connection status", () => {
|
||||||
let clusterStore: ClusterStore;
|
let clusterStore: ClusterStore;
|
||||||
@ -40,6 +42,37 @@ describe("cluster connection status", () => {
|
|||||||
|
|
||||||
const createCluster = applicationBuilder.dis.mainDi.inject(createClusterInjectable);
|
const createCluster = applicationBuilder.dis.mainDi.inject(createClusterInjectable);
|
||||||
|
|
||||||
|
applicationBuilder.dis.rendererDi.inject(catalogEntityRegistryInjectable).updateItems([
|
||||||
|
new KubernetesCluster({
|
||||||
|
metadata: {
|
||||||
|
labels: {},
|
||||||
|
name: "minikube",
|
||||||
|
uid: "some-cluster-id",
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
kubeconfigContext: "minikube",
|
||||||
|
kubeconfigPath: "/some/file/path",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "disconnected",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new KubernetesCluster({
|
||||||
|
metadata: {
|
||||||
|
labels: {},
|
||||||
|
name: "minikube-2",
|
||||||
|
uid: "some-cluster-id-2",
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
kubeconfigContext: "minikube-2",
|
||||||
|
kubeconfigPath: "/some/file/path",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "disconnected",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
cluster = createCluster({
|
cluster = createCluster({
|
||||||
contextName: "minikube",
|
contextName: "minikube",
|
||||||
id: "some-cluster-id",
|
id: "some-cluster-id",
|
||||||
|
|||||||
@ -3,9 +3,5 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import catalogCategoryRegistryInjectable from "../../common/catalog/category-registry.injectable";
|
|
||||||
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
|
||||||
|
|
||||||
export type { CategoryFilter } from "../../common/catalog";
|
export type { CategoryFilter } from "../../common/catalog";
|
||||||
|
|
||||||
export const catalogCategoryRegistry = asLegacyGlobalForExtensionApi(catalogCategoryRegistryInjectable);
|
|
||||||
|
|||||||
@ -13,7 +13,9 @@ import { autoBind } from "../../../common/utils";
|
|||||||
import type { CatalogCategory, CatalogEntityAddMenuContext, CatalogEntityAddMenu } from "../../api/catalog-entity";
|
import type { CatalogCategory, CatalogEntityAddMenuContext, CatalogEntityAddMenu } from "../../api/catalog-entity";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
import { catalogCategoryRegistry } from "../../api/catalog-category-registry";
|
import type { CatalogCategoryRegistry } from "../../../common/catalog";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import catalogCategoryRegistryInjectable from "../../../common/catalog/category-registry.injectable";
|
||||||
|
|
||||||
export interface CatalogAddButtonProps {
|
export interface CatalogAddButtonProps {
|
||||||
category: CatalogCategory;
|
category: CatalogCategory;
|
||||||
@ -21,12 +23,16 @@ export interface CatalogAddButtonProps {
|
|||||||
|
|
||||||
type CategoryId = string;
|
type CategoryId = string;
|
||||||
|
|
||||||
|
interface Dependencies {
|
||||||
|
catalogCategoryRegistry: CatalogCategoryRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
|
class NonInjectedCatalogAddButton extends React.Component<CatalogAddButtonProps & Dependencies> {
|
||||||
@observable protected isOpen = false;
|
@observable protected isOpen = false;
|
||||||
@observable menuItems = new Map<CategoryId, CatalogEntityAddMenu[]>();
|
@observable menuItems = new Map<CategoryId, CatalogEntityAddMenu[]>();
|
||||||
|
|
||||||
constructor(props: CatalogAddButtonProps) {
|
constructor(props: CatalogAddButtonProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
autoBind(this);
|
autoBind(this);
|
||||||
@ -43,7 +49,7 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get categories() {
|
get categories() {
|
||||||
return catalogCategoryRegistry.filteredItems;
|
return this.props.catalogCategoryRegistry.filteredItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@ -133,3 +139,10 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const CatalogAddButton = withInjectables<Dependencies, CatalogAddButtonProps>(NonInjectedCatalogAddButton, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
catalogCategoryRegistry: di.inject(catalogCategoryRegistryInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
@ -9,23 +9,21 @@ import styles from "./catalog-menu.module.scss";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import type { TreeItemProps } from "@material-ui/lab";
|
import type { TreeItemProps } from "@material-ui/lab";
|
||||||
import { TreeItem, TreeView } from "@material-ui/lab";
|
import { TreeItem, TreeView } from "@material-ui/lab";
|
||||||
import { catalogCategoryRegistry } from "../../api/catalog-category-registry";
|
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { StylesProvider } from "@material-ui/core";
|
import { StylesProvider } from "@material-ui/core";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
import type { CatalogCategory } from "../../api/catalog-entity";
|
import type { CatalogCategory } from "../../api/catalog-entity";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { CatalogCategoryLabel } from "./catalog-category-label";
|
import { CatalogCategoryLabel } from "./catalog-category-label";
|
||||||
|
import type { CatalogCategoryRegistry } from "../../../common/catalog";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import catalogCategoryRegistryInjectable from "../../../common/catalog/category-registry.injectable";
|
||||||
|
|
||||||
export interface CatalogMenuProps {
|
export interface CatalogMenuProps {
|
||||||
activeTab: string | undefined;
|
activeTab: string | undefined;
|
||||||
onItemClick: (id: string) => void;
|
onItemClick: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCategories() {
|
|
||||||
return catalogCategoryRegistry.filteredItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCategoryIcon(category: CatalogCategory) {
|
function getCategoryIcon(category: CatalogCategory) {
|
||||||
const { icon } = category.metadata ?? {};
|
const { icon } = category.metadata ?? {};
|
||||||
|
|
||||||
@ -44,7 +42,15 @@ function Item(props: TreeItemProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CatalogMenu = observer((props: CatalogMenuProps) => {
|
interface Dependencies {
|
||||||
|
catalogCategoryRegistry: CatalogCategoryRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NonInjectedCatalogMenu = observer(({
|
||||||
|
activeTab = "browse",
|
||||||
|
onItemClick,
|
||||||
|
catalogCategoryRegistry,
|
||||||
|
}: CatalogMenuProps & Dependencies) => {
|
||||||
return (
|
return (
|
||||||
// Overwrite Material UI styles with injectFirst https://material-ui.com/guides/interoperability/#controlling-priority-4
|
// Overwrite Material UI styles with injectFirst https://material-ui.com/guides/interoperability/#controlling-priority-4
|
||||||
<StylesProvider injectFirst>
|
<StylesProvider injectFirst>
|
||||||
@ -54,13 +60,13 @@ export const CatalogMenu = observer((props: CatalogMenuProps) => {
|
|||||||
defaultExpanded={["catalog"]}
|
defaultExpanded={["catalog"]}
|
||||||
defaultCollapseIcon={<Icon material="expand_more"/>}
|
defaultCollapseIcon={<Icon material="expand_more"/>}
|
||||||
defaultExpandIcon={<Icon material="chevron_right" />}
|
defaultExpandIcon={<Icon material="chevron_right" />}
|
||||||
selected={props.activeTab || "browse"}
|
selected={activeTab}
|
||||||
>
|
>
|
||||||
<Item
|
<Item
|
||||||
nodeId="browse"
|
nodeId="browse"
|
||||||
label="Browse"
|
label="Browse"
|
||||||
data-testid="*-tab"
|
data-testid="*-tab"
|
||||||
onClick={() => props.onItemClick("*")}
|
onClick={() => onItemClick("*")}
|
||||||
/>
|
/>
|
||||||
<Item
|
<Item
|
||||||
nodeId="catalog"
|
nodeId="catalog"
|
||||||
@ -68,14 +74,14 @@ export const CatalogMenu = observer((props: CatalogMenuProps) => {
|
|||||||
className={cssNames(styles.bordered)}
|
className={cssNames(styles.bordered)}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
getCategories().map(category => (
|
catalogCategoryRegistry.filteredItems.map(category => (
|
||||||
<Item
|
<Item
|
||||||
icon={getCategoryIcon(category)}
|
icon={getCategoryIcon(category)}
|
||||||
key={category.getId()}
|
key={category.getId()}
|
||||||
nodeId={category.getId()}
|
nodeId={category.getId()}
|
||||||
label={<CatalogCategoryLabel category={category}/>}
|
label={<CatalogCategoryLabel category={category}/>}
|
||||||
data-testid={`${category.getId()}-tab`}
|
data-testid={`${category.getId()}-tab`}
|
||||||
onClick={() => props.onItemClick(category.getId())}
|
onClick={() => onItemClick(category.getId())}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -85,3 +91,10 @@ export const CatalogMenu = observer((props: CatalogMenuProps) => {
|
|||||||
</StylesProvider>
|
</StylesProvider>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const CatalogMenu = withInjectables<Dependencies, CatalogMenuProps>(NonInjectedCatalogMenu, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
catalogCategoryRegistry: di.inject(catalogCategoryRegistryInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
@ -5,12 +5,11 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import "../../common/catalog-entities/kubernetes-cluster";
|
|
||||||
import { ClusterStore } from "../../common/cluster-store/cluster-store";
|
import { ClusterStore } from "../../common/cluster-store/cluster-store";
|
||||||
import { catalogCategoryRegistry } from "../api/catalog-category-registry";
|
|
||||||
import { WeblinkAddCommand } from "../components/catalog-entities/weblink-add-command";
|
import { WeblinkAddCommand } from "../components/catalog-entities/weblink-add-command";
|
||||||
import { loadConfigFromString } from "../../common/kube-helpers";
|
import { loadConfigFromString } from "../../common/kube-helpers";
|
||||||
import type { OpenDeleteClusterDialog } from "../components/delete-cluster-dialog/open.injectable";
|
import type { OpenDeleteClusterDialog } from "../components/delete-cluster-dialog/open.injectable";
|
||||||
|
import type { CatalogCategoryRegistry } from "../../common/catalog";
|
||||||
|
|
||||||
async function onClusterDelete(clusterId: string, openDeleteClusterDialog: OpenDeleteClusterDialog) {
|
async function onClusterDelete(clusterId: string, openDeleteClusterDialog: OpenDeleteClusterDialog) {
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
@ -31,9 +30,14 @@ async function onClusterDelete(clusterId: string, openDeleteClusterDialog: OpenD
|
|||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
openCommandDialog: (component: React.ReactElement) => void;
|
openCommandDialog: (component: React.ReactElement) => void;
|
||||||
openDeleteClusterDialog: OpenDeleteClusterDialog;
|
openDeleteClusterDialog: OpenDeleteClusterDialog;
|
||||||
|
catalogCategoryRegistry: CatalogCategoryRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initCatalog({ openCommandDialog, openDeleteClusterDialog }: Dependencies) {
|
export function initCatalog({
|
||||||
|
openCommandDialog,
|
||||||
|
openDeleteClusterDialog,
|
||||||
|
catalogCategoryRegistry,
|
||||||
|
}: Dependencies) {
|
||||||
catalogCategoryRegistry
|
catalogCategoryRegistry
|
||||||
.getForGroupKind("entity.k8slens.dev", "WebLink")
|
.getForGroupKind("entity.k8slens.dev", "WebLink")
|
||||||
?.on("catalogAddMenu", ctx => {
|
?.on("catalogAddMenu", ctx => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user