mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 21:08:17 +00:00
* feat: Give Theme-Sized Controls Their Own Padding and Gap Roles The theme variants of Button and Chip, CheckboxButton and every composer control read spaceNormal and spaceCompact, which also pad message rows, steer bubbles and the composer send button, so a theme could not give its controls Click UI's button spacing without reshaping the chat. Add controlPaddingX and controlGap appearance roles, which those controls read instead. Their defaults are the shared spacing values, a theme that names only spaceNormal or spaceCompact keeps its controls on them, and the preset falls back to the shared roles for a stylesheet that predates these. The ClickHouse theme takes Click UI's button.basic.space.x and space.gap, and the drift guard pins both values and measures the themed Button's padding and gap. * test: Reach the Temporary Chat Chip Through a Sent Message The header status chip only appears once a temporary chat has its first message, so the scenarios send one, and measure the real message bubble instead of a probe for the shared spacing. * fix: Let the Control Spacing Roles Replace the Base Gap Tailwind Merge could not classify px-theme-control-x or gap-theme-control-gap, so a theme-sized Button kept the base gap-2 beside the role and a caller's own padding beside both, leaving the winner to stylesheet order. Register both utilities with their groups. * fix: Alias the Stock Control Spacing to the Shared Spacing Roles A stylesheet that set only --theme-space-normal or --theme-space-compact stopped reaching Button, Chip and the composer controls once the stock CSS declared the control roles as literals, so the preset's fallback never ran. The stock declarations now read the shared roles, with the same defaults. * test: Assert the Control Spacing Utilities Declare Their Own Properties
190 lines
6.6 KiB
TypeScript
190 lines
6.6 KiB
TypeScript
import userEvent from '@testing-library/user-event';
|
|
import { render, screen, within } from '@testing-library/react';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import { QueryKeys, Constants, LocalStorageKeys } from 'librechat-data-provider';
|
|
import type { TConversation } from 'librechat-data-provider';
|
|
import CodeApprovalMenu from '../CodeApprovalMenu';
|
|
|
|
const mockSetConversation = jest.fn();
|
|
const mockUseCodeApprovalMode = jest.fn();
|
|
|
|
jest.mock('~/hooks', () => ({
|
|
useLocalize: () => (key: string) => key,
|
|
useCodeApprovalMode: () => mockUseCodeApprovalMode(),
|
|
}));
|
|
|
|
const conversation = {
|
|
conversationId: 'conversation-1',
|
|
endpoint: 'agents',
|
|
agent_id: 'agent-1',
|
|
title: 'Code',
|
|
} as TConversation;
|
|
|
|
describe('CodeApprovalMenu', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mockUseCodeApprovalMode.mockReturnValue({
|
|
available: true,
|
|
modes: ['ask', 'acceptEdits'],
|
|
selected: 'ask',
|
|
});
|
|
});
|
|
|
|
let queryClient: QueryClient;
|
|
|
|
const renderMenu = () => {
|
|
queryClient = new QueryClient();
|
|
return render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<CodeApprovalMenu
|
|
conversation={conversation}
|
|
setConversation={mockSetConversation}
|
|
disabled={false}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
};
|
|
|
|
test('defaults to ask and stores accept-edits on the conversation', async () => {
|
|
renderMenu();
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
await userEvent.click(await screen.findByText('com_ui_code_approval_accept_edits'));
|
|
|
|
const update = mockSetConversation.mock.calls[0][0];
|
|
expect(update(conversation)).toEqual({ ...conversation, codeApprovalMode: 'acceptEdits' });
|
|
});
|
|
|
|
test('writes the pick into the conversation detail cache', async () => {
|
|
renderMenu();
|
|
const key = [QueryKeys.conversation, conversation.conversationId];
|
|
queryClient.setQueryData<TConversation>(key, { ...conversation, codeApprovalMode: 'ask' });
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
await userEvent.click(await screen.findByText('com_ui_code_approval_accept_edits'));
|
|
|
|
expect(queryClient.getQueryData<TConversation>(key)?.codeApprovalMode).toBe('acceptEdits');
|
|
});
|
|
|
|
test('seeds a detail record from the live conversation when none exists yet', async () => {
|
|
renderMenu();
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
await userEvent.click(await screen.findByText('com_ui_code_approval_accept_edits'));
|
|
|
|
expect(queryClient.getQueryData([QueryKeys.conversation, conversation.conversationId])).toEqual(
|
|
{ ...conversation, codeApprovalMode: 'acceptEdits' },
|
|
);
|
|
});
|
|
|
|
test('leaves the detail cache alone for a chat that has no id yet', async () => {
|
|
queryClient = new QueryClient();
|
|
render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<CodeApprovalMenu
|
|
conversation={{ ...conversation, conversationId: Constants.NEW_CONVO as string }}
|
|
setConversation={mockSetConversation}
|
|
disabled={false}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
await userEvent.click(await screen.findByText('com_ui_code_approval_accept_edits'));
|
|
|
|
expect(queryClient.getQueryData([QueryKeys.conversation, Constants.NEW_CONVO])).toBeUndefined();
|
|
});
|
|
|
|
test('offers every mode as a radio and marks the selected one', async () => {
|
|
renderMenu();
|
|
|
|
const trigger = screen.getByTestId('code-approval-mode');
|
|
expect(trigger).toHaveTextContent('com_ui_code_approval_ask');
|
|
await userEvent.click(trigger);
|
|
expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
|
|
const menu = await screen.findByRole('menu', { name: 'com_ui_code_approval_mode' });
|
|
expect(document.querySelector('h1')).toBeNull();
|
|
const options = within(menu).getAllByRole('menuitemradio');
|
|
expect(options).toHaveLength(2);
|
|
expect(options[0]).toHaveAttribute('aria-checked', 'true');
|
|
expect(options[0]).toHaveTextContent('com_ui_code_approval_ask_description');
|
|
expect(options[1]).toHaveAttribute('aria-checked', 'false');
|
|
expect(options[1]).toHaveTextContent('com_ui_code_approval_accept_edits_description');
|
|
});
|
|
|
|
test('draws the trigger from the shared composer control appearance', () => {
|
|
renderMenu();
|
|
|
|
expect(screen.getByTestId('code-approval-mode')).toHaveClass(
|
|
'h-theme-control',
|
|
'rounded-theme-control-round',
|
|
'gap-theme-control-gap',
|
|
'border-border-medium',
|
|
);
|
|
});
|
|
|
|
test('offers only the modes the conversation allows', async () => {
|
|
mockUseCodeApprovalMode.mockReturnValue({
|
|
available: true,
|
|
modes: ['ask'],
|
|
selected: 'ask',
|
|
});
|
|
renderMenu();
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
|
|
const menu = await screen.findByRole('menu');
|
|
expect(within(menu).getAllByRole('menuitemradio')).toHaveLength(1);
|
|
});
|
|
|
|
test('hides the control when code approvals are unavailable', () => {
|
|
mockUseCodeApprovalMode.mockReturnValue({ available: false, modes: [] });
|
|
|
|
renderMenu();
|
|
expect(screen.queryByTestId('code-approval-mode')).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('selects full access on the conversation with sandbox scope explained', async () => {
|
|
mockUseCodeApprovalMode.mockReturnValue({
|
|
available: true,
|
|
modes: ['ask', 'acceptEdits', 'fullAccess'],
|
|
selected: 'ask',
|
|
});
|
|
renderMenu();
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
expect(within(await screen.findByRole('menu')).getAllByRole('menuitemradio')).toHaveLength(3);
|
|
expect(screen.getByText('com_ui_code_approval_full_access_description')).toBeInTheDocument();
|
|
await userEvent.click(screen.getByText('com_ui_code_approval_full_access'));
|
|
expect(mockSetConversation.mock.calls[0][0](conversation)).toEqual({
|
|
...conversation,
|
|
codeApprovalMode: 'fullAccess',
|
|
});
|
|
});
|
|
});
|
|
|
|
test("remembers the pick as this browser's default for the next chat", async () => {
|
|
localStorage.clear();
|
|
mockUseCodeApprovalMode.mockReturnValue({
|
|
available: true,
|
|
modes: ['ask', 'acceptEdits'],
|
|
selected: 'ask',
|
|
});
|
|
render(
|
|
<QueryClientProvider client={new QueryClient()}>
|
|
<CodeApprovalMenu
|
|
conversation={conversation}
|
|
setConversation={mockSetConversation}
|
|
disabled={false}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
|
|
await userEvent.click(screen.getByTestId('code-approval-mode'));
|
|
await userEvent.click(await screen.findByText('com_ui_code_approval_accept_edits'));
|
|
|
|
expect(localStorage.getItem(LocalStorageKeys.LAST_CODE_APPROVAL_MODE)).toBe(
|
|
JSON.stringify('acceptEdits'),
|
|
);
|
|
});
|