55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
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");
|
|
});
|
|
});
|