From a2815ae05fea11911336bc2277ed1930bc62c219 Mon Sep 17 00:00:00 2001
From: adilallo <39313955+adilallo@users.noreply.github.com>
Date: Sun, 22 Nov 2026 17:56:38 -0700
Subject: [PATCH] Keep every picked card on the finished Rule, and wait for its
words before Continue.
---
.../screens/review/FinalReviewScreen.tsx | 23 ++-
.../create/utils/createFlowFooterLabels.ts | 14 +-
lib/create/buildPublishPayload.ts | 34 ++--
lib/create/finalReviewChipPresets.ts | 19 ++-
lib/create/finalReviewChipWarnings.ts | 136 +++++++++++++--
lib/create/methodCardWizardPrefill.ts | 2 +-
.../normalizePublishedDocumentForEdit.ts | 40 +----
.../publishedDocumentToDisplaySections.ts | 12 +-
.../ruleSectionsFromMethodSelections.ts | 7 +-
.../create/reviewAndComplete/finalReview.json | 4 +
tests/components/FinalReviewPage.test.tsx | 8 +
tests/unit/buildPublishPayload.test.ts | 28 ++--
tests/unit/finalReviewContinue.test.ts | 158 +++++++++++++++++-
...publishedDocumentToDisplaySections.test.ts | 5 +-
tests/unit/ruleInviteCardMeta.test.ts | 31 ++++
.../ruleSectionsFromMethodSelections.test.ts | 10 ++
16 files changed, 417 insertions(+), 114 deletions(-)
diff --git a/app/(app)/create/screens/review/FinalReviewScreen.tsx b/app/(app)/create/screens/review/FinalReviewScreen.tsx
index e4e084a..bd313dc 100644
--- a/app/(app)/create/screens/review/FinalReviewScreen.tsx
+++ b/app/(app)/create/screens/review/FinalReviewScreen.tsx
@@ -18,7 +18,10 @@ import {
type FinalReviewCategoryRowDetailed,
} from "../../../../../lib/create/buildFinalReviewCategories";
import { communityInitialsFromTitle } from "../../../../../lib/create/communityInitials";
-import { finalReviewChipHasWarning } from "../../../../../lib/create/finalReviewChipWarnings";
+import {
+ finalReviewChipHasWarning,
+ finalReviewMissingWordsLabels,
+} from "../../../../../lib/create/finalReviewChipWarnings";
import { applyFinalReviewChipEditPatch } from "../../../../../lib/create/applyFinalReviewChipEditPatch";
import type {
TemplateChipDetail,
@@ -234,6 +237,11 @@ export function FinalReviewScreen({
const descriptionEmptyHint = t("communityContextEditModal.emptyHint");
+ const missingWordsLabels = useMemo(
+ () => finalReviewMissingWordsLabels(state),
+ [state],
+ );
+
const templatePath = isTemplateCreatePath(state);
const avatarUpload = useCommunityAvatarUpload();
const serverAvatarUrl = useCommunityAvatarDisplayUrl(state.communityAvatarUrl);
@@ -277,6 +285,19 @@ export function FinalReviewScreen({
: t("description")
}
>
+ {missingWordsLabels.length > 0 ? (
+
+ ) : null}
{bindingArbitrationNeedsSeparateYes(state) ? (
{
+ const missingRequiredCard = FINAL_REVIEW_REQUIRED_GROUPS.some((groupKey) => {
const row = rows.find((candidate) => candidate.groupKey === groupKey);
return !row || row.entries.length === 0;
});
+ if (missingRequiredCard) return true;
+ return rows.some((row) =>
+ row.entries.some((entry) =>
+ finalReviewChipBlocksContinue(state, entry.groupKey, entry.overrideKey),
+ ),
+ );
}
/**
diff --git a/lib/create/buildPublishPayload.ts b/lib/create/buildPublishPayload.ts
index 55db1db..a733b95 100644
--- a/lib/create/buildPublishPayload.ts
+++ b/lib/create/buildPublishPayload.ts
@@ -8,11 +8,10 @@ import type {
import type { CommunityRuleSection } from "../../app/components/type/CommunityRule/CommunityRule.types";
import { resolveMethodPresetIdFromLabel } from "./buildFinalReviewCategories";
import {
- communicationPresetFor,
- conflictManagementPresetFor,
- decisionApproachPresetFor,
- membershipPresetFor,
- mergeCoreValueDetailWithPresets,
+ emptyCommunicationDetails,
+ emptyConflictManagementDetails,
+ emptyDecisionApproachDetails,
+ emptyMembershipDetails,
publishedMethodDisplayLabel,
} from "./finalReviewChipPresets";
import { isDocumentEntry } from "./documentEntryGuards";
@@ -61,12 +60,12 @@ export function buildCoreValuesForDocument(state: CreateFlowState): Array<{
return snap
.filter((r) => selected.has(r.id))
.map((r) => {
- const merged = mergeCoreValueDetailWithPresets(r.id, r.label, details[r.id]);
+ const saved = details[r.id];
return {
chipId: r.id,
label: r.label,
- meaning: merged.meaning,
- signals: merged.signals,
+ meaning: typeof saved?.meaning === "string" ? saved.meaning : "",
+ signals: typeof saved?.signals === "string" ? saved.signals : "",
};
});
}
@@ -278,10 +277,8 @@ function publishedRowSupportText(
/**
* Merge `selected*MethodIds` with any saved `{group}MethodDetailsById`
- * overrides authored on the final-review screen. Preset defaults from the
- * shipped `messages/en/create/customRule/*.json` seed any sub-fields the
- * user didn't edit so consumers of `document.methodSelections` always see
- * a complete payload per method.
+ * overrides authored on the final-review screen. Blank parts stay blank —
+ * library presets are not filled in for text the pen holder never wrote.
*/
export function buildMethodSelectionsForDocument(
state: CreateFlowState,
@@ -297,7 +294,6 @@ export function buildMethodSelectionsForDocument(
);
if (commIds.length > 0) {
out.communication = commIds.map((id) => {
- const preset = communicationPresetFor(id);
const override = state.communicationMethodDetailsById?.[id];
const supportText = publishedRowSupportText(
id,
@@ -310,7 +306,7 @@ export function buildMethodSelectionsForDocument(
id,
state.customMethodCardMetaById,
),
- sections: override ? { ...preset, ...override } : preset,
+ sections: override ?? emptyCommunicationDetails(),
...(supportText ? { supportText } : {}),
};
});
@@ -322,7 +318,6 @@ export function buildMethodSelectionsForDocument(
);
if (memIds.length > 0) {
out.membership = memIds.map((id) => {
- const preset = membershipPresetFor(id);
const override = state.membershipMethodDetailsById?.[id];
const supportText = publishedRowSupportText(
id,
@@ -335,7 +330,7 @@ export function buildMethodSelectionsForDocument(
id,
state.customMethodCardMetaById,
),
- sections: override ? { ...preset, ...override } : preset,
+ sections: override ?? emptyMembershipDetails(),
...(supportText ? { supportText } : {}),
};
});
@@ -347,13 +342,11 @@ export function buildMethodSelectionsForDocument(
);
if (daIds.length > 0) {
out.decisionApproaches = daIds.map((id) => {
- const preset = decisionApproachPresetFor(id);
const override = state.decisionApproachDetailsById?.[id];
const supportText = publishedRowSupportText(
id,
state.customMethodCardMetaById,
);
- const merged = override ? { ...preset, ...override } : preset;
return {
id,
label: publishedMethodDisplayLabel(
@@ -362,7 +355,7 @@ export function buildMethodSelectionsForDocument(
state.customMethodCardMetaById,
),
sections: withoutUnpublishedDecisionConsensus(
- { ...merged },
+ { ...(override ?? emptyDecisionApproachDetails()) },
state.customMethodCardFieldBlocksById?.[id],
) as DecisionApproachDetailEntry,
...(supportText ? { supportText } : {}),
@@ -376,7 +369,6 @@ export function buildMethodSelectionsForDocument(
);
if (cmIds.length > 0) {
out.conflictManagement = cmIds.map((id) => {
- const preset = conflictManagementPresetFor(id);
const override = state.conflictManagementDetailsById?.[id];
const supportText = publishedRowSupportText(
id,
@@ -389,7 +381,7 @@ export function buildMethodSelectionsForDocument(
id,
state.customMethodCardMetaById,
),
- sections: override ? { ...preset, ...override } : preset,
+ sections: override ?? emptyConflictManagementDetails(),
...(supportText ? { supportText } : {}),
};
});
diff --git a/lib/create/finalReviewChipPresets.ts b/lib/create/finalReviewChipPresets.ts
index bf97fba..d120cc8 100644
--- a/lib/create/finalReviewChipPresets.ts
+++ b/lib/create/finalReviewChipPresets.ts
@@ -15,9 +15,8 @@ import type {
/**
* Catalog copy for method/value sections. Generate draft inserts these into
- * empty creation-modal fields. Publish still merges them onto saved overrides
- * so every method carries a complete section payload when the author only
- * edited a subset of fields.
+ * empty creation-modal fields. Publish keeps blank parts blank — it does not
+ * fill library text the pen holder never wrote.
*/
type CustomRuleMethodRow = {
id: string;
@@ -145,6 +144,16 @@ export function emptyDecisionApproachTextFields(
};
}
+export function emptyDecisionApproachDetails(): DecisionApproachDetailEntry {
+ return {
+ corePrinciple: "",
+ applicableScope: [],
+ selectedApplicableScope: [],
+ stepByStepInstructions: "",
+ objectionsDeadlocks: "",
+ };
+}
+
export function conflictManagementPresetFor(
id: string,
): ConflictManagementDetailEntry {
@@ -233,8 +242,8 @@ export function coreValuePresetForLabel(label: string): CoreValueDetailEntry {
}
/**
- * Published / display copy: saved draft wins when non-empty; otherwise preset
- * by chip id (numeric presets), then by label match in `coreValues.json`.
+ * Generate draft and legacy placeholder replacement: saved copy wins when
+ * non-empty; otherwise preset by chip id, then by label match.
*/
export function mergeCoreValueDetailWithPresets(
chipId: string,
diff --git a/lib/create/finalReviewChipWarnings.ts b/lib/create/finalReviewChipWarnings.ts
index aa1e7c5..c04f7a6 100644
--- a/lib/create/finalReviewChipWarnings.ts
+++ b/lib/create/finalReviewChipWarnings.ts
@@ -5,12 +5,34 @@ import type {
DecisionApproachDetailEntry,
MembershipMethodDetailEntry,
} from "../../app/(app)/create/types";
+import {
+ buildFinalReviewCategoryRowsDetailed,
+ type FinalReviewCategoryNames,
+} from "./buildFinalReviewCategories";
+import type { CustomMethodCardFieldBlock } from "./customMethodCardFieldBlocks";
+import { facetBlockHasContent } from "./methodCardWizardPrefill";
import type { TemplateFacetGroupKey } from "./templateReviewMapping";
+import { usesWizardFieldBlocksModalBody } from "./usesWizardFieldBlocksModalBody";
+
+const LABEL_NAMES: FinalReviewCategoryNames = {
+ values: "values",
+ communication: "communication",
+ membership: "membership",
+ decisions: "decisions",
+ conflict: "conflict",
+};
function missingText(...values: readonly (string | undefined)[]): boolean {
return values.some((value) => (value ?? "").trim().length === 0);
}
+function customFieldBlocksHaveWords(
+ blocks: readonly CustomMethodCardFieldBlock[] | undefined,
+): boolean {
+ if (!blocks || blocks.length === 0) return false;
+ return blocks.every(facetBlockHasContent);
+}
+
function communicationMissingWords(
saved: CommunicationMethodDetailEntry | undefined,
): boolean {
@@ -55,21 +77,30 @@ function conflictMissingWords(
);
}
-/**
- * A review chip shows a warning when its value is missing meaning or signals,
- * or a card is missing its words.
- */
-export function finalReviewChipHasWarning(
+function methodUsesCustomFieldBlocks(
state: CreateFlowState,
- groupKey: TemplateFacetGroupKey | null,
- overrideKey: string | null,
+ overrideKey: string,
): boolean {
- if (!groupKey || !overrideKey) return true;
+ return usesWizardFieldBlocksModalBody({
+ methodId: overrideKey,
+ meta: state.customMethodCardMetaById,
+ fieldBlocksById: state.customMethodCardFieldBlocksById,
+ modalEditUnlocked: true,
+ draftFieldBlocks: null,
+ });
+}
+
+function methodCardMissingWords(
+ state: CreateFlowState,
+ groupKey: Exclude,
+ overrideKey: string,
+): boolean {
+ if (methodUsesCustomFieldBlocks(state, overrideKey)) {
+ return !customFieldBlocksHaveWords(
+ state.customMethodCardFieldBlocksById?.[overrideKey],
+ );
+ }
switch (groupKey) {
- case "coreValues": {
- const saved = state.coreValueDetailsByChipId?.[overrideKey];
- return missingText(saved?.meaning, saved?.signals);
- }
case "communication":
return communicationMissingWords(
state.communicationMethodDetailsById?.[overrideKey],
@@ -88,3 +119,84 @@ export function finalReviewChipHasWarning(
);
}
}
+
+function valueHasMeaning(
+ state: CreateFlowState,
+ overrideKey: string,
+): boolean {
+ const saved = state.coreValueDetailsByChipId?.[overrideKey];
+ if ((saved?.meaning ?? "").trim().length > 0) return true;
+ const blocks = state.customMethodCardFieldBlocksById?.[overrideKey];
+ if (!blocks || blocks.length === 0) return false;
+ return blocks.some(
+ (block) =>
+ block.kind === "text" &&
+ block.id !== "facet-signals" &&
+ facetBlockHasContent(block),
+ );
+}
+
+function valueHasSignals(
+ state: CreateFlowState,
+ overrideKey: string,
+): boolean {
+ const saved = state.coreValueDetailsByChipId?.[overrideKey];
+ if ((saved?.signals ?? "").trim().length > 0) return true;
+ const blocks = state.customMethodCardFieldBlocksById?.[overrideKey];
+ if (!blocks || blocks.length === 0) return false;
+ const signalsBlock = blocks.find(
+ (block) => block.kind === "text" && block.id === "facet-signals",
+ );
+ if (!signalsBlock) return true;
+ return facetBlockHasContent(signalsBlock);
+}
+
+/**
+ * A review chip shows a warning when its value is missing meaning or signals,
+ * or a card is missing its words. Custom field text counts as those words.
+ */
+export function finalReviewChipHasWarning(
+ state: CreateFlowState,
+ groupKey: TemplateFacetGroupKey | null,
+ overrideKey: string | null,
+): boolean {
+ if (!groupKey || !overrideKey) return true;
+ if (groupKey === "coreValues") {
+ return !valueHasMeaning(state, overrideKey) || !valueHasSignals(state, overrideKey);
+ }
+ return methodCardMissingWords(state, groupKey, overrideKey);
+}
+
+/**
+ * Continue waits for every picked card's words and every picked value's
+ * meaning. Missing signals stay a warning only.
+ */
+export function finalReviewChipBlocksContinue(
+ state: CreateFlowState,
+ groupKey: TemplateFacetGroupKey | null,
+ overrideKey: string | null,
+): boolean {
+ if (!groupKey || !overrideKey) return false;
+ if (groupKey === "coreValues") {
+ return !valueHasMeaning(state, overrideKey);
+ }
+ return methodCardMissingWords(state, groupKey, overrideKey);
+}
+
+/** Chip labels that still need words before Continue. */
+export function finalReviewMissingWordsLabels(
+ state: CreateFlowState,
+): string[] {
+ const rows = buildFinalReviewCategoryRowsDetailed(state, LABEL_NAMES);
+ const labels: string[] = [];
+ for (const row of rows) {
+ for (const entry of row.entries) {
+ if (
+ finalReviewChipBlocksContinue(state, entry.groupKey, entry.overrideKey)
+ ) {
+ labels.push(entry.label);
+ }
+ }
+ }
+ return labels;
+}
diff --git a/lib/create/methodCardWizardPrefill.ts b/lib/create/methodCardWizardPrefill.ts
index 4eefee8..4fd7d70 100644
--- a/lib/create/methodCardWizardPrefill.ts
+++ b/lib/create/methodCardWizardPrefill.ts
@@ -233,7 +233,7 @@ export function facetDetailsToWizardFieldBlocks(
return mapFacetPrefillToWizardFieldBlocks(prefill);
}
-function facetBlockHasContent(block: CustomMethodCardFieldBlock): boolean {
+export function facetBlockHasContent(block: CustomMethodCardFieldBlock): boolean {
switch (block.kind) {
case "text":
return hasTrimmedText(block.placeholderText);
diff --git a/lib/create/normalizePublishedDocumentForEdit.ts b/lib/create/normalizePublishedDocumentForEdit.ts
index f31ea9e..fc128bb 100644
--- a/lib/create/normalizePublishedDocumentForEdit.ts
+++ b/lib/create/normalizePublishedDocumentForEdit.ts
@@ -4,13 +4,6 @@ import type { PublishedMethodSelections } from "./buildPublishPayload";
import { parseDocumentSectionsForDisplay } from "./buildPublishPayload";
import { resolveMethodPresetIdFromLabel } from "./buildFinalReviewCategories";
import { resolveCoreValueChipIdFromLabel } from "./finalReviewChipPresets";
-import {
- communicationPresetFor,
- conflictManagementPresetFor,
- decisionApproachPresetFor,
- membershipPresetFor,
- mergeCoreValueDetailWithPresets,
-} from "./finalReviewChipPresets";
import { templateCategoryToGroupKey } from "./templateReviewMapping";
import type { TemplateFacetGroupKey } from "./templateReviewMapping";
import { RULE_SECTION_CATEGORY } from "./ruleSectionsFromMethodSelections";
@@ -110,26 +103,9 @@ function sectionsRecordFromBlocks(
return out;
}
-function presetForMethod(
- groupKey: Exclude,
- id: string,
-): Record {
- switch (groupKey) {
- case "communication":
- return { ...communicationPresetFor(id) } as Record;
- case "membership":
- return { ...membershipPresetFor(id) } as Record;
- case "decisionApproaches":
- return { ...decisionApproachPresetFor(id) } as Record;
- case "conflictManagement":
- return { ...conflictManagementPresetFor(id) } as Record;
- }
-}
-
function sectionsRecordFromEntry(
entry: CommunityRuleSection["entries"][number],
groupKey: Exclude,
- presetId: string,
): Record {
const labelByKey = LABELS_BY_GROUP[groupKey];
const consensusKey =
@@ -140,16 +116,16 @@ function sectionsRecordFromEntry(
consensusLevelKey: consensusKey,
});
if (Object.keys(fromBlocks).length > 0) {
- return { ...presetForMethod(groupKey, presetId), ...fromBlocks };
+ return fromBlocks;
}
}
const body = (entry.body ?? "").trim();
if (body.length === 0) {
- return presetForMethod(groupKey, presetId);
+ return {};
}
- return { ...presetForMethod(groupKey, presetId), corePrinciple: body };
+ return { corePrinciple: body };
}
function coreValuesFromValuesSection(
@@ -169,18 +145,14 @@ function coreValuesFromValuesSection(
const parts = body.length > 0 ? body.split(/\n\n+/) : [];
const meaning = (parts[0] ?? "").trim();
const signals = parts.slice(1).join("\n\n").trim();
- const merged = mergeCoreValueDetailWithPresets("", label, {
- meaning,
- signals,
- });
const chipId =
resolveCoreValueChipIdFromLabel(label) ??
`hydrated-${label.toLowerCase()}`;
out.push({
chipId,
label,
- meaning: merged.meaning,
- signals: merged.signals,
+ meaning,
+ signals,
});
}
@@ -213,7 +185,7 @@ function methodSelectionsFromDisplaySections(
rows.push({
id,
label,
- sections: sectionsRecordFromEntry(entry, groupKey, id),
+ sections: sectionsRecordFromEntry(entry, groupKey),
});
}
if (rows.length > 0) {
diff --git a/lib/create/publishedDocumentToDisplaySections.ts b/lib/create/publishedDocumentToDisplaySections.ts
index 452b914..ebb07be 100644
--- a/lib/create/publishedDocumentToDisplaySections.ts
+++ b/lib/create/publishedDocumentToDisplaySections.ts
@@ -80,7 +80,6 @@ const CM_LABELS: Record = {
function needsPlaceholderPresetEnrichment(entry: CommunityRuleEntry): boolean {
if (entry.blocks && entry.blocks.length > 0) return false;
const b = (entry.body ?? "").trim();
- if (b.length === 0) return true;
return b === TEMPLATE_COMPOSITION_SUGGESTED_BODY;
}
@@ -196,15 +195,12 @@ function sectionFromStoredCoreValues(
for (const row of raw) {
if (!row || typeof row !== "object") continue;
const o = row as Record;
- const chipId = typeof o.chipId === "string" ? o.chipId : "";
const label = nonEmptyTrimmed(o.label);
if (!label) continue;
- const merged = mergeCoreValueDetailWithPresets(chipId, label, {
- meaning: typeof o.meaning === "string" ? o.meaning : "",
- signals: typeof o.signals === "string" ? o.signals : "",
- });
- const meaning = (merged.meaning ?? "").trim();
- const signals = (merged.signals ?? "").trim();
+ const meaning =
+ typeof o.meaning === "string" ? o.meaning.trim() : "";
+ const signals =
+ typeof o.signals === "string" ? o.signals.trim() : "";
const bodyParts: string[] = [];
if (meaning.length > 0) bodyParts.push(meaning);
if (signals.length > 0) bodyParts.push(signals);
diff --git a/lib/create/ruleSectionsFromMethodSelections.ts b/lib/create/ruleSectionsFromMethodSelections.ts
index fc1b469..a24b327 100644
--- a/lib/create/ruleSectionsFromMethodSelections.ts
+++ b/lib/create/ruleSectionsFromMethodSelections.ts
@@ -221,8 +221,7 @@ export function communityRuleEntryFromMethodChip(
const blocks = [...presetBlocks, ...wizardBlocks];
const description = nonEmptyTrimmed(options?.supportText);
if (blocks.length === 0) {
- if (!description) return null;
- return { title, body: description };
+ return { title, body: description ?? "" };
}
return {
title,
@@ -387,8 +386,8 @@ export function sectionFromConflict(
}
/**
- * Swap template `sections` method rows for fully-resolved entries built from
- * `methodSelections` (preset + overrides).
+ * Swap template `sections` method rows for entries built from
+ * `methodSelections`.
*/
export function replaceMethodSectionsWithMethodSelections(
sections: CommunityRuleSection[],
diff --git a/messages/en/create/reviewAndComplete/finalReview.json b/messages/en/create/reviewAndComplete/finalReview.json
index 59a6508..f5440f6 100644
--- a/messages/en/create/reviewAndComplete/finalReview.json
+++ b/messages/en/create/reviewAndComplete/finalReview.json
@@ -30,6 +30,10 @@
"title": "Binding arbitration needs each member’s own yes",
"description": "Open admission and membership by token do not record that yes. Each member still has to agree separately before binding arbitration applies to them."
},
+ "missingWordsWarning": {
+ "title": "Add words before you finish",
+ "description": "These still need words: {labels}."
+ },
"categories": [
{
"name": "Values",
diff --git a/tests/components/FinalReviewPage.test.tsx b/tests/components/FinalReviewPage.test.tsx
index 9cffcba..f8f2f72 100644
--- a/tests/components/FinalReviewPage.test.tsx
+++ b/tests/components/FinalReviewPage.test.tsx
@@ -241,6 +241,14 @@ describe("FinalReviewScreen — prefilled selections", () => {
expect(
screen.getByRole("button", { name: "Signal, missing words" }),
).toBeInTheDocument();
+ expect(
+ screen.getByText("Add words before you finish"),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(
+ /These still need words: Accessibility, Signal, Open admission/,
+ ),
+ ).toBeInTheDocument();
});
it("warns when binding arbitration sits next to a join that records no yes", async () => {
diff --git a/tests/unit/buildPublishPayload.test.ts b/tests/unit/buildPublishPayload.test.ts
index d7c92f8..b87bcdd 100644
--- a/tests/unit/buildPublishPayload.test.ts
+++ b/tests/unit/buildPublishPayload.test.ts
@@ -4,7 +4,6 @@ import {
parseDocumentSectionsForDisplay,
parseSectionsFromCreateFlowState,
} from "../../lib/create/buildPublishPayload";
-import { mergeCoreValueDetailWithPresets } from "../../lib/create/finalReviewChipPresets";
import type { CreateFlowState } from "../../app/(app)/create/types";
describe("buildPublishPayload", () => {
@@ -144,15 +143,9 @@ 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: preset2.meaning,
- signals: preset2.signals,
- },
+ { chipId: "2", label: "Beta", meaning: "", signals: "" },
]);
});
});
@@ -188,11 +181,12 @@ describe("buildPublishPayload — methodSelections", () => {
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);
+ expect(first?.sections.corePrinciple).toBe("");
const entries =
- (r.document.sections as Array<{ entries: Array<{ blocks?: unknown[] }> }>)[0]
- ?.entries;
- expect(entries?.[0]?.blocks?.length).toBeGreaterThanOrEqual(1);
+ (r.document.sections as Array<{
+ entries: Array<{ title: string; body: string; blocks?: unknown[] }>;
+ }>)[0]?.entries;
+ expect(entries?.[0]).toEqual({ title: "Slack", body: "" });
});
it("uses customMethodCardMetaById label when preset id is unknown", () => {
@@ -251,7 +245,7 @@ describe("buildPublishPayload — methodSelections", () => {
]);
});
- it("emits preset-only sections when a method is selected without an override", () => {
+ it("keeps blank card parts blank when a method is selected without an override", () => {
const r = buildPublishPayload({
title: "T",
selectedCommunicationMethodIds: ["signal"],
@@ -270,9 +264,7 @@ describe("buildPublishPayload — methodSelections", () => {
};
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);
+ expect(entry.sections.corePrinciple).toBe("");
});
it("does not seed 75% consensus on a custom decision-making card", () => {
@@ -311,7 +303,7 @@ describe("buildPublishPayload — methodSelections", () => {
expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBeUndefined();
});
- it("keeps catalog decision consensus in methodSelections", () => {
+ it("does not fill catalog decision consensus when the card has no words", () => {
const r = buildPublishPayload({
title: "T",
selectedDecisionApproachIds: ["lazy-consensus"],
@@ -321,7 +313,7 @@ describe("buildPublishPayload — methodSelections", () => {
const ms = r.document.methodSelections as {
decisionApproaches?: Array<{ sections: { consensusLevel?: number } }>;
};
- expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBe(100);
+ expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBeUndefined();
});
it("merges override on top of preset for the selected method", () => {
diff --git a/tests/unit/finalReviewContinue.test.ts b/tests/unit/finalReviewContinue.test.ts
index 2351fcf..dc7edf8 100644
--- a/tests/unit/finalReviewContinue.test.ts
+++ b/tests/unit/finalReviewContinue.test.ts
@@ -1,7 +1,11 @@
import { describe, it, expect } from "vitest";
import { isFinalReviewContinueBlocked } from "../../app/(app)/create/utils/createFlowFooterLabels";
import { communityInitialsFromTitle } from "../../lib/create/communityInitials";
-import { finalReviewChipHasWarning } from "../../lib/create/finalReviewChipWarnings";
+import {
+ finalReviewChipBlocksContinue,
+ finalReviewChipHasWarning,
+ finalReviewMissingWordsLabels,
+} from "../../lib/create/finalReviewChipWarnings";
import type { CreateFlowState } from "../../app/(app)/create/types";
const completeCards: CreateFlowState = {
@@ -12,11 +16,47 @@ const completeCards: CreateFlowState = {
selectedConflictManagementIds: ["conflict-ladder"],
};
+const completeCardsWithWords: CreateFlowState = {
+ ...completeCards,
+ communicationMethodDetailsById: {
+ signal: {
+ corePrinciple: "We talk in the open.",
+ logisticsAdmin: "Post in Signal.",
+ codeOfConduct: "No pile-ons.",
+ },
+ },
+ membershipMethodDetailsById: {
+ "open-admission": {
+ eligibility: "Anyone who shares the work.",
+ joiningProcess: "Show up.",
+ expectations: "Keep the keys.",
+ },
+ },
+ decisionApproachDetailsById: {
+ "lazy-consensus": {
+ corePrinciple: "Silence is assent.",
+ applicableScope: [],
+ selectedApplicableScope: [],
+ stepByStepInstructions: "Post the proposal.",
+ objectionsDeadlocks: "A named block stops it.",
+ },
+ },
+ conflictManagementDetailsById: {
+ "conflict-ladder": {
+ corePrinciple: "Start small.",
+ applicableScope: [],
+ selectedApplicableScope: [],
+ processProtocol: "Talk, then mediate.",
+ restorationFallbacks: "A panel if that fails.",
+ },
+ },
+};
+
describe("isFinalReviewContinueBlocked", () => {
it("blocks when the community name is empty", () => {
expect(
isFinalReviewContinueBlocked({
- ...completeCards,
+ ...completeCardsWithWords,
title: " ",
}),
).toBe(true);
@@ -25,14 +65,45 @@ describe("isFinalReviewContinueBlocked", () => {
it("blocks when any of the four questions has no card", () => {
expect(
isFinalReviewContinueBlocked({
- ...completeCards,
+ ...completeCardsWithWords,
selectedMembershipMethodIds: [],
}),
).toBe(true);
});
- it("does not block when values are empty and the four questions have cards", () => {
- expect(isFinalReviewContinueBlocked(completeCards)).toBe(false);
+ it("blocks when a picked card is missing its words", () => {
+ expect(isFinalReviewContinueBlocked(completeCards)).toBe(true);
+ });
+
+ it("does not block when values are empty and every card has its words", () => {
+ expect(isFinalReviewContinueBlocked(completeCardsWithWords)).toBe(false);
+ });
+
+ it("blocks when a picked value is missing its meaning", () => {
+ expect(
+ isFinalReviewContinueBlocked({
+ ...completeCardsWithWords,
+ selectedCoreValueIds: ["1"],
+ coreValuesChipsSnapshot: [
+ { id: "1", label: "Care", state: "selected" },
+ ],
+ }),
+ ).toBe(true);
+ });
+
+ it("does not block when a value has meaning but no signals", () => {
+ expect(
+ isFinalReviewContinueBlocked({
+ ...completeCardsWithWords,
+ selectedCoreValueIds: ["1"],
+ coreValuesChipsSnapshot: [
+ { id: "1", label: "Care", state: "selected" },
+ ],
+ coreValueDetailsByChipId: {
+ "1": { meaning: "We look after each other.", signals: "" },
+ },
+ }),
+ ).toBe(false);
});
});
@@ -70,6 +141,83 @@ describe("finalReviewChipHasWarning", () => {
),
).toBe(false);
});
+
+ it("clears the warning when a custom card's fields have text", () => {
+ const customId = "00000000-0000-4000-8000-000000000190";
+ expect(
+ finalReviewChipHasWarning(
+ {
+ customMethodCardMetaById: {
+ [customId]: { label: "S13 comms card", supportText: "" },
+ },
+ customMethodCardFieldBlocksById: {
+ [customId]: [
+ {
+ kind: "text",
+ id: "b1",
+ blockTitle: "How we talk",
+ placeholderText: "Post in the hall.",
+ },
+ ],
+ },
+ },
+ "communication",
+ customId,
+ ),
+ ).toBe(false);
+ });
+});
+
+describe("finalReviewChipBlocksContinue", () => {
+ it("does not block a value that has meaning but no signals", () => {
+ expect(
+ finalReviewChipBlocksContinue(
+ {
+ coreValueDetailsByChipId: {
+ "1": { meaning: "Care", signals: "" },
+ },
+ },
+ "coreValues",
+ "1",
+ ),
+ ).toBe(false);
+ });
+
+ it("blocks a custom card until its fields have text", () => {
+ const customId = "00000000-0000-4000-8000-000000000191";
+ expect(
+ finalReviewChipBlocksContinue(
+ {
+ customMethodCardMetaById: {
+ [customId]: { label: "S13 comms card", supportText: "" },
+ },
+ customMethodCardFieldBlocksById: {
+ [customId]: [
+ {
+ kind: "text",
+ id: "b1",
+ blockTitle: "How we talk",
+ placeholderText: "",
+ },
+ ],
+ },
+ },
+ "communication",
+ customId,
+ ),
+ ).toBe(true);
+ });
+});
+
+describe("finalReviewMissingWordsLabels", () => {
+ it("names the cards that still need words", () => {
+ expect(finalReviewMissingWordsLabels(completeCards)).toEqual([
+ "Signal",
+ "Open admission",
+ "Lazy consensus",
+ "Conflict ladder",
+ ]);
+ });
});
describe("communityInitialsFromTitle", () => {
diff --git a/tests/unit/publishedDocumentToDisplaySections.test.ts b/tests/unit/publishedDocumentToDisplaySections.test.ts
index 7a38a7b..3836ef1 100644
--- a/tests/unit/publishedDocumentToDisplaySections.test.ts
+++ b/tests/unit/publishedDocumentToDisplaySections.test.ts
@@ -81,7 +81,7 @@ describe("parsePublishedDocumentForCommunityRuleDisplay", () => {
expect(out[0].entries[0].body).toBe("x\n\ny");
});
- it("enriches empty core value copy from presets (label match)", () => {
+ it("keeps empty core value copy blank instead of filling library text", () => {
const doc = {
sections: [],
coreValues: [
@@ -89,7 +89,8 @@ describe("parsePublishedDocumentForCommunityRuleDisplay", () => {
],
};
const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
- expect(out[0].entries[0].body).toMatch(/well-being is bound up/);
+ expect(out[0].entries[0].title).toBe("Interdependence");
+ expect(out[0].entries[0].body).toBe("");
});
it("replaces template placeholder bodies with preset copy, Values first", () => {
diff --git a/tests/unit/ruleInviteCardMeta.test.ts b/tests/unit/ruleInviteCardMeta.test.ts
index 2470ef2..1934e83 100644
--- a/tests/unit/ruleInviteCardMeta.test.ts
+++ b/tests/unit/ruleInviteCardMeta.test.ts
@@ -61,6 +61,37 @@ describe("inviteRuleCountsLabel", () => {
}),
).toBe("3 VALUES AND 2 CARDS");
});
+
+ it("counts titled cards that still have no words", () => {
+ expect(
+ inviteRuleCountsLabel({
+ methodSelections: {
+ communication: [
+ {
+ id: "signal",
+ label: "Signal",
+ sections: {
+ corePrinciple: "",
+ logisticsAdmin: "",
+ codeOfConduct: "",
+ },
+ },
+ ],
+ membership: [
+ {
+ id: "open-admission",
+ label: "Open admission",
+ sections: {
+ eligibility: "",
+ joiningProcess: "",
+ expectations: "",
+ },
+ },
+ ],
+ },
+ }),
+ ).toBe("0 VALUES AND 2 CARDS");
+ });
});
describe("inviteRuleCountsSpoken", () => {
diff --git a/tests/unit/ruleSectionsFromMethodSelections.test.ts b/tests/unit/ruleSectionsFromMethodSelections.test.ts
index 28069d4..08212e3 100644
--- a/tests/unit/ruleSectionsFromMethodSelections.test.ts
+++ b/tests/unit/ruleSectionsFromMethodSelections.test.ts
@@ -45,6 +45,16 @@ describe("withoutUnpublishedDecisionConsensus", () => {
});
describe("communityRuleEntryFromMethodChip", () => {
+ it("keeps a titled card when there are no words yet", () => {
+ expect(
+ communityRuleEntryFromMethodChip(
+ "Signal",
+ { corePrinciple: "" },
+ { corePrinciple: "Core Principle" },
+ ),
+ ).toEqual({ title: "Signal", body: "" });
+ });
+
it("publishes supportText as body when there are no labeled blocks", () => {
expect(
communityRuleEntryFromMethodChip(