Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ jest.mock("@/lib/api", () => ({
fetchBounties: jest.fn(),
}));
jest.mock("@/context/AuthContext", () => ({ useAuth: jest.fn() }));
let mockSearchParams = new URLSearchParams();
jest.mock("next/navigation", () => ({
useRouter: () => ({ replace: jest.fn(), refresh: jest.fn() }),
usePathname: () => "/dashboard/contributor",
useSearchParams: () => new URLSearchParams(),
useSearchParams: () => mockSearchParams,
}));

const mockUseAuth = useAuth as jest.MockedFunction<typeof useAuth>;
Expand Down Expand Up @@ -63,6 +64,7 @@ function deferred<T>() {

beforeEach(() => {
jest.clearAllMocks();
mockSearchParams = new URLSearchParams();
mockFetchBounties.mockResolvedValue({
data: mockBounties,
source: "live",
Expand Down Expand Up @@ -165,3 +167,44 @@ describe("ContributorDashboardClient — out-of-order response guard", () => {
expect(await screen.findByText("Live data")).toBeInTheDocument();
});
});

describe("ContributorDashboardClient — tab query param validation (#692)", () => {
it("defaults to active tab when ?tab= is missing", async () => {
mockSearchParams = new URLSearchParams();
await act(async () => {
render(<ContributorDashboardClient />);
});
expect(screen.getByRole("tab", { name: /Active/ })).toHaveAttribute(
"aria-selected",
"true",
);
});

it("selects completed tab when ?tab=completed is passed", async () => {
mockSearchParams = new URLSearchParams({ tab: "completed" });
await act(async () => {
render(<ContributorDashboardClient />);
});
expect(screen.getByRole("tab", { name: /Completed/ })).toHaveAttribute(
"aria-selected",
"true",
);
});

it("falls back to active tab when an invalid ?tab= value is provided", async () => {
mockSearchParams = new URLSearchParams({ tab: "foo" });
await act(async () => {
render(<ContributorDashboardClient />);
});
expect(screen.getByRole("tab", { name: /Active/ })).toHaveAttribute(
"aria-selected",
"true",
);
expect(screen.getByRole("tab", { name: /Completed/ })).toHaveAttribute(
"aria-selected",
"false",
);
});
});


3 changes: 2 additions & 1 deletion src/app/dashboard/contributor/ContributorDashboardClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ export default function ContributorDashboardClient() {
const [bounties, setBounties] = useState<Bounty[]>(mockBounties);
const [statsSource, setStatsSource] = useState<DataSource>("loading");
const [bountiesSource, setBountiesSource] = useState<DataSource>("loading");
const tabParam = searchParams.get("tab");
const [tab, setTabState] = useState<"active" | "completed">(
(searchParams.get("tab") as "active" | "completed") || "active"
tabParam === "completed" ? "completed" : "active"
);
// Explicit fetch status: starts "loading" so cards shimmer rather than
// flashing zeroes while the auth check + API call are in flight.
Expand Down