Sign-in was clearing the staged file before it uploaded, and review only read the server URL, so a chosen logo disappeared after the upload step.
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
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();
|
|
});
|
|
});
|