import { describe, expect, it } from "vitest"; import { isMessagingToolDuplicate, normalizeTextForComparison, } from "./pi-embedded-helpers.js"; describe("normalizeTextForComparison", () => { it("lowercases text", () => { expect(normalizeTextForComparison("Hello World")).toBe("hello world"); }); it("trims whitespace", () => { expect(normalizeTextForComparison(" hello ")).toBe("hello"); }); it("collapses multiple spaces", () => { expect(normalizeTextForComparison("hello world")).toBe("hello world"); }); it("strips emoji", () => { expect(normalizeTextForComparison("Hello 👋 World 🌍")).toBe("hello world"); }); it("handles mixed normalization", () => { expect(normalizeTextForComparison(" Hello 👋 WORLD 🌍 ")).toBe( "hello world", ); }); }); describe("isMessagingToolDuplicate", () => { it("returns false for empty sentTexts", () => { expect(isMessagingToolDuplicate("hello world", [])).toBe(false); }); it("returns false for short texts", () => { expect(isMessagingToolDuplicate("short", ["short"])).toBe(false); }); it("detects exact duplicates", () => { expect( isMessagingToolDuplicate("Hello, this is a test message!", [ "Hello, this is a test message!", ]), ).toBe(true); }); it("detects duplicates with different casing", () => { expect( isMessagingToolDuplicate("HELLO, THIS IS A TEST MESSAGE!", [ "hello, this is a test message!", ]), ).toBe(true); }); it("detects duplicates with emoji variations", () => { expect( isMessagingToolDuplicate("Hello! 👋 This is a test message!", [ "Hello! This is a test message!", ]), ).toBe(true); }); it("detects substring duplicates (LLM elaboration)", () => { expect( isMessagingToolDuplicate( 'I sent the message: "Hello, this is a test message!"', ["Hello, this is a test message!"], ), ).toBe(true); }); it("detects when sent text contains block reply (reverse substring)", () => { expect( isMessagingToolDuplicate("Hello, this is a test message!", [ 'I sent the message: "Hello, this is a test message!"', ]), ).toBe(true); }); it("returns false for non-matching texts", () => { expect( isMessagingToolDuplicate("This is completely different content.", [ "Hello, this is a test message!", ]), ).toBe(false); }); });