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

import {
  buildChatImageOverlayUrl,
  buildChatWithoutImageOverlayUrl,
  getChatImageOverlayMessageId,
} from "../chat-image-overlay-url";

describe("chat image overlay url helpers", () => {
  it("reads a non-empty image message id from search params", () => {
    expect(
      getChatImageOverlayMessageId(new URLSearchParams("image=msg_1")),
    ).toBe("msg_1");
  });

  it("ignores missing or blank image message ids", () => {
    expect(getChatImageOverlayMessageId(new URLSearchParams(""))).toBeNull();
    expect(
      getChatImageOverlayMessageId(new URLSearchParams("image=%20")),
    ).toBeNull();
  });

  it("builds the chat image overlay url", () => {
    expect(buildChatImageOverlayUrl("msg 1")).toBe("/chat?image=msg+1");
  });

  it("removes only the image param when closing the overlay", () => {
    expect(
      buildChatWithoutImageOverlayUrl(
        new URLSearchParams("image=msg_1&foo=bar"),
      ),
    ).toBe("/chat?foo=bar");
    expect(
      buildChatWithoutImageOverlayUrl(new URLSearchParams("image=msg_1")),
    ).toBe("/chat");
  });
});
