import { describe, expect, it } from "vitest";
import { parsePreSap } from "./utils";

describe("parsePreSap", () => {
  it("returns null for null", () => {
    expect(parsePreSap(null)).toBeNull();
  });

  it("returns null for undefined", () => {
    expect(parsePreSap(undefined)).toBeNull();
  });

  it("returns null for empty string", () => {
    expect(parsePreSap("")).toBeNull();
  });

  it("parses new format with letter prefix", () => {
    expect(parsePreSap("D55")).toEqual({ letter: "D", display: "D55" });
  });

  it("derives letter for legacy numeric-only format", () => {
    expect(parsePreSap("56")).toEqual({ letter: "D", display: "D56" });
  });

  it("handles other EPC bands correctly", () => {
    expect(parsePreSap("G10")).toEqual({ letter: "G", display: "G10" });
    expect(parsePreSap("A95")).toEqual({ letter: "A", display: "A95" });
  });

  it("trims surrounding whitespace", () => {
    expect(parsePreSap("  D55  ")).toEqual({ letter: "D", display: "D55" });
  });

  it("normalises letter to uppercase", () => {
    expect(parsePreSap("d55")).toEqual({ letter: "D", display: "D55" });
  });
});
