test(context): OrderItemContextPopoverTrigger UI tests
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
f75c1b2bbd
commit
c5fbb7422f
1 changed files with 36 additions and 0 deletions
36
src/components/order-item-context-popover-trigger.test.tsx
Normal file
36
src/components/order-item-context-popover-trigger.test.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { cleanup, render, screen, waitFor, fireEvent } from "@testing-library/react";
|
||||
import { OrderItemContextPopoverTrigger } from "@/components/order-item-context-popover-trigger";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("OrderItemContextPopoverTrigger", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("renders the ⓘ button by default", () => {
|
||||
render(<OrderItemContextPopoverTrigger itemId="x" />);
|
||||
expect(screen.getByRole("button", { name: /View item context/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("fetches on first open, not on render", async () => {
|
||||
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
generated_at: "2026-08-07T10:00:00Z",
|
||||
match: { sku: "X", match_kind: "sku_exact", match_confidence: 1 },
|
||||
last_quote: null, last_order: null, last_invoiced: null, stock: null,
|
||||
suppliers: [], cheapest: null,
|
||||
}),
|
||||
} as Response);
|
||||
|
||||
render(<OrderItemContextPopoverTrigger itemId="abc" />);
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /View item context/ }));
|
||||
await waitFor(() => expect(fetchSpy).toHaveBeenCalledTimes(1));
|
||||
expect(fetchSpy.mock.calls[0][0]).toContain("/api/v1/order-items/abc/context");
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue