import { beforeEach, describe, expect, it, vi } from "vitest"; const clearPendingCommunityAvatarFile = vi.fn(); const forgetFlushedCommunityAvatarUrl = vi.fn(); vi.mock("../../lib/create/pendingCommunityAvatarUpload", () => ({ clearPendingCommunityAvatarFile: () => clearPendingCommunityAvatarFile(), })); vi.mock("../../lib/create/flushPendingCommunityAvatar", () => ({ forgetFlushedCommunityAvatarUrl: () => forgetFlushedCommunityAvatarUrl(), })); import { CREATE_FLOW_ANONYMOUS_KEY, CREATE_FLOW_TRANSFER_PENDING_KEY, clearAnonymousCreateFlowStorage, } from "../../app/(app)/create/utils/anonymousDraftStorage"; describe("clearAnonymousCreateFlowStorage", () => { beforeEach(() => { localStorage.clear(); clearPendingCommunityAvatarFile.mockReset(); forgetFlushedCommunityAvatarUrl.mockReset(); localStorage.setItem(CREATE_FLOW_ANONYMOUS_KEY, "{\"title\":\"Garden\"}"); localStorage.setItem(CREATE_FLOW_TRANSFER_PENDING_KEY, "1"); }); it("removes the draft and the staged logo", () => { clearAnonymousCreateFlowStorage(); expect(localStorage.getItem(CREATE_FLOW_ANONYMOUS_KEY)).toBeNull(); expect(localStorage.getItem(CREATE_FLOW_TRANSFER_PENDING_KEY)).toBeNull(); expect(clearPendingCommunityAvatarFile).toHaveBeenCalledTimes(1); expect(forgetFlushedCommunityAvatarUrl).toHaveBeenCalledTimes(1); }); it("keeps the staged logo when a transfer upload still needs to retry", () => { clearAnonymousCreateFlowStorage({ preservePendingAvatar: true }); expect(localStorage.getItem(CREATE_FLOW_ANONYMOUS_KEY)).toBeNull(); expect(clearPendingCommunityAvatarFile).not.toHaveBeenCalled(); expect(forgetFlushedCommunityAvatarUrl).not.toHaveBeenCalled(); }); });