Skip to content

Commit

Permalink
Fix remaining tests and client updates.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity committed Mar 7, 2023
1 parent ef870d9 commit 3e7ae06
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 136 deletions.
10 changes: 5 additions & 5 deletions dashboard/src/actions/installedpackages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,16 @@ describe("rollbackInstalledPackage", () => {
);

it("success and re-request apps info", async () => {
const installedPackageDetail = {
const installedPackageDetail = new InstalledPackageDetail({
availablePackageRef: {
context: { cluster: "default", namespace: "my-ns" },
identifier: "test",
plugin: { name: PluginNames.PACKAGES_HELM, version: "0.0.1" } as Plugin,
},
currentVersion: { appVersion: "4.5.6", pkgVersion: "1.2.3" },
} as InstalledPackageDetail;
});

const availablePackageDetail = { name: "test" } as AvailablePackageDetail;
const availablePackageDetail = new AvailablePackageDetail({ name: "test" });

InstalledPackage.RollbackInstalledPackage = jest.fn().mockImplementationOnce(() => true);
InstalledPackage.GetInstalledPackageDetail = jest.fn().mockReturnValue({
Expand All @@ -352,7 +352,7 @@ describe("rollbackInstalledPackage", () => {
expect(res).toBe(true);

const selectCMD = actions.installedpackages.selectInstalledPackage(
installedPackageDetail as any,
installedPackageDetail,
availablePackageDetail,
);
const res2 = await store.dispatch(selectCMD);
Expand Down Expand Up @@ -410,7 +410,7 @@ describe("getInstalledPkgStatus", () => {
plugin: { name: "bad-plugin", version: "0.0.1" } as Plugin,
} as InstalledPackageReference;
const status = {
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_INSTALLED,
reason: InstalledPackageStatus_StatusReason.INSTALLED,
} as InstalledPackageStatus;
const installedPackageDetail = { status } as InstalledPackageDetail;
InstalledPackage.GetInstalledPackageDetail = jest.fn().mockReturnValue({
Expand Down
7 changes: 3 additions & 4 deletions dashboard/src/components/AppList/AppListItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ const defaultProps = {
app: {
name: "foo",
pkgDisplayName: "foo",
installedPackageRef: {
installedPackageRef: new InstalledPackageReference({
identifier: "foo",
pkgVersion: "1.0.0",
context: { cluster: "default", namespace: "package-namespace" } as Context,
plugin: { name: "my.plugin", version: "0.0.1" } as Plugin,
} as InstalledPackageReference,
}),
status: {
ready: true,
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_INSTALLED,
reason: InstalledPackageStatus_StatusReason.INSTALLED,
userReason: "deployed",
} as InstalledPackageStatus,
latestMatchingVersion: { appVersion: "10.0.0", pkgVersion: "1.0.0" } as PackageAppVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ it("should render an enabled button and tooltip if when passing a pending status
...defaultProps,
releaseStatus: {
ready: false,
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
reason: InstalledPackageStatus_StatusReason.PENDING,
userReason: "Pending",
} as InstalledPackageStatus,
};
Expand All @@ -96,7 +96,7 @@ it("should render a deactivated button if when passing a uninstalled status", as
...defaultProps,
releaseStatus: {
ready: false,
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED,
reason: InstalledPackageStatus_StatusReason.UNINSTALLED,
userReason: "Uninstalling",
} as InstalledPackageStatus,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ type TProps = IStatusAwareButtonProps & {
tooltip?: string;
};

it("tests the disabled flag and tooltip for each release with default and custom status condition", async () => {
describe("tests the disabled flag and tooltip for each release with default and custom status condition", () => {
// this should cover all conditions
const testsProps: TProps[] = [
{
code: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
code: InstalledPackageStatus_StatusReason.PENDING,
disabled: true,
tooltip: "The application is pending installation.",
id: "",
releaseStatus: {} as InstalledPackageStatus,
},
{
code: InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED,
code: InstalledPackageStatus_StatusReason.UNINSTALLED,
disabled: true,
tooltip: "The application is being deleted.",
id: "",
Expand All @@ -47,65 +47,65 @@ it("tests the disabled flag and tooltip for each release with default and custom
releaseStatus: {} as InstalledPackageStatus,
},
{
code: InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED,
code: InstalledPackageStatus_StatusReason.UNINSTALLED,
disabled: true,
tooltip: "test tooltip for uninstalled",
id: "",
releaseStatus: {} as InstalledPackageStatus,
statusesToDeactivate: [InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED],
statusesToDeactivate: [InstalledPackageStatus_StatusReason.UNINSTALLED],
statusesToDeactivateTooltips: {
[InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED]:
"test tooltip for uninstalled",
[InstalledPackageStatus_StatusReason.UNINSTALLED]: "test tooltip for uninstalled",
},
},
{
code: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
code: InstalledPackageStatus_StatusReason.PENDING,
disabled: false,
id: "",
releaseStatus: {} as InstalledPackageStatus,
statusesToDeactivate: [InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED],
statusesToDeactivate: [InstalledPackageStatus_StatusReason.UNINSTALLED],
statusesToDeactivateTooltips: {
[InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED]:
"test tooltip for uninstalled",
[InstalledPackageStatus_StatusReason.UNINSTALLED]: "test tooltip for uninstalled",
},
},
];

for (const testProps of testsProps) {
let releaseStatus;
switch (testProps.code) {
case null:
releaseStatus = null;
break;
case undefined:
releaseStatus = undefined;
break;
default:
releaseStatus = {
reason: testProps.code,
} as InstalledPackageStatus;
}
const wrapper = mountWrapper(
defaultStore,
<StatusAwareButton
id={testProps.id}
releaseStatus={releaseStatus}
disabled={testProps.disabled}
statusesToDeactivate={testProps.statusesToDeactivate}
statusesToDeactivateTooltips={testProps.statusesToDeactivateTooltips}
/>,
);
it(`shows tooltip when code is ${testProps.code} and tooltip "${testProps.tooltip}"`, async () => {
let releaseStatus;
switch (testProps.code) {
case null:
releaseStatus = null;
break;
case undefined:
releaseStatus = undefined;
break;
default:
releaseStatus = {
reason: testProps.code,
} as InstalledPackageStatus;
}
const wrapper = mountWrapper(
defaultStore,
<StatusAwareButton
id={testProps.id}
releaseStatus={releaseStatus}
disabled={testProps.disabled}
statusesToDeactivate={testProps.statusesToDeactivate}
statusesToDeactivateTooltips={testProps.statusesToDeactivateTooltips}
/>,
);

// test disabled flag
expect(wrapper.find(CdsButton).prop("disabled")).toBe(testProps.disabled);
// test disabled flag
expect(wrapper.find(CdsButton).prop("disabled")).toBe(testProps.disabled);

// test tooltip
const tooltipUI = wrapper.find(ReactTooltip);
if (testProps.tooltip) {
expect(tooltipUI).toExist();
expect(tooltipUI).toIncludeText(testProps.tooltip);
} else {
expect(tooltipUI.exists()).toBeFalsy();
}
// test tooltip
const tooltipUI = wrapper.find(ReactTooltip);
if (testProps.tooltip) {
expect(tooltipUI).toExist();
expect(tooltipUI).toIncludeText(testProps.tooltip);
} else {
expect(tooltipUI.exists()).toBeFalsy();
}
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ export default function StatusAwareButton<T extends IStatusAwareButtonProps>(pro
} = props;

const defaultStatusesToDeactivate = [
InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED,
InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
InstalledPackageStatus_StatusReason.UNINSTALLED,
InstalledPackageStatus_StatusReason.PENDING,
];
const defaultStatusesToDeactivateTooltips = {
[InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED]:
"The application is being deleted.",
[InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING]:
"The application is pending installation.",
[InstalledPackageStatus_StatusReason.UNINSTALLED]: "The application is being deleted.",
[InstalledPackageStatus_StatusReason.PENDING]: "The application is pending installation.",
};

// allow buttons to override the default statuses to deactivate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ it("should render a deactivated button if when passing an in-progress status", a
...defaultProps,
releaseStatus: {
ready: false,
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
reason: InstalledPackageStatus_StatusReason.PENDING,
userReason: "Pending",
} as InstalledPackageStatus,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ it("renders a deleting status", () => {
{
status: {
ready: false,
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED,
reason: InstalledPackageStatus_StatusReason.UNINSTALLED,
userReason: "Deleted",
} as InstalledPackageStatus,
} as InstalledPackageDetail
Expand All @@ -65,7 +65,7 @@ it("renders a failed status", () => {
{
status: {
ready: false,
reason: InstalledPackageStatus_StatusReason.STATUS_REASON_FAILED,
reason: InstalledPackageStatus_StatusReason.FAILED,
userReason: "Failed",
} as InstalledPackageStatus,
} as InstalledPackageDetail
Expand Down Expand Up @@ -94,7 +94,7 @@ describe("isFetching", () => {
deployed: false,
totalPods: 0,
readyPods: 0,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
infoReason: InstalledPackageStatus_StatusReason.PENDING,
},
{
title: "shows a deploying status if there is a non deployed deployment",
Expand All @@ -117,7 +117,7 @@ describe("isFetching", () => {
deployed: false,
totalPods: 1,
readyPods: 0,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
infoReason: InstalledPackageStatus_StatusReason.PENDING,
},
{
title: "shows a deploying status if there is a non deployed statefulset",
Expand All @@ -140,7 +140,7 @@ describe("isFetching", () => {
deployed: false,
totalPods: 1,
readyPods: 0,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
infoReason: InstalledPackageStatus_StatusReason.PENDING,
},
{
title: "shows a deploying status if there is a non deployed daemonset",
Expand All @@ -161,7 +161,7 @@ describe("isFetching", () => {
deployed: false,
totalPods: 1,
readyPods: 0,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
infoReason: InstalledPackageStatus_StatusReason.PENDING,
},
{
title: "shows a deployed status if it has a daemonset, deployment and statefulset deployed",
Expand Down Expand Up @@ -208,7 +208,7 @@ describe("isFetching", () => {
deployed: true,
totalPods: 3,
readyPods: 3,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_INSTALLED,
infoReason: InstalledPackageStatus_StatusReason.INSTALLED,
},
{
title:
Expand Down Expand Up @@ -256,7 +256,7 @@ describe("isFetching", () => {
deployed: true,
totalPods: 3,
readyPods: 2,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
infoReason: InstalledPackageStatus_StatusReason.PENDING,
},
{
title:
Expand Down Expand Up @@ -316,7 +316,7 @@ describe("isFetching", () => {
deployed: true,
totalPods: 3,
readyPods: 2,
infoReason: InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
infoReason: InstalledPackageStatus_StatusReason.PENDING,
},
];
tests.forEach(t => {
Expand Down
16 changes: 8 additions & 8 deletions dashboard/src/components/ApplicationStatus/ApplicationStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ function flattenItemList(items: Array<IKubeItem<IResource | IK8sList<IResource,

function codeToString(status: InstalledPackageStatus | null | undefined) {
const codes = {
[InstalledPackageStatus_StatusReason.STATUS_REASON_UNSPECIFIED]: "Unknown",
[InstalledPackageStatus_StatusReason.STATUS_REASON_INSTALLED]: "Installed",
[InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED]: "Deleted",
[InstalledPackageStatus_StatusReason.STATUS_REASON_FAILED]: "Failed",
[InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING]: "Pending",
[InstalledPackageStatus_StatusReason.UNSPECIFIED]: "Unknown",
[InstalledPackageStatus_StatusReason.INSTALLED]: "Installed",
[InstalledPackageStatus_StatusReason.UNINSTALLED]: "Deleted",
[InstalledPackageStatus_StatusReason.FAILED]: "Failed",
[InstalledPackageStatus_StatusReason.PENDING]: "Pending",
[InstalledPackageStatus_StatusReason.UNRECOGNIZED]: "Unknown",
};
let msg = codes[0];
Expand Down Expand Up @@ -125,7 +125,7 @@ export default function ApplicationStatus({
</div>
);
}
if (info?.status?.reason === InstalledPackageStatus_StatusReason.STATUS_REASON_UNINSTALLED) {
if (info?.status?.reason === InstalledPackageStatus_StatusReason.UNINSTALLED) {
return (
<div className="center">
<div className="color-icon-danger">
Expand All @@ -140,8 +140,8 @@ export default function ApplicationStatus({
const packageStatus = codeToString(info.status);
if (
![
InstalledPackageStatus_StatusReason.STATUS_REASON_INSTALLED,
InstalledPackageStatus_StatusReason.STATUS_REASON_PENDING,
InstalledPackageStatus_StatusReason.INSTALLED,
InstalledPackageStatus_StatusReason.PENDING,
].includes(info?.status?.reason)
) {
return (
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/reducers/installedpackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { LocationChangeAction, LOCATION_CHANGE } from "connected-react-router";
import { InstalledPackageDetailCustomDataHelm } from "gen/kubeappsapis/plugins/helm/packages/v1alpha1/helm_pb";
import { IInstalledPackageState } from "shared/types";
import { CustomInstalledPackageDetail, IInstalledPackageState } from "shared/types";
import { getType } from "typesafe-actions";
import actions from "../actions";
import { InstalledPackagesAction } from "../actions/installedpackages";
Expand Down Expand Up @@ -47,7 +47,7 @@ const installedPackagesReducer = (
...action.payload.pkg,
// TODO(agamez): remove it once we have a core mechanism for rolling back
revision: revision,
},
} as CustomInstalledPackageDetail,
selectedDetails: action.payload.details,
};
}
Expand Down
Loading

0 comments on commit 3e7ae06

Please sign in to comment.