fix log-resource-selector.test.tsx tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-05-04 08:45:53 -04:00
1 parent 383a50cdbf
commit 35e49fe6e6
11 files changed
+40 -45

No files matched your search

+2 -2
View File
@@ -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;
+7 -7
View File
@@ -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];
+1 -1
View File
@@ -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";
+1 -1
View File
@@ -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>
);