import { normalizeChartData } from "./ChatInlineChart";

describe("normalizeChartData", () => {
  it("keeps standard bar chart series data", () => {
    const result = normalizeChartData(["A", "B"], [
      { name: "数量", data: [3, 5], type: "bar" },
    ]);

    expect(result).toEqual({
      xData: ["A", "B"],
      series: [{ name: "数量", data: [3, 5], type: "bar" }],
    });
  });

  it("normalizes line chart point arrays into x labels and y values", () => {
    const result = normalizeChartData(undefined, [
      { name: "压力", data: [["10:00", 12.5], ["11:00", 13.1]] },
    ]);

    expect(result).toEqual({
      xData: ["10:00", "11:00"],
      series: [{ name: "压力", data: [12.5, 13.1], type: undefined }],
    });
  });

  it("normalizes pie chart point objects into a single series", () => {
    const result = normalizeChartData(undefined, [
      { name: "低风险", value: 8 },
      { name: "高风险", value: 2 },
    ]);

    expect(result).toEqual({
      xData: ["低风险", "高风险"],
      series: [{ name: "数据", data: [8, 2], type: undefined }],
    });
  });

  it("accepts a single series object", () => {
    const result = normalizeChartData(["A", "B"], {
      name: "流量",
      values: ["1.2", "2.4"],
    });

    expect(result).toEqual({
      xData: ["A", "B"],
      series: [{ name: "流量", data: [1.2, 2.4], type: undefined }],
    });
  });
});
