trails/apps/journal/app/lib/notifications/link-for.test.ts
Ullrich Schäfer 0306d90de8 Merge /follows/requests into /notifications as a tabbed inbox
Folds the actionable follow-requests surface into the Notifications page
as a Requests tab (alongside the existing Activity tab), so the navbar
exposes a single bell instead of two adjacent inboxes. The Requests tab
shows a count badge for pending rows regardless of read state, while the
bell badge keeps reflecting the unread-notifications count (which already
covers `follow_request_received` rows). The standalone /follows/requests
URL is preserved as a 301 redirect so prior notification deep-links,
emails, and bookmarks still resolve.

Driven by the IA review captured in docs/information-architecture.md.
Specs (notifications, social-follows, journal-landing) are updated in
the same change to reflect the new structure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 08:24:59 +02:00

75 lines
2.4 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { linkFor } from "./link-for.ts";
describe("linkFor", () => {
it("follow_received uses payload.followerUsername", () => {
const link = linkFor({
type: "follow_received",
subjectId: null,
payloadVersion: 1,
payload: { followerUsername: "alice", followerDisplayName: null },
});
expect(link.web).toBe("/users/alice");
expect(link.mobile).toBe("trails:/users/alice");
expect(link.email).toMatch(/^https?:\/\//);
expect(link.email).toMatch(/\/users\/alice$/);
});
it("follow_received falls back to / when payload is missing", () => {
const link = linkFor({
type: "follow_received",
subjectId: null,
payloadVersion: 1,
payload: null,
});
expect(link.web).toBe("/");
});
it("follow_request_received always points at the Requests tab on /notifications", () => {
const link = linkFor({
type: "follow_request_received",
subjectId: null,
payloadVersion: 1,
payload: { followerUsername: "bob", followerDisplayName: null },
});
expect(link.web).toBe("/notifications?tab=requests");
});
it("follow_request_approved uses payload.targetUsername", () => {
const link = linkFor({
type: "follow_request_approved",
subjectId: null,
payloadVersion: 1,
payload: { targetUsername: "carol", targetDisplayName: null },
});
expect(link.web).toBe("/users/carol");
});
it("activity_published prefers subjectId, falls back to payload.activityId", () => {
const fromSubject = linkFor({
type: "activity_published",
subjectId: "sub-id-1",
payloadVersion: 1,
payload: { activityId: "payload-id", activityName: "x", ownerUsername: "o", ownerDisplayName: null },
});
expect(fromSubject.web).toBe("/activities/sub-id-1");
const fromPayload = linkFor({
type: "activity_published",
subjectId: null,
payloadVersion: 1,
payload: { activityId: "payload-id", activityName: "x", ownerUsername: "o", ownerDisplayName: null },
});
expect(fromPayload.web).toBe("/activities/payload-id");
});
it("activity_published falls back to / when both subjectId and payload are missing", () => {
const link = linkFor({
type: "activity_published",
subjectId: null,
payloadVersion: 1,
payload: null,
});
expect(link.web).toBe("/");
});
});