mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix/improve tests
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
0208d64648
commit
2e6dc57c82
@ -24,8 +24,7 @@ import { render, waitFor, fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
import { DeploymentScaleDialog } from "./deployment-scale-dialog";
|
||||
jest.mock("../../../common/k8s-api/endpoints");
|
||||
import { Deployment, deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { Deployment, DeploymentApi } from "../../../common/k8s-api/endpoints/deployment.api";
|
||||
|
||||
const dummyDeployment: Deployment = {
|
||||
apiVersion: "v1",
|
||||
@ -116,6 +115,13 @@ const dummyDeployment: Deployment = {
|
||||
};
|
||||
|
||||
describe("<DeploymentScaleDialog />", () => {
|
||||
let deploymentApi: DeploymentApi;
|
||||
|
||||
beforeEach(() => {
|
||||
deploymentApi = new DeploymentApi({
|
||||
objectConstructor: Deployment,
|
||||
});
|
||||
});
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
const { container } = render(<DeploymentScaleDialog />);
|
||||
@ -129,7 +135,7 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
const initReplicas = 3;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog />);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog deploymentApi={deploymentApi} />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
// we need to wait for the DeploymentScaleDialog to show up
|
||||
@ -150,7 +156,7 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const component = render(<DeploymentScaleDialog />);
|
||||
const component = render(<DeploymentScaleDialog deploymentApi={deploymentApi} />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
await waitFor(async () => {
|
||||
|
||||
@ -26,13 +26,14 @@ import { computed, observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { Dialog, DialogProps } from "../dialog";
|
||||
import { Wizard, WizardStep } from "../wizard";
|
||||
import { Deployment, deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { Deployment, DeploymentApi, deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { Icon } from "../icon";
|
||||
import { Slider } from "../slider";
|
||||
import { Notifications } from "../notifications";
|
||||
import { cssNames } from "../../utils";
|
||||
|
||||
interface Props extends Partial<DialogProps> {
|
||||
deploymentApi: DeploymentApi
|
||||
}
|
||||
|
||||
const dialogState = observable.object({
|
||||
@ -42,6 +43,10 @@ const dialogState = observable.object({
|
||||
|
||||
@observer
|
||||
export class DeploymentScaleDialog extends Component<Props> {
|
||||
static defaultProps = {
|
||||
deploymentApi
|
||||
};
|
||||
|
||||
@observable ready = false;
|
||||
@observable currentReplicas = 0;
|
||||
@observable desiredReplicas = 0;
|
||||
@ -80,7 +85,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
onOpen = async () => {
|
||||
const { deployment } = this;
|
||||
|
||||
this.currentReplicas = await deploymentApi.getReplicas({
|
||||
this.currentReplicas = await this.props.deploymentApi.getReplicas({
|
||||
namespace: deployment.getNs(),
|
||||
name: deployment.getName(),
|
||||
});
|
||||
@ -102,7 +107,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await deploymentApi.scale({
|
||||
await this.props.deploymentApi.scale({
|
||||
name: deployment.getName(),
|
||||
namespace: deployment.getNs(),
|
||||
}, desiredReplicas);
|
||||
|
||||
@ -21,11 +21,10 @@
|
||||
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
jest.mock("../../../common/k8s-api/endpoints/replica-set.api");
|
||||
import { ReplicaSetScaleDialog } from "./replicaset-scale-dialog";
|
||||
import { render, waitFor, fireEvent } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { ReplicaSet, replicaSetApi } from "../../../common/k8s-api/endpoints/replica-set.api";
|
||||
import { ReplicaSet, ReplicaSetApi } from "../../../common/k8s-api/endpoints/replica-set.api";
|
||||
|
||||
const dummyReplicaSet: ReplicaSet = {
|
||||
apiVersion: "v1",
|
||||
@ -111,8 +110,16 @@ const dummyReplicaSet: ReplicaSet = {
|
||||
};
|
||||
|
||||
describe("<ReplicaSetScaleDialog />", () => {
|
||||
let replicaSetApi: ReplicaSetApi;
|
||||
|
||||
beforeEach(() => {
|
||||
replicaSetApi = new ReplicaSetApi({
|
||||
objectConstructor: ReplicaSet
|
||||
});
|
||||
});
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
const { container } = render(<ReplicaSetScaleDialog/>);
|
||||
const { container } = render(<ReplicaSetScaleDialog replicaSetApi={replicaSetApi} />);
|
||||
|
||||
expect(container).toBeInstanceOf(HTMLElement);
|
||||
});
|
||||
@ -123,7 +130,7 @@ describe("<ReplicaSetScaleDialog />", () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
replicaSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<ReplicaSetScaleDialog/>);
|
||||
const { getByTestId } = render(<ReplicaSetScaleDialog replicaSetApi={replicaSetApi} />);
|
||||
|
||||
ReplicaSetScaleDialog.open(dummyReplicaSet);
|
||||
// we need to wait for the replicaSetScaleDialog to show up
|
||||
@ -143,7 +150,7 @@ describe("<ReplicaSetScaleDialog />", () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
replicaSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const component = render(<ReplicaSetScaleDialog/>);
|
||||
const component = render(<ReplicaSetScaleDialog replicaSetApi={replicaSetApi} />);
|
||||
|
||||
ReplicaSetScaleDialog.open(dummyReplicaSet);
|
||||
await waitFor(async () => {
|
||||
|
||||
@ -30,9 +30,10 @@ import { Icon } from "../icon";
|
||||
import { Slider } from "../slider";
|
||||
import { Notifications } from "../notifications";
|
||||
import { cssNames } from "../../utils";
|
||||
import { ReplicaSet, replicaSetApi } from "../../../common/k8s-api/endpoints/replica-set.api";
|
||||
import { ReplicaSet, ReplicaSetApi, replicaSetApi } from "../../../common/k8s-api/endpoints/replica-set.api";
|
||||
|
||||
interface Props extends Partial<DialogProps> {
|
||||
replicaSetApi: ReplicaSetApi
|
||||
}
|
||||
|
||||
const dialogState = observable.object({
|
||||
@ -42,6 +43,10 @@ const dialogState = observable.object({
|
||||
|
||||
@observer
|
||||
export class ReplicaSetScaleDialog extends Component<Props> {
|
||||
static defaultProps = {
|
||||
replicaSetApi
|
||||
};
|
||||
|
||||
@observable ready = false;
|
||||
@observable currentReplicas = 0;
|
||||
@observable desiredReplicas = 0;
|
||||
@ -71,7 +76,7 @@ export class ReplicaSetScaleDialog extends Component<Props> {
|
||||
onOpen = async () => {
|
||||
const { replicaSet } = this;
|
||||
|
||||
this.currentReplicas = await replicaSetApi.getReplicas({
|
||||
this.currentReplicas = await this.props.replicaSetApi.getReplicas({
|
||||
namespace: replicaSet.getNs(),
|
||||
name: replicaSet.getName(),
|
||||
});
|
||||
@ -102,7 +107,7 @@ export class ReplicaSetScaleDialog extends Component<Props> {
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await replicaSetApi.scale({
|
||||
await this.props.replicaSetApi.scale({
|
||||
name: replicaSet.getName(),
|
||||
namespace: replicaSet.getNs(),
|
||||
}, desiredReplicas);
|
||||
|
||||
@ -21,8 +21,7 @@
|
||||
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
jest.mock("../../../common/k8s-api/endpoints");
|
||||
import { StatefulSet, statefulSetApi } from "../../../common/k8s-api/endpoints";
|
||||
import { StatefulSet, StatefulSetApi } from "../../../common/k8s-api/endpoints";
|
||||
import { StatefulSetScaleDialog } from "./statefulset-scale-dialog";
|
||||
import { render, waitFor, fireEvent } from "@testing-library/react";
|
||||
import React from "react";
|
||||
@ -121,8 +120,16 @@ const dummyStatefulSet: StatefulSet = {
|
||||
};
|
||||
|
||||
describe("<StatefulSetScaleDialog />", () => {
|
||||
let statefulSetApi: StatefulSetApi;
|
||||
|
||||
beforeEach(() => {
|
||||
statefulSetApi = new StatefulSetApi({
|
||||
objectConstructor: StatefulSet
|
||||
});
|
||||
});
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
const { container } = render(<StatefulSetScaleDialog/>);
|
||||
const { container } = render(<StatefulSetScaleDialog statefulSetApi={statefulSetApi} />);
|
||||
|
||||
expect(container).toBeInstanceOf(HTMLElement);
|
||||
});
|
||||
@ -133,7 +140,7 @@ describe("<StatefulSetScaleDialog />", () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
statefulSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<StatefulSetScaleDialog/>);
|
||||
const { getByTestId } = render(<StatefulSetScaleDialog statefulSetApi={statefulSetApi} />);
|
||||
|
||||
StatefulSetScaleDialog.open(dummyStatefulSet);
|
||||
// we need to wait for the StatefulSetScaleDialog to show up
|
||||
@ -153,7 +160,7 @@ describe("<StatefulSetScaleDialog />", () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
statefulSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const component = render(<StatefulSetScaleDialog/>);
|
||||
const component = render(<StatefulSetScaleDialog statefulSetApi={statefulSetApi} />);
|
||||
|
||||
StatefulSetScaleDialog.open(dummyStatefulSet);
|
||||
await waitFor(async () => {
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
import "./statefulset-scale-dialog.scss";
|
||||
|
||||
import { StatefulSet, statefulSetApi } from "../../../common/k8s-api/endpoints";
|
||||
import { StatefulSet, StatefulSetApi, statefulSetApi } from "../../../common/k8s-api/endpoints";
|
||||
import React, { Component } from "react";
|
||||
import { computed, makeObservable, observable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
@ -33,6 +33,7 @@ import { Notifications } from "../notifications";
|
||||
import { cssNames } from "../../utils";
|
||||
|
||||
interface Props extends Partial<DialogProps> {
|
||||
statefulSetApi: StatefulSetApi
|
||||
}
|
||||
|
||||
const dialogState = observable.object({
|
||||
@ -42,6 +43,9 @@ const dialogState = observable.object({
|
||||
|
||||
@observer
|
||||
export class StatefulSetScaleDialog extends Component<Props> {
|
||||
static defaultProps = {
|
||||
statefulSetApi
|
||||
};
|
||||
@observable ready = false;
|
||||
@observable currentReplicas = 0;
|
||||
@observable desiredReplicas = 0;
|
||||
@ -71,7 +75,7 @@ export class StatefulSetScaleDialog extends Component<Props> {
|
||||
onOpen = async () => {
|
||||
const { statefulSet } = this;
|
||||
|
||||
this.currentReplicas = await statefulSetApi.getReplicas({
|
||||
this.currentReplicas = await this.props.statefulSetApi.getReplicas({
|
||||
namespace: statefulSet.getNs(),
|
||||
name: statefulSet.getName(),
|
||||
});
|
||||
@ -102,7 +106,7 @@ export class StatefulSetScaleDialog extends Component<Props> {
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await statefulSetApi.scale({
|
||||
await this.props.statefulSetApi.scale({
|
||||
name: statefulSet.getName(),
|
||||
namespace: statefulSet.getNs(),
|
||||
}, desiredReplicas);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user