// The Lucia project.
// Copyright 2026-2026 DSP, inc.  All rights reserved.
// Authors:
//   imacat.yang@dsp.im (imacat), 2026/03/05

import { describe, it, expect } from "vitest";
import abbreviateNumber from "@/module/abbreviateNumber.js";

describe("abbreviateNumber", () => {
  it('returns "0" for 0 seconds', () => {
    expect(abbreviateNumber(0)).toBe("0");
  });

  it("returns seconds only when < 60", () => {
    expect(abbreviateNumber(45).trim()).toBe("45s");
  });

  it("returns minutes and seconds", () => {
    // 2m 30s = 150s
    expect(abbreviateNumber(150).trim()).toBe("2m 30s");
  });

  it("returns hours, minutes, and seconds", () => {
    // 1h 1m 1s = 3661s
    expect(abbreviateNumber(3661).trim()).toBe("1h 1m 1s");
  });

  it("returns days, hours, minutes, and seconds", () => {
    // 1d 2h 3m 4s = 93784s
    expect(abbreviateNumber(93784).trim()).toBe("1d 2h 3m 4s");
  });

  it("handles exact day boundary", () => {
    // 1d = 86400s
    expect(abbreviateNumber(86400).trim()).toBe("1d");
  });

  it("handles exact hour boundary", () => {
    // 1h = 3600s
    expect(abbreviateNumber(3600).trim()).toBe("1h");
  });

  it("handles string input by parsing as int", () => {
    expect(abbreviateNumber("150").trim()).toBe("2m 30s");
  });

  it("handles NaN input", () => {
    expect(abbreviateNumber("abc").trim()).toBe("");
  });

  it("does not have trailing whitespace", () => {
    expect(abbreviateNumber(45)).toBe("45s");
    expect(abbreviateNumber(3661)).toBe("1h 1m 1s");
  });
});
