Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(composer): correct trigger test to expect newline after mention

Steven Enamakel594eb92dd32a
diff --git a/app/src/features/conversations/aui/ComposerTriggers.test.tsx b/app/src/features/conversations/aui/ComposerTriggers.test.tsx
new file mode 100644
index 0000000000..ece3a016c4
--- /dev/null
+++ b/app/src/features/conversations/aui/ComposerTriggers.test.tsx
@@ -0,0 +1,78 @@
+import { combineReducers, configureStore } from '@reduxjs/toolkit';
+import {
+ AssistantRuntimeProvider,
+ ComposerPrimitive,
+ type ThreadMessageLike,
+ useExternalStoreRuntime,
+} from '@assistant-ui/react';
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import { Provider } from 'react-redux';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { callCoreRpc } from '../../../services/coreRpcClient';
+import chatRuntimeReducer from '../../../store/chatRuntimeSlice';
+import runModeReducer from '../../../store/runModeSlice';
+import { ComposerTriggers } from './ComposerTriggers';
+
+vi.mock('../../../services/coreRpcClient', () => ({ callCoreRpc: vi.fn() }));
+
+function Harness({ children }: { children: ReactNode }) {
+ const messages: ThreadMessageLike[] = [];
+ const runtime = useExternalStoreRuntime({
+ messages,
+ convertMessage: (m: ThreadMessageLike) => m,
+ onNew: async () => {},
+ });
+ return <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>;
+}
+
+function renderComposer() {
+ const store = configureStore({
+ reducer: combineReducers({ chatRuntime: chatRuntimeReducer, runMode: runModeReducer }),
+ });
+ render(
+ <Provider store={store}>
+ <Harness>
+ <ComposerPrimitive.Unstable_TriggerPopoverRoot>
+ <ComposerPrimitive.Root>
+ <ComposerPrimitive.Input aria-label="Message input" />
+ <ComposerTriggers />
+ </ComposerPrimitive.Root>
+ </ComposerPrimitive.Unstable_TriggerPopoverRoot>
+ </Harness>
+ </Provider>
+ );
+ return screen.getByRole('textbox', { name: 'Message input' });
+}
+
+async function type(input: HTMLElement, value: string) {
+ await act(async () => {
+ fireEvent.change(input, { target: { value } });
+ });
+}
+
+describe('ComposerTriggers', () => {
+ beforeEach(() => {
+ vi.mocked(callCoreRpc).mockReset();
+ vi.mocked(callCoreRpc).mockResolvedValue({});
+ });
+
+ it('opens the slash popover with the builtin commands on `/`', async () => {
+ const input = renderComposer();
+ await type(input, '/pl');
+
+ const popover = await screen.findByTestId('composer-slash-popover');
+ expect(popover).toHaveTextContent('/plan');
+ expect(popover).toHaveTextContent('Plan first: review the steps before anything runs');
+ });
+
+ it('opens the mention popover with Memory and Files on `@`', async () => {
+ const input = renderComposer();
+ await type(input, 'look at @');
+
+ const popover = await screen.findByTestId('composer-mention-popover');
+ await waitFor(() => expect(popover).toHaveTextContent('Memory'));
+ expect(popover).toHaveTextContent('Files');
+ });
+});