Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 10 additions & 43 deletions src/app/__tests__/public-endorsements-groups.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { describe, it, expect, vi, beforeEach } from "vitest"
import { render, screen, fireEvent, cleanup } from "@testing-library/react"

/**
* P1: /endorsements and /groups used to redirect anonymous (signed-out)
* visitors to /welcome via the route-level <AuthGuard>. That guard was
* removed; instead each page renders a public sign-in prompt in place.
* P1: /endorsements used to redirect anonymous (signed-out) visitors to
* /welcome via the route-level <AuthGuard>. That guard was removed;
* instead the page renders a public sign-in prompt in place.
*
* Both pages are personal, owner-scoped surfaces (a personal inbox and
* the viewer's own membership list, keyed on the viewer's DID), so there
* is no public listing to show — the "best available public view" is an
* explanation + a sign-in CTA. These tests pin that:
* /endorsements is a personal, owner-scoped surface (a personal inbox
* keyed on the viewer's DID), so there is no public listing to show —
* the "best available public view" is an explanation + a sign-in CTA.
* These tests pin that:
* - signed-out renders the prompt (no crash, no error state),
* - the CTA invokes the shared openSignIn() flow,
* - signed-in still renders the real management UI.
*
* The shared SignedOutPrompt lets us assert one openSignIn() spy across
* both routes.
* (The sibling /groups index has since been retired — it now redirects
* to /home — so only /endorsements remains covered here.)
*/

const openSignIn = vi.fn().mockResolvedValue(undefined)
Expand All @@ -41,7 +41,7 @@ vi.mock("next/navigation", () => ({
useSearchParams: () => new URLSearchParams(""),
}))

// --- /groups dependencies -------------------------------------------------
// org-context is pulled in transitively by the endorsements page chrome.
vi.mock("@/lib/groups/org-context", () => ({
useOrg: () => ({
activeOrg: null,
Expand All @@ -52,12 +52,6 @@ vi.mock("@/lib/groups/org-context", () => ({
}),
}))

vi.mock("@/lib/groups/api", () => ({
putMembership: vi.fn().mockResolvedValue(undefined),
deleteMembership: vi.fn().mockResolvedValue(undefined),
removeOrgMember: vi.fn().mockResolvedValue(undefined),
}))

// --- /endorsements dependencies ------------------------------------------
vi.mock("@/hooks/use-endorsements", () => ({
useGivenEndorsements: () => ({
Expand Down Expand Up @@ -119,30 +113,3 @@ describe("/endorsements public view (signed out)", () => {
expect(screen.getByRole("tab", { name: "Given" })).toBeTruthy()
})
})

describe("/groups public view (signed out)", () => {
it("renders the sign-in prompt instead of redirecting", async () => {
const { default: GroupsPage } = await import("../../app/groups/page")
render(<GroupsPage />)

expect(screen.getByText("Sign in to see your groups")).toBeTruthy()
expect(replace).not.toHaveBeenCalled()
})

it("invokes openSignIn when the CTA is clicked", async () => {
const { default: GroupsPage } = await import("../../app/groups/page")
render(<GroupsPage />)

fireEvent.click(screen.getByRole("button", { name: "Sign in" }))
expect(openSignIn).toHaveBeenCalledTimes(1)
})

it("renders the real Groups UI when authenticated", async () => {
authState = { did: "did:plc:me", isAuthenticated: true, isLoading: false }
const { default: GroupsPage } = await import("../../app/groups/page")
render(<GroupsPage />)

expect(screen.queryByText("Sign in to see your groups")).toBeNull()
expect(screen.getByRole("heading", { name: "Membership" })).toBeTruthy()
})
})
122 changes: 0 additions & 122 deletions src/app/groups/__tests__/leave-group-confirm-dialog.test.tsx

This file was deleted.

8 changes: 4 additions & 4 deletions src/app/groups/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default function CreateGroupPage() {
// in the account switcher + group list.
await putMembership(did, groupDid, "owner")
await refetchOrgs()
router.push("/groups")
router.push("/home")
} catch (err) {
console.error("[groups/create] failed", err)
if (
Expand Down Expand Up @@ -343,9 +343,9 @@ export default function CreateGroupPage() {
>
<Button
variant="secondary"
onClick={() => router.push("/groups")}
onClick={() => router.push("/home")}
>
Back to groups
Back to home
</Button>
</EmptyState>
</div>
Expand Down Expand Up @@ -592,7 +592,7 @@ export default function CreateGroupPage() {
<Button
type="button"
variant="ghost"
onClick={() => router.push("/groups")}
onClick={() => router.push("/home")}
disabled={isCreating}
>
Cancel
Expand Down
2 changes: 1 addition & 1 deletion src/app/groups/import/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function ImportGroupPage() {
console.error("[groups/import] putMembership failed", err)
}
await refetchOrgs()
router.push("/groups")
router.push("/home")
} catch (err) {
if (err instanceof RegisterGroupError && err.code === "GroupAlreadyRegistered") {
setError("This account is already registered as a group.")
Expand Down
Loading
Loading