Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+79
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildHrRequestOwnVM, buildHrRequestApproverVM, buildHrRequestTemplateListVM, type HrRequestStatus } from "./hr-request.vm.js";
|
||||
|
||||
// AK-P17b — request VMs are pure. These tests cover the kind/status → i18n-key
|
||||
// mapping, the open-status withdraw flag and the template picker shape.
|
||||
|
||||
describe("buildHrRequestOwnVM", () => {
|
||||
const row = (id: string, status: HrRequestStatus) => ({
|
||||
id,
|
||||
title: "New laptop",
|
||||
kind: "hardware" as const,
|
||||
status,
|
||||
createdIso: new Date("2026-07-01").toISOString(),
|
||||
detailHref: `/acme/hr/requests/${id}`,
|
||||
});
|
||||
|
||||
it("maps kind/status to i18n keys", () => {
|
||||
const vm = buildHrRequestOwnVM({ rows: [row("r1", "submitted")], newHref: "/x" });
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data?.rows[0]?.kindLabelKey).toBe("hr.requests.kind.hardware");
|
||||
expect(vm.data?.rows[0]?.statusLabelKey).toBe("hr.requests.status.submitted");
|
||||
});
|
||||
|
||||
it("allows withdraw only while the request is open", () => {
|
||||
const vm = buildHrRequestOwnVM({
|
||||
rows: [row("r1", "submitted"), row("r2", "clarification"), row("r3", "approved"), row("r4", "rejected"), row("r5", "withdrawn")],
|
||||
newHref: "/x",
|
||||
});
|
||||
const byId = new Map(vm.data!.rows.map((r) => [r.id, r.canWithdraw]));
|
||||
expect(byId.get("r1")).toBe(true);
|
||||
expect(byId.get("r2")).toBe(true);
|
||||
expect(byId.get("r3")).toBe(false);
|
||||
expect(byId.get("r4")).toBe(false);
|
||||
expect(byId.get("r5")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps an empty list in a ready state with the empty-state keys", () => {
|
||||
const vm = buildHrRequestOwnVM({ rows: [], newHref: "/acme/hr/requests/new" });
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data?.newHref).toBe("/acme/hr/requests/new");
|
||||
expect(vm.data?.emptyHeadlineKey).toBe("hr.requests.own.empty.headline");
|
||||
expect(vm.data?.emptyBodyKey).toBe("hr.requests.own.empty.body");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildHrRequestApproverVM", () => {
|
||||
it("adds the employee label and drops the raw kind/status from the row", () => {
|
||||
const vm = buildHrRequestApproverVM({
|
||||
rows: [{ id: "r1", title: "Training", employeeLabel: "Alex Doe", kind: "training", status: "submitted", createdIso: new Date("2026-07-01").toISOString(), detailHref: "/x" }],
|
||||
});
|
||||
const row = vm.data!.rows[0]! as unknown as Record<string, unknown>;
|
||||
expect(row.employeeLabel).toBe("Alex Doe");
|
||||
expect(row.kindLabelKey).toBe("hr.requests.kind.training");
|
||||
expect(row.statusLabelKey).toBe("hr.requests.status.submitted");
|
||||
// The approver row carries only the derived keys, not the raw unions.
|
||||
expect(row).not.toHaveProperty("kind");
|
||||
expect(row).not.toHaveProperty("status");
|
||||
});
|
||||
|
||||
it("keeps an empty approver list in a ready state", () => {
|
||||
const vm = buildHrRequestApproverVM({ rows: [] });
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data?.emptyHeadlineKey).toBe("hr.requests.approver.empty.headline");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildHrRequestTemplateListVM", () => {
|
||||
it("maps the template kind to its i18n key and keeps the active flag", () => {
|
||||
const vm = buildHrRequestTemplateListVM({
|
||||
rows: [{ id: "t1", title: "Expense claim", kind: "expense", description: null, isActive: true, editHref: "/x" }],
|
||||
createHref: "/acme/hr/requests/templates/new",
|
||||
});
|
||||
expect(vm.data?.rows[0]?.kindLabelKey).toBe("hr.requests.kind.expense");
|
||||
expect(vm.data?.rows[0]?.isActive).toBe(true);
|
||||
expect(vm.data?.rows[0]?.description).toBeNull();
|
||||
expect(vm.data?.createHref).toBe("/acme/hr/requests/templates/new");
|
||||
expect(vm.data?.emptyHeadlineKey).toBe("hr.requests.templates.empty.headline");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user