Skip to content

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

fix(conversations): correct test for elicitation adapter

Steven Enamakel452c4d9016de
diff --git a/app/src/features/conversations/aui/ElicitationAdapter.test.tsx b/app/src/features/conversations/aui/ElicitationAdapter.test.tsx
new file mode 100644
index 0000000000..35ea0aa4ba
--- /dev/null
+++ b/app/src/features/conversations/aui/ElicitationAdapter.test.tsx
@@ -0,0 +1,61 @@
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { describe, expect, it, vi } from 'vitest';
+
+import { ElicitationAdapter } from './ElicitationAdapter';
+
+describe('ElicitationAdapter', () => {
+ it('renders the question and lets the user type an answer', async () => {
+ const onAnswer = vi.fn();
+ render(
+ <ElicitationAdapter server="OpenHuman" message="Which repo?" pending onAnswer={onAnswer} />
+ );
+
+ expect(screen.getByText('Which repo?')).toBeInTheDocument();
+ const input = screen.getByRole('textbox');
+ await userEvent.type(input, 'openhuman');
+ await userEvent.click(screen.getByRole('button', { name: 'Send' }));
+
+ expect(onAnswer).toHaveBeenCalledWith('openhuman');
+ });
+
+ it('does not call onAnswer for a blank answer', async () => {
+ const onAnswer = vi.fn();
+ render(<ElicitationAdapter server="OpenHuman" message="?" pending onAnswer={onAnswer} />);
+
+ await userEvent.click(screen.getByRole('button', { name: 'Send' }));
+ expect(onAnswer).not.toHaveBeenCalled();
+ });
+
+ it('shows the accepted state once the run is no longer pending', () => {
+ render(
+ <ElicitationAdapter server="OpenHuman" message="?" pending={false} onAnswer={vi.fn()} />
+ );
+
+ expect(screen.getByText('Sent to OpenHuman')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Send' })).not.toBeInTheDocument();
+ });
+
+ it('hides the decline button when onDecline is not supplied', () => {
+ render(<ElicitationAdapter server="OpenHuman" message="?" pending onAnswer={vi.fn()} />);
+
+ expect(screen.queryByRole('button', { name: 'Decline' })).not.toBeInTheDocument();
+ });
+
+ it('declines when onDecline is supplied and clicked', async () => {
+ const onDecline = vi.fn();
+ render(
+ <ElicitationAdapter
+ server="OpenHuman"
+ message="?"
+ pending
+ onAnswer={vi.fn()}
+ onDecline={onDecline}
+ />
+ );
+
+ await userEvent.click(screen.getByRole('button', { name: 'Decline' }));
+ expect(onDecline).toHaveBeenCalled();
+ expect(screen.getByText('Declined')).toBeInTheDocument();
+ });
+});