Implement share and export components

This commit is contained in:
adilallo
2026-04-29 22:27:46 -06:00
parent a31a36c926
commit a37a72c71d
58 changed files with 3153 additions and 117 deletions
@@ -1,5 +1,185 @@
import { describe, expect, it } from "vitest";
import { createFlowStateFromPublishedRule } from "../../lib/create/publishedDocumentToCreateFlowState";
import {
createFlowStateFromPublishedRule,
isPublishedRuleSelectionMissing,
methodSectionsPinsForHydratedSelections,
methodSectionsPinsFromPublishedHydratePatch,
} from "../../lib/create/publishedDocumentToCreateFlowState";
import type { CreateFlowState } from "../../app/(app)/create/types";
describe("isPublishedRuleSelectionMissing", () => {
it("is true when published patch has communication ids but state has none", () => {
const patch = createFlowStateFromPublishedRule({
id: "r",
title: "T",
summary: "",
document: {
methodSelections: {
communication: [
{
id: "slack",
label: "Slack",
sections: {
corePrinciple: "",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
},
},
});
const state = {
sections: [],
title: "T",
editingPublishedRuleId: "r",
} as CreateFlowState;
expect(isPublishedRuleSelectionMissing(state, patch)).toBe(true);
});
it("is false when sections are clear and state already has matching facet ids", () => {
const patch = createFlowStateFromPublishedRule({
id: "r",
title: "T",
summary: "",
document: {
methodSelections: {
communication: [
{
id: "slack",
label: "Slack",
sections: {
corePrinciple: "",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
},
},
});
const state = {
sections: [],
title: "T",
editingPublishedRuleId: "r",
selectedCommunicationMethodIds: ["slack"],
} as CreateFlowState;
expect(isPublishedRuleSelectionMissing(state, patch)).toBe(false);
});
});
describe("methodSectionsPinsForHydratedSelections / methodSectionsPinsFromPublishedHydratePatch", () => {
it("alias matches hydrated-selection helper output", () => {
const partial: Partial<CreateFlowState> = {
selectedCommunicationMethodIds: ["a"],
selectedConflictManagementIds: ["b"],
};
expect(methodSectionsPinsFromPublishedHydratePatch(partial)).toEqual(
methodSectionsPinsForHydratedSelections(partial),
);
});
});
describe("methodSectionsPinsFromPublishedHydratePatch", () => {
it("sets communication when published patch includes communication ids", () => {
const patch = createFlowStateFromPublishedRule({
id: "r",
title: "T",
summary: "",
document: {
methodSelections: {
communication: [
{
id: "slack",
label: "Slack",
sections: {
corePrinciple: "",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
},
},
});
expect(methodSectionsPinsFromPublishedHydratePatch(patch)).toEqual({
communication: true,
});
});
it("sets all four method facets when each has selections on the patch", () => {
const patch = createFlowStateFromPublishedRule({
id: "r",
title: "T",
summary: "",
document: {
methodSelections: {
communication: [
{
id: "slack",
label: "S",
sections: {
corePrinciple: "",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
membership: [
{
id: "x",
label: "X",
sections: {
eligibility: "",
joiningProcess: "",
expectations: "",
},
},
],
decisionApproaches: [
{
id: "d",
label: "D",
sections: {
corePrinciple: "",
applicableScope: [],
selectedApplicableScope: [],
stepByStepInstructions: "",
consensusLevel: 0,
objectionsDeadlocks: "",
},
},
],
conflictManagement: [
{
id: "c",
label: "C",
sections: {
corePrinciple: "",
applicableScope: [],
selectedApplicableScope: [],
processProtocol: "",
restorationFallbacks: "",
},
},
],
},
},
});
expect(methodSectionsPinsFromPublishedHydratePatch(patch)).toEqual({
communication: true,
membership: true,
decisionApproaches: true,
conflictManagement: true,
});
});
it("returns {} when patch has no method-card selections", () => {
expect(methodSectionsPinsFromPublishedHydratePatch({ sections: [] })).toEqual(
{},
);
});
});
describe("createFlowStateFromPublishedRule", () => {
it("maps coreValues and methodSelections into draft fields", () => {