import {
  permissionCodes,
  permissionForPath,
  resourcePermissions,
} from "./permissions";

describe("permission mappings", () => {
  it("maps protected routes to backend permission codes", () => {
    expect(permissionForPath("/system-admin")).toBe(
      permissionCodes.environmentManage,
    );
    expect(permissionForPath("/scada-data-cleaning/devices")).toBe(
      permissionCodes.scadaClean,
    );
    expect(permissionForPath("/monitoring-place-optimization")).toBe(
      permissionCodes.optimizationRun,
    );
    expect(
      permissionForPath("/hydraulic-simulation/burst-location"),
    ).toBe(permissionCodes.burstRun);
  });

  it("leaves public or project-selection routes without a feature permission", () => {
    expect(permissionForPath("/login")).toBeUndefined();
    expect(permissionForPath("/")).toBeUndefined();
  });

  it("uses the same permission codes for resources and routes", () => {
    expect(resourcePermissions["系统管理"]).toBe(
      permissionCodes.environmentManage,
    );
    expect(resourcePermissions["审计日志"]).toBe(permissionCodes.auditView);
  });
});
