import { describe, expect, it } from "vitest";

import { createOperationalScheduledConditions } from "./scheduled-conditions";

describe("createOperationalScheduledConditions", () => {
  it("keeps a scheduled condition running during the previous gap window", () => {
    const conditions = createOperationalScheduledConditions(new Date("2026-07-07T11:43:30+08:00"));
    const runningCondition = conditions.find(
      (condition) => condition.kind === "condition" && condition.status === "running"
    );

    expect(runningCondition?.title).toBe("SCADA 数据诊断");
    expect(runningCondition?.durationMinutes).toBe(5);
    expect(runningCondition?.scheduledAt).toContain("T11:40:");
  });

  it("rolls the running condition into history when the next interval starts", () => {
    const conditions = createOperationalScheduledConditions(new Date("2026-07-07T11:45:30+08:00"));
    const previousCondition = conditions.find(
      (condition) => condition.kind === "condition" && condition.id.includes("scada-diagnosis-202607071140")
    );
    const currentCondition = conditions.find(
      (condition) => condition.kind === "condition" && condition.id.includes("scada-diagnosis-202607071145")
    );

    expect(previousCondition?.status).not.toBe("running");
    expect(previousCondition?.durationMinutes).toBe(5);
    expect(currentCondition?.status).toBe("running");
    expect(currentCondition?.durationMinutes).toBe(5);
  });
});
