Keep the browser draft on screen after Save your progress, including when the save link is dead.

This commit is contained in:
adilallo committed 2026-11-22 17:50:06 -07:00
1 parent d576ed81d9
commit d31045b0e5
6 files changed
+141 -12

No files matched your search

+68 -2
View File
@@ -1,10 +1,14 @@
import { describe, it, expect } from "vitest";
import { act, render, screen } from "@testing-library/react";
import { afterEach, describe, it, expect } from "vitest";
import { act, render, screen, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import {
CreateFlowProvider,
useCreateFlow,
} from "../../app/(app)/create/context/CreateFlowContext";
import {
CREATE_FLOW_ANONYMOUS_KEY,
CREATE_FLOW_TRANSFER_PENDING_KEY,
} from "../../app/(app)/create/utils/anonymousDraftStorage";
/**
* Harness: mounts a consumer that renders the state we want to assert on and
@@ -46,6 +50,15 @@ function Harness() {
<div data-testid="pin-method">
{state.methodSectionsPinCommitted?.communication ? "yes" : "no"}
</div>
<div data-testid="size">
{(state.selectedCommunitySizeIds ?? []).join(",")}
</div>
<div data-testid="kind">
{(state.selectedOrganizationTypeIds ?? []).join(",")}
</div>
<div data-testid="maturity">
{(state.selectedMaturityIds ?? []).join(",")}
</div>
</>
);
}
@@ -129,3 +142,56 @@ describe("CreateFlowContext — resetCustomRuleSelections", () => {
expect(screen.getByTestId("core").textContent).toBe("");
});
});
describe("CreateFlowContext — draft hydration after Save your progress", () => {
afterEach(() => {
window.localStorage.clear();
});
it("loads the stored draft when mirroring turns on, even with the transfer flag", async () => {
window.localStorage.setItem(
CREATE_FLOW_ANONYMOUS_KEY,
JSON.stringify({
title: "Juniper Street Tenants",
selectedCommunitySizeIds: ["thirteenToOneHundred"],
selectedOrganizationTypeIds: ["housing"],
selectedMaturityIds: ["forming"],
}),
);
window.localStorage.setItem(CREATE_FLOW_TRANSFER_PENDING_KEY, "1");
const { rerender } = render(
<CreateFlowProvider enableLocalDraftMirroring={false}>
<Harness />
</CreateFlowProvider>,
);
rerender(
<CreateFlowProvider enableLocalDraftMirroring>
<Harness />
</CreateFlowProvider>,
);
await waitFor(() => {
expect(screen.getByTestId("title").textContent).toBe(
"Juniper Street Tenants",
);
});
expect(screen.getByTestId("size").textContent).toBe("thirteenToOneHundred");
expect(screen.getByTestId("kind").textContent).toBe("housing");
expect(screen.getByTestId("maturity").textContent).toBe("forming");
act(() => {
getUpdateState()({ title: "Juniper Street Tenants Union" });
});
await waitFor(() => {
const stored = JSON.parse(
window.localStorage.getItem(CREATE_FLOW_ANONYMOUS_KEY) ?? "{}",
) as Record<string, unknown>;
expect(stored.title).toBe("Juniper Street Tenants Union");
expect(stored.selectedCommunitySizeIds).toEqual(["thirteenToOneHundred"]);
expect(stored.selectedOrganizationTypeIds).toEqual(["housing"]);
expect(stored.selectedMaturityIds).toEqual(["forming"]);
});
});
});