Files
stock-manager/tests/unit/app/users/user.copy.test.ts
T

84 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest"
import {
formatPersonDepartment,
formatUserRole,
} from "@/app/(dashboard)/admin/users/_components/user.copy"
describe("user copy helpers", () => {
const roleCopy = {
ADMIN: "Administrador",
MANAGER: "Gerente",
STAFF: "Personal",
VIEWER: "Visor",
NO_USER: "Sin cuenta de usuario",
}
const fallbackCopy = {
unknownRole: "Rol desconocido",
}
it("formats known role values with localized display labels", () => {
expect(formatUserRole("ADMIN", roleCopy, fallbackCopy)).toBe(
"Administrador",
)
expect(formatUserRole("STAFF", roleCopy, fallbackCopy)).toBe("Personal")
})
it("falls back for unknown role values without exposing the raw enum value", () => {
expect(formatUserRole("UNKNOWN_ROLE", roleCopy, fallbackCopy)).toBe(
"Rol desconocido",
)
})
it("falls back for null role values", () => {
expect(
formatUserRole(null as unknown as string, roleCopy, fallbackCopy),
).toBe("Rol desconocido")
})
})
describe("formatPersonDepartment helper", () => {
const departmentCopy = {
IT: "IT",
ENGINEERING: "Ingeniería",
LOGISTICS: "Logística",
TRAFFIC: "Tráfico",
DRIVER: "Chofer",
ADMINISTRATION: "Administración",
SALES: "Ventas",
OTHER: "Otro",
}
const fallbackCopy = {
unknownDepartment: "Departamento desconocido",
}
it("formats known department values with localized labels", () => {
expect(
formatPersonDepartment("ENGINEERING", departmentCopy, fallbackCopy),
).toBe("Ingeniería")
expect(
formatPersonDepartment("ADMINISTRATION", departmentCopy, fallbackCopy),
).toBe("Administración")
})
it("falls back for unknown department values", () => {
expect(
formatPersonDepartment("UNKNOWN_DEPT", departmentCopy, fallbackCopy),
).toBe("Departamento desconocido")
})
it("falls back for null department values", () => {
expect(formatPersonDepartment(null, departmentCopy, fallbackCopy)).toBe(
"Departamento desconocido",
)
})
it("falls back for undefined department values", () => {
expect(
formatPersonDepartment(undefined, departmentCopy, fallbackCopy),
).toBe("Departamento desconocido")
})
})