import { describe, expect, it } from "vitest";
import { createValueLabelCollection, formatFeatureValue, getNumericFeatureProperties } from "./value-label";

describe("workbench value labels", () => {
  const feature = {
    type: "Feature" as const,
    geometry: { type: "Point" as const, coordinates: [120, 28] },
    properties: { diameter: 600.125, name: "P-1", invalid: Number.NaN, depth: 2 }
  };

  it("lists finite numeric properties only", () => {
    expect(getNumericFeatureProperties(feature.properties)).toEqual([["depth", 2], ["diameter", 600.125]]);
  });

  it("formats precision and unit with hard limits", () => {
    expect(formatFeatureValue(12.3456, 2, "mm")).toBe("12.35 mm");
    expect(formatFeatureValue(12.3456, 8, "")).toBe("12.346");
  });

  it("creates a single controlled label feature", () => {
    expect(createValueLabelCollection(feature, "diameter", 1, "mm").features[0]?.properties?.label).toBe("600.1 mm");
    expect(() => createValueLabelCollection(feature, "name", 1)).toThrow("INVALID_VALUE_PROPERTY");
  });
});
