diff --git a/client/src/components/Conversations/PinnedSection.tsx b/client/src/components/Conversations/PinnedSection.tsx index 0fb624dd64..45c1eac41f 100644 --- a/client/src/components/Conversations/PinnedSection.tsx +++ b/client/src/components/Conversations/PinnedSection.tsx @@ -279,6 +279,7 @@ const FavoriteRow = ({ item={{ model: favorite.model, endpoint: favorite.endpoint }} type="model" onSelectEndpoint={onSelectEndpoint} + endpointsConfig={endpointsConfig} onRemoveFocus={onRemoveFocus} keyShortcuts={keyShortcuts} /> diff --git a/client/src/components/Conversations/__tests__/PinnedSection.spec.tsx b/client/src/components/Conversations/__tests__/PinnedSection.spec.tsx index fe47a5038c..5cb58fcdf0 100644 --- a/client/src/components/Conversations/__tests__/PinnedSection.spec.tsx +++ b/client/src/components/Conversations/__tests__/PinnedSection.spec.tsx @@ -3,7 +3,8 @@ import { render, screen, fireEvent, act } from '@testing-library/react'; import '@testing-library/jest-dom'; import { DndProvider } from 'react-dnd'; import { HTML5Backend } from 'react-dnd-html5-backend'; -import type { TConversation } from 'librechat-data-provider'; +import type { TConversation, TEndpointsConfig } from 'librechat-data-provider'; +import FavoriteItem from '~/components/Nav/Favorites/FavoriteItem'; import PinnedSection from '../PinnedSection'; const mockSetExpanded = jest.fn(); @@ -106,22 +107,24 @@ jest.mock('../Convo', () => { jest.mock('~/components/Nav/Favorites/FavoriteItem', () => ({ __esModule: true, - default: ({ - item, - type, - keyShortcuts, - }: { - item: { model?: string; id?: string; label?: string }; - type: string; - keyShortcuts?: string; - }) => { - const label = item.id ?? item.label ?? item.model ?? ''; - return ( -
- {label} -
- ); - }, + default: jest.fn( + ({ + item, + type, + keyShortcuts, + }: { + item: { model?: string; id?: string; label?: string }; + type: string; + keyShortcuts?: string; + }) => { + const label = item.id ?? item.label ?? item.model ?? ''; + return ( +
+ {label} +
+ ); + }, + ), })); const pinnedConvo = (id: string, title: string) => @@ -159,6 +162,7 @@ describe('PinnedSection unified list', () => { mockFavoritesData.isAgentsLoading = false; mockFavoritesData.agentsMap = {}; mockFavoritesData.specsMap = {}; + mockFavoritesData.endpointsConfig = {}; }); it('renders nothing when there are no favorites or pinned conversations', () => { @@ -172,6 +176,28 @@ describe('PinnedSection unified list', () => { expect(itemLabels()).toEqual(['gpt-4o', 'Pinned Chat', 'Another Pin']); }); + it('forwards endpoint config to pinned models when the config loads', () => { + const item = { model: 'claude-sonnet-4-5', endpoint: 'AnthropicClaude' }; + mockFavoritesData.favorites = [item]; + const { rerender } = renderSection([]); + + expect(FavoriteItem).toHaveBeenLastCalledWith( + expect.objectContaining({ type: 'model', item, endpointsConfig: {} }), + expect.anything(), + ); + + const endpointsConfig: TEndpointsConfig = { + AnthropicClaude: { iconURL: 'anthropic', order: 0 }, + }; + mockFavoritesData.endpointsConfig = endpointsConfig; + rerender(renderTree([])); + + expect(FavoriteItem).toHaveBeenLastCalledWith( + expect.objectContaining({ type: 'model', item, endpointsConfig }), + expect.anything(), + ); + }); + /* Chats and favorites are two independently ordered groups: an order saved * before that rule, with the two interleaved, is read back grouped. */ it('orders each kind by the stored order and keeps the kinds grouped', () => { diff --git a/client/src/components/Nav/Favorites/FavoriteItem.tsx b/client/src/components/Nav/Favorites/FavoriteItem.tsx index f8840deb96..9e380e39f1 100644 --- a/client/src/components/Nav/Favorites/FavoriteItem.tsx +++ b/client/src/components/Nav/Favorites/FavoriteItem.tsx @@ -32,6 +32,7 @@ type ModelFavoriteProps = FavoriteItemBaseProps & { type: 'model'; item: FavoriteModel; onSelectEndpoint?: (endpoint?: EModelEndpoint | string | null, kwargs?: Kwargs) => void; + endpointsConfig?: TEndpointsConfig; }; type SpecFavoriteProps = FavoriteItemBaseProps & { @@ -105,7 +106,13 @@ export default function FavoriteItem(props: FavoriteItemProps) { } return (
- +
); }; diff --git a/client/src/components/Nav/Favorites/tests/FavoriteItem.providerIcon.spec.tsx b/client/src/components/Nav/Favorites/tests/FavoriteItem.providerIcon.spec.tsx new file mode 100644 index 0000000000..da5d03625b --- /dev/null +++ b/client/src/components/Nav/Favorites/tests/FavoriteItem.providerIcon.spec.tsx @@ -0,0 +1,47 @@ +import { render, screen } from '@testing-library/react'; +import type { TEndpointsConfig } from 'librechat-data-provider'; +import type { FavoriteModel } from '~/store/favorites'; +import FavoriteItem from '../FavoriteItem'; + +/** Renders the real MinimalIcon so the provider resolution is exercised, unlike + * FavoriteItem.spec.tsx which stubs it to assert layout. */ +jest.mock('~/hooks', () => ({ + useLocalize: () => (key: string) => key, + useFavorites: () => ({ + removeFavoriteAgent: jest.fn(), + removeFavoriteModel: jest.fn(), + removeFavoriteSpec: jest.fn(), + }), +})); + +const endpointsConfig: TEndpointsConfig = { + AnthropicClaude: { iconURL: 'anthropic', order: 0 }, + MetaLlama: { iconURL: '/assets/meta-llama.png', order: 1 }, +}; + +const claudeModel: FavoriteModel = { + model: 'claude-sonnet-4-5', + endpoint: 'AnthropicClaude', +}; + +const llamaModel: FavoriteModel = { + model: 'llama3-3-70b-instruct', + endpoint: 'MetaLlama', +}; + +describe('FavoriteItem type="model" provider art', () => { + it('renders the art named by the endpoint iconURL', () => { + render(); + expect(screen.getByRole('img', { name: 'Anthropic', hidden: true })).toBeInTheDocument(); + }); + + it('renders an image iconURL as the art', () => { + render(); + expect(screen.getByAltText('MetaLlama Icon')).toHaveAttribute('src', '/assets/meta-llama.png'); + }); + + it('falls back to the custom art when the endpoint resolves to no provider', () => { + render(); + expect(screen.getByRole('img', { name: 'Custom', hidden: true })).toBeInTheDocument(); + }); +});