import { spaceDelimitedList } from "./spaceDelimitedList";

describe("spaceDelimitedList", () => {
  it("returns undefined when given an empty list", () => {
    expect(spaceDelimitedList([])).toBeUndefined();
  });

  it("returns a string when given a non-empty list", () => {
    expect(spaceDelimitedList(["a", "b", "c"])).toBe("a b c");
  });

  it("returns a string when given a list with a single element", () => {
    expect(spaceDelimitedList(["a"])).toBe("a");
  });

  it("returns a undefined when given a list with a single null element", () => {
    expect(spaceDelimitedList([null])).toBeUndefined();
  });

  it("returns a undefined when given a list with a single undefined element", () => {
    expect(spaceDelimitedList([undefined])).toBeUndefined();
  });

  it("returns a undefined when given a list with a single empty string element", () => {
    expect(spaceDelimitedList([""])).toBeUndefined();
  });

  it("Removes any null or undefined values", () => {
    expect(spaceDelimitedList(["a", null, "b", undefined, "c"])).toBe("a b c");
  });
});
