import { describe, it, expect } from "vitest";
import { truncatePreview } from "./truncate-preview";

describe("truncatePreview", () => {
  it("keeps short text unchanged", () => {
    expect(truncatePreview("Olá, tudo bem?")).toBe("Olá, tudo bem?");
  });

  it("keeps text exactly at the length boundary unchanged", () => {
    const text = "a".repeat(200);
    expect(truncatePreview(text, 200)).toBe(text);
  });

  it("truncates long text and appends an ellipsis", () => {
    const text = "a".repeat(250);
    const result = truncatePreview(text, 200);

    expect(result).toHaveLength(201);
    expect(result.endsWith("…")).toBe(true);
  });

  it("trims leading/trailing whitespace before truncating", () => {
    expect(truncatePreview("   olá mundo   ")).toBe("olá mundo");
  });
});
