Resume the draft from Create rule instead of deleting it.
This commit is contained in:
1 parent
d31045b0e5
commit
a846169960
9 files changed
+119
-71
No files matched your search
@@ -67,16 +67,13 @@ describe('Top "Create rule" button', () => {
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
/**
|
||||
* Guards against localStorage stickiness on the marketing homepage: hitting
|
||||
* the top-nav "Create rule" from anywhere outside `/create` must wipe the
|
||||
* in-flight anonymous draft so the wizard always starts fresh. See
|
||||
* handleCreateRuleClick in Top.container.tsx for the contract.
|
||||
*/
|
||||
it("clears anonymous draft + core-value-details localStorage before routing to /create/informational", async () => {
|
||||
it("keeps the browser draft and resumes the step it was left on", async () => {
|
||||
window.localStorage.setItem(
|
||||
CREATE_FLOW_ANONYMOUS_KEY,
|
||||
JSON.stringify({ title: "Stale community" }),
|
||||
JSON.stringify({
|
||||
title: "Stale community",
|
||||
currentStep: "community-name",
|
||||
}),
|
||||
);
|
||||
window.localStorage.setItem(
|
||||
CORE_VALUE_DETAILS_STORAGE_KEY,
|
||||
@@ -91,12 +88,14 @@ describe('Top "Create rule" button', () => {
|
||||
await userEvent.click(btn);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(pushMock).toHaveBeenCalledWith("/create/informational");
|
||||
expect(pushMock).toHaveBeenCalledWith("/create/community-name");
|
||||
});
|
||||
expect(window.localStorage.getItem(CREATE_FLOW_ANONYMOUS_KEY)).toBeNull();
|
||||
expect(window.localStorage.getItem(CREATE_FLOW_ANONYMOUS_KEY)).toContain(
|
||||
"Stale community",
|
||||
);
|
||||
expect(
|
||||
window.localStorage.getItem(CORE_VALUE_DETAILS_STORAGE_KEY),
|
||||
).toBeNull();
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("pads the standard header to hug Create rule", () => {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { CREATE_FLOW_ANONYMOUS_KEY } from "../../app/(app)/create/utils/anonymousDraftStorage";
|
||||
import { CORE_VALUE_DETAILS_STORAGE_KEY } from "../../app/(app)/create/utils/coreValueDetailsLocalStorage";
|
||||
import {
|
||||
createRuleEntryPath,
|
||||
hasBrowserCreateFlowDraft,
|
||||
} from "../../app/(app)/create/utils/createRuleEntry";
|
||||
|
||||
describe("createRuleEntryPath", () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
it("opens the first step when there is no draft", () => {
|
||||
expect(hasBrowserCreateFlowDraft()).toBe(false);
|
||||
expect(createRuleEntryPath()).toBe("/create/informational");
|
||||
});
|
||||
|
||||
it("resumes the stored step", () => {
|
||||
window.localStorage.setItem(
|
||||
CREATE_FLOW_ANONYMOUS_KEY,
|
||||
JSON.stringify({
|
||||
title: "Garden coop",
|
||||
currentStep: "community-size",
|
||||
}),
|
||||
);
|
||||
expect(hasBrowserCreateFlowDraft()).toBe(true);
|
||||
expect(createRuleEntryPath()).toBe("/create/community-size");
|
||||
});
|
||||
|
||||
it("does not resume a finished Rule screen", () => {
|
||||
window.localStorage.setItem(
|
||||
CREATE_FLOW_ANONYMOUS_KEY,
|
||||
JSON.stringify({
|
||||
title: "Garden coop",
|
||||
currentStep: "completed",
|
||||
}),
|
||||
);
|
||||
expect(createRuleEntryPath()).toBe("/create/informational");
|
||||
});
|
||||
|
||||
it("treats leftover core-value details as a draft", () => {
|
||||
window.localStorage.setItem(
|
||||
CORE_VALUE_DETAILS_STORAGE_KEY,
|
||||
JSON.stringify({ "1": { meaning: "m", signals: "s" } }),
|
||||
);
|
||||
expect(hasBrowserCreateFlowDraft()).toBe(true);
|
||||
expect(createRuleEntryPath()).toBe("/create/informational");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user