Skip to content
Merged
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
12 changes: 6 additions & 6 deletions packages/core/src/components/action-panel/ActionPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ describe("ActionPanel", () => {
});
});

describe("ActionPanel context registration", () => {
const ActionsReader = ({ onActions }: { onActions: (a: unknown[]) => void }) => {
const actions = useCommandPaletteActions();
onActions(actions);
return null;
};
const ActionsReader = ({ onActions }: { onActions: (a: unknown[]) => void }) => {
const actions = useCommandPaletteActions();
onActions(actions);
return null;
};

describe("ActionPanel context registration", () => {
it("registers actions to CommandPaletteContext on mount", () => {
const onActions = vi.fn();

Expand Down
36 changes: 19 additions & 17 deletions packages/core/src/components/ai-chat/ai-chat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ afterEach(() => {

const textbox = () => screen.getByRole("textbox", { name: "Message" }) as HTMLTextAreaElement;
const sendButton = () => screen.getByRole("button", { name: "Send" }) as HTMLButtonElement;
type AIChatStatus = "ready" | "submitted" | "streaming" | "error";

// A tree whose transcript changes per render, with one child the root rejects.
const strayChildTree = (token: string) => (
Expand All @@ -21,6 +22,24 @@ const strayChildTree = (token: string) => (
</AIChat>
);

const WrappedComposer = () => <AIChat.Composer onSubmit={vi.fn()} />;

function renderComposer(
composerProps: Partial<Parameters<typeof AIChat.Composer>[0]> = {},
status?: AIChatStatus,
) {
const onSubmit = vi.fn();
const view = render(
<AIChat status={status}>
<AIChat.Conversation>
<div />
</AIChat.Conversation>
<AIChat.Composer onSubmit={onSubmit} {...composerProps} />
</AIChat>,
);
return { ...view, onSubmit };
}

describe("AIChat", () => {
describe("snapshots", () => {
it("default", () => {
Expand Down Expand Up @@ -156,7 +175,6 @@ describe("AIChat", () => {

it("names the direct-child requirement so a wrapped region is diagnosable", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const WrappedComposer = () => <AIChat.Composer onSubmit={vi.fn()} />;
render(
<AIChat>
<AIChat.Conversation>
Expand Down Expand Up @@ -218,22 +236,6 @@ describe("AIChat", () => {
});

describe("composer", () => {
function renderComposer(
composerProps: Partial<Parameters<typeof AIChat.Composer>[0]> = {},
status?: "ready" | "submitted" | "streaming" | "error",
) {
const onSubmit = vi.fn();
const view = render(
<AIChat status={status}>
<AIChat.Conversation>
<div />
</AIChat.Conversation>
<AIChat.Composer onSubmit={onSubmit} {...composerProps} />
</AIChat>,
);
return { ...view, onSubmit };
}

it("submits the trimmed message on Enter and clears the draft", async () => {
const user = userEvent.setup();
const { onSubmit } = renderComposer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ afterEach(() => {

const suggestions = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];

/** Advance timers and flush microtasks. */
async function advanceAndFlush(ms: number) {
await act(async () => {
vi.advanceTimersByTime(ms);
});
}

function SimpleAutocomplete(props: {
onValueChange?: (value: string, event: unknown) => void;
defaultValue?: string;
Expand Down Expand Up @@ -206,13 +213,6 @@ describe("useAsync", () => {
vi.useRealTimers();
});

/** Advance timers and flush microtasks. */
async function advanceAndFlush(ms: number) {
await act(async () => {
vi.advanceTimersByTime(ms);
});
}

it("returns correct shape with mapped property names", () => {
const fetcher = vi.fn(async () => []);
const { result } = renderHook(() => useAsync({ fetcher }));
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/components/combobox/combobox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ afterEach(() => {

const fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];

/** Advance timers and flush microtasks. */
async function advanceAndFlush(ms: number) {
await act(async () => {
vi.advanceTimersByTime(ms);
});
}

function SimpleCombobox(props: {
onValueChange?: (value: string | null, event: unknown) => void;
defaultValue?: string;
Expand Down Expand Up @@ -1341,13 +1348,6 @@ describe("useAsync", () => {
vi.useRealTimers();
});

/** Advance timers and flush microtasks. */
async function advanceAndFlush(ms: number) {
await act(async () => {
vi.advanceTimersByTime(ms);
});
}

it("returns correct shape", () => {
const fetcher = vi.fn(async () => []);
const { result } = renderHook(() => useAsync({ fetcher }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ vi.mock("react-router", async (importOriginal) => {
// Wrapper for hooks that need router context
const wrapper = ({ children }: { children: ReactNode }) => <MemoryRouter>{children}</MemoryRouter>;

const createMixedSources = (): Array<SearchSource> => [
{
prefix: "ORD",
title: "Orders",
search: vi.fn().mockResolvedValue([]),
},
{
prefix: "CU",
title: "Customers",
search: vi.fn().mockResolvedValue([]),
},
];

describe("useCommandPalette", () => {
const renderCommandPaletteHook = (routes = createTestRoutes()) => {
return renderHook(
Expand Down Expand Up @@ -916,19 +929,6 @@ describe("useCommandPalette with actions, routes, and searchSources combined", (
},
];

const createMixedSources = (): Array<SearchSource> => [
{
prefix: "ORD",
title: "Orders",
search: vi.fn().mockResolvedValue([]),
},
{
prefix: "CU",
title: "Customers",
search: vi.fn().mockResolvedValue([]),
},
];

const renderMixed = (
routes = createTestRoutes2(),
contextualActions = createMixedActions(),
Expand Down
Loading
Loading