import { describe, expect, it } from "vitest";
import {
  compareOrgRanks,
  getOrgRankDisplayName,
  getOrgRankWeight,
} from "./rankPriority";

describe("org chart rank priority", () => {
  it("normalizes long rank aliases to short display labels", () => {
    expect(getOrgRankDisplayName("전무이사")).toBe("전무");
    expect(getOrgRankDisplayName("상무이사")).toBe("상무");
    expect(getOrgRankDisplayName("수석연구원")).toBe("수석");
    expect(getOrgRankDisplayName("책임연구원")).toBe("책임");
    expect(getOrgRankDisplayName("선임연구원")).toBe("선임");
  });

  it("orders executive and research ranks with shared priority weights", () => {
    expect(getOrgRankWeight("사장")).toBeLessThan(getOrgRankWeight("부사장"));
    expect(getOrgRankWeight("전무이사")).toBeLessThan(getOrgRankWeight("상무"));
    expect(getOrgRankWeight("수석연구원")).toBeLessThan(
      getOrgRankWeight("책임"),
    );
    expect(getOrgRankWeight("책임연구원")).toBeLessThan(
      getOrgRankWeight("선임"),
    );
    expect(compareOrgRanks("부장", "차장")).toBeLessThan(0);
  });

  it("orders top executive ranks before the existing vice president and lower ranks", () => {
    const ranks = ["부사장", "고문", "부회장", "사장", "회장"];

    expect(ranks.toSorted(compareOrgRanks)).toEqual([
      "회장",
      "사장",
      "부회장",
      "고문",
      "부사장",
    ]);
    expect(getOrgRankWeight("부사장")).toBe(10);
    expect(getOrgRankWeight("전무")).toBe(20);
  });
});
