Let anyone finish a Rule without an account or email.
Continue on final review and Finish without inviting no longer open a login wall. The header stays Exit until Save your progress is done, and Send invitations is the only invite-path login.
This commit is contained in:
1 parent
077942166c
commit
0535f6f167
14 files changed
+377
-225
No files matched your search
@@ -0,0 +1,244 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import CreateFlowLayoutClient from "../../app/(app)/create/CreateFlowLayoutClient";
|
||||
import { CREATE_FLOW_ANONYMOUS_KEY } from "../../app/(app)/create/utils/anonymousDraftStorage";
|
||||
import {
|
||||
CREATE_FLOW_SYNC_DRAFT_QUERY,
|
||||
CREATE_FLOW_SYNC_DRAFT_VALUE,
|
||||
} from "../../app/(app)/create/utils/createFlowPaths";
|
||||
import {
|
||||
fetchAuthSession,
|
||||
publishRule,
|
||||
requestMagicLink,
|
||||
} from "../../lib/create/api";
|
||||
import { CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY } from "../../lib/create/pendingKeepRuleLogin";
|
||||
import type { CreateFlowState } from "../../app/(app)/create/types";
|
||||
import {
|
||||
cleanup,
|
||||
renderWithProviders as render,
|
||||
screen,
|
||||
waitFor,
|
||||
} from "../utils/test-utils";
|
||||
|
||||
const nav = vi.hoisted(() => ({
|
||||
pathname: "/create/final-review",
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: nav.push,
|
||||
replace: nav.replace,
|
||||
prefetch: vi.fn(),
|
||||
back: vi.fn(),
|
||||
}),
|
||||
usePathname: () => nav.pathname,
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/create/api", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../lib/create/api")>();
|
||||
return {
|
||||
...actual,
|
||||
fetchAuthSession: vi.fn(async () => ({ user: null })),
|
||||
publishRule: vi.fn(async () => ({
|
||||
ok: true as const,
|
||||
id: "guest-rule-1",
|
||||
title: "Oak Park Commons",
|
||||
})),
|
||||
requestMagicLink: vi.fn(async () => ({ ok: true as const })),
|
||||
};
|
||||
});
|
||||
|
||||
const readyToContinue: CreateFlowState = {
|
||||
title: "Oak Park Commons",
|
||||
selectedCommunicationMethodIds: ["signal"],
|
||||
selectedMembershipMethodIds: ["open-admission"],
|
||||
selectedDecisionApproachIds: ["lazy-consensus"],
|
||||
selectedConflictManagementIds: ["conflict-ladder"],
|
||||
communicationMethodDetailsById: {
|
||||
signal: {
|
||||
corePrinciple: "We talk in the open.",
|
||||
logisticsAdmin: "Post in Signal.",
|
||||
codeOfConduct: "No pile-ons.",
|
||||
},
|
||||
},
|
||||
membershipMethodDetailsById: {
|
||||
"open-admission": {
|
||||
eligibility: "Anyone who shares the work.",
|
||||
joiningProcess: "Show up.",
|
||||
expectations: "Keep the keys.",
|
||||
},
|
||||
},
|
||||
decisionApproachDetailsById: {
|
||||
"lazy-consensus": {
|
||||
corePrinciple: "Silence is assent.",
|
||||
applicableScope: [],
|
||||
selectedApplicableScope: [],
|
||||
stepByStepInstructions: "Post the proposal.",
|
||||
objectionsDeadlocks: "A named block stops it.",
|
||||
},
|
||||
},
|
||||
conflictManagementDetailsById: {
|
||||
"conflict-ladder": {
|
||||
corePrinciple: "Start small.",
|
||||
applicableScope: [],
|
||||
selectedApplicableScope: [],
|
||||
processProtocol: "Talk, then mediate.",
|
||||
restorationFallbacks: "A panel if that fails.",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function seedDraft(state: CreateFlowState = readyToContinue) {
|
||||
window.localStorage.setItem(CREATE_FLOW_ANONYMOUS_KEY, JSON.stringify(state));
|
||||
}
|
||||
|
||||
function renderFlow() {
|
||||
return render(
|
||||
<CreateFlowLayoutClient>
|
||||
<div>step</div>
|
||||
</CreateFlowLayoutClient>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("guest finish without an account", () => {
|
||||
beforeEach(() => {
|
||||
nav.pathname = "/create/final-review";
|
||||
nav.push.mockReset();
|
||||
nav.replace.mockReset();
|
||||
vi.mocked(fetchAuthSession).mockResolvedValue({ user: null });
|
||||
vi.mocked(publishRule).mockResolvedValue({
|
||||
ok: true,
|
||||
id: "guest-rule-1",
|
||||
title: "Oak Park Commons",
|
||||
});
|
||||
vi.mocked(requestMagicLink).mockResolvedValue({ ok: true });
|
||||
window.localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
window.localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
});
|
||||
|
||||
it("keeps Exit on final review and continues to Invite your members without login", async () => {
|
||||
const user = userEvent.setup();
|
||||
seedDraft();
|
||||
renderFlow();
|
||||
|
||||
expect(
|
||||
await screen.findByRole("button", { name: "Exit" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("button", { name: "Save and exit" }),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
const continueButton = await screen.findByRole("button", {
|
||||
name: "Continue",
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(continueButton).toBeEnabled();
|
||||
});
|
||||
await user.click(continueButton);
|
||||
|
||||
expect(
|
||||
screen.queryByRole("heading", {
|
||||
name: "Log in to invite your members",
|
||||
}),
|
||||
).not.toBeInTheDocument();
|
||||
expect(nav.push).toHaveBeenCalledWith("/create/confirm-stakeholders");
|
||||
});
|
||||
|
||||
it("opens the invite login from Send invitations and does not publish", async () => {
|
||||
const user = userEvent.setup();
|
||||
nav.pathname = "/create/confirm-stakeholders";
|
||||
seedDraft();
|
||||
renderFlow();
|
||||
|
||||
const sendInvitations = await screen.findByRole("button", {
|
||||
name: "Send invitations",
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(sendInvitations).toBeEnabled();
|
||||
});
|
||||
await user.click(sendInvitations);
|
||||
|
||||
expect(
|
||||
await screen.findByRole("heading", {
|
||||
name: "Log in to invite your members",
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
expect(publishRule).not.toHaveBeenCalled();
|
||||
expect(nav.push).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("finishes without inviting and does not ask for an email", async () => {
|
||||
const user = userEvent.setup();
|
||||
nav.pathname = "/create/confirm-stakeholders";
|
||||
seedDraft();
|
||||
renderFlow();
|
||||
|
||||
const finishWithoutInviting = await screen.findByRole("button", {
|
||||
name: "Finish without inviting",
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(finishWithoutInviting).toBeEnabled();
|
||||
});
|
||||
await user.click(finishWithoutInviting);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(publishRule).toHaveBeenCalled();
|
||||
});
|
||||
expect(
|
||||
screen.queryByRole("heading", {
|
||||
name: "Log in to invite your members",
|
||||
}),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("heading", {
|
||||
name: "Log in to keep this rule on your profile",
|
||||
}),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY),
|
||||
).toBeNull();
|
||||
expect(nav.push).toHaveBeenCalledWith(
|
||||
expect.stringMatching(/^\/create\/completed/),
|
||||
);
|
||||
});
|
||||
|
||||
it("asks the invite login to return to Invite your members after the link", async () => {
|
||||
const user = userEvent.setup();
|
||||
nav.pathname = "/create/confirm-stakeholders";
|
||||
seedDraft();
|
||||
renderFlow();
|
||||
|
||||
const sendInvitations = await screen.findByRole("button", {
|
||||
name: "Send invitations",
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(sendInvitations).toBeEnabled();
|
||||
});
|
||||
await user.click(sendInvitations);
|
||||
expect(
|
||||
await screen.findByRole("heading", {
|
||||
name: "Log in to invite your members",
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
|
||||
const email = screen.getByRole("textbox", { name: /email address/i });
|
||||
await user.type(email, "maya@example.org");
|
||||
await user.click(screen.getByRole("button", { name: "Send login link" }));
|
||||
|
||||
expect(requestMagicLink).toHaveBeenCalledWith(
|
||||
"maya@example.org",
|
||||
`/create/confirm-stakeholders?${CREATE_FLOW_SYNC_DRAFT_QUERY}=${CREATE_FLOW_SYNC_DRAFT_VALUE}`,
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -17,7 +17,7 @@ describe("InformationalScreen", () => {
|
||||
render(<InformationalScreen />);
|
||||
expect(
|
||||
screen.getByText(
|
||||
/Work through it together or on your own/i,
|
||||
/you don’t need an account to write or finish it/i,
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -12,7 +12,10 @@ import {
|
||||
readPendingCommunityAvatarFile,
|
||||
storePendingCommunityAvatarFile,
|
||||
} from "../../lib/create/pendingCommunityAvatarUpload";
|
||||
import { fetchAuthSession } from "../../lib/create/api";
|
||||
import {
|
||||
CreateFlowUploadValidationError,
|
||||
uploadCreateFlowFile,
|
||||
} from "../../lib/create/uploadToServer";
|
||||
import messages from "../../messages/en/index";
|
||||
|
||||
vi.mock("../../lib/create/pendingCommunityAvatarUpload", () => ({
|
||||
@@ -21,9 +24,14 @@ vi.mock("../../lib/create/pendingCommunityAvatarUpload", () => ({
|
||||
clearPendingCommunityAvatarFile: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/create/api", () => ({
|
||||
fetchAuthSession: vi.fn().mockResolvedValue({ user: null }),
|
||||
}));
|
||||
vi.mock("../../lib/create/uploadToServer", async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import("../../lib/create/uploadToServer")>();
|
||||
return {
|
||||
...actual,
|
||||
uploadCreateFlowFile: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const pngBytes = Uint8Array.from(
|
||||
Buffer.from(
|
||||
@@ -46,7 +54,7 @@ describe("CommunityUploadScreen", () => {
|
||||
vi.mocked(readPendingCommunityAvatarFile).mockResolvedValue(null);
|
||||
vi.mocked(storePendingCommunityAvatarFile).mockResolvedValue(undefined);
|
||||
vi.mocked(clearPendingCommunityAvatarFile).mockResolvedValue(undefined);
|
||||
vi.mocked(fetchAuthSession).mockResolvedValue({ user: null });
|
||||
vi.mocked(uploadCreateFlowFile).mockReset();
|
||||
Object.defineProperty(URL, "createObjectURL", {
|
||||
value: vi.fn(() => "blob:pending-avatar"),
|
||||
writable: true,
|
||||
@@ -98,7 +106,35 @@ describe("CommunityUploadScreen", () => {
|
||||
expect(screen.getByText("avatar.png")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("uploads a guest logo without signing in", async () => {
|
||||
vi.mocked(uploadCreateFlowFile).mockResolvedValue({
|
||||
url: "/api/uploads/guest-logo",
|
||||
id: "11111111-1111-4111-8111-111111111111",
|
||||
mimeType: "image/png",
|
||||
byteLength: pngBytes.byteLength,
|
||||
});
|
||||
|
||||
render(<CommunityUploadScreen />);
|
||||
await screen.findByRole("heading", { name: copy.title });
|
||||
|
||||
fireEvent.change(fileInput(), {
|
||||
target: {
|
||||
files: [new File([pngBytes], "logo.png", { type: "image/png" })],
|
||||
},
|
||||
});
|
||||
|
||||
expect(await screen.findByText("logo.png")).toBeInTheDocument();
|
||||
expect(uploadCreateFlowFile).toHaveBeenCalledWith(
|
||||
expect.any(File),
|
||||
"communityAvatar",
|
||||
);
|
||||
expect(storePendingCommunityAvatarFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects an empty file with a clear error and does not stage it", async () => {
|
||||
vi.mocked(uploadCreateFlowFile).mockRejectedValue(
|
||||
new CreateFlowUploadValidationError("empty"),
|
||||
);
|
||||
render(<CommunityUploadScreen />);
|
||||
await screen.findByRole("heading", { name: copy.title });
|
||||
|
||||
@@ -113,6 +149,9 @@ describe("CommunityUploadScreen", () => {
|
||||
});
|
||||
|
||||
it("rejects a text file renamed as PNG", async () => {
|
||||
vi.mocked(uploadCreateFlowFile).mockRejectedValue(
|
||||
new CreateFlowUploadValidationError("invalidType"),
|
||||
);
|
||||
render(<CommunityUploadScreen />);
|
||||
await screen.findByRole("heading", { name: copy.title });
|
||||
|
||||
@@ -129,6 +168,9 @@ describe("CommunityUploadScreen", () => {
|
||||
});
|
||||
|
||||
it("rejects SVG uploads", async () => {
|
||||
vi.mocked(uploadCreateFlowFile).mockRejectedValue(
|
||||
new CreateFlowUploadValidationError("svg"),
|
||||
);
|
||||
render(<CommunityUploadScreen />);
|
||||
await screen.findByRole("heading", { name: copy.title });
|
||||
|
||||
|
||||
@@ -259,24 +259,38 @@ describe("flowSteps", () => {
|
||||
expect(parseReviewReturnSearchParam(null)).toBeNull();
|
||||
});
|
||||
|
||||
it("offers Save and exit from community-save through final-review and on edit-rule", () => {
|
||||
it("offers Save and exit from community-save only after Save your progress", () => {
|
||||
expect(shouldOfferCreateFlowSaveAndExit("informational")).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("community-name")).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("community-structure")).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("setup-questions")).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("community-upload")).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("community-save")).toBe(true);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("review")).toBe(true);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("final-review")).toBe(true);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("edit-rule")).toBe(true);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("community-save")).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("community-save", null)).toBe(
|
||||
false,
|
||||
);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("final-review", null)).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("edit-rule", null)).toBe(false);
|
||||
expect(
|
||||
shouldOfferCreateFlowSaveAndExit("community-save", { id: "user-1" }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldOfferCreateFlowSaveAndExit("review", { id: "user-1" }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldOfferCreateFlowSaveAndExit("final-review", { id: "user-1" }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldOfferCreateFlowSaveAndExit("edit-rule", { id: "user-1" }),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("offers Save & Exit on completed only for guests", () => {
|
||||
it("keeps Exit on completed for guests and signed-in users", () => {
|
||||
expect(shouldOfferCreateFlowSaveAndExit("completed")).toBe(false);
|
||||
expect(
|
||||
shouldOfferCreateFlowSaveAndExit("completed", { id: "user-1" }),
|
||||
).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("completed", null)).toBe(true);
|
||||
expect(shouldOfferCreateFlowSaveAndExit("completed", null)).toBe(false);
|
||||
expect(shouldOfferCreateFlowSaveAndExit(null)).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ describe("useCreateFlowFinalize", () => {
|
||||
});
|
||||
expect(onGuestPublished).toHaveBeenCalledWith({ skippedInvites: true });
|
||||
expect(openLogin).not.toHaveBeenCalled();
|
||||
expect(sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY)).toBe("1");
|
||||
expect(sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY)).toBeNull();
|
||||
expect(router.push).toHaveBeenCalledWith(
|
||||
`/create/completed?${CREATE_FLOW_COMPLETED_CELEBRATE_QUERY}=${CREATE_FLOW_COMPLETED_CELEBRATE_VALUE}`,
|
||||
);
|
||||
@@ -304,7 +304,7 @@ describe("useCreateFlowFinalize", () => {
|
||||
});
|
||||
expect(onGuestPublished).toHaveBeenCalledWith({ skippedInvites: false });
|
||||
expect(openLogin).not.toHaveBeenCalled();
|
||||
expect(sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY)).toBe("1");
|
||||
expect(sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY)).toBeNull();
|
||||
expect(router.push).toHaveBeenCalledWith(
|
||||
`/create/completed?${CREATE_FLOW_COMPLETED_CELEBRATE_QUERY}=${CREATE_FLOW_COMPLETED_CELEBRATE_VALUE}`,
|
||||
);
|
||||
@@ -480,7 +480,7 @@ describe("useCreateFlowFinalize", () => {
|
||||
summary: "Published summary",
|
||||
document: {},
|
||||
});
|
||||
expect(sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY)).toBe("1");
|
||||
expect(sessionStorage.getItem(CREATE_FLOW_PENDING_KEEP_RULE_LOGIN_KEY)).toBeNull();
|
||||
expect(router.push).toHaveBeenCalledWith("/create/completed");
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user