232 lines
6.3 KiB
TypeScript
232 lines
6.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { isFinalReviewContinueBlocked } from "../../app/(app)/create/utils/createFlowFooterLabels";
|
|
import { communityInitialsFromTitle } from "../../lib/create/communityInitials";
|
|
import {
|
|
finalReviewChipBlocksContinue,
|
|
finalReviewChipHasWarning,
|
|
finalReviewMissingWordsLabels,
|
|
} from "../../lib/create/finalReviewChipWarnings";
|
|
import type { CreateFlowState } from "../../app/(app)/create/types";
|
|
|
|
const completeCards: CreateFlowState = {
|
|
title: "Oak Park Commons",
|
|
selectedCommunicationMethodIds: ["signal"],
|
|
selectedMembershipMethodIds: ["open-admission"],
|
|
selectedDecisionApproachIds: ["lazy-consensus"],
|
|
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({
|
|
...completeCardsWithWords,
|
|
title: " ",
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("blocks when any of the four questions has no card", () => {
|
|
expect(
|
|
isFinalReviewContinueBlocked({
|
|
...completeCardsWithWords,
|
|
selectedMembershipMethodIds: [],
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|
|
|
|
describe("finalReviewChipHasWarning", () => {
|
|
it("warns when a value is missing meaning or signals", () => {
|
|
expect(
|
|
finalReviewChipHasWarning(
|
|
{
|
|
coreValueDetailsByChipId: {
|
|
"1": { meaning: "Care", signals: "" },
|
|
},
|
|
},
|
|
"coreValues",
|
|
"1",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("warns when a method card has no saved words", () => {
|
|
expect(
|
|
finalReviewChipHasWarning({}, "communication", "signal"),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("does not warn when meaning and signals are both filled", () => {
|
|
expect(
|
|
finalReviewChipHasWarning(
|
|
{
|
|
coreValueDetailsByChipId: {
|
|
"1": { meaning: "Care", signals: "We talk over people." },
|
|
},
|
|
},
|
|
"coreValues",
|
|
"1",
|
|
),
|
|
).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", () => {
|
|
it("uses the first letters of the first two words", () => {
|
|
expect(communityInitialsFromTitle("Oak Park Commons")).toBe("OP");
|
|
});
|
|
|
|
it("uses two letters from a single word", () => {
|
|
expect(communityInitialsFromTitle("Neighbors")).toBe("NE");
|
|
});
|
|
});
|