Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

test(frontend): cover the schedule a deploy task shows

zchpeterb0c499b9ddfe
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskHeader.test.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskHeader.test.tsx
new file mode 100644
index 0000000000..424ba65bee
--- /dev/null
+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskHeader.test.tsx
@@ -0,0 +1,88 @@
+import { create } from "@bufbuild/protobuf";
+import { act } from "react";
+import { createRoot } from "react-dom/client";
+import { afterEach, describe, expect, test, vi } from "vitest";
+import {
+ TaskSchema,
+ Task_Status,
+} from "@/types/proto-es/v1/rollout_service_pb";
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+ // @/lib/i18n initializes with this, and the timestamp reads the locale there.
+ initReactI18next: { type: "3rdParty", init: () => {} },
+}));
+
+// The header's identity block pulls the database stores; this spec is about
+// the scheduled badge beside it.
+vi.mock("../PlanTargetDisplay", () => ({
+ PlanTargetDisplay: () => null,
+}));
+
+vi.mock("@/components/TaskStatusIcon", () => ({
+ TaskStatusIcon: () => null,
+}));
+
+import { DeployTaskHeader } from "./DeployTaskHeader";
+
+(
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
+).IS_REACT_ACT_ENVIRONMENT = true;
+
+const SCHEDULED_AT_MS = Date.UTC(2026, 8, 15, 1, 0);
+
+const roots: ReturnType<typeof createRoot>[] = [];
+
+afterEach(() => {
+ for (const root of roots.splice(0)) {
+ act(() => root.unmount());
+ }
+});
+
+const render = (props: { scheduledTimeMs: number | undefined; isExpanded: boolean }) => {
+ const container = document.createElement("div");
+ document.body.appendChild(container);
+ const root = createRoot(container);
+ roots.push(root);
+ act(() =>
+ root.render(
+ <DeployTaskHeader
+ actionItems={[]}
+ collapsedContextInfo=""
+ collapsedStatusText=""
+ isSelectable={false}
+ isSelected={false}
+ onAction={() => {}}
+ onRollback={() => {}}
+ onToggleExpand={() => {}}
+ onToggleSelect={() => {}}
+ showRollback={false}
+ task={create(TaskSchema, { status: Task_Status.PENDING })}
+ timingDisplay=""
+ {...props}
+ />
+ )
+ );
+ return container;
+};
+
+describe("DeployTaskHeader", () => {
+ test.each([true, false])(
+ "names when a scheduled task runs, expanded: %s",
+ (isExpanded) => {
+ const container = render({ scheduledTimeMs: SCHEDULED_AT_MS, isExpanded });
+ // The operational form: the zone is part of the string, since a rollout
+ // time read in the wrong zone is the mistake this display exists to stop.
+ expect(container.textContent).toContain("Sep 15, 2026");
+ expect(container.textContent).toContain("GMT+8");
+ }
+ );
+
+ test.each([true, false])(
+ "shows no schedule for a task that has none, expanded: %s",
+ (isExpanded) => {
+ const container = render({ scheduledTimeMs: undefined, isExpanded });
+ expect(container.textContent).not.toContain("2026");
+ }
+ );
+});
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx
index 6827455a88..5e32a3ea76 100644
--- a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx
+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskItem.tsx
@@ -2,7 +2,6 @@ import { memo, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { formatTaskRunDuration } from "@/lib/taskRun";
import { cn } from "@/lib/utils";
-import { getTimeForPbTimestampProtoEs } from "@/types";
import type { Issue } from "@/types/proto-es/v1/issue_service_pb";
import type { Plan } from "@/types/proto-es/v1/plan_service_pb";
import type { Project } from "@/types/proto-es/v1/project_service_pb";
@@ -25,6 +24,7 @@ import {
import { DeployTaskBody } from "./DeployTaskBody";
import { DeployTaskHeader } from "./DeployTaskHeader";
import { DeployTaskRunHistorySheet } from "./DeployTaskRunHistorySheet";
+import { scheduledRunTimeMs } from "./scheduledRunTime";
import { useDeployTaskActions } from "./taskActions";
import { useDeployTaskStatement } from "./useDeployTaskStatement";
@@ -133,10 +133,7 @@ export const DeployTaskItem = memo(function DeployTaskItem({
latestTaskRun.hasPriorBackup
? latestTaskRun
: undefined;
- const scheduledTimeMs =
- task.runTime && task.status === Task_Status.PENDING
- ? getTimeForPbTimestampProtoEs(task.runTime)
- : undefined;
+ const scheduledTimeMs = scheduledRunTimeMs(task);
// Same duration source as the history sheet and the expanded body, so all
// three render identical strings for the same run.
const timingDisplay = latestTaskRun
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.test.ts b/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.test.ts
new file mode 100644
index 0000000000..146b0eb495
--- /dev/null
+++ b/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.test.ts
@@ -0,0 +1,42 @@
+// @vitest-environment node
+
+import { create } from "@bufbuild/protobuf";
+import { timestampFromMs } from "@bufbuild/protobuf/wkt";
+import { describe, expect, test } from "vitest";
+import {
+ Task_Status,
+ TaskSchema,
+} from "@/types/proto-es/v1/rollout_service_pb";
+import { scheduledRunTimeMs } from "./scheduledRunTime";
+
+const RUN_AT_MS = 1_772_452_800_000;
+
+const task = (status: Task_Status, runTimeMs?: number) =>
+ create(TaskSchema, {
+ status,
+ runTime: runTimeMs === undefined ? undefined : timestampFromMs(runTimeMs),
+ });
+
+describe("scheduledRunTimeMs", () => {
+ test("gives the instant a waiting task is due to run", () => {
+ expect(scheduledRunTimeMs(task(Task_Status.PENDING, RUN_AT_MS))).toBe(
+ RUN_AT_MS
+ );
+ });
+
+ test("gives nothing for a waiting task with no time set", () => {
+ // Zero is an instant, and an instant reads as a schedule: a task waiting
+ // for nothing in particular must not show one.
+ expect(scheduledRunTimeMs(task(Task_Status.PENDING))).toBeUndefined();
+ });
+
+ test.each([
+ ["running", Task_Status.RUNNING],
+ ["done", Task_Status.DONE],
+ ["failed", Task_Status.FAILED],
+ ["skipped", Task_Status.SKIPPED],
+ ["canceled", Task_Status.CANCELED],
+ ])("gives nothing for a %s task that carries one", (_name, status) => {
+ expect(scheduledRunTimeMs(task(status, RUN_AT_MS))).toBeUndefined();
+ });
+});
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.ts b/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.ts
new file mode 100644
index 0000000000..7dcad2ad33
--- /dev/null
+++ b/frontend/src/routes/project/plan-detail/components/deploy/scheduledRunTime.ts
@@ -0,0 +1,14 @@
+import { getTimeForPbTimestampProtoEs } from "@/types";
+import type { Task } from "@/types/proto-es/v1/rollout_service_pb";
+import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
+
+/**
+ * When a task is due to run, or nothing at all: a schedule belongs to a task
+ * still waiting for it, and a task that has started or finished is described
+ * by its run, not by the time it was once meant to begin.
+ */
+export function scheduledRunTimeMs(task: Task): number | undefined {
+ return task.status === Task_Status.PENDING
+ ? getTimeForPbTimestampProtoEs(task.runTime)
+ : undefined;
+}