1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix log-resource-selector.test.tsx tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-04-08 09:29:18 -04:00
parent 383a50cdbf
commit 35e49fe6e6
11 changed files with 40 additions and 45 deletions

View File

@ -319,7 +319,6 @@
"@types/react-beautiful-dnd": "^13.1.2", "@types/react-beautiful-dnd": "^13.1.2",
"@types/react-dom": "^17.0.14", "@types/react-dom": "^17.0.14",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"@types/react-select": "3.1.2",
"@types/react-table": "^7.7.11", "@types/react-table": "^7.7.11",
"@types/react-virtualized-auto-sizer": "^1.0.1", "@types/react-virtualized-auto-sizer": "^1.0.1",
"@types/react-window": "^1.8.5", "@types/react-window": "^1.8.5",

View File

@ -6,7 +6,7 @@
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api"; import { metricsApi } from "./metrics.api";
import type { IPodContainer, PodMetricData, PodSpec } from "./pods.api"; import type { PodContainer, PodMetricData, PodSpec } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object"; import type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
@ -24,7 +24,7 @@ export interface JobSpec {
}; };
spec: PodSpec; spec: PodSpec;
}; };
containers?: IPodContainer[]; containers?: PodContainer[];
restartPolicy?: string; restartPolicy?: string;
terminationGracePeriodSeconds?: number; terminationGracePeriodSeconds?: number;
dnsPolicy?: string; dnsPolicy?: string;

View File

