Final review edit modals created

This commit is contained in:
adilallo
2026-04-20 17:57:17 -06:00
parent c08cd62872
commit a22d53e860
27 changed files with 2410 additions and 620 deletions
+47 -1
View File
@@ -1,5 +1,8 @@
import { describe, expect, it } from "vitest";
import { buildTemplateCustomizePrefill } from "../../lib/create/applyTemplatePrefill";
import {
buildCoreValuesPrefillFromTemplateBody,
buildTemplateCustomizePrefill,
} from "../../lib/create/applyTemplatePrefill";
import coreValuesMessages from "../../messages/en/create/customRule/coreValues.json";
function coreValuePresetId(label: string): string {
@@ -107,3 +110,46 @@ describe("buildTemplateCustomizePrefill", () => {
expect(prefill).toEqual({});
});
});
describe("buildCoreValuesPrefillFromTemplateBody", () => {
it("returns {} for malformed bodies", () => {
expect(buildCoreValuesPrefillFromTemplateBody(null)).toEqual({});
expect(buildCoreValuesPrefillFromTemplateBody({})).toEqual({});
expect(
buildCoreValuesPrefillFromTemplateBody({ sections: "nope" }),
).toEqual({});
});
it("returns {} when the body has no Values section", () => {
expect(
buildCoreValuesPrefillFromTemplateBody({
sections: [
{ categoryName: "Communication", entries: [{ title: "Signal" }] },
],
}),
).toEqual({});
});
it("seeds the snapshot + selected ids from the Values section only", () => {
const prefill = buildCoreValuesPrefillFromTemplateBody({
sections: [
{
categoryName: "Values",
entries: [
{ title: "Consensus", body: "" },
{ title: "Community Care", body: "" },
],
},
{
categoryName: "Communication",
entries: [{ title: "Signal", body: "" }],
},
],
});
const selected = prefill.selectedCoreValueIds ?? [];
expect(selected).toContain(coreValuePresetId("Consensus"));
expect(selected).toContain(coreValuePresetId("Community Care"));
// Methods should not be touched by the values-only helper.
expect(prefill.selectedCommunicationMethodIds).toBeUndefined();
});
});
@@ -114,7 +114,11 @@ describe("buildFinalReviewCategoriesFromState", () => {
]);
});
it("does not duplicate Values when sections already includes one", () => {
it("prefers the chip snapshot over a duplicated Values section in sections", () => {
// The use-without-changes handler now strips Values from `sections` and
// seeds the snapshot, but legacy drafts persisted before that fix can
// still arrive here with both sources present. The snapshot wins so the
// final-review chip modal can attach edits via the per-chip id.
const state: CreateFlowState = {
sections: [
{
@@ -129,7 +133,7 @@ describe("buildFinalReviewCategoriesFromState", () => {
};
const rows = buildFinalReviewCategoriesFromState(state, NAMES);
expect(rows).toEqual([
{ name: "Values", chips: ["Consciousness"] },
{ name: "Values", chips: ["Accessibility"] },
]);
});
});
+83
View File
@@ -113,6 +113,89 @@ describe("buildPublishPayload", () => {
});
});
describe("buildPublishPayload — methodSelections", () => {
it("omits document.methodSelections when no method group is selected", () => {
const r = buildPublishPayload({ title: "T" });
expect(r.ok).toBe(true);
if (!r.ok) return;
expect(r.document.methodSelections).toBeUndefined();
});
it("emits preset-only sections when a method is selected without an override", () => {
const r = buildPublishPayload({
title: "T",
selectedCommunicationMethodIds: ["signal"],
});
expect(r.ok).toBe(true);
if (!r.ok) return;
const ms = r.document.methodSelections as
| Record<string, Array<Record<string, unknown>>>
| undefined;
expect(ms).toBeDefined();
expect(ms?.communication?.length).toBe(1);
const entry = ms?.communication?.[0] as {
id: string;
label: string;
sections: { corePrinciple: string };
};
expect(entry.id).toBe("signal");
expect(entry.label).toBe("Signal");
// Preset corePrinciple is non-empty for `signal` in the shipped messages
// file — proves we read presets when no override is present.
expect(entry.sections.corePrinciple.length).toBeGreaterThan(0);
});
it("merges override on top of preset for the selected method", () => {
const r = buildPublishPayload({
title: "T",
selectedCommunicationMethodIds: ["signal"],
communicationMethodDetailsById: {
signal: {
corePrinciple: "OVERRIDE PRINCIPLE",
logisticsAdmin: "OVERRIDE LOGISTICS",
codeOfConduct: "OVERRIDE COC",
},
},
});
expect(r.ok).toBe(true);
if (!r.ok) return;
const ms = r.document.methodSelections as
| Record<string, Array<Record<string, unknown>>>
| undefined;
const entry = ms?.communication?.[0] as {
sections: {
corePrinciple: string;
logisticsAdmin: string;
codeOfConduct: string;
};
};
expect(entry.sections.corePrinciple).toBe("OVERRIDE PRINCIPLE");
expect(entry.sections.logisticsAdmin).toBe("OVERRIDE LOGISTICS");
expect(entry.sections.codeOfConduct).toBe("OVERRIDE COC");
});
it("emits a methodSelections entry per selected group", () => {
const r = buildPublishPayload({
title: "T",
selectedCommunicationMethodIds: ["signal"],
selectedMembershipMethodIds: ["open-access"],
selectedDecisionApproachIds: ["lazy-consensus"],
selectedConflictManagementIds: ["peer-mediation"],
});
expect(r.ok).toBe(true);
if (!r.ok) return;
const ms = r.document.methodSelections as
| Record<string, Array<unknown>>
| undefined;
expect(Object.keys(ms ?? {}).sort()).toEqual([
"communication",
"conflictManagement",
"decisionApproaches",
"membership",
]);
});
});
describe("parseDocumentSectionsForDisplay", () => {
it("returns empty for non-object", () => {
expect(parseDocumentSectionsForDisplay(null)).toEqual([]);