Open a template from its cards even when a saved draft exists.

This commit is contained in:
adilallo committed 2026-11-22 18:08:34 -07:00
1 parent 851133e56d
commit 55b071aa83
11 files changed
+326 -140

No files matched your search

@@ -35,10 +35,15 @@ describe("useTemplateReviewActions", () => {
const router = { push: vi.fn() };
const updateState = vi.fn();
const markCreateFlowInteraction = vi.fn();
const requestConfirm = vi.fn();
let applied: CreateFlowState | undefined;
const replaceState = vi.fn(
(updater: (_prev: CreateFlowState) => CreateFlowState) => {
applied = updater({});
applied = updater({
title: "Juniper Street Tenants",
communityAvatarUrl: "/old.png",
setupTraits: { employer: true },
});
},
);
@@ -48,8 +53,12 @@ describe("useTemplateReviewActions", () => {
router.push.mockReset();
updateState.mockReset();
markCreateFlowInteraction.mockReset();
requestConfirm.mockReset();
requestConfirm.mockResolvedValue(true);
replaceState.mockClear();
applied = undefined;
window.sessionStorage.clear();
window.localStorage.clear();
});
function renderActions(
@@ -64,6 +73,7 @@ describe("useTemplateReviewActions", () => {
replaceState,
router,
fromCreateWizard,
requestConfirm,
markCreateFlowInteraction,
}),
);
@@ -86,9 +96,10 @@ describe("useTemplateReviewActions", () => {
);
});
it("Customize Continue prefills cards, drops setup answers, and walks the decks", async () => {
it("Customize Continue prefills cards, drops leftover identity, and walks the decks", async () => {
const { result } = renderActions({
setupTraits: { employer: true },
communityAvatarUrl: "/old.png",
});
await act(async () => {
@@ -103,32 +114,19 @@ describe("useTemplateReviewActions", () => {
});
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",
}),
);
expect(applied?.title).toBe("Neighborhood");
expect(applied?.communityContext).toBe("We meet weekly");
expect(applied?.communityLocation).toBe("Oakland");
expect(applied?.communityAvatarUrl).toBeUndefined();
expect(applied?.setupTraits).toBeUndefined();
expect(applied?.pendingTemplateAction).toEqual({
slug: "mutual-aid-mondays",
mode: "customize",
});
expect(applied?.templateReviewBackSlug).toBe("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({
title: "Neighborhood",
communityContext: "Stale description",
currentStep: "confirm-stakeholders",
setupTraits: { employer: true, network: false },
});
},
);
const { result } = renderActions({ title: "Neighborhood" });
await act(async () => {
@@ -138,8 +136,9 @@ describe("useTemplateReviewActions", () => {
expect(router.push).toHaveBeenCalledWith("/create/final-review");
expect(applied?.title).toBeUndefined();
expect(applied?.communityContext).toBeUndefined();
expect(applied?.currentStep).toBeUndefined();
expect(applied?.communityAvatarUrl).toBeUndefined();
expect(applied?.setupTraits).toBeUndefined();
expect(applied?.currentStep).toBeUndefined();
expect(applied?.pendingTemplateAction).toEqual({
slug: "mutual-aid-mondays",
mode: "useWithoutChanges",
@@ -147,18 +146,12 @@ describe("useTemplateReviewActions", () => {
});
it("in-flow Use without changes keeps the community name and pins the template path", async () => {
replaceState.mockImplementation(
(updater: (_prev: CreateFlowState) => CreateFlowState) => {
applied = updater({
title: "Neighborhood",
communityContext: "We meet weekly",
templateReviewEntryFromCreateFlow: true,
setupTraits: { employer: true },
});
},
);
const { result } = renderActions(
{ title: "Neighborhood", templateReviewEntryFromCreateFlow: true },
{
title: "Neighborhood",
communityContext: "We meet weekly",
templateReviewEntryFromCreateFlow: true,
},
true,
);
@@ -176,4 +169,21 @@ describe("useTemplateReviewActions", () => {
});
expect(applied?.templateReviewBackSlug).toBe("mutual-aid-mondays");
});
it("asks before replacing a draft in progress", async () => {
requestConfirm.mockResolvedValueOnce(false);
const { result } = renderActions({ title: "Juniper Street Tenants" });
await act(async () => {
await result.current.handleUseWithoutChanges();
});
expect(requestConfirm).toHaveBeenCalledWith(
expect.objectContaining({
title: "Replace the draft in progress?",
}),
);
expect(router.push).not.toHaveBeenCalled();
expect(replaceState).not.toHaveBeenCalled();
});
});