Skip setup questions on the template path and collect name, photo, and description without recommendations.
Customize opens a dialog then walks the template decks; Use without changes lands on final review with Has Name Field. Template cards stay first, the engine is not called, and the catalog no longer shows a recommended tag.
This commit is contained in:
1 parent
53d236d0d5
commit
6498d52541
37 files changed
+1450
-733
No files matched your search
@@ -196,10 +196,10 @@ describe("CommunityReviewScreen — pendingTemplateAction redirect", () => {
|
||||
expect(testRouter.push).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("redirects Use without changes to community-name so identity is not skipped", async () => {
|
||||
it("redirects Use without changes leftover pins to final review", async () => {
|
||||
render(<ReviewWithPendingAction mode="useWithoutChanges" />);
|
||||
await waitFor(() => {
|
||||
expect(testRouter.replace).toHaveBeenCalledWith("/create/community-name");
|
||||
expect(testRouter.replace).toHaveBeenCalledWith("/create/final-review");
|
||||
});
|
||||
expect(testRouter.push).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -30,5 +30,6 @@ describe("Create flow templates picker", () => {
|
||||
"href",
|
||||
"/create/review-template/solidarity-network?fromFlow=1",
|
||||
);
|
||||
expect(screen.queryByText("RECOMMENDED")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -52,6 +52,7 @@ describe("Templates page (/templates)", () => {
|
||||
for (const entry of GOVERNANCE_TEMPLATE_CATALOG) {
|
||||
expect(screen.getByText(entry.title)).toBeInTheDocument();
|
||||
}
|
||||
expect(screen.queryByText("RECOMMENDED")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("each template card is a link to review flow for its slug", () => {
|
||||
|
||||
@@ -332,4 +332,37 @@ describe("Rule Component", () => {
|
||||
|
||||
expect(screen.queryByText("RECOMMENDED")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders name, logo upload, and description fields when hasNameField is set", () => {
|
||||
const onNameChange = vi.fn();
|
||||
const onDescriptionChange = vi.fn();
|
||||
const onLogoClick = vi.fn();
|
||||
render(
|
||||
<Rule
|
||||
title=""
|
||||
interactive={false}
|
||||
expanded
|
||||
hasNameField
|
||||
nameValue=""
|
||||
nameLabel="Community name"
|
||||
namePlaceholder="Enter community name"
|
||||
onNameChange={onNameChange}
|
||||
descriptionLabel="What does your community do?"
|
||||
descriptionPlaceholder="Describe your community"
|
||||
descriptionHelperText="Optional"
|
||||
onDescriptionChange={onDescriptionChange}
|
||||
onLogoClick={onLogoClick}
|
||||
logoUploadAriaLabel="Add a logo"
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByLabelText("Community name")).toBeInTheDocument();
|
||||
expect(screen.getByPlaceholderText("Enter community name")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByLabelText("What does your community do?"),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("Optional")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add a logo" }));
|
||||
expect(onLogoClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildCoreValuesPrefillFromTemplateBody,
|
||||
buildTemplateCustomizePrefill,
|
||||
templatePresetDetailsFromPrefill,
|
||||
} from "../../lib/create/applyTemplatePrefill";
|
||||
import { methodSectionsPinsForHydratedSelections } from "../../lib/create/publishedDocumentToCreateFlowState";
|
||||
import coreValuesMessages from "../../messages/en/create/customRule/coreValues.json";
|
||||
@@ -196,3 +197,45 @@ describe("buildTemplateCustomizePrefill + method card pins", () => {
|
||||
expect(methodSectionsPinsForHydratedSelections(prefill)).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildTemplateCustomizePrefill from templateChips.json", () => {
|
||||
it("prefers chip ids for a known slug over body titles", () => {
|
||||
const prefill = buildTemplateCustomizePrefill(
|
||||
{
|
||||
sections: [
|
||||
{
|
||||
categoryName: "Communication",
|
||||
entries: [{ title: "Signal" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
"consensus",
|
||||
);
|
||||
expect(prefill.selectedCommunicationMethodIds).toEqual([
|
||||
"how-we-run-meetings",
|
||||
"in-person-meetings",
|
||||
"loomio",
|
||||
]);
|
||||
expect(prefill.selectedCoreValueIds).toEqual([
|
||||
"consensus",
|
||||
"community-care",
|
||||
"horizontalism",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("templatePresetDetailsFromPrefill", () => {
|
||||
it("fills catalog copy for each prefilled chip", () => {
|
||||
const details = templatePresetDetailsFromPrefill({
|
||||
selectedCommunicationMethodIds: ["in-person-meetings"],
|
||||
selectedCoreValueIds: ["consensus"],
|
||||
});
|
||||
expect(
|
||||
details.communicationMethodDetailsById?.["in-person-meetings"]
|
||||
?.corePrinciple,
|
||||
).not.toBe("");
|
||||
expect(
|
||||
details.coreValueDetailsByChipId?.consensus?.meaning,
|
||||
).not.toBe("");
|
||||
});
|
||||
});
|
||||
@@ -92,30 +92,67 @@ describe("flowSteps", () => {
|
||||
expect(getPreviousStep("communication-methods", opts)).toBe("core-values");
|
||||
});
|
||||
|
||||
it("useWithoutChangesIdentityOnly walks name → description → photo → final-review", () => {
|
||||
const opts = { useWithoutChangesIdentityOnly: true } as const;
|
||||
expect(getNextStep("community-name", opts)).toBe("community-context");
|
||||
expect(getNextStep("community-context", opts)).toBe("community-upload");
|
||||
expect(getNextStep("community-size", opts)).toBe("community-upload");
|
||||
expect(getNextStep("setup-questions", opts)).toBe("community-upload");
|
||||
expect(getNextStep("community-upload", opts)).toBe("final-review");
|
||||
expect(getNextStep("final-review", opts)).toBe("confirm-stakeholders");
|
||||
expect(getPreviousStep("community-context", opts)).toBe("community-name");
|
||||
expect(getPreviousStep("community-upload", opts)).toBe("community-context");
|
||||
expect(getPreviousStep("final-review", opts)).toBe("community-upload");
|
||||
expect(getPreviousStep("community-name", opts)).toBeNull();
|
||||
it("templatePathMode customize skips community setup and walks the decks", () => {
|
||||
const opts = { templatePathMode: "customize" as const };
|
||||
expect(getNextStep("informational", opts)).toBe("core-values");
|
||||
expect(getNextStep("community-name", opts)).toBe("core-values");
|
||||
expect(getNextStep("setup-questions", opts)).toBe("core-values");
|
||||
expect(getNextStep("core-values", opts)).toBe("communication-methods");
|
||||
expect(getNextStep("conflict-management", opts)).toBe("final-review");
|
||||
expect(getPreviousStep("core-values", opts)).toBeNull();
|
||||
expect(getPreviousStep("final-review", opts)).toBe("conflict-management");
|
||||
});
|
||||
|
||||
it("useWithoutChangesIdentityOnly composes with skipCommunitySave", () => {
|
||||
it("templatePathMode useWithoutChanges skips community setup and the decks", () => {
|
||||
const opts = { templatePathMode: "useWithoutChanges" as const };
|
||||
expect(getNextStep("informational", opts)).toBe("final-review");
|
||||
expect(getNextStep("community-name", opts)).toBe("final-review");
|
||||
expect(getNextStep("setup-questions", opts)).toBe("final-review");
|
||||
expect(getNextStep("core-values", opts)).toBe("final-review");
|
||||
expect(getNextStep("final-review", opts)).toBe("confirm-stakeholders");
|
||||
expect(getPreviousStep("final-review", opts)).toBeNull();
|
||||
});
|
||||
|
||||
it("templatePathMode composes with skipCommunitySave", () => {
|
||||
const opts = {
|
||||
skipCommunitySave: true,
|
||||
useWithoutChangesIdentityOnly: true,
|
||||
} as const;
|
||||
templatePathMode: "useWithoutChanges" as const,
|
||||
};
|
||||
expect(getNextStep("community-upload", opts)).toBe("final-review");
|
||||
expect(getPreviousStep("final-review", opts)).toBe("community-upload");
|
||||
expect(getPreviousStep("final-review", opts)).toBeNull();
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget returns template review when use-without slug is set on final-review", () => {
|
||||
it("resolveCreateFlowBackTarget returns template review from use-without-changes final-review", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget(
|
||||
"final-review",
|
||||
{ templatePathMode: "useWithoutChanges" },
|
||||
"mutual-aid-mondays",
|
||||
),
|
||||
).toEqual({ kind: "templateReview", slug: "mutual-aid-mondays" });
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget returns template review from customize values", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget(
|
||||
"core-values",
|
||||
{ templatePathMode: "customize" },
|
||||
"mutual-aid-mondays",
|
||||
),
|
||||
).toEqual({ kind: "templateReview", slug: "mutual-aid-mondays" });
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget sends customize final-review back to the conflict deck", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget(
|
||||
"final-review",
|
||||
{ templatePathMode: "customize" },
|
||||
"mutual-aid-mondays",
|
||||
),
|
||||
).toEqual({ kind: "step", step: "conflict-management" });
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget returns template review when a slug is set without a mode", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget(
|
||||
"final-review",
|
||||
@@ -125,26 +162,6 @@ describe("flowSteps", () => {
|
||||
).toEqual({ kind: "templateReview", slug: "mutual-aid-mondays" });
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget sends identity-only community-name back to template review", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget(
|
||||
"community-name",
|
||||
{ useWithoutChangesIdentityOnly: true },
|
||||
"mutual-aid-mondays",
|
||||
),
|
||||
).toEqual({ kind: "templateReview", slug: "mutual-aid-mondays" });
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget uses photo step behind final-review on the identity-only path", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget(
|
||||
"final-review",
|
||||
{ useWithoutChangesIdentityOnly: true },
|
||||
"mutual-aid-mondays",
|
||||
),
|
||||
).toEqual({ kind: "step", step: "community-upload" });
|
||||
});
|
||||
|
||||
it("resolveCreateFlowBackTarget falls back to linear previous when slug is absent", () => {
|
||||
expect(
|
||||
resolveCreateFlowBackTarget("confirm-stakeholders", undefined, undefined),
|
||||
|
||||
@@ -69,22 +69,56 @@ describe("useTemplateReviewActions", () => {
|
||||
);
|
||||
}
|
||||
|
||||
it("direct Use without changes walks identity from community-name", async () => {
|
||||
it("Customize opens the dialog and does not route until Continue", async () => {
|
||||
const { result } = renderActions({});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.handleUseWithoutChanges();
|
||||
await result.current.handleCustomize();
|
||||
});
|
||||
|
||||
expect(markCreateFlowInteraction).toHaveBeenCalled();
|
||||
expect(router.push).toHaveBeenCalledWith("/create/community-name");
|
||||
expect(applied?.pendingTemplateAction).toEqual({
|
||||
slug: "mutual-aid-mondays",
|
||||
mode: "useWithoutChanges",
|
||||
});
|
||||
expect(router.push).not.toHaveBeenCalled();
|
||||
expect(result.current.customizeDialog).toEqual(
|
||||
expect.objectContaining({
|
||||
slug: "mutual-aid-mondays",
|
||||
templateTitle: "Mutual Aid Mondays",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("direct Use without changes ignores a leftover draft title", async () => {
|
||||
it("Customize Continue prefills cards, drops setup answers, and walks the decks", async () => {
|
||||
const { result } = renderActions({
|
||||
setupTraits: { employer: true },
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.handleCustomize();
|
||||
});
|
||||
act(() => {
|
||||
result.current.confirmCustomizeDialog({
|
||||
title: "Neighborhood",
|
||||
communityContext: "We meet weekly",
|
||||
communityLocation: "Oakland",
|
||||
});
|
||||
});
|
||||
|
||||
expect(router.push).toHaveBeenCalledWith("/create/core-values");
|
||||
expect(updateState).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
title: "Neighborhood",
|
||||
communityContext: "We meet weekly",
|
||||
communityLocation: "Oakland",
|
||||
setupTraits: undefined,
|
||||
pendingTemplateAction: {
|
||||
slug: "mutual-aid-mondays",
|
||||
mode: "customize",
|
||||
},
|
||||
templateReviewBackSlug: "mutual-aid-mondays",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("direct Use without changes goes to final review and clears leftover identity", async () => {
|
||||
replaceState.mockImplementation(
|
||||
(updater: (_prev: CreateFlowState) => CreateFlowState) => {
|
||||
applied = updater({
|
||||
@@ -101,15 +135,18 @@ describe("useTemplateReviewActions", () => {
|
||||
await result.current.handleUseWithoutChanges();
|
||||
});
|
||||
|
||||
expect(router.push).toHaveBeenCalledWith("/create/community-name");
|
||||
expect(router.push).toHaveBeenCalledWith("/create/final-review");
|
||||
expect(applied?.title).toBeUndefined();
|
||||
expect(applied?.communityContext).toBeUndefined();
|
||||
expect(applied?.currentStep).toBeUndefined();
|
||||
expect(applied?.setupTraits).toBeUndefined();
|
||||
expect(applied?.pendingTemplateAction?.mode).toBe("useWithoutChanges");
|
||||
expect(applied?.pendingTemplateAction).toEqual({
|
||||
slug: "mutual-aid-mondays",
|
||||
mode: "useWithoutChanges",
|
||||
});
|
||||
});
|
||||
|
||||
it("in-flow Use without changes skips identity and keeps the community name", async () => {
|
||||
it("in-flow Use without changes keeps the community name and pins the template path", async () => {
|
||||
replaceState.mockImplementation(
|
||||
(updater: (_prev: CreateFlowState) => CreateFlowState) => {
|
||||
applied = updater({
|
||||
@@ -132,38 +169,11 @@ describe("useTemplateReviewActions", () => {
|
||||
expect(router.push).toHaveBeenCalledWith("/create/final-review");
|
||||
expect(applied?.title).toBe("Neighborhood");
|
||||
expect(applied?.communityContext).toBe("We meet weekly");
|
||||
expect(applied?.setupTraits).toEqual({ employer: true });
|
||||
expect(applied?.pendingTemplateAction).toBeUndefined();
|
||||
expect(applied?.setupTraits).toBeUndefined();
|
||||
expect(applied?.pendingTemplateAction).toEqual({
|
||||
slug: "mutual-aid-mondays",
|
||||
mode: "useWithoutChanges",
|
||||
});
|
||||
expect(applied?.templateReviewBackSlug).toBe("mutual-aid-mondays");
|
||||
});
|
||||
|
||||
it("customize with a community name drops leftover setup answers", async () => {
|
||||
const { result } = renderActions({
|
||||
title: "Neighborhood",
|
||||
setupTraits: { employer: true },
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.handleCustomize();
|
||||
});
|
||||
|
||||
expect(router.push).toHaveBeenCalledWith("/create/core-values");
|
||||
expect(updateState).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ setupTraits: undefined }),
|
||||
);
|
||||
});
|
||||
|
||||
it("customize without a community name leaves setup answers for the questionnaire", async () => {
|
||||
const { result } = renderActions({
|
||||
setupTraits: { employer: true },
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.handleCustomize();
|
||||
});
|
||||
|
||||
expect(router.push).toHaveBeenCalledWith("/create/informational");
|
||||
const patch = updateState.mock.calls[0]?.[0] as CreateFlowState;
|
||||
expect(patch).not.toHaveProperty("setupTraits");
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import {
|
||||
deriveRecommendedTemplateSlugs,
|
||||
gridEntriesWithFacetScores,
|
||||
} from "../../lib/templates/templateGridPresentation";
|
||||
import { fetchRankedTemplatesByFacets } from "../../lib/create/fetchTemplates";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { ruleTemplateToGridEntry } from "../../lib/templates/templateGridPresentation";
|
||||
import type { RuleTemplateDto } from "../../lib/create/fetchTemplates";
|
||||
|
||||
const minimalTemplate = (slug: string, title: string): RuleTemplateDto => ({
|
||||
@@ -17,116 +13,9 @@ const minimalTemplate = (slug: string, title: string): RuleTemplateDto => ({
|
||||
featured: false,
|
||||
});
|
||||
|
||||
describe("deriveRecommendedTemplateSlugs", () => {
|
||||
it("returns at most limit slugs in the top score tier (API order for ties)", () => {
|
||||
const templates = ["a", "b", "c", "d", "e", "f"].map((s) => ({ slug: s }));
|
||||
const scores = Object.fromEntries(
|
||||
["a", "b", "c", "d", "e", "f"].map((s) => [
|
||||
s,
|
||||
{ score: 1, matchedFacets: [] as string[] },
|
||||
]),
|
||||
);
|
||||
const set = deriveRecommendedTemplateSlugs(templates, scores, 5);
|
||||
expect(set.size).toBe(5);
|
||||
expect([...set]).toEqual(["a", "b", "c", "d", "e"]);
|
||||
});
|
||||
|
||||
it("only recommends the highest score group, not lower tiers to fill the cap", () => {
|
||||
const templates = ["a", "b", "c", "d", "e"].map((s) => ({ slug: s }));
|
||||
const scores = {
|
||||
a: { score: 4, matchedFacets: [] as string[] },
|
||||
b: { score: 4, matchedFacets: [] as string[] },
|
||||
c: { score: 3, matchedFacets: [] as string[] },
|
||||
d: { score: 3, matchedFacets: [] as string[] },
|
||||
e: { score: 3, matchedFacets: [] as string[] },
|
||||
};
|
||||
const set = deriveRecommendedTemplateSlugs(templates, scores, 5);
|
||||
expect([...set]).toEqual(["a", "b"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("gridEntriesWithFacetScores", () => {
|
||||
it("sets recommended true only for top compact matches (like card decks)", () => {
|
||||
const t = minimalTemplate("do-ocracy", "Do-ocracy");
|
||||
const [row] = gridEntriesWithFacetScores([t], {
|
||||
"do-ocracy": { score: 3, matchedFacets: ["a"] },
|
||||
});
|
||||
expect(row.recommended).toBe(true);
|
||||
});
|
||||
|
||||
it("does not mark lower-scoring templates recommended when a higher tier exists", () => {
|
||||
const high = [
|
||||
minimalTemplate("a", "A"),
|
||||
minimalTemplate("b", "B"),
|
||||
];
|
||||
const low = minimalTemplate("c", "C");
|
||||
const rows = gridEntriesWithFacetScores([...high, low], {
|
||||
a: { score: 4, matchedFacets: [] },
|
||||
b: { score: 4, matchedFacets: [] },
|
||||
c: { score: 3, matchedFacets: [] },
|
||||
});
|
||||
const rec = rows.filter((r) => r.recommended).map((r) => r.slug);
|
||||
expect(rec).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("caps top-tier recommended badges to compactRecommendedLimit", () => {
|
||||
const slugs = ["a", "b", "c", "d", "e", "f"];
|
||||
const templates = slugs.map((s) => minimalTemplate(s, s));
|
||||
const scores = Object.fromEntries(
|
||||
slugs.map((s) => [s, { score: 1, matchedFacets: [] as string[] }]),
|
||||
);
|
||||
const rows = gridEntriesWithFacetScores(templates, scores, {
|
||||
compactRecommendedLimit: 5,
|
||||
});
|
||||
expect(rows.filter((r) => r.recommended).map((r) => r.slug)).toEqual([
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
]);
|
||||
});
|
||||
|
||||
it("sets recommended false when score is zero or missing", () => {
|
||||
const t = minimalTemplate("consensus", "Consensus");
|
||||
const [a] = gridEntriesWithFacetScores([t], {
|
||||
consensus: { score: 0, matchedFacets: [] },
|
||||
});
|
||||
const [b] = gridEntriesWithFacetScores([t], {});
|
||||
expect(a.recommended).toBe(false);
|
||||
expect(b.recommended).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchRankedTemplatesByFacets", () => {
|
||||
beforeEach(() => {
|
||||
global.fetch = vi.fn();
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("parses ok JSON with templates and scores", async () => {
|
||||
const template = minimalTemplate("s", "T");
|
||||
vi.mocked(global.fetch).mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
templates: [template],
|
||||
scores: { s: { score: 1, matchedFacets: ["size:oneMember"] } },
|
||||
}),
|
||||
} as Response);
|
||||
const r = await fetchRankedTemplatesByFacets({
|
||||
facetQuery: "facet.size=oneMember",
|
||||
});
|
||||
expect("error" in r).toBe(false);
|
||||
if (!("error" in r)) {
|
||||
expect(r.templates).toEqual([template]);
|
||||
expect(r.scores.s?.score).toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
it("returns error when facetQuery is empty", async () => {
|
||||
const r = await fetchRankedTemplatesByFacets({ facetQuery: "" });
|
||||
expect("error" in r).toBe(true);
|
||||
describe("ruleTemplateToGridEntry", () => {
|
||||
it("never marks a template recommended", () => {
|
||||
const row = ruleTemplateToGridEntry(minimalTemplate("do-ocracy", "Do-ocracy"));
|
||||
expect(row.recommended).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { deckData, templateDeck } from "../../lib/create/deckRecommend";
|
||||
import {
|
||||
isTemplateCreatePath,
|
||||
orderIdsFirst,
|
||||
templateCardIdsForDeck,
|
||||
templateChipCounts,
|
||||
templatePathFromState,
|
||||
templateValueIdsForSlug,
|
||||
} from "../../lib/create/templatePath";
|
||||
|
||||
describe("templatePathFromState", () => {
|
||||
it("reads a customize or use-without-changes pin", () => {
|
||||
expect(templatePathFromState({})).toBeNull();
|
||||
expect(
|
||||
templatePathFromState({
|
||||
pendingTemplateAction: { slug: "consensus", mode: "customize" },
|
||||
}),
|
||||
).toEqual({ slug: "consensus", mode: "customize" });
|
||||
expect(
|
||||
isTemplateCreatePath({
|
||||
pendingTemplateAction: {
|
||||
slug: "consensus",
|
||||
mode: "useWithoutChanges",
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("ignores a pin with no slug or an unknown mode", () => {
|
||||
expect(
|
||||
templatePathFromState({
|
||||
pendingTemplateAction: { slug: " ", mode: "customize" },
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(
|
||||
templatePathFromState({
|
||||
pendingTemplateAction: {
|
||||
slug: "consensus",
|
||||
mode: "other" as "customize",
|
||||
},
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("template chips", () => {
|
||||
it("returns the consensus template's values and communication cards", () => {
|
||||
expect(templateValueIdsForSlug("consensus")).toEqual([
|
||||
"consensus",
|
||||
"community-care",
|
||||
"horizontalism",
|
||||
]);
|
||||
expect(templateCardIdsForDeck("consensus", "communication")).toEqual([
|
||||
"how-we-run-meetings",
|
||||
"in-person-meetings",
|
||||
"loomio",
|
||||
]);
|
||||
expect(templateChipCounts("consensus")).toEqual({
|
||||
values: 3,
|
||||
cards: 10,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null counts for an unknown slug", () => {
|
||||
expect(templateChipCounts("not-a-template")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("orderIdsFirst", () => {
|
||||
it("puts named ids first and keeps the rest in their original order", () => {
|
||||
const items = [{ id: "a" }, { id: "b" }, { id: "c" }, { id: "d" }];
|
||||
expect(orderIdsFirst(items, ["c", "a", "missing"])).toEqual([
|
||||
{ id: "c" },
|
||||
{ id: "a" },
|
||||
{ id: "b" },
|
||||
{ id: "d" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("templateDeck", () => {
|
||||
it("puts the template's cards first, then the rest of the deck, with no cut", () => {
|
||||
const data = deckData("communication");
|
||||
const firstIds = templateCardIdsForDeck("consensus", "communication");
|
||||
const ordered = templateDeck(data, firstIds);
|
||||
expect(ordered.first).toEqual(firstIds);
|
||||
expect(ordered.rest.some((id) => firstIds.includes(id))).toBe(false);
|
||||
const all = [...ordered.first, ...ordered.rest];
|
||||
expect(new Set(all).size).toBe(all.length);
|
||||
expect(all.length).toBe(Object.keys(data.engine.cards).length);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user