import { describe, expect, it } from "../test/testHarness";

import {
  calculateEstimatedProgress,
  formatEstimatedRemainingLabel,
  resolveProgressStartedAt,
} from "./useSmoothedProgress";

describe("useSmoothedProgress helpers", () => {
  it("calculates estimated progress from elapsed time with an easing curve", () => {
    expect(
      Math.round(
        calculateEstimatedProgress({
          nowMs: 220_000,
          startedAtMs: 100_000,
          expectedDurationMs: 120_000,
        }),
      ),
    ).toBe(85);
  });

  it("caps estimated progress below completion", () => {
    expect(
      Math.round(
        calculateEstimatedProgress({
          nowMs: 900_000,
          startedAtMs: 0,
          expectedDurationMs: 120_000,
        }),
      ),
    ).toBe(92);
  });

  it("parses local workbench timestamps", () => {
    expect(resolveProgressStartedAt("2026-06-10 09:30")).toBe(
      new Date(2026, 5, 10, 9, 30).getTime(),
    );
  });

  it("formats remaining time for estimated tasks", () => {
    expect(
      formatEstimatedRemainingLabel({
        nowMs: new Date(2026, 5, 10, 9, 30).getTime(),
        startedAt: "2026-06-10 09:29",
        expectedDurationMs: 120_000,
      }),
    ).toBe("预计还需 1 分钟");
  });
});
