mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* [870467e6] Frontend: page-scoped refresh provider, hook, and navbar button (#347) * [55376b8a] Create page-scoped refresh provider and context (#327) * [55376b8a] feat(panel): add page-scoped refresh context and provider * [55376b8a] docs(frontend): add page-refresh-provider component documentation --------- Co-authored-by: Frontend Developer 1 <fe-dev-1@roboco.tech> Co-authored-by: Frontend Documenter <fe-doc@roboco.tech> * [a0c02d0f] Add public usePageRefresh hook (#332) * [a0c02d0f] test(hooks): assert usePageRefresh is exported from hooks barrel * [a0c02d0f] feat(hooks): add public usePageRefresh hook with provider and tests * [a0c02d0f] fix(panel): move hook test wrappers to components and rename providers.tsx to unshadow barrel * [a0c02d0f] docs(panel): document usePageRefresh hook and PageRefreshProvider API --------- Co-authored-by: Frontend Developer 2 <fe-dev-2@roboco.tech> Co-authored-by: Frontend Documenter <fe-doc@roboco.tech> Co-authored-by: Renn F <rennf93@users.noreply.github.com> * [5f28dd9b] Add navbar refresh button and remove inline dashboard refresh buttons (#336) * [5f28dd9b] Align PageRefreshProvider with active hook API and remove inline dashboard refresh buttons * [5f28dd9b] Remove unused scope-keyed PageRefreshProvider, context, and associated tests * [5f28dd9b] Address QA revision: add header refresh tests, page-scoped label, remove dead provider code and .venv symlink, revert formatting-only changes * [5f28dd9b] Remove remaining inline dashboard refresh buttons and committed .venv symlink * [5f28dd9b] docs(frontend): update page-refresh provider docs and panel README for navbar refresh button * [5f28dd9b] fix(panel): remove .venv symlink, ignore root .venv entries, and thin task-detail page data fetch into useTaskDetail hook * [5f28dd9b] Extract GitBrowser data fetching into useGitBrowser hook and add tests; verify .venv cleanup and task-detail thin hook usage * [5f28dd9b] fix(panel): remove root .venv symlink, restore .gitignore anchored rule, and revert lifecycle.json formatting noise * Delete .venv --------- Co-authored-by: Frontend Developer 2 <fe-dev-2@roboco.tech> Co-authored-by: Frontend Documenter <fe-doc@roboco.tech> --------- Co-authored-by: Frontend Developer 1 <fe-dev-1@roboco.tech> Co-authored-by: Frontend Documenter <fe-doc@roboco.tech> Co-authored-by: Frontend Developer 2 <fe-dev-2@roboco.tech> Co-authored-by: Renn F <rennf93@users.noreply.github.com> * [b8e1de1b] Fix navbar refresh button disabled state when registry is empty (#356) (#358) * [b8e1de1b] fix(panel): derive navbar refresh disabled state from registry, not unused prop PageRefreshProvider now computes `disabled` from whether any refresh callback is currently registered (registry size > 0) instead of a static, never-passed `disabled` prop that left the button permanently enabled. header.tsx now destructures `disabled` from usePageRefresh() and disables the button on `disabled || loading`. Updated the tests that asserted the old always-enabled-by-default behavior and added a new header test asserting the button is disabled with zero registered callbacks. * [b8e1de1b] docs(panel): document PageRefreshProvider disabled state derived from registry Updated documentation to reflect the refactored PageRefreshProvider behavior: the `disabled` state is now derived from whether any refresh callbacks are currently registered (empty registry = disabled), rather than a static `disabled` prop. Clarified in both panel/README.md and the full component guide that the navbar refresh button disables when no callbacks are registered and when a refresh cycle is in progress. Updated API documentation to remove the now-removed `disabled` prop from PageRefreshProviderProps and updated code examples and test coverage descriptions to reflect the new callback-driven semantics. --------- Co-authored-by: Frontend Developer 1 <fe-dev-1@roboco.tech> Co-authored-by: Frontend Documenter <fe-doc@roboco.tech> * test(panel): mock usePageRefresh in tests predating the provider Merge-skew: the page-refresh feature makes CommandCenter and the agent detail page call usePageRefresh; three tests merged from master render them without the new provider. Mock the hook module, matching the files' stub-everything style. --------- Co-authored-by: Frontend Developer 1 <fe-dev-1@roboco.tech> Co-authored-by: Frontend Documenter <fe-doc@roboco.tech> Co-authored-by: Frontend Developer 2 <fe-dev-2@roboco.tech> Co-authored-by: Renn F <rennf93@users.noreply.github.com>
127 lines
3.9 KiB
TypeScript
127 lines
3.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import type { ReactNode } from "react";
|
|
import type { ReleaseProposal } from "@/lib/api/release";
|
|
|
|
// Control useQuery per test; the mutation + queryClient hooks just need to exist.
|
|
const { mockUseQuery } = vi.hoisted(() => ({
|
|
mockUseQuery: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@tanstack/react-query", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("@tanstack/react-query")>();
|
|
return {
|
|
...actual,
|
|
useQuery: mockUseQuery,
|
|
useMutation: vi.fn(() => ({ mutate: vi.fn(), mutateAsync: vi.fn() })),
|
|
useQueryClient: vi.fn(() => ({
|
|
invalidateQueries: vi.fn(),
|
|
})),
|
|
};
|
|
});
|
|
|
|
// releaseApi methods never run (useQuery/useMutation are mocked) — the
|
|
// component imports releaseApi from the barrel, so provide a stub object.
|
|
vi.mock("@/lib/api", () => ({
|
|
releaseApi: {
|
|
getProposal: vi.fn(),
|
|
approve: vi.fn(),
|
|
reject: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
import { ReleaseProposalCard } from "../release-proposal-card";
|
|
import { PageRefreshProvider } from "@/components/providers";
|
|
|
|
function withPageRefresh(ui: ReactNode) {
|
|
return <PageRefreshProvider>{ui}</PageRefreshProvider>;
|
|
}
|
|
|
|
function buildProposal(): ReleaseProposal {
|
|
return {
|
|
task_id: "t1",
|
|
title: "Cut v0.14.0",
|
|
status: "awaiting_ceo_approval",
|
|
required_changes: null,
|
|
report: {
|
|
proposed_version: "0.14.0",
|
|
bump_kind: "minor",
|
|
change_summary: ["feat: metrics"],
|
|
drafted_changelog: "## 0.14.0\n- metrics",
|
|
version_bump_plan: ["pyproject.toml"],
|
|
gaps: [],
|
|
migration_notes: [],
|
|
gate_state: "green",
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("ReleaseProposalCard — query-failure surfacing (F082)", () => {
|
|
beforeEach(() => {
|
|
mockUseQuery.mockReturnValue({
|
|
data: undefined,
|
|
isLoading: false,
|
|
isError: false,
|
|
error: null,
|
|
refetch: vi.fn(),
|
|
});
|
|
});
|
|
|
|
it("surfaces a backend error (not a 404) instead of silently hiding", () => {
|
|
// A non-404 failure (500, network drop) rethrows in releaseApi.getProposal,
|
|
// so useQuery sees isError=true + data=undefined. Before the fix the card
|
|
// collapsed this onto `!proposal` and returned null — the CEO had no idea
|
|
// the release-proposal endpoint was unreachable.
|
|
mockUseQuery.mockReturnValue({
|
|
data: undefined,
|
|
isLoading: false,
|
|
isError: true,
|
|
error: new Error("release service unavailable"),
|
|
refetch: vi.fn(),
|
|
});
|
|
|
|
render(withPageRefresh(<ReleaseProposalCard />));
|
|
|
|
// The failure must be visible — not a silent hide. The error card surfaces
|
|
// the underlying message. Refresh is now handled by the navbar refresh button.
|
|
expect(
|
|
screen.getByText(/couldn't load the release proposal/i),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText(/release service unavailable/i),
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it("still hides on the 404 no-open-proposal empty state (regression guard)", () => {
|
|
// 404 → releaseApi.getProposal returns null → data=null, isError=false.
|
|
// That's the normal empty state and must stay hidden (mirrors PrReviewQueue).
|
|
mockUseQuery.mockReturnValue({
|
|
data: null,
|
|
isLoading: false,
|
|
isError: false,
|
|
error: null,
|
|
refetch: vi.fn(),
|
|
});
|
|
|
|
const { container } = render(withPageRefresh(<ReleaseProposalCard />));
|
|
expect(container).toBeEmptyDOMElement();
|
|
});
|
|
|
|
it("renders the proposal card on the happy path (regression guard)", () => {
|
|
mockUseQuery.mockReturnValue({
|
|
data: buildProposal(),
|
|
isLoading: false,
|
|
isError: false,
|
|
error: null,
|
|
refetch: vi.fn(),
|
|
});
|
|
|
|
render(withPageRefresh(<ReleaseProposalCard />));
|
|
expect(screen.getByText(/Release Proposal/i)).toBeInTheDocument();
|
|
expect(screen.getByText("v0.14.0")).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("button", { name: /Approve & publish/i }),
|
|
).toBeInTheDocument();
|
|
});
|
|
});
|