40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|||
|
|
import { DEPARTMENTS } from "../test/auth";
|
||
|
|
import type { Department } from "./types";
|
||
|
|
import { firstScreen, homePath, roleChipClass, roleFromKind, roleLabel, screensFor } from "./roles";
|
||
|
|
|
||
|
|
const depts = DEPARTMENTS as Department[];
|
||
|
|
|
||
|
|
describe("roles", () => {
|
||
|
|
it("labels shop and office roles", () => {
|
||
|
|
expect(roleLabel("shop:03:supervisor", depts)).toBe("03 Weld Parts · Supervisor");
|
||
|
|
expect(roleLabel("shop:09:lead")).toBe("09 · Lead");
|
||
|
|
expect(roleLabel("clerical_supervisor")).toBe("Clerical supervisor");
|
||
|
|
expect(roleLabel("qc")).toBe("Q.C.");
|
||
|
|
expect(roleLabel("pm")).toBe("Project Management");
|
||
|
|
expect(roleLabel("admin")).toBe("Admin");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("maps roles to screens", () => {
|
||
|
|
expect(screensFor(["clerical", "shop:06:supervisor"])).toEqual(["clerical", "supervisor", "stall"]);
|
||
|
|
expect(screensFor(["shop:03:worker"])).toEqual(["stall"]);
|
||
|
|
expect(screensFor(["warehouse_supervisor", "qc"])).toEqual(["warehouse", "qc"]);
|
||
|
|
expect(screensFor(["admin"])).toHaveLength(7);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("lands on the first non-admin screen", () => {
|
||
|
|
expect(firstScreen(["admin", "clerical"])).toBe("clerical");
|
||
|
|
expect(firstScreen(["admin"])).toBe("admin");
|
||
|
|
expect(homePath(["stall", "supervisor"])).toBe("/supervisor");
|
||
|
|
expect(homePath([])).toBe("/account");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("builds role strings from kinds and picks chip colours", () => {
|
||
|
|
expect(roleFromKind("shop_lead", "03")).toBe("shop:03:lead");
|
||
|
|
expect(roleFromKind("qc_supervisor", "QC")).toBe("qc_supervisor");
|
||
|
|
expect(roleChipClass("shop:03:supervisor")).toBe("rchip supervisor");
|
||
|
|
expect(roleChipClass("admin")).toBe("rchip admin");
|
||
|
|
expect(roleChipClass("clerical")).toBe("rchip");
|
||
|
|
});
|
||
|
|
});
|