import { describe, expect, it } from "vitest";
import { getOnlineBoardDefaultTimeRange } from "./timeDefaults.js";

describe("4.1.1-R4 + R5: Online-Board default time range", () => {
  it("desktop/tablet default = 00:00-24:00 regardless of time", () => {
    expect(getOnlineBoardDefaultTimeRange(false, new Date(2026, 4, 15, 9, 0))).toEqual({
      timeFrom: "0000",
      timeTo: "2400",
    });
    expect(getOnlineBoardDefaultTimeRange(false, new Date(2026, 4, 15, 22, 30))).toEqual({
      timeFrom: "0000",
      timeTo: "2400",
    });
  });

  it("mobile default = -1h/+3h from user's current hour", () => {
    expect(getOnlineBoardDefaultTimeRange(true, new Date(2026, 4, 15, 9, 0))).toEqual({
      timeFrom: "0800",
      timeTo: "1200",
    });
  });

  it("mobile default clamps to 00:00 when current hour < 1", () => {
    expect(getOnlineBoardDefaultTimeRange(true, new Date(2026, 4, 15, 0, 30))).toEqual({
      timeFrom: "0000",
      timeTo: "0330",
    });
  });

  it("mobile default clamps to 24:00 when current hour > 21", () => {
    expect(getOnlineBoardDefaultTimeRange(true, new Date(2026, 4, 15, 22, 15))).toEqual({
      timeFrom: "2115",
      timeTo: "2400",
    });
  });

  it("mobile default preserves minutes in HHmm format", () => {
    expect(getOnlineBoardDefaultTimeRange(true, new Date(2026, 4, 15, 14, 37))).toEqual({
      timeFrom: "1337",
      timeTo: "1737",
    });
  });
});
