import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { PathLinkRestore } from "../src/App";
import type { PacketDetail } from "../src/types/api";
const getPacketDetail = vi.fn();
vi.mock("../src/api/client", () => ({
getPacketDetail: (hash: string) => getPacketDetail(hash),
}));
const wrapper = ({ children }: { children: React.ReactNode }) => (
{children}
);
beforeEach(() => getPacketDetail.mockReset());
const detail = { packetHash: "AA11", observations: [] } as unknown as PacketDetail;
describe("PathLinkRestore", () => {
// Regression: PacketPathMapModal's Copy Link strips ?analyze, so a copied path link carries ?hash
// without it — the popup can't rely on the analyzer drawer's fetch and needs its own.
it("restores the path popup from ?hash&?path alone, with no ?analyze", async () => {
getPacketDetail.mockResolvedValue(detail);
const onRestore = vi.fn();
render(
,
{ wrapper },
);
await waitFor(() => expect(onRestore).toHaveBeenCalledWith(detail, "obs-alpha"));
expect(getPacketDetail).toHaveBeenCalledWith("AA11");
});
it("does not fetch when there is no ?path", () => {
render(
,
{ wrapper },
);
expect(getPacketDetail).not.toHaveBeenCalled();
});
it("uses the analyzer's already-fetched detail instead of waiting on its own fetch", () => {
const onRestore = vi.fn();
render(
,
{ wrapper },
);
expect(onRestore).toHaveBeenCalledWith(detail, "obs-alpha");
});
});