Skip to content
555 changes: 555 additions & 0 deletions backend/tests/stream-completed-event.test.ts

Large diffs are not rendered by default.

614 changes: 614 additions & 0 deletions backend/tests/stream-topped-up-rate.test.ts

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions frontend/src/app/activity/activity-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Loader2, Download } from "lucide-react";
import { formatAmount } from "@/utils/amount";
import { downloadCSV } from "@/utils/csvExport";
import { getApiBaseUrl } from "@/lib/api/_shared";
import { useAsyncPageData } from "@/hooks/useAsyncPageData";
import { logger } from "@/lib/logger";

const PAGE_SIZE = 10;
Expand Down Expand Up @@ -91,6 +92,14 @@ export default function ActivityContent() {
fetchActivity(nextPage, activeTab, true);
};

const view = useAsyncPageData({
enabled: status === "connected",
isLoading: loading,
isError: error !== null,
isEmpty: events.length === 0,
error,
});

const handleExportCSV = () => {
const csvData = events.map(event => ({
'Stream ID': event.streamId,
Expand All @@ -103,7 +112,7 @@ export default function ActivityContent() {
downloadCSV(csvData, `flowfi-activity-${Date.now()}.csv`);
};

if (status !== "connected") {
if (!view.isEnabled) {
return (
<div className="flex flex-col items-center justify-center min-h-[60vh] text-center">
<h1 className="text-2xl font-bold mb-2 text-white">Access Denied</h1>
Expand Down Expand Up @@ -157,9 +166,9 @@ export default function ActivityContent() {

<ActivityHistory events={events} isLoading={loading && events.length === 0} />

{error && (
{view.isError && (
<div role="alert" className="mt-6 text-center">
<p className="text-slate-400">{error}</p>
<p className="text-slate-400">{view.error}</p>
<Button
variant="secondary"
onClick={() => {
Expand Down
144 changes: 144 additions & 0 deletions frontend/src/app/incoming/__tests__/incoming-content.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { describe, expect, it, vi, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";

// The incoming page now derives its loading / error / empty / ready branches
// from `useAsyncPageData` (#1085). These tests pin the rendered result of each
// branch so the shared hook cannot silently change what the page shows.

const wallet = vi.hoisted(() => ({
current: {
session: { publicKey: "GAAAA", network: "testnet" } as Record<string, string> | null,
status: "connected" as string,
isHydrated: true,
},
}));

vi.mock("@/context/wallet-context", () => ({
useWallet: () => wallet.current,
}));

vi.mock("@/components/TransactionTracker", () => ({
default: () => null,
useTransactionTracker: () => ({
status: "idle",
txHash: null,
error: null,
start: vi.fn(),
submit: vi.fn(),
confirm: vi.fn(),
fail: vi.fn(),
succeed: vi.fn(),
}),
}));

const query = vi.hoisted(() => ({
current: {
data: undefined as unknown,
isLoading: false,
isError: false,
error: null as unknown,
},
}));

vi.mock("@/hooks/useIncomingStreams", () => ({
useIncomingStreams: () => query.current,
useWithdrawIncomingStream: () => ({
isPending: false,
variables: undefined,
mutateAsync: vi.fn(),
}),
}));

vi.mock("@/components/streams/IncomingStreamCard", () => ({
IncomingStreamCard: ({ stream }: { stream: { id: string } }) => (
<div data-testid="stream-card">{stream.id}</div>
),
}));

import IncomingContent from "@/app/incoming/incoming-content";

function setWallet(overrides: Partial<typeof wallet.current> = {}) {
wallet.current = { ...wallet.current, ...overrides };
}

beforeEach(() => {
setWallet({
session: { publicKey: "GAAAA", network: "testnet" },
status: "connected",
isHydrated: true,
});
query.current = { data: [], isLoading: false, isError: false, error: null };
});

describe("IncomingContent page states (#1085)", () => {
it("shows skeletons before hydration has resolved the wallet", () => {
setWallet({ isHydrated: false });
render(<IncomingContent />);

expect(screen.getByText(/Streams paying into your wallet/i)).toBeInTheDocument();
expect(screen.queryByText(/Connect a wallet to view incoming streams/i)).toBeNull();
expect(screen.queryByTestId("stream-card")).toBeNull();
});

it("asks for a wallet once hydrated but still disconnected", () => {
setWallet({ isHydrated: true, status: "disconnected", session: null });
render(<IncomingContent />);

expect(screen.getByText(/Connect a wallet to view incoming streams/i)).toBeInTheDocument();
});

it("renders the query error message when the fetch failed", () => {
query.current = {
data: undefined,
isLoading: false,
isError: true,
error: new Error("upstream exploded"),
};
render(<IncomingContent />);

expect(screen.getByText(/We couldn.t load your incoming streams/i)).toBeInTheDocument();
expect(screen.getByText("upstream exploded")).toBeInTheDocument();
});

it("prefers the error branch while a retry is already in flight", () => {
query.current = {
data: undefined,
isLoading: true,
isError: true,
error: new Error("upstream exploded"),
};
render(<IncomingContent />);

expect(screen.getByText(/We couldn.t load your incoming streams/i)).toBeInTheDocument();
});

it("falls back to a generic message when the error is not an Error", () => {
query.current = { data: undefined, isLoading: false, isError: true, error: "nope" };
render(<IncomingContent />);

expect(screen.getByText("Please try again in a moment.")).toBeInTheDocument();
});

it("shows the empty state once loaded with no streams", () => {
query.current = { data: [], isLoading: false, isError: false, error: null };
render(<IncomingContent />);

expect(screen.getByText(/No incoming streams yet/i)).toBeInTheDocument();
});

it("renders one card per stream when ready", () => {
query.current = {
data: [
{ id: "s1", streamId: 1, withdrawn: 0 },
{ id: "s2", streamId: 2, withdrawn: 0 },
],
isLoading: false,
isError: false,
error: null,
};
render(<IncomingContent />);

expect(screen.getAllByTestId("stream-card")).toHaveLength(2);
expect(screen.queryByText(/No incoming streams yet/i)).toBeNull();
});
});
28 changes: 16 additions & 12 deletions frontend/src/app/incoming/incoming-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useIncomingStreams,
useWithdrawIncomingStream,
} from "@/hooks/useIncomingStreams";
import { useAsyncPageData } from "@/hooks/useAsyncPageData";

function LoadingCard() {
return (
Expand Down Expand Up @@ -77,10 +78,17 @@ export default function IncomingContent() {
}
};

const isLoading =
!isHydrated ||
(status === "connected" && incomingStreamsQuery.isLoading);
const streams = incomingStreamsQuery.data ?? [];
const view = useAsyncPageData({
enabled: isHydrated && status === "connected",
isLoading: incomingStreamsQuery.isLoading,
isError: incomingStreamsQuery.isError,
isEmpty: streams.length === 0,
error:
incomingStreamsQuery.error instanceof Error
? incomingStreamsQuery.error.message
: "Please try again in a moment.",
});

return (
<main className="px-4 py-10 sm:px-6 lg:px-8">
Expand Down Expand Up @@ -116,7 +124,7 @@ export default function IncomingContent() {
<LoadingCard />
<LoadingCard />
</section>
) : status !== "connected" ? (
) : !view.isEnabled ? (
<section className="mt-8 rounded-[2rem] border border-white/45 bg-white/75 p-10 text-center shadow-[0_24px_50px_rgba(15,23,42,0.07)]">
<h2 className="text-2xl font-semibold text-slate-950">
Connect a wallet to view incoming streams
Expand All @@ -126,24 +134,20 @@ export default function IncomingContent() {
where you are the recipient and keep the claimable balance fresh.
</p>
</section>
) : incomingStreamsQuery.isError ? (
) : view.isError ? (
<section className="mt-8 rounded-[2rem] border border-rose-200 bg-rose-50/80 p-8 shadow-[0_18px_36px_rgba(190,24,93,0.08)]">
<h2 className="text-xl font-semibold text-rose-900">
We couldn&apos;t load your incoming streams
</h2>
<p className="mt-2 text-sm text-rose-700">
{incomingStreamsQuery.error instanceof Error
? incomingStreamsQuery.error.message
: "Please try again in a moment."}
</p>
<p className="mt-2 text-sm text-rose-700">{view.error}</p>
</section>
) : isLoading ? (
) : view.isLoading ? (
<section className="mt-8 grid gap-5 md:grid-cols-2 xl:grid-cols-3">
<LoadingCard />
<LoadingCard />
<LoadingCard />
</section>
) : streams.length === 0 ? (
) : view.isEmpty ? (
<section className="mt-8 rounded-[2rem] border border-white/45 bg-white/75 p-10 text-center shadow-[0_24px_50px_rgba(15,23,42,0.07)]">
<h2 className="text-2xl font-semibold text-slate-950">
No incoming streams yet
Expand Down
61 changes: 61 additions & 0 deletions frontend/src/components/dashboard/DashboardSettings.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { DashboardSettings } from "./DashboardSettings";
import type { WalletSession } from "@/lib/wallet";

const session: WalletSession = {
walletId: "freighter",
walletName: "Freighter",
publicKey: "GABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC",
connectedAt: "2026-11-21T00:00:00.000Z",
network: "testnet",
mocked: false,
};

function renderSettings() {
return render(<DashboardSettings session={session} onDisconnect={vi.fn()} />);
}

describe("DashboardSettings form labeling (#632)", () => {
it("associates the template name input with a label via id + htmlFor", () => {
const { container } = renderSettings();

const input = screen.getByLabelText("Template name");
expect(input).toBeInTheDocument();
expect(input.tagName).toBe("INPUT");
expect(input).toHaveAttribute("id", "stream-template-name");

const label = container.querySelector<HTMLLabelElement>(
'label[for="stream-template-name"]',
);
expect(label).not.toBeNull();
expect(label?.textContent?.trim()).toBe("Template name");
});

it("keeps the label visually hidden so the layout is unchanged", () => {
const { container } = renderSettings();

const label = container.querySelector('label[for="stream-template-name"]');
expect(label?.getAttribute("class")).toContain("sr-only");
});

it("gives every form control an id and a programmatic label", () => {
const { container } = renderSettings();

const controls = container.querySelectorAll<HTMLElement>(
"input, textarea, select",
);
expect(controls.length).toBeGreaterThan(0);

for (const control of controls) {
expect(control.id, `${control.tagName} is missing an id`).not.toBe("");
expect(
container.querySelector(`label[for="${CSS.escape(control.id)}"]`),
`${control.id} has no label targeting it`,
).not.toBeNull();
}

// Each control must resolve through its accessible name, not just markup.
expect(screen.getAllByLabelText("Template name")).toHaveLength(1);
});
});
5 changes: 4 additions & 1 deletion frontend/src/components/dashboard/DashboardSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export function DashboardSettings({ session, onDisconnect }: DashboardSettingsPr
</p>

<div className="stream-template-editor">
<label className="sr-only" htmlFor="stream-template-name">
Template name
</label>
<input
id="stream-template-name"
placeholder="e.g. Monthly Contributor Payroll"
aria-label="Template name"
/>
<div className="stream-template-editor__actions">
<button className="secondary-button" disabled>
Expand Down
Loading
Loading