Skip to content

Commit

Permalink
Additional info for application status (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Feb 27, 2020
1 parent 878c94f commit 775254e
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 70 deletions.
1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"react-feather": "^1.0.8",
"react-jsonschema-form": "^1.0.3",
"react-markdown": "^4.2.2",
"react-minimal-pie-chart": "^6.0.1",
"react-modal": "^3.1.11",
"react-redux": "^5.0.6",
"react-router": "^5.1.2",
Expand Down
30 changes: 30 additions & 0 deletions dashboard/src/components/ApplicationStatus/ApplicationStatus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
height: 2.5em;
}

.ApplicationStatusPieChart {
text-align: center;
max-width: 100px;
margin-bottom: -50px;
a {
color: unset;
}
a:hover {
text-decoration: none !important;
color: unset;
}
&__title {
margin-top: 0px;
}
&__label {
position: relative;
bottom: 80px;
&__number {
margin: 0;
font-size: 1.5em;
}
&__text {
margin: -5px 0 0 0;
}
}
tr {
line-height: 5px;
}
}

.ApplicationStatus--success {
color: #fff;
background-color: #1598cb;
Expand Down
108 changes: 100 additions & 8 deletions dashboard/src/components/ApplicationStatus/ApplicationStatus.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shallow } from "enzyme";
import * as React from "react";
import * as ReactTooltip from "react-tooltip";

import { IKubeItem, IResource } from "shared/types";
import ApplicationStatus from "./ApplicationStatus";
Expand All @@ -12,6 +13,17 @@ const defaultProps = {
daemonsets: [],
};

const consoleError = global.console.error;
beforeEach(() => {
// Mute console.error since we are getting a lot of error for rendering the PieChart component
// more info here: https://github.com/toomuchdesign/react-minimal-pie-chart/issues/131
global.console.error = jest.fn();
});
afterEach(() => {
jest.resetAllMocks();
global.console.error = consoleError;
});

describe("componentDidMount", () => {
it("calls watchWorkloads", () => {
const mock = jest.fn();
Expand Down Expand Up @@ -77,20 +89,25 @@ describe("isFetching", () => {
statefulsets: Array<IKubeItem<IResource>>;
daemonsets: Array<IKubeItem<IResource>>;
deployed: boolean;
totalPods: number;
readyPods: number;
}> = [
{
title: "shows a deployed status if there are no resources",
deployments: [],
statefulsets: [],
daemonsets: [],
deployed: true,
totalPods: 0,
readyPods: 0,
},
{
title: "shows a deploying status if there is a non deployed deployment",
deployments: [
{
isFetching: false,
item: {
metadata: { name: "foo" },
status: {
replicas: 1,
availableReplicas: 0,
Expand All @@ -101,13 +118,16 @@ describe("isFetching", () => {
statefulsets: [],
daemonsets: [],
deployed: false,
totalPods: 1,
readyPods: 0,
},
{
title: "shows a deploying status if there is a non deployed statefulset",
statefulsets: [
{
isFetching: false,
item: {
metadata: { name: "foo" },
status: {
replicas: 1,
readyReplicas: 0,
Expand All @@ -118,13 +138,16 @@ describe("isFetching", () => {
deployments: [],
daemonsets: [],
deployed: false,
totalPods: 1,
readyPods: 0,
},
{
title: "shows a deploying status if there is a non deployed daemonset",
daemonsets: [
{
isFetching: false,
item: {
metadata: { name: "foo" },
status: {
currentNumberScheduled: 1,
numberReady: 0,
Expand All @@ -135,13 +158,16 @@ describe("isFetching", () => {
deployments: [],
statefulsets: [],
deployed: false,
totalPods: 1,
readyPods: 0,
},
{
title: "shows a deployed status if it has a daemonset, deployment and statefulset deployed",
daemonsets: [
{
isFetching: false,
item: {
metadata: { name: "foo" },
status: {
currentNumberScheduled: 1,
numberReady: 1,
Expand All @@ -153,6 +179,7 @@ describe("isFetching", () => {
{
isFetching: false,
item: {
metadata: { name: "foo" },
status: {
replicas: 1,
availableReplicas: 1,
Expand All @@ -164,6 +191,7 @@ describe("isFetching", () => {
{
isFetching: false,
item: {
metadata: { name: "foo" },
status: {
replicas: 1,
readyReplicas: 1,
Expand All @@ -172,19 +200,83 @@ describe("isFetching", () => {
},
],
deployed: true,
totalPods: 3,
readyPods: 3,
},
{
title:
"shows a deploying status if it has a daemonset, deployment (deployed) and statefulset (not deployed)",
daemonsets: [
{
isFetching: false,
item: {
metadata: { name: "foo-ds" },
status: {
currentNumberScheduled: 1,
numberReady: 1,
},
} as IResource,
},
],
deployments: [
{
isFetching: false,
item: {
metadata: { name: "foo-dp" },
status: {
replicas: 1,
availableReplicas: 1,
},
} as IResource,
},
],
statefulsets: [
{
isFetching: false,
item: {
metadata: { name: "foo-ss" },
status: {
replicas: 1,
readyReplicas: 0,
},
} as IResource,
},
],
deployed: true,
totalPods: 3,
readyPods: 2,
},
];
tests.forEach(t => {
it(t.title, () => {
const wrapper = shallow(
<ApplicationStatus
{...defaultProps}
deployments={t.deployments}
statefulsets={t.statefulsets}
daemonsets={t.daemonsets}
/>,
);
const wrapper = shallow(<ApplicationStatus {...defaultProps} />);
wrapper.setProps({
deployments: t.deployments,
statefulsets: t.statefulsets,
daemonsets: t.daemonsets,
});
expect(wrapper.text()).toContain(t.deployed ? "Ready" : "Not Ready");
expect(wrapper.state()).toMatchObject({ totalPods: t.totalPods, readyPods: t.readyPods });
// Check tooltip text
const tooltipText = wrapper
.find(ReactTooltip)
.dive()
.text();
t.deployments.forEach(d =>
expect(tooltipText).toContain(
`${d.item?.status.availableReplicas}/${d.item?.status.replicas}${d.item?.metadata.name}`,
),
);
t.statefulsets.forEach(d =>
expect(tooltipText).toContain(
`${d.item?.status.readyReplicas}/${d.item?.status.replicas}${d.item?.metadata.name}`,
),
);
t.daemonsets.forEach(d =>
expect(tooltipText).toContain(
`${d.item?.status.numberReady}/${d.item?.status.currentNumberScheduled}${d.item?.metadata.name}`,
),
);
});
});
});
Loading

0 comments on commit 775254e

Please sign in to comment.