test: teach MCP hook mocks about useMCPServerNames

Three specs mock ~/hooks/MCP with a hand-listed factory, so adding the hook
to ToolCall made useMCPServerNames undefined under test and every render
threw. Returns a stable array so the mock cannot perturb render counts.
This commit is contained in:
Danny Avila 2026-07-27 08:24:13 -04:00
parent f6fbf08687
commit 28131fed03
3 changed files with 22 additions and 10 deletions

View file

@ -1,8 +1,8 @@
import React from 'react';
import { RecoilRoot } from 'recoil';
import { ContentTypes } from 'librechat-data-provider';
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
import { fireEvent, render, screen } from '@testing-library/react';
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
import ContentParts from '../ContentParts';
jest.mock('~/hooks', () => ({
@ -20,9 +20,13 @@ jest.mock('~/hooks', () => ({
scheduleMessageContentLayoutReconcile: jest.fn(() => jest.fn()),
}));
jest.mock('~/hooks/MCP', () => ({
useMCPIconMap: () => new Map(),
}));
jest.mock('~/hooks/MCP', () => {
const mcpServerNames: string[] = [];
return {
useMCPIconMap: () => new Map(),
useMCPServerNames: () => mcpServerNames,
};
});
jest.mock('../ToolOutput', () => ({
StackedToolIcons: () => <span data-testid="stacked-icons" />,

View file

@ -33,9 +33,13 @@ jest.mock('~/hooks', () => ({
}),
}));
jest.mock('~/hooks/MCP', () => ({
useMCPIconMap: () => new Map(),
}));
jest.mock('~/hooks/MCP', () => {
const mcpServerNames: string[] = [];
return {
useMCPIconMap: () => new Map(),
useMCPServerNames: () => mcpServerNames,
};
});
jest.mock('~/components/Chat/Messages/Content/MessageContent', () => ({
__esModule: true,

View file

@ -32,9 +32,13 @@ jest.mock('~/hooks', () => ({
scheduleMessageContentLayoutReconcile: jest.fn(() => jest.fn()),
}));
jest.mock('~/hooks/MCP', () => ({
useMCPIconMap: () => new Map(),
}));
jest.mock('~/hooks/MCP', () => {
const mcpServerNames: string[] = [];
return {
useMCPIconMap: () => new Map(),
useMCPServerNames: () => mcpServerNames,
};
});
jest.mock('../ToolOutput', () => ({
StackedToolIcons: ({ toolNames }: { toolNames: string[] }) => (