import { describe, expect, it } from "vitest";
import {
  filenameWithExtension,
  middleEllipsisFilename,
} from "./filenameDisplay";

describe("filenameWithExtension", () => {
  it("keeps filenames that already have an extension", () => {
    expect(filenameWithExtension("sample.pdf", "image/png")).toBe("sample.pdf");
  });

  it("adds common extensions from mime type", () => {
    expect(filenameWithExtension("uuid-file", "image/png")).toBe(
      "uuid-file.png",
    );
    expect(filenameWithExtension("uuid-file", "audio/mpeg")).toBe(
      "uuid-file.mp3",
    );
    expect(filenameWithExtension("uuid-file", "application/pdf")).toBe(
      "uuid-file.pdf",
    );
  });
});

describe("middleEllipsisFilename", () => {
  it("keeps short filenames unchanged", () => {
    expect(middleEllipsisFilename("sample.pdf")).toBe("sample.pdf");
  });

  it("preserves the extension when truncating", () => {
    expect(middleEllipsisFilename("afbb9ebe-5af2-425a-9779-9d7.jpg", 22)).toBe(
      "afbb9ebe-5af2…-9d7.jpg",
    );
    expect(middleEllipsisFilename("afbb9ebe-5af2-425a-9779-9d7.png", 22)).toBe(
      "afbb9ebe-5af2…-9d7.png",
    );
    expect(middleEllipsisFilename("afbb9ebe-5af2-425a-9779-9d7.mp3", 22)).toBe(
      "afbb9ebe-5af2…-9d7.mp3",
    );
  });

  it("handles filenames without extension", () => {
    expect(middleEllipsisFilename("afbb9ebe-5af2-425a-9779-9d7", 18)).toBe(
      "afbb9ebe-5af2…-9d7",
    );
  });
});