@ -101,7 +101,7 @@ export interface VolumeMount {
subPathExpr?: string; subPathExpr?: string;
} }
export interface IPodContainer extends Partial<Record<PodContainerProbe, IContainerProbe>> { export interface PodContainer extends Partial<Record<PodContainerProbe, IContainerProbe>> {
name: string; name: string;
image: string; image: string;
command?: string[]; command?: string[];
@ -702,7 +702,7 @@ export interface PodSpec {
activeDeadlineSeconds?: number; activeDeadlineSeconds?: number;
affinity?: Affinity; affinity?: Affinity;
automountServiceAccountToken?: boolean; automountServiceAccountToken?: boolean;
containers?: IPodContainer[]; containers?: PodContainer[];
dnsPolicy?: string; dnsPolicy?: string;
enableServiceLinks?: boolean; enableServiceLinks?: boolean;
ephemeralContainers?: unknown[]; ephemeralContainers?: unknown[];
@ -712,7 +712,7 @@ export interface PodSpec {
hostNetwork?: boolean; hostNetwork?: boolean;
hostPID?: boolean; hostPID?: boolean;
imagePullSecrets?: LocalObjectReference[]; imagePullSecrets?: LocalObjectReference[];
initContainers?: IPodContainer[]; initContainers?: PodContainer[];
nodeName?: string; nodeName?: string;
nodeSelector?: Record<string, string | undefined>; nodeSelector?: Record<string, string | undefined>;
overhead?: Record<string, string | undefined>; overhead?: Record<string, string | undefined>;
@ -906,19 +906,19 @@ export class Pod extends KubeObject<PodStatus, PodSpec, KubeObjectScope.Namespac
return this.getStatusPhase() !== "Running"; return this.getStatusPhase() !== "Running";
} }
getLivenessProbe(container: IPodContainer) { getLivenessProbe(container: PodContainer) {
return this.getProbe(container, "livenessProbe"); return this.getProbe(container, "livenessProbe");
} }
getReadinessProbe(container: IPodContainer) { getReadinessProbe(container: PodContainer) {
return this.getProbe(container, "readinessProbe"); return this.getProbe(container, "readinessProbe");
} }
getStartupProbe(container: IPodContainer) { getStartupProbe(container: PodContainer) {
return this.getProbe(container, "startupProbe"); return this.getProbe(container, "startupProbe");
} }
private getProbe(container: IPodContainer, field: PodContainerProbe): string[] { private getProbe(container: PodContainer, field: PodContainerProbe): string[] {
const probe: string[] = []; const probe: string[] = [];
const probeData = container[field]; const probeData = container[field];

View File

@ -48,7 +48,7 @@ export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints
// types // types
export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api"; export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api";
export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api"; export type { PodContainer as IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api";
export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints/secret.api"; export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints/secret.api";
export type { KubeObjectMetadata, KubeJsonApiObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object"; export type { KubeObjectMetadata, KubeJsonApiObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
export type { KubeObjectStoreLoadAllParams, KubeObjectStoreLoadingParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store"; export type { KubeObjectStoreLoadAllParams, KubeObjectStoreLoadingParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";

View File

@ -63,7 +63,7 @@ export { KubeJsonApi } from "../../common/k8s-api/kube-json-api";
// types // types
export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api"; export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api";
export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints"; export type { PodContainer as IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints";
export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints"; export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints";
export type { KubeObjectStatus } from "./kube-object-status"; export type { KubeObjectStatus } from "./kube-object-status";
export type { KubeJsonApiObjectMetadata as KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object"; export type { KubeJsonApiObjectMetadata as KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";

View File

@ -7,7 +7,7 @@ import "./pod-container-env.scss";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { IPodContainer, Secret } from "../../../common/k8s-api/endpoints"; import type { PodContainer, Secret } from "../../../common/k8s-api/endpoints";
import { DrawerItem } from "../drawer"; import { DrawerItem } from "../drawer";
import { autorun } from "mobx"; import { autorun } from "mobx";
import { secretStore } from "../+config-secrets/secrets.store"; import { secretStore } from "../+config-secrets/secrets.store";
@ -17,7 +17,7 @@ import { base64, cssNames, iter } from "../../utils";
import _ from "lodash"; import _ from "lodash";
export interface ContainerEnvironmentProps { export interface ContainerEnvironmentProps {
container: IPodContainer; container: PodContainer;
namespace: string; namespace: string;
} }

View File

@ -6,7 +6,7 @@
import "./pod-details-container.scss"; import "./pod-details-container.scss";
import React from "react"; import React from "react";
import type { IPodContainer, IPodContainerStatus, Pod } from "../../../common/k8s-api/endpoints"; import type { PodContainer, IPodContainerStatus, Pod } from "../../../common/k8s-api/endpoints";
import { DrawerItem } from "../drawer"; import { DrawerItem } from "../drawer";
import { cssNames, isDefined } from "../../utils"; import { cssNames, isDefined } from "../../utils";
import { StatusBrick } from "../status-brick"; import { StatusBrick } from "../status-brick";
@ -26,7 +26,7 @@ import portForwardStoreInjectable from "../../port-forward/port-forward-store/po
export interface PodDetailsContainerProps { export interface PodDetailsContainerProps {
pod: Pod; pod: Pod;
container: IPodContainer; container: PodContainer;
metrics?: Partial<Record<string, MetricData>>; metrics?: Partial<Record<string, MetricData>>;
} }

View File

@ -155,7 +155,7 @@ describe("<LogResourceSelector />", () => {
mockFs.restore(); mockFs.restore();
}); });
describe.only("with one pod", () => { describe("with one pod", () => {
let model: LogTabViewModel; let model: LogTabViewModel;
beforeEach(() => { beforeEach(() => {
@ -175,7 +175,7 @@ describe("<LogResourceSelector />", () => {
expect(ns).toHaveTextContent("default"); expect(ns).toHaveTextContent("default");
}); });
it.only("renders proper selected items within dropdowns", async () => { it("renders proper selected items within dropdowns", async () => {
const { findByText } = render(<LogResourceSelector model={model} />); const { findByText } = render(<LogResourceSelector model={model} />);
expect(await findByText("dockerExporter")).toBeInTheDocument(); expect(await findByText("dockerExporter")).toBeInTheDocument();
@ -185,9 +185,11 @@ describe("<LogResourceSelector />", () => {
describe("with several pods", () => { describe("with several pods", () => {
let model: LogTabViewModel; let model: LogTabViewModel;
let renameTab: jest.MockedFunction<LogTabViewModelDependencies["renameTab"]>;
beforeEach(() => { beforeEach(() => {
model = getFewPodsTabData("foobar"); renameTab = jest.fn();
model = getFewPodsTabData("foobar", { renameTab });
}); });
it("renders sibling pods in dropdown", async () => { it("renders sibling pods in dropdown", async () => {
@ -223,7 +225,6 @@ describe("<LogResourceSelector />", () => {
}); });
it("updates tab name if selected pod changes", async () => { it("updates tab name if selected pod changes", async () => {
const renameTab = jest.fn();
const { findByText, container } = render(<LogResourceSelector model={model} />); const { findByText, container } = render(<LogResourceSelector model={model} />);
const selector = container.querySelector<HTMLElement>(".pod-selector"); const selector = container.querySelector<HTMLElement>(".pod-selector");

View File

@ -3,13 +3,13 @@
* 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 type { IPodContainer, Pod } from "../../../../common/k8s-api/endpoints"; import type { PodContainer, Pod } from "../../../../common/k8s-api/endpoints";
import type { TabId } from "../dock/store"; import type { TabId } from "../dock/store";
import createLogsTabInjectable from "./create-logs-tab.injectable"; import createLogsTabInjectable from "./create-logs-tab.injectable";
export interface PodLogsTabData { export interface PodLogsTabData {
selectedPod: Pod; selectedPod: Pod;
selectedContainer: IPodContainer; selectedContainer: PodContainer;
} }
const createPodLogsTabInjectable = getInjectable({ const createPodLogsTabInjectable = getInjectable({

View File

@ -11,7 +11,7 @@ import { observer } from "mobx-react";
import { Badge } from "../../badge"; import { Badge } from "../../badge";
import { Select } from "../../select"; import { Select } from "../../select";
import type { LogTabViewModel } from "./logs-view-model"; import type { LogTabViewModel } from "./logs-view-model";
import type { Pod } from "../../../../common/k8s-api/endpoints"; import type { PodContainer, Pod } from "../../../../common/k8s-api/endpoints";
import type { GroupBase } from "react-select"; import type { GroupBase } from "react-select";
export interface LogResourceSelectorProps { export interface LogResourceSelectorProps {
@ -33,13 +33,15 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
return null; return null;
} }
const onContainerChange = (container: string | null) => { const allContainers = pod.getAllContainers();
const container = allContainers.find(container => container.name === selectedContainer) ?? null;
const onContainerChange = (container: PodContainer | null) => {
if (!container) { if (!container) {
return; return;
} }
model.updateLogTabData({ model.updateLogTabData({
selectedContainer: container, selectedContainer: container.name,
}); });
model.reloadLogs(); model.reloadLogs();
}; };
@ -60,11 +62,11 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
const containerSelectOptions = [ const containerSelectOptions = [
{ {
label: "Containers", label: "Containers",
options: pod.getContainers().map(container => container.name), options: pod.getContainers(),
}, },
{ {
label: "Init Containers", label: "Init Containers",
options: pod.getInitContainers().map(container => container.name), options: pod.getInitContainers(),
}, },
]; ];
@ -93,13 +95,15 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
menuClass="pod-selector-menu" menuClass="pod-selector-menu"
/> />
<span>Container</span> <span>Container</span>
<Select<string, false, GroupBase<string>> <Select<PodContainer, false, GroupBase<PodContainer>>
id="container-selector-input" id="container-selector-input"
options={containerSelectOptions} options={containerSelectOptions}
value={selectedContainer} value={container}
onChange={onContainerChange} onChange={onContainerChange}
getOptionLabel={opt => opt.name}
className="container-selector" className="container-selector"
menuClass="container-selector-menu" menuClass="container-selector-menu"
controlShouldRenderValue
/> />
</div> </div>
); );

View File

@ -1843,15 +1843,6 @@
"@types/history" "*" "@types/history" "*"
"@types/react" "*" "@types/react" "*"
"@types/react-select@3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@types/react-select/-/react-select-3.1.2.tgz#38627df4b49be9b28f800ed72b35d830369a624b"
integrity sha512-ygvR/2FL87R2OLObEWFootYzkvm67LRA+URYEAcBuvKk7IXmdsnIwSGm60cVXGaqkJQHozb2Cy1t94tCYb6rJA==
dependencies:
"@types/react" "*"
"@types/react-dom" "*"
"@types/react-transition-group" "*"
"@types/react-table@^7.7.11": "@types/react-table@^7.7.11":
version "7.7.11" version "7.7.11"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.11.tgz#0efbb69aabf5b4b9c26c4c027b1e1ceb0f342303" resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.11.tgz#0efbb69aabf5b4b9c26c4c027b1e1ceb0f342303"
@ -1859,13 +1850,6 @@
dependencies: dependencies:
"@types/react" "*" "@types/react" "*"
"@types/react-transition-group@*", "@types/react-transition-group@^4.4.0":
version "4.4.4"
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.4.tgz#acd4cceaa2be6b757db61ed7b432e103242d163e"
integrity sha512-7gAPz7anVK5xzbeQW9wFBDg7G++aPLAFY0QaSMOou9rJZpbuI58WAuJrgu+qR92l61grlnCUe7AFX8KGahAgug==
dependencies:
"@types/react" "*"
"@types/react-transition-group@^4.2.0": "@types/react-transition-group@^4.2.0":
version "4.4.0" version "4.4.0"
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.0.tgz#882839db465df1320e4753e6e9f70ca7e9b4d46d" resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.0.tgz#882839db465df1320e4753e6e9f70ca7e9b4d46d"
@ -1873,6 +1857,13 @@
dependencies: dependencies:
"@types/react" "*" "@types/react" "*"
"@types/react-transition-group@^4.4.0":
version "4.4.4"
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.4.tgz#acd4cceaa2be6b757db61ed7b432e103242d163e"
integrity sha512-7gAPz7anVK5xzbeQW9wFBDg7G++aPLAFY0QaSMOou9rJZpbuI58WAuJrgu+qR92l61grlnCUe7AFX8KGahAgug==
dependencies:
"@types/react" "*"
"@types/react-virtualized-auto-sizer@^1.0.1": "@types/react-virtualized-auto-sizer@^1.0.1":
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.1.tgz#b3187dae1dfc4c15880c9cfc5b45f2719ea6ebd4" resolved "https://registry.yarnpkg.com/@types/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.1.tgz#b3187dae1dfc4c15880c9cfc5b45f2719ea6ebd4"