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:
parent
383a50cdbf
commit
35e49fe6e6
@ -319,7 +319,6 @@
|
||||
"@types/react-beautiful-dnd": "^13.1.2",
|
||||
"@types/react-dom": "^17.0.14",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"@types/react-select": "3.1.2",
|
||||
"@types/react-table": "^7.7.11",
|
||||
"@types/react-virtualized-auto-sizer": "^1.0.1",
|
||||
"@types/react-window": "^1.8.5",
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-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 type { KubeObjectScope, KubeObjectStatus, LabelSelector } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@ -24,7 +24,7 @@ export interface JobSpec {
|
||||
};
|
||||
spec: PodSpec;
|
||||
};
|
||||
containers?: IPodContainer[];
|
||||
containers?: PodContainer[];
|
||||
restartPolicy?: string;
|
||||
terminationGracePeriodSeconds?: number;
|
||||
dnsPolicy?: string;
|
||||
|
||||
@ -101,7 +101,7 @@ export interface VolumeMount {
|
||||
subPathExpr?: string;
|
||||
}
|
||||
|
||||
export interface IPodContainer extends Partial<Record<PodContainerProbe, IContainerProbe>> {
|
||||
export interface PodContainer extends Partial<Record<PodContainerProbe, IContainerProbe>> {
|
||||
name: string;
|
||||
image: string;
|
||||
command?: string[];
|
||||
@ -702,7 +702,7 @@ export interface PodSpec {
|
||||
activeDeadlineSeconds?: number;
|
||||
affinity?: Affinity;
|
||||
automountServiceAccountToken?: boolean;
|
||||
containers?: IPodContainer[];
|
||||
containers?: PodContainer[];
|
||||
dnsPolicy?: string;
|
||||
enableServiceLinks?: boolean;
|
||||
ephemeralContainers?: unknown[];
|
||||
@ -712,7 +712,7 @@ export interface PodSpec {
|
||||
hostNetwork?: boolean;
|
||||
hostPID?: boolean;
|
||||
imagePullSecrets?: LocalObjectReference[];
|
||||
initContainers?: IPodContainer[];
|
||||
initContainers?: PodContainer[];
|
||||
nodeName?: string;
|
||||
nodeSelector?: 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";
|
||||
}
|
||||
|
||||
getLivenessProbe(container: IPodContainer) {
|
||||
getLivenessProbe(container: PodContainer) {
|
||||
return this.getProbe(container, "livenessProbe");
|
||||
}
|
||||
|
||||
getReadinessProbe(container: IPodContainer) {
|
||||
getReadinessProbe(container: PodContainer) {
|
||||
return this.getProbe(container, "readinessProbe");
|
||||
}
|
||||
|
||||
getStartupProbe(container: IPodContainer) {
|
||||
getStartupProbe(container: PodContainer) {
|
||||
return this.getProbe(container, "startupProbe");
|
||||
}
|
||||
|
||||
private getProbe(container: IPodContainer, field: PodContainerProbe): string[] {
|
||||
private getProbe(container: PodContainer, field: PodContainerProbe): string[] {
|
||||
const probe: string[] = [];
|
||||
const probeData = container[field];
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints
|
||||
|
||||
// types
|
||||
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 { KubeObjectMetadata, KubeJsonApiObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
export type { KubeObjectStoreLoadAllParams, KubeObjectStoreLoadingParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
|
||||
|
||||
@ -63,7 +63,7 @@ export { KubeJsonApi } from "../../common/k8s-api/kube-json-api";
|
||||
|
||||
// types
|
||||
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 { KubeObjectStatus } from "./kube-object-status";
|
||||
export type { KubeJsonApiObjectMetadata as KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
|
||||
@ -7,7 +7,7 @@ import "./pod-container-env.scss";
|
||||
|
||||
import React, { useEffect, useState } from "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 { autorun } from "mobx";
|
||||
import { secretStore } from "../+config-secrets/secrets.store";
|
||||
@ -17,7 +17,7 @@ import { base64, cssNames, iter } from "../../utils";
|
||||
import _ from "lodash";
|
||||
|
||||
export interface ContainerEnvironmentProps {
|
||||
container: IPodContainer;
|
||||
container: PodContainer;
|
||||
namespace: string;
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import "./pod-details-container.scss";
|
||||
|
||||
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 { cssNames, isDefined } from "../../utils";
|
||||
import { StatusBrick } from "../status-brick";
|
||||
@ -26,7 +26,7 @@ import portForwardStoreInjectable from "../../port-forward/port-forward-store/po
|
||||
|
||||
export interface PodDetailsContainerProps {
|
||||
pod: Pod;
|
||||
container: IPodContainer;
|
||||
container: PodContainer;
|
||||
metrics?: Partial<Record<string, MetricData>>;
|
||||
}
|
||||
|
||||
|
||||
@ -155,7 +155,7 @@ describe("<LogResourceSelector />", () => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe.only("with one pod", () => {
|
||||
describe("with one pod", () => {
|
||||
let model: LogTabViewModel;
|
||||
|
||||
beforeEach(() => {
|
||||
@ -175,7 +175,7 @@ describe("<LogResourceSelector />", () => {
|
||||
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} />);
|
||||
|
||||
expect(await findByText("dockerExporter")).toBeInTheDocument();
|
||||
@ -185,9 +185,11 @@ describe("<LogResourceSelector />", () => {
|
||||
|
||||
describe("with several pods", () => {
|
||||
let model: LogTabViewModel;
|
||||
let renameTab: jest.MockedFunction<LogTabViewModelDependencies["renameTab"]>;
|
||||
|
||||
beforeEach(() => {
|
||||
model = getFewPodsTabData("foobar");
|
||||
renameTab = jest.fn();
|
||||
model = getFewPodsTabData("foobar", { renameTab });
|
||||
});
|
||||
|
||||
it("renders sibling pods in dropdown", async () => {
|
||||
@ -223,7 +225,6 @@ describe("<LogResourceSelector />", () => {
|
||||
});
|
||||
|
||||
it("updates tab name if selected pod changes", async () => {
|
||||
const renameTab = jest.fn();
|
||||
const { findByText, container } = render(<LogResourceSelector model={model} />);
|
||||
const selector = container.querySelector<HTMLElement>(".pod-selector");
|
||||
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
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 createLogsTabInjectable from "./create-logs-tab.injectable";
|
||||
|
||||
export interface PodLogsTabData {
|
||||
selectedPod: Pod;
|
||||
selectedContainer: IPodContainer;
|
||||
selectedContainer: PodContainer;
|
||||
}
|
||||
|
||||
const createPodLogsTabInjectable = getInjectable({
|
||||
|
||||
@ -11,7 +11,7 @@ import { observer } from "mobx-react";
|
||||
import { Badge } from "../../badge";
|
||||
import { Select } from "../../select";
|
||||
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";
|
||||
|
||||
export interface LogResourceSelectorProps {
|
||||
@ -33,13 +33,15 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
model.updateLogTabData({
|
||||
selectedContainer: container,
|
||||
selectedContainer: container.name,
|
||||
});
|
||||
model.reloadLogs();
|
||||
};
|
||||
@ -60,11 +62,11 @@ export const LogResourceSelector = observer(({ model }: LogResourceSelectorProps
|
||||
const containerSelectOptions = [
|
||||
{
|
||||
label: "Containers",
|
||||
options: pod.getContainers().map(container => container.name),
|
||||
options: pod.getContainers(),
|
||||
},
|
||||
{
|
||||
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"
|
||||
/>
|
||||
<span>Container</span>
|
||||
<Select<string, false, GroupBase<string>>
|
||||
<Select<PodContainer, false, GroupBase<PodContainer>>
|
||||
id="container-selector-input"
|
||||
options={containerSelectOptions}
|
||||
value={selectedContainer}
|
||||
value={container}
|
||||
onChange={onContainerChange}
|
||||
getOptionLabel={opt => opt.name}
|
||||
className="container-selector"
|
||||
menuClass="container-selector-menu"
|
||||
controlShouldRenderValue
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
23
yarn.lock
23
yarn.lock
@ -1843,15 +1843,6 @@
|
||||
"@types/history" "*"
|
||||
"@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":
|
||||
version "7.7.11"
|
||||
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.11.tgz#0efbb69aabf5b4b9c26c4c027b1e1ceb0f342303"
|
||||
@ -1859,13 +1850,6 @@
|
||||
dependencies:
|
||||
"@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":
|
||||
version "4.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.0.tgz#882839db465df1320e4753e6e9f70ca7e9b4d46d"
|
||||
@ -1873,6 +1857,13 @@
|
||||
dependencies:
|
||||
"@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":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.1.tgz#b3187dae1dfc4c15880c9cfc5b45f2719ea6ebd4"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user