Persist choices through to completed page
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
parseDocumentSectionsForDisplay,
|
||||
parseSectionsFromCreateFlowState,
|
||||
} from "../../lib/create/buildPublishPayload";
|
||||
import { mergeCoreValueDetailWithPresets } from "../../lib/create/finalReviewChipPresets";
|
||||
import type { CreateFlowState } from "../../app/(app)/create/types";
|
||||
|
||||
describe("buildPublishPayload", () => {
|
||||
@@ -63,6 +64,17 @@ describe("buildPublishPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers communityContext over summary for the published summary field", () => {
|
||||
const r = buildPublishPayload({
|
||||
title: "T",
|
||||
summary: "One-liner or leftover",
|
||||
communityContext: " Full community context. ",
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
if (!r.ok) return;
|
||||
expect(r.summary).toBe("Full community context.");
|
||||
});
|
||||
|
||||
it("uses valid state.sections when present", () => {
|
||||
const sections: CreateFlowState["sections"] = [
|
||||
{
|
||||
@@ -106,9 +118,15 @@ describe("buildPublishPayload", () => {
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
if (!r.ok) return;
|
||||
const preset2 = mergeCoreValueDetailWithPresets("2", "Beta", undefined);
|
||||
expect(r.document.coreValues).toEqual([
|
||||
{ chipId: "1", label: "Alpha", meaning: "m1", signals: "s1" },
|
||||
{ chipId: "2", label: "Beta", meaning: "", signals: "" },
|
||||
{
|
||||
chipId: "2",
|
||||
label: "Beta",
|
||||
meaning: preset2.meaning,
|
||||
signals: preset2.signals,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -121,6 +139,36 @@ describe("buildPublishPayload — methodSelections", () => {
|
||||
expect(r.document.methodSelections).toBeUndefined();
|
||||
});
|
||||
|
||||
it("derives methodSelections from template sections when selected ids are empty", () => {
|
||||
const r = buildPublishPayload({
|
||||
title: "T",
|
||||
sections: [
|
||||
{
|
||||
categoryName: "Communication",
|
||||
entries: [{ title: "Slack", body: "" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
if (!r.ok) return;
|
||||
const ms = r.document.methodSelections as
|
||||
| {
|
||||
communication?: Array<{
|
||||
id: string;
|
||||
sections: { corePrinciple: string };
|
||||
}>;
|
||||
}
|
||||
| undefined;
|
||||
expect(ms?.communication?.length).toBe(1);
|
||||
expect(ms?.communication?.[0]?.id).toBe("slack");
|
||||
const first = ms?.communication?.[0];
|
||||
expect(first?.sections.corePrinciple.length).toBeGreaterThan(10);
|
||||
const entries =
|
||||
(r.document.sections as Array<{ entries: Array<{ blocks?: unknown[] }> }>)[0]
|
||||
?.entries;
|
||||
expect(entries?.[0]?.blocks?.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("emits preset-only sections when a method is selected without an override", () => {
|
||||
const r = buildPublishPayload({
|
||||
title: "T",
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parsePublishedDocumentForCommunityRuleDisplay } from "../../lib/create/publishedDocumentToDisplaySections";
|
||||
|
||||
describe("parsePublishedDocumentForCommunityRuleDisplay", () => {
|
||||
it("returns [] for non-object document", () => {
|
||||
expect(parsePublishedDocumentForCommunityRuleDisplay(null)).toEqual([]);
|
||||
});
|
||||
|
||||
it("drops Overview and appends Values + methods with value body text", () => {
|
||||
const doc = {
|
||||
sections: [
|
||||
{
|
||||
categoryName: "Overview",
|
||||
entries: [{ title: "Community", body: "Our river cleanup org." }],
|
||||
},
|
||||
],
|
||||
coreValues: [
|
||||
{ chipId: "1", label: "Ecology", meaning: "We protect water.", signals: "Litter = violation." },
|
||||
],
|
||||
methodSelections: {
|
||||
communication: [
|
||||
{
|
||||
id: "signal",
|
||||
label: "Signal",
|
||||
sections: {
|
||||
corePrinciple: "Privacy first.",
|
||||
logisticsAdmin: "Admins rotate.",
|
||||
codeOfConduct: "No doxxing.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
|
||||
expect(out.map((s) => s.categoryName)).toEqual(["Values", "Communication"]);
|
||||
expect(out[0].entries[0].title).toBe("Ecology");
|
||||
expect(out[0].entries[0].body).toBe(
|
||||
"We protect water.\n\nLitter = violation.",
|
||||
);
|
||||
expect(out[0].entries[0].blocks).toBeUndefined();
|
||||
expect(out[1].entries[0].title).toBe("Signal");
|
||||
expect(out[1].entries[0].blocks?.length).toBeGreaterThanOrEqual(3);
|
||||
});
|
||||
|
||||
it("strips Overview but keeps other categories when both exist", () => {
|
||||
const doc = {
|
||||
sections: [
|
||||
{ categoryName: "Overview", entries: [{ title: "Community", body: "x" }] },
|
||||
{ categoryName: "Membership", entries: [{ title: "Open", body: "y" }] },
|
||||
],
|
||||
};
|
||||
const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
|
||||
expect(out.map((s) => s.categoryName)).toEqual(["Membership"]);
|
||||
});
|
||||
|
||||
it("prefers document.coreValues over a parallel Values section in document.sections", () => {
|
||||
const doc = {
|
||||
sections: [
|
||||
{
|
||||
categoryName: "Values",
|
||||
entries: [{ title: "From template", body: "Template body" }],
|
||||
},
|
||||
],
|
||||
coreValues: [
|
||||
{ label: "Should not duplicate", meaning: "x", signals: "y" },
|
||||
],
|
||||
};
|
||||
const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
|
||||
expect(out.length).toBe(1);
|
||||
expect(out[0].categoryName).toBe("Values");
|
||||
expect(out[0].entries[0].title).toBe("Should not duplicate");
|
||||
expect(out[0].entries[0].body).toBe("x\n\ny");
|
||||
});
|
||||
|
||||
it("enriches empty core value copy from presets (label match)", () => {
|
||||
const doc = {
|
||||
sections: [],
|
||||
coreValues: [
|
||||
{ chipId: "", label: "Interdependence", meaning: "", signals: "" },
|
||||
],
|
||||
};
|
||||
const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
|
||||
expect(out[0].entries[0].body).toMatch(/survival and success/);
|
||||
});
|
||||
|
||||
it("replaces template placeholder bodies with preset copy, Values first", () => {
|
||||
const placeholder =
|
||||
"Suggested focus for this governance area. Replace with your own language in the create flow.";
|
||||
const doc = {
|
||||
sections: [
|
||||
{
|
||||
categoryName: "Communication",
|
||||
entries: [{ title: "Slack", body: placeholder }],
|
||||
},
|
||||
{
|
||||
categoryName: "Values",
|
||||
entries: [{ title: "Adaptability", body: placeholder }],
|
||||
},
|
||||
],
|
||||
};
|
||||
const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
|
||||
expect(out.map((s) => s.categoryName)).toEqual(["Values", "Communication"]);
|
||||
expect(out[0].entries[0].body).not.toContain("Suggested focus");
|
||||
expect(out[0].entries[0].body.length).toBeGreaterThan(20);
|
||||
expect(out[1].entries[0].blocks?.length).toBeGreaterThanOrEqual(1);
|
||||
expect(out[1].entries[0].blocks?.[0]?.body?.length).toBeGreaterThan(10);
|
||||
});
|
||||
|
||||
it("matches parseDocumentSectionsForDisplay when no coreValues or methodSelections", () => {
|
||||
const doc = {
|
||||
sections: [
|
||||
{ categoryName: "X", entries: [{ title: "t", body: "b" }] },
|
||||
],
|
||||
};
|
||||
expect(parsePublishedDocumentForCommunityRuleDisplay(doc)).toEqual(
|
||||
doc.sections,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user