d3f721ce58
Extract types.ts, FilterDropdown.tsx, BooleanBadge.tsx from ResourcesClient.tsx into resource-client/ subdirectory. ResourcesClient reduced from 1,613 to 1,507 lines. Fix TypeScript strict mode errors across 8 test files: - Add id/order to BlueprintFieldDefinition test objects - Use FieldType enum instead of string literals in useFilters - Add non-null assertions for mock.calls array access - Type ScrollDiv for jsdom scrollLeft workaround - Fix exactOptionalPropertyTypes violations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getPlanningEntryMutationId } from "./planningEntryIds.js";
|
|
|
|
describe("getPlanningEntryMutationId", () => {
|
|
// ---------------------------------------------------------------------------
|
|
// Priority: entityId first
|
|
// ---------------------------------------------------------------------------
|
|
|
|
it("returns entityId when all three fields are present", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
entityId: "entity-1",
|
|
sourceAllocationId: "alloc-1",
|
|
});
|
|
expect(result).toBe("entity-1");
|
|
});
|
|
|
|
it("returns entityId when sourceAllocationId is absent", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
entityId: "entity-1",
|
|
});
|
|
expect(result).toBe("entity-1");
|
|
});
|
|
|
|
it("returns entityId when sourceAllocationId is null", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
entityId: "entity-1",
|
|
sourceAllocationId: null,
|
|
});
|
|
expect(result).toBe("entity-1");
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Fallback: sourceAllocationId when entityId is absent/null/undefined
|
|
// ---------------------------------------------------------------------------
|
|
|
|
it("returns sourceAllocationId when entityId is null", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
entityId: null,
|
|
sourceAllocationId: "alloc-1",
|
|
});
|
|
expect(result).toBe("alloc-1");
|
|
});
|
|
|
|
it("returns sourceAllocationId when entityId is undefined", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
entityId: undefined as string | undefined,
|
|
sourceAllocationId: "alloc-1",
|
|
} as Parameters<typeof getPlanningEntryMutationId>[0]);
|
|
expect(result).toBe("alloc-1");
|
|
});
|
|
|
|
it("returns sourceAllocationId when entityId field is omitted", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
sourceAllocationId: "alloc-1",
|
|
});
|
|
expect(result).toBe("alloc-1");
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Final fallback: id
|
|
// ---------------------------------------------------------------------------
|
|
|
|
it("returns id when both entityId and sourceAllocationId are null", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
entityId: null,
|
|
sourceAllocationId: null,
|
|
});
|
|
expect(result).toBe("id-1");
|
|
});
|
|
|
|
it("returns id when both entityId and sourceAllocationId are undefined", () => {
|
|
const result = getPlanningEntryMutationId({
|
|
id: "id-1",
|
|
} as Parameters<typeof getPlanningEntryMutationId>[0]);
|
|
expect(result).toBe("id-1");
|
|
});
|
|
|
|
it("returns id when only id is provided", () => {
|
|
const result = getPlanningEntryMutationId({ id: "id-only" });
|
|
expect(result).toBe("id-only");
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Return-type guarantee
|
|
// ---------------------------------------------------------------------------
|
|
|
|
it("always returns a string", () => {
|
|
const cases = [
|
|
{ id: "x", entityId: "e", sourceAllocationId: "a" },
|
|
{ id: "x", entityId: null, sourceAllocationId: "a" },
|
|
{ id: "x", entityId: null, sourceAllocationId: null },
|
|
];
|
|
cases.forEach((entry) => {
|
|
expect(typeof getPlanningEntryMutationId(entry)).toBe("string");
|
|
});
|
|
});
|
|
});
|