feat: unify Person and User creation form with conditional password

This commit is contained in:
2026-06-16 21:48:59 +02:00
parent e5717461cf
commit 1f5a849bf5
21 changed files with 462 additions and 171 deletions
@@ -28,8 +28,16 @@ describe("admin users dictionary", () => {
expect(users.form).toEqual({
nameLabel: "Name",
namePlaceholder: "Full name",
firstNameLabel: "First Name",
firstNamePlaceholder: "First name",
lastNameLabel: "Last Name",
lastNamePlaceholder: "Last name",
departmentLabel: "Department",
departmentPlaceholder: "Select a department",
emailLabel: "Email",
emailPlaceholder: "user@example.com",
phoneLabel: "Phone",
phonePlaceholder: "Phone",
passwordLabel: "Password",
passwordPlaceholder: "Minimum 8 characters",
roleLabel: "Role",
@@ -112,8 +120,16 @@ describe("admin users dictionary", () => {
expect(users.form).toEqual({
nameLabel: "Nombre",
namePlaceholder: "Nombre completo",
firstNameLabel: "Nombre",
firstNamePlaceholder: "Nombre",
lastNameLabel: "Apellido",
lastNamePlaceholder: "Apellido",
departmentLabel: "Departamento",
departmentPlaceholder: "Selecciona un departamento",
emailLabel: "Correo electrónico",
emailPlaceholder: "usuario@ejemplo.com",
phoneLabel: "Teléfono",
phonePlaceholder: "Teléfono",
passwordLabel: "Contraseña",
passwordPlaceholder: "Mínimo 8 caracteres",
roleLabel: "Rol",
@@ -0,0 +1,52 @@
import { describe, expect, it } from "vitest"
import { dictionaries, getDictionary } from "@/i18n/dictionaries"
describe("admin users unified form dictionary", () => {
it("provides unified form Person field keys in English admin.users.form", () => {
const form = getDictionary("en").admin.users.form
expect(form.firstNameLabel).toBe("First Name")
expect(form.firstNamePlaceholder).toBe("First name")
expect(form.lastNameLabel).toBe("Last Name")
expect(form.lastNamePlaceholder).toBe("Last name")
expect(form.departmentLabel).toBe("Department")
expect(form.departmentPlaceholder).toBe("Select a department")
expect(form.phoneLabel).toBe("Phone")
expect(form.phonePlaceholder).toBe("Phone")
})
it("provides unified form Person field keys in Spanish admin.users.form", () => {
const form = getDictionary("es").admin.users.form
expect(form.firstNameLabel).toBe("Nombre")
expect(form.firstNamePlaceholder).toBe("Nombre")
expect(form.lastNameLabel).toBe("Apellido")
expect(form.lastNamePlaceholder).toBe("Apellido")
expect(form.departmentLabel).toBe("Departamento")
expect(form.departmentPlaceholder).toBe("Selecciona un departamento")
expect(form.phoneLabel).toBe("Teléfono")
expect(form.phonePlaceholder).toBe("Teléfono")
})
it("maintains structural parity for admin.users.form between English and Spanish after Person keys", () => {
const enKeys = extractKeyPaths(dictionaries.en.admin.users.form)
const esKeys = extractKeyPaths(dictionaries.es.admin.users.form)
expect(esKeys).toEqual(enKeys)
})
})
function extractKeyPaths(value: unknown, prefix = ""): string[] {
if (!isPlainObject(value)) return [prefix]
return Object.keys(value)
.sort()
.flatMap((key) =>
extractKeyPaths(value[key], prefix ? `${prefix}.${key}` : key),
)
}
function isPlainObject(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value)
}