import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { formatDateWithTodayTomorrow } from "./dateLabels.js";

describe("4.1.9-R: formatDateWithTodayTomorrow (Board calendar display)", () => {
  beforeEach(() => {
    vi.useFakeTimers();
    vi.setSystemTime(new Date(2026, 4, 15, 12, 0, 0));
  });
  afterEach(() => { vi.useRealTimers(); });

  it("returns 'Сегодня' for today's date", () => {
    const t = (k: string) => (k === "SHARED.TODAY" ? "Сегодня" : k === "SHARED.TOMORROW" ? "Завтра" : k);
    expect(formatDateWithTodayTomorrow(new Date(2026, 4, 15), t)).toBe("Сегодня");
  });

  it("returns 'Завтра' for tomorrow's date", () => {
    const t = (k: string) => (k === "SHARED.TODAY" ? "Сегодня" : k === "SHARED.TOMORROW" ? "Завтра" : k);
    expect(formatDateWithTodayTomorrow(new Date(2026, 4, 16), t)).toBe("Завтра");
  });

  it("returns dd.MM.yyyy for other dates", () => {
    const t = (k: string) => k;
    expect(formatDateWithTodayTomorrow(new Date(2026, 4, 17), t)).toBe("17.05.2026");
    expect(formatDateWithTodayTomorrow(new Date(2026, 11, 31), t)).toBe("31.12.2026");
  });

  it("returns dd.MM.yyyy for yesterday (not 'Вчера')", () => {
    const t = (k: string) => k;
    expect(formatDateWithTodayTomorrow(new Date(2026, 4, 14), t)).toBe("14.05.2026");
  });

  it("returns empty string for null/undefined", () => {
    expect(formatDateWithTodayTomorrow(null, () => "")).toBe("");
    expect(formatDateWithTodayTomorrow(undefined, () => "")).toBe("");
  });
});
