diff --git a/client/src/components/Chat/Input/ChatForm.tsx b/client/src/components/Chat/Input/ChatForm.tsx index 686cd9f6b6..49955aec2d 100644 --- a/client/src/components/Chat/Input/ChatForm.tsx +++ b/client/src/components/Chat/Input/ChatForm.tsx @@ -254,6 +254,7 @@ const ChatForm = memo(function ChatForm({ * answer box, or is locked behind the batch card that owns the answer. A * collapsed batch is neither, it hands the composer back to the thread. */ const composerReserved = answerMode.composerAnswers || answerMode.composerLocked; + const textValue = useWatch({ control: methods.control, name: 'text' }); const { consumeDraft, preserveText, settleText } = useAutoSave({ index, @@ -437,7 +438,6 @@ const ChatForm = memo(function ChatForm({ ), }); - const textValue = useWatch({ control: methods.control, name: 'text' }); const interfaceDirection = useDirection(); /** An empty `dir="auto"` field resolves to LTR, which would park an RTL interface's placeholder on * the wrong edge, so the empty field follows the interface until text gives it a direction. */ diff --git a/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx b/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx index 5d9a4f9e2d..1a84941fc0 100644 --- a/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx +++ b/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx @@ -233,6 +233,17 @@ describe('ChatForm URL submission', () => { jest.useRealTimers(); }); + it('enables Send when an existing conversation restores a saved draft', async () => { + const conversation = { ...initialConversation, conversationId: 'existing-chat' }; + setDraft({ id: conversation.conversationId, value: 'restored draft' }); + + mountComposer(conversation, { query: '' }); + await act(async () => jest.advanceTimersByTime(100)); + + expect(screen.getByTestId('text-input')).toHaveValue('restored draft'); + expect(screen.getByRole('button', { name: 'Send message' })).toBeEnabled(); + }); + it('processes a queued prompt URL after ordinary conversation navigation without remounting', async () => { const source = { ...initialConversation, conversationId: 'source-chat' }; const view = mountComposer(source, { query: '' }); diff --git a/e2e/specs/mock/scenarios/chat-settings-owners.spec.ts b/e2e/specs/mock/scenarios/chat-settings-owners.spec.ts index 27f3baa2ff..4974827afc 100644 --- a/e2e/specs/mock/scenarios/chat-settings-owners.spec.ts +++ b/e2e/specs/mock/scenarios/chat-settings-owners.spec.ts @@ -1,6 +1,12 @@ import { expect, test } from '@playwright/test'; import type { Page } from '@playwright/test'; -import { sendMessage, selectMockEndpoint, MOCK_ENDPOINTS, NEW_CHAT_PATH } from '../helpers'; +import { + sendMessageAndWaitForCompletion, + selectMockEndpoint, + MOCK_ENDPOINTS, + NEW_CHAT_PATH, + sendMessage, +} from '../helpers'; /** * Save-drafts and temporary chat are app preferences the chat reads through the host's chat @@ -69,11 +75,15 @@ test.describe('chat settings owners', () => { await setPreference(page, 'saveDrafts', true); await page.reload(); + await selectMockEndpoint(page, MOCK_ENDPOINTS[0]); + await sendMessageAndWaitForCompletion(page, `draft-owner-${Date.now()}`); + await expect(page).toHaveURL(/\/c\/(?!new)[^/?]+$/); const kept = `kept draft ${Date.now()}`; await messageInput(page).fill(kept); await expect.poll(() => storedDraftContains(page, kept)).toBe(true); await page.reload(); await expect(messageInput(page)).toHaveValue(kept, { timeout: 20000 }); + await expect(page.getByTestId('send-button')).toBeEnabled(); await messageInput(page).fill(''); await setPreference(page, 'saveDrafts', false); @@ -86,5 +96,6 @@ test.describe('chat settings owners', () => { await page.reload(); await expect(messageInput(page)).toBeVisible({ timeout: 20000 }); await expect(messageInput(page)).toHaveValue(''); + await expect(page.getByTestId('send-button')).toBeDisabled(); }); });