Create flow centralization and cleanup

This commit is contained in:
adilallo
2026-04-30 08:11:55 -06:00
parent a37a72c71d
commit b7446873cd
26 changed files with 709 additions and 361 deletions
+42
View File
@@ -0,0 +1,42 @@
import { describe, expect, it } from "vitest";
import {
CREATE_FLOW_SYNC_DRAFT_QUERY,
CREATE_FLOW_SYNC_DRAFT_VALUE,
CREATE_ROUTES,
createFlowStepPath,
createFlowStepPathAfterStrippingReviewReturn,
createFlowStepPathWithSyncDraft,
} from "../../app/(app)/create/utils/createFlowPaths";
import { CREATE_FLOW_REVIEW_RETURN_QUERY_KEY } from "../../app/(app)/create/utils/flowSteps";
describe("createFlowPaths (CR-92 §2)", () => {
it("createFlowStepPath builds segment path", () => {
expect(createFlowStepPath("review")).toBe("/create/review");
});
it("createFlowStepPath encodes query", () => {
expect(
createFlowStepPath("completed", { celebrate: "1", foo: "bar" }),
).toBe("/create/completed?celebrate=1&foo=bar");
});
it("createFlowStepPathWithSyncDraft", () => {
expect(createFlowStepPathWithSyncDraft("final-review")).toBe(
`/create/final-review?${CREATE_FLOW_SYNC_DRAFT_QUERY}=${CREATE_FLOW_SYNC_DRAFT_VALUE}`,
);
});
it("createFlowStepPathAfterStrippingReviewReturn drops reviewReturn only", () => {
const sp = new URLSearchParams(
`a=1&${CREATE_FLOW_REVIEW_RETURN_QUERY_KEY}=final-review&b=2`,
);
expect(createFlowStepPathAfterStrippingReviewReturn("final-review", sp)).toBe(
"/create/final-review?a=1&b=2",
);
});
it("CREATE_ROUTES constants", () => {
expect(CREATE_ROUTES.review).toBe("/create/review");
expect(CREATE_ROUTES.completed).toBe("/create/completed");
});
});
@@ -0,0 +1,13 @@
import { describe, expect, it } from "vitest";
import { CREATE_FLOW_SCREEN_REGISTRY } from "../../app/(app)/create/utils/createFlowScreenRegistry";
import { VALID_STEPS } from "../../app/(app)/create/utils/flowSteps";
describe("create flow registry vs valid steps (CR-92 §3)", () => {
it("CREATE_FLOW_SCREEN_REGISTRY defines every VALID_STEPS id", () => {
const keys = new Set(Object.keys(CREATE_FLOW_SCREEN_REGISTRY));
for (const step of VALID_STEPS) {
expect(keys.has(step), `missing registry entry for ${step}`).toBe(true);
}
expect(keys.size).toBe(VALID_STEPS.length);
});
});
+78
View File
@@ -0,0 +1,78 @@
import { describe, expect, it } from "vitest";
import {
assignTemplateMethodSlugsToPrefill,
createFlowStepForCustomRuleFacetGroup,
CUSTOM_RULE_FACETS,
CUSTOM_RULE_FACET_BY_GROUP,
METHOD_FACET_API_SECTION_IDS,
PUBLISHED_CUSTOM_RULE_SELECTION_KEYS,
readMethodPresetsForFacetGroup,
STRIP_CUSTOM_RULE_SELECTION_STATE_KEYS,
} from "../../lib/create/customRuleFacets";
import { SECTION_IDS } from "../../lib/server/validation/methodFacetsSchemas";
import type { CreateFlowStep } from "../../app/(app)/create/types";
describe("customRuleFacets (CR-92)", () => {
it("METHOD_FACET_API_SECTION_IDS matches API SECTION_IDS", () => {
expect([...METHOD_FACET_API_SECTION_IDS]).toEqual([...SECTION_IDS]);
});
it("has five rows in stable order", () => {
expect(CUSTOM_RULE_FACETS.map((r) => r.facetGroupKey)).toEqual([
"coreValues",
"communication",
"membership",
"decisionApproaches",
"conflictManagement",
]);
});
it("facet group map covers every TemplateFacetGroupKey", () => {
for (const row of CUSTOM_RULE_FACETS) {
expect(CUSTOM_RULE_FACET_BY_GROUP.get(row.facetGroupKey)).toBe(row);
}
});
it("createFlowStepForCustomRuleFacetGroup matches footer steps", () => {
const steps = new Set<CreateFlowStep>();
for (const row of CUSTOM_RULE_FACETS) {
steps.add(createFlowStepForCustomRuleFacetGroup(row.facetGroupKey));
}
expect(steps.has("core-values")).toBe(true);
expect(steps.has("communication-methods")).toBe(true);
expect(steps.has("membership-methods")).toBe(true);
expect(steps.has("decision-approaches")).toBe(true);
expect(steps.has("conflict-management")).toBe(true);
});
it("assignTemplateMethodSlugsToPrefill maps normalised keys", () => {
const prefill: Record<string, unknown> = {};
expect(assignTemplateMethodSlugsToPrefill(prefill, "communications", ["a"])).toBe(
true,
);
expect(prefill.selectedCommunicationMethodIds).toEqual(["a"]);
});
it("published selection keys are the five selected* fields", () => {
expect(PUBLISHED_CUSTOM_RULE_SELECTION_KEYS).toEqual([
"selectedCoreValueIds",
"selectedCommunicationMethodIds",
"selectedMembershipMethodIds",
"selectedDecisionApproachIds",
"selectedConflictManagementIds",
]);
});
it("strip keys include method pins once", () => {
const pinCount = STRIP_CUSTOM_RULE_SELECTION_STATE_KEYS.filter(
(k) => k === "methodSectionsPinCommitted",
).length;
expect(pinCount).toBe(1);
});
it("readMethodPresetsForFacetGroup returns ids for communication", () => {
const m = readMethodPresetsForFacetGroup("communication");
expect(m.length).toBeGreaterThan(0);
expect(typeof m[0]!.id).toBe("string");
});
});