Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor(automations): express the activity track height in CSS (#18788)

Engel Nyst70b8f9069dec
diff --git a/__tests__/components/features/home/automation-run-activity-sparkline.test.ts b/__tests__/components/features/home/automation-run-activity-sparkline.test.ts
index 208b360d50..0e399754e8 100644
--- a/__tests__/components/features/home/automation-run-activity-sparkline.test.ts
+++ b/__tests__/components/features/home/automation-run-activity-sparkline.test.ts
@@ -1,5 +1,13 @@
+import { readFile } from "node:fs/promises";
+import { resolve } from "node:path";
+import { compile } from "@tailwindcss/node";
+import { createElement } from "react";
+import { screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
+import { renderWithProviders } from "../../../../test-utils";
+import { AutomationRunActivitySparkline } from "#/components/features/home/featured-automations/automation-run-activity-sparkline";
import {
+ AUTOMATION_RUN_ACTIVITY_TRACK_PX,
AUTOMATION_RUN_ACTIVITY_MAX_BAR_PX,
AUTOMATION_RUN_ACTIVITY_MIN_BAR_PX,
AUTOMATION_RUN_ACTIVITY_UNKNOWN_BAR_PX,
@@ -112,3 +120,39 @@ describe("barColorClassForStatus", () => {
expect(barColorClassForStatus("unknown")).toContain("bg-warning");
});
});
+
+describe("AutomationRunActivitySparkline", () => {
+ it("builds the track height from the custom property supplied by the rendered component", async () => {
+ // Arrange: use the real component and production stylesheet, without
+ // prescribing a utility spelling or repeating its custom-property name.
+ renderWithProviders(
+ createElement(AutomationRunActivitySparkline, {
+ automationId: "automation-1",
+ runs: [makeRun()],
+ testId: "run-activity-track",
+ }),
+ );
+ const track = screen.getByTestId("run-activity-track");
+ const compiler = await compile(
+ await readFile(resolve("src/tailwind.css"), "utf8"),
+ { base: resolve("src"), onDependency: () => {} },
+ );
+
+ // Act: compile the classes actually emitted by this render.
+ const css = compiler.build([...track.classList]);
+ const declarations = [...css.matchAll(/\.((?:\\.|[\w-])+)\s*\{([^}]+)\}/g)]
+ .filter(([, selector]) =>
+ track.classList.contains(selector.replace(/\\(.)/g, "$1")),
+ )
+ .map(([, , body]) => body)
+ .join("\n");
+ const height = /(?:^|\n)\s*height:\s*var\((--[\w-]+)\);/.exec(declarations);
+
+ // Assert: the emitted height rule consumes the property's real value.
+ // Removing the class or misspelling either side breaks this contract.
+ expect(height).not.toBeNull();
+ expect(track.style.getPropertyValue(height![1])).toBe(
+ `${AUTOMATION_RUN_ACTIVITY_TRACK_PX}px`,
+ );
+ });
+});
diff --git a/src/components/features/home/featured-automations/automation-run-activity-sparkline.tsx b/src/components/features/home/featured-automations/automation-run-activity-sparkline.tsx
index 386f35ec98..0b26af5014 100644
--- a/src/components/features/home/featured-automations/automation-run-activity-sparkline.tsx
+++ b/src/components/features/home/featured-automations/automation-run-activity-sparkline.tsx
@@ -1,5 +1,5 @@
import { Tooltip } from "@heroui/react";
-import { useEffect, useState, type ReactNode } from "react";
+import { useEffect, useState, type CSSProperties, type ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { NavigationLink } from "#/components/shared/navigation-link";
import { AUTOMATION_RUN_ACTIVITY_LIMIT } from "#/hooks/query/use-latest-automation-runs";
@@ -177,8 +177,12 @@ export function AutomationRunActivitySparkline({
aria-label={t(I18nKey.FEATURED_AUTOMATIONS$RUN_ACTIVITY_LABEL, {
count: bars.length,
})}
- className="inline-flex shrink-0 items-end"
- style={{ height: AUTOMATION_RUN_ACTIVITY_TRACK_PX }}
+ className="inline-flex h-(--automation-run-activity-track-height) shrink-0 items-end"
+ style={
+ {
+ "--automation-run-activity-track-height": `${AUTOMATION_RUN_ACTIVITY_TRACK_PX}px`,
+ } as CSSProperties
+ }
onMouseDown={(event) => event.preventDefault()}
>
{bars.map((run, index) => (