diff --git a/src/components/HealthChecks/CheckLink.tsx b/src/components/HealthChecks/CheckLink.tsx index ef53a17a12..90b86de5e4 100644 --- a/src/components/HealthChecks/CheckLink.tsx +++ b/src/components/HealthChecks/CheckLink.tsx @@ -1,7 +1,8 @@ import { Link } from "react-router-dom"; import { ComponentHealthCheckView } from "../../api/services/topology"; +import { HealthCheck } from "../../types/healthChecks"; import { Icon } from "../Icon"; -import { Status } from "../Status"; +import { HealthCheckStatus } from "../Status/HealthCheckStatus"; type ComponentCheckLinkProps = { componentCheck: ComponentHealthCheckView; @@ -18,7 +19,7 @@ export function CheckLink({ componentCheck: check }: ComponentCheckLinkProps) { >
- + } />
{check.name} diff --git a/src/components/HealthChecks/__tests__/CheckLink.unit.test.tsx b/src/components/HealthChecks/__tests__/CheckLink.unit.test.tsx new file mode 100644 index 0000000000..16c43000a4 --- /dev/null +++ b/src/components/HealthChecks/__tests__/CheckLink.unit.test.tsx @@ -0,0 +1,48 @@ +import { render, screen } from "@testing-library/react"; +import { MemoryRouter } from "react-router-dom"; +import { CheckLink } from "./../CheckLink"; +import { ComponentHealthCheckView } from "../../../api/services/topology"; + +describe("CheckLink", () => { + const check: ComponentHealthCheckView = { + id: "1", + name: "Example Check", + type: "example", + status: "healthy", + component_id: "1", + severity: "critical" + }; + + it("renders with healthy status", () => { + render( + + + + ); + + const linkElement = screen.getByRole("link"); + expect(linkElement).toHaveAttribute( + "href", + "/health?checkId=1&timeRange=1h" + ); + + const statusElement = screen.getByTestId("health-check-status"); + expect(statusElement).toHaveClass("bg-green-400"); + + const nameElement = screen.getByText("Example Check"); + expect(nameElement).toBeInTheDocument(); + }); + + it("renders with unhealthy status", () => { + const unhealthyCheck = { ...check, status: "unhealthy" }; + + render( + + + + ); + + const statusElement = screen.getByTestId("health-check-status"); + expect(statusElement).toHaveClass("bg-red-400"); + }); +}); diff --git a/src/components/Status/HealthCheckStatus.story.tsx b/src/components/Status/HealthCheckStatus.story.tsx new file mode 100644 index 0000000000..c769945abb --- /dev/null +++ b/src/components/Status/HealthCheckStatus.story.tsx @@ -0,0 +1,41 @@ +import { Meta, Story } from "@storybook/react"; +import { HealthCheckStatus } from "./HealthCheckStatus"; + +type StatusProps = React.ComponentProps; + +export default { + title: "Components/HealthCheckStatus", + component: HealthCheckStatus +} as Meta; + +export const Default: Story = (args) => ( + +); + +export const Mixed: Story = (args) => ( + +); + +Mixed.args = { + isMixed: true +}; + +export const Healthy: Story = (args) => ( + +); + +Healthy.args = { + check: { + status: "healthy" + } +}; + +export const Unhealthy: Story = (args) => ( + +); + +Unhealthy.args = { + check: { + status: "unhealthy" + } +}; diff --git a/src/components/Status/HealthCheckStatus.tsx b/src/components/Status/HealthCheckStatus.tsx new file mode 100644 index 0000000000..241a58fdf8 --- /dev/null +++ b/src/components/Status/HealthCheckStatus.tsx @@ -0,0 +1,27 @@ +import { HealthCheck } from "../../types/healthChecks"; + +type StatusProps = { + check?: Pick; + isMixed?: boolean; + className?: string; +}; + +export function HealthCheckStatus({ + check, + isMixed = false, + className = "" +}: StatusProps) { + const color = isMixed + ? "bg-light-orange" + : check?.status === "healthy" + ? "bg-green-400" + : "bg-red-400"; + return ( +