import { describe, expect, it } from "vitest";

import { getSplashLatestMessagePreview } from "@/lib/chat/splash_latest_message_preview";

describe("getSplashLatestMessagePreview", () => {
  it("uses text content for text messages", () => {
    expect(
      getSplashLatestMessagePreview({
        type: "text",
        content: " Come closer? ",
        audioUrl: null,
        image: { type: null, url: null },
      }),
    ).toBe("Come closer?");
  });

  it("uses image placeholder for image messages", () => {
    expect(
      getSplashLatestMessagePreview({
        type: "image",
        content: "",
        image: { type: "elio_schedule", url: null },
      }),
    ).toBe("[图片]");
  });

  it("uses image placeholder when the image url exists", () => {
    expect(
      getSplashLatestMessagePreview({
        type: "text",
        content: "",
        image: { type: null, url: "https://example.com/image.jpg" },
      }),
    ).toBe("[图片]");
  });

  it("uses voice placeholder for voice messages", () => {
    expect(
      getSplashLatestMessagePreview({
        type: "audio",
        content: "",
        audioUrl: "https://example.com/voice.mp3",
      }),
    ).toBe("[语音]");
  });

  it("uses voice placeholder for locked voice messages", () => {
    expect(
      getSplashLatestMessagePreview({
        type: "text",
        content: "",
        lockDetail: { reason: "voice_message" },
      }),
    ).toBe("[语音]");
  });

  it("falls back when the latest message has no displayable content", () => {
    expect(
      getSplashLatestMessagePreview({
        type: "text",
        content: "   ",
        image: { type: null, url: null },
        audioUrl: null,
      }),
    ).toBe("[消息]");
  });
});
