import ArrayUtil from "./ArrayUtil";

describe("ArrayUtil", () => {
  it("isEmpty", () => {
    expect(ArrayUtil.isEmpty()).toBe(true);
    expect(ArrayUtil.isEmpty(null)).toBe(true);
    expect(ArrayUtil.isEmpty([])).toBe(true);

    expect(ArrayUtil.isEmpty([undefined])).toBe(false);
  });

  it("removeDuplicates", () => {
    expect(
      ArrayUtil.removeDuplicates(
        [
          { val: "a" },
          { val: "a" },
          { val: "b" },
          { val: "b " },
          { val: "c" },
          { val: "c" },
          { val: "d" },
        ],
        "val",
      ),
    ).toEqual([
      { val: "a" },
      { val: "b" },
      { val: "b " },
      { val: "c" },
      { val: "d" },
    ]);
  });

  it("uniqueStrings", () => {
    expect(ArrayUtil.uniqueStrings(["A@a.ee", "a@A.ee", "a@a.ee"])).toEqual([
      "a@a.ee",
    ]);
    expect(
      ArrayUtil.uniqueStrings(["A.B@a.ee", "a.b@A.ee", "a.b@a.ee", "b.c@a.ee"]),
    ).toEqual(["a.b@a.ee", "b.c@a.ee"]);
  });
});
