import { describe, it, expect } from "bun:test";
import { getRarityConfig, RARITY_CONFIG, defaultName } from "./rarity";

describe("getRarityConfig", () => {
  it("returns correct config for known rarities", () => {
    expect(getRarityConfig("SSR").color).toBe(0xF1C40F);
    expect(getRarityConfig("SSR").emoji).toBe("🌟");
    expect(getRarityConfig("SSR").label).toBe("SSR");
  });

  it("returns correct config for loot types", () => {
    expect(getRarityConfig("CURRENCY").color).toBe(0x2ECC71);
    expect(getRarityConfig("XP").color).toBe(0x1ABC9C);
    expect(getRarityConfig("NOTHING").color).toBe(0x636363);
  });

  it("falls back to Common for unknown rarity", () => {
    const result = getRarityConfig("LEGENDARY");
    expect(result).toEqual(RARITY_CONFIG["C"]!);
  });

  it("falls back to Common for null/undefined input", () => {
    expect(getRarityConfig(null as any)).toEqual(RARITY_CONFIG["C"]!);
    expect(getRarityConfig(undefined as any)).toEqual(RARITY_CONFIG["C"]!);
  });
});

describe("defaultName", () => {
  it("extracts filename from path", () => {
    expect(defaultName("/assets/items/sword.png")).toBe("sword.png");
  });

  it("returns image.png for empty path", () => {
    expect(defaultName("")).toBe("image.png");
  });
});
