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:
adilallo committed 2026-11-05 20:02:40 -07:00
1 parent 2348a9e94f
commit 8212423ec3
19 files changed
+780 -61

No files matched your search

+37 -1
View File
@@ -1,4 +1,4 @@
import { beforeEach, describe, it, expect } from "vitest";
import { beforeEach, describe, it, expect, vi } from "vitest";
import React, { useEffect } from "react";
import {
renderWithProviders as render,
@@ -9,6 +9,13 @@ import "@testing-library/jest-dom/vitest";
import { CommunityReviewScreen } from "../../app/(app)/create/screens/review/CommunityReviewScreen";
import { useCreateFlow } from "../../app/(app)/create/context/CreateFlowContext";
import { testRouter } from "../mocks/navigation";
import { readPendingCommunityAvatarFile } from "../../lib/create/pendingCommunityAvatarUpload";
vi.mock("../../lib/create/pendingCommunityAvatarUpload", () => ({
readPendingCommunityAvatarFile: vi.fn().mockResolvedValue(null),
storePendingCommunityAvatarFile: vi.fn(),
clearPendingCommunityAvatarFile: vi.fn(),
}));
function ReviewWithTitle({ title }: { title: string }) {
const { state, updateState } = useCreateFlow();
@@ -43,6 +50,8 @@ describe("CommunityReviewScreen", () => {
beforeEach(() => {
testRouter.replace.mockReset();
testRouter.push.mockReset();
vi.mocked(readPendingCommunityAvatarFile).mockReset();
vi.mocked(readPendingCommunityAvatarFile).mockResolvedValue(null);
});
it("renders without crashing", () => {
@@ -89,6 +98,33 @@ describe("CommunityReviewScreen", () => {
expect(screen.getByText("Garden Club")).toBeInTheDocument();
});
it("shows a guest logo staged in the browser on the rule card", async () => {
const pending = new File([new Uint8Array([1, 2, 3])], "logo.png", {
type: "image/png",
});
vi.mocked(readPendingCommunityAvatarFile).mockResolvedValue(pending);
Object.defineProperty(URL, "createObjectURL", {
value: vi.fn(() => "blob:pending-avatar"),
writable: true,
configurable: true,
});
Object.defineProperty(URL, "revokeObjectURL", {
value: vi.fn(),
writable: true,
configurable: true,
});
render(<ReviewWithTitle title="Garden Club" />);
await waitFor(() => {
expect(screen.getByRole("img", { name: "Garden Club" })).toHaveAttribute(
"src",
"blob:pending-avatar",
);
});
expect(readPendingCommunityAvatarFile).toHaveBeenCalled();
});
it("omits the Rule description when the user has not entered community context", () => {
render(<ReviewWithTitle title="Garden Club" />);
expect(