Keep a guest community logo on review and on the published rule.
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.
This commit is contained in:
1 parent
2348a9e94f
commit
8212423ec3
19 files changed
+780
-61
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { act } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { CreateFlowPendingAvatarFlush } from "../../app/(app)/create/components/CreateFlowPendingAvatarFlush";
|
||||
import { useCreateFlow } from "../../app/(app)/create/context/CreateFlowContext";
|
||||
import { flushPendingCommunityAvatar } from "../../lib/create/flushPendingCommunityAvatar";
|
||||
import {
|
||||
renderWithProviders as render,
|
||||
screen,
|
||||
} from "../utils/test-utils";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
|
||||
vi.mock("../../lib/create/flushPendingCommunityAvatar", () => ({
|
||||
flushPendingCommunityAvatar: vi.fn(),
|
||||
}));
|
||||
|
||||
function AvatarProbe() {
|
||||
const { state } = useCreateFlow();
|
||||
return <div data-testid="avatar">{state.communityAvatarUrl ?? ""}</div>;
|
||||
}
|
||||
|
||||
describe("CreateFlowPendingAvatarFlush", () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.mocked(flushPendingCommunityAvatar).mockReset();
|
||||
});
|
||||
|
||||
it("retries a transient upload and then stores the url", async () => {
|
||||
vi.useFakeTimers();
|
||||
vi.mocked(flushPendingCommunityAvatar)
|
||||
.mockResolvedValueOnce({ status: "failed" })
|
||||
.mockResolvedValueOnce({
|
||||
status: "uploaded",
|
||||
url: "/api/uploads/retry",
|
||||
});
|
||||
|
||||
render(
|
||||
<>
|
||||
<CreateFlowPendingAvatarFlush
|
||||
sessionUser={{ id: "user-1", email: "maya@example.com" }}
|
||||
sessionResolved
|
||||
/>
|
||||
<AvatarProbe />
|
||||
</>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
expect(flushPendingCommunityAvatar).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByTestId("avatar")).toHaveTextContent("");
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(5_000);
|
||||
});
|
||||
|
||||
expect(flushPendingCommunityAvatar).toHaveBeenCalledTimes(2);
|
||||
expect(screen.getByTestId("avatar")).toHaveTextContent(
|
||||
"/api/uploads/retry",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user