Custom add and create flow polish

This commit is contained in:
adilallo
2026-05-08 20:32:24 -06:00
parent 26bcd61ea3
commit 026a1e6d71
68 changed files with 6208 additions and 527 deletions
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import {
createFlowStateFromPublishedRule,
isPublishedRuleHydratePatchIncomplete,
isPublishedRuleSelectionMissing,
methodSectionsPinsForHydratedSelections,
methodSectionsPinsFromPublishedHydratePatch,
@@ -68,6 +69,72 @@ describe("isPublishedRuleSelectionMissing", () => {
});
});
describe("isPublishedRuleHydratePatchIncomplete", () => {
it("is true when facet ids are present but custom method meta from patch is missing in state", () => {
const customId = "b7c0a9f3-0000-4000-8000-000000000001";
const patch = createFlowStateFromPublishedRule({
id: "r",
title: "T",
summary: "",
document: {
methodSelections: {
communication: [
{
id: customId,
label: "My custom comms method",
sections: {
corePrinciple: "x",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
},
},
});
const state = {
sections: [],
title: "T",
editingPublishedRuleId: "r",
selectedCommunicationMethodIds: [customId],
} as CreateFlowState;
expect(isPublishedRuleSelectionMissing(state, patch)).toBe(false);
expect(isPublishedRuleHydratePatchIncomplete(state, patch)).toBe(true);
});
it("is false when patch meta keys exist on state", () => {
const customId = "b7c0a9f3-0000-4000-8000-000000000001";
const patch = createFlowStateFromPublishedRule({
id: "r",
title: "T",
summary: "",
document: {
methodSelections: {
communication: [
{
id: customId,
label: "My custom comms method",
sections: {
corePrinciple: "",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
},
},
});
const state = {
sections: [],
title: "T",
editingPublishedRuleId: "r",
selectedCommunicationMethodIds: [customId],
customMethodCardMetaById: patch.customMethodCardMetaById,
} as CreateFlowState;
expect(isPublishedRuleHydratePatchIncomplete(state, patch)).toBe(false);
});
});
describe("methodSectionsPinsForHydratedSelections / methodSectionsPinsFromPublishedHydratePatch", () => {
it("alias matches hydrated-selection helper output", () => {
const partial: Partial<CreateFlowState> = {
@@ -218,6 +285,35 @@ describe("createFlowStateFromPublishedRule", () => {
expect(partial.sections).toEqual([]);
});
it("hydrates customMethodCardMetaById for user-authored method ids from methodSelections", () => {
const customId = "b7c0a9f3-0000-4000-8000-000000000001";
const partial = createFlowStateFromPublishedRule({
id: "rule-custom",
title: "C",
summary: "",
document: {
methodSelections: {
communication: [
{
id: customId,
label: "Custom channel policy",
sections: {
corePrinciple: "cp",
logisticsAdmin: "la",
codeOfConduct: "cc",
},
},
],
},
},
});
expect(partial.selectedCommunicationMethodIds).toEqual([customId]);
expect(partial.customMethodCardMetaById?.[customId]).toEqual({
label: "Custom channel policy",
supportText: "",
});
});
it("sets sections to [] even when methodSelections is missing (edit hydrate)", () => {
const partial = createFlowStateFromPublishedRule({
id: "rule-2",