import { describe, expect, it } from "vitest";
import { formatAddressDisplayLabel } from "@/lib/frontend/format-address";

describe("formatAddressDisplayLabel", () => {
  it("优先使用 street/city/state 组合，不含邮编", () => {
    expect(
      formatAddressDisplayLabel({
        street: "1234 Warehouse Blvd",
        city: "Los Angeles",
        state: "CA",
        formatted_address: "1234 Warehouse Blvd, Los Angeles, CA 90001",
      }),
    ).toBe("1234 Warehouse Blvd, Los Angeles, CA");
  });

  it("从 formatted_address 剥离邮编与 USA", () => {
    expect(
      formatAddressDisplayLabel({
        formatted_address: "5678 Distribution Dr, Dallas, TX 75201, USA",
      }),
    ).toBe("5678 Distribution Dr, Dallas, TX");
  });

  it("MotherShip 确认后展示与弹窗一致的 display_label", () => {
    expect(
      formatAddressDisplayLabel({
        street: "3131 Western Ave",
        city: "Seattle",
        state: "WA",
        selected_from_mothership: true,
        mothership_display_label:
          "3131 Western Avenue, Seattle, WA, USA",
      }),
    ).toBe("3131 Western Avenue, Seattle, WA");
  });
});
