diff --git a/README.md b/README.md index 1691d070..4a7cb01f 100644 --- a/README.md +++ b/README.md @@ -175,14 +175,6 @@ interface RequestAtCommandPreview extends ActionFromChat { payload: { id: string; query: string; cursor: number }; } -/** - * This message is sent from the host to the chat contains the result of command preview request. - */ -interface ReceiveAtCommandPreview extends ActionToChat { - type: EVENT_NAMES_TO_CHAT.RECEIVE_AT_COMMAND_PREVIEW; // = "chat_receive_at_command_preview" - payload: { id: string; preview: ChatContextFileMessage[] }; -} - /** * This message is sent from the chat component to the host when the response to the question is received. */ diff --git a/src/components/ChatForm/CharForm.test.tsx b/src/components/ChatForm/CharForm.test.tsx index 6c5db8eb..b7e773e7 100644 --- a/src/components/ChatForm/CharForm.test.tsx +++ b/src/components/ChatForm/CharForm.test.tsx @@ -1,44 +1,50 @@ import { render } from "../../utils/test-utils"; import { describe, expect, test, vi } from "vitest"; -import { ChatForm } from "./ChatForm"; +import { ChatForm, ChatFormProps } from "./ChatForm"; +import React from "react"; + +const noop = () => ({}); + +const App: React.FC> = (props) => { + const defaultProps: ChatFormProps = { + removePreviewFileByName: noop, + selectedSnippet: { code: "", language: "" }, + onSubmit: noop, + isStreaming: false, + onStopStreaming: noop, + onSetChatModel: noop, + model: "gpt-3.5-turbo", + caps: { fetching: false, default_cap: "foo", available_caps: [] }, + error: "", + clearError: noop, + canChangeModel: false, + handleContextFile: noop, + hasContextFile: false, + commands: { + available_commands: [], + selected_command: "", + arguments: [], + is_cmd_executable: false, + }, + requestCommandsCompletion: noop, + attachFile: { + name: "", + can_paste: false, + attach: false, + }, + setSelectedCommand: noop, + filesInPreview: [], + ...props, + }; + + return ; +}; describe("ChatForm", () => { test("when I push enter it should call onSubmit", async () => { const fakeOnSubmit = vi.fn(); - const { user, ...app } = render( - ({})} - selectedSnippet={{ code: "", language: "" }} - onSubmit={fakeOnSubmit} - isStreaming={false} - onStopStreaming={vi.fn} - onSetChatModel={vi.fn} - model="gpt-3.5-turbo" - caps={{ fetching: false, default_cap: "foo", available_caps: [] }} - error="" - clearError={vi.fn} - canChangeModel={false} - handleContextFile={vi.fn} - hasContextFile={false} - commands={{ - available_commands: [], - selected_command: "", - arguments: [], - is_cmd_executable: false, - }} - requestCommandsCompletion={() => ({})} - attachFile={{ - name: "", - can_paste: false, - attach: false, - }} - setSelectedCommand={() => ({})} - executeCommand={() => ({})} - filesInPreview={[]} - // setSelectedCommand={() => ({})} - />, - ); + const { user, ...app } = render(); const textarea: HTMLTextAreaElement | null = app.container.querySelector("textarea"); @@ -54,38 +60,7 @@ describe("ChatForm", () => { test("when I hole shift and push enter it should not call onSubmit", async () => { const fakeOnSubmit = vi.fn(); - const { user, ...app } = render( - ({})} - selectedSnippet={{ code: "", language: "" }} - onSubmit={fakeOnSubmit} - isStreaming={false} - onStopStreaming={vi.fn} - onSetChatModel={vi.fn} - model="gpt-3.5-turbo" - caps={{ fetching: false, default_cap: "foo", available_caps: [] }} - error="" - clearError={vi.fn} - canChangeModel={false} - handleContextFile={vi.fn} - hasContextFile={false} - commands={{ - available_commands: [], - selected_command: "", - arguments: [], - is_cmd_executable: false, - }} - requestCommandsCompletion={() => ({})} - attachFile={{ - name: "", - can_paste: false, - attach: false, - }} - setSelectedCommand={() => ({})} - executeCommand={() => ({})} - filesInPreview={[]} - />, - ); + const { user, ...app } = render(); const textarea = app.container.querySelector("textarea"); expect(textarea).not.toBeNull(); if (textarea) { diff --git a/src/components/ChatForm/ChatForm.stories.tsx b/src/components/ChatForm/ChatForm.stories.tsx index a78165ed..337f4b65 100644 --- a/src/components/ChatForm/ChatForm.stories.tsx +++ b/src/components/ChatForm/ChatForm.stories.tsx @@ -81,7 +81,6 @@ const meta = { selectedSnippet: { code: "", language: "" }, removePreviewFileByName: () => ({}), requestCommandsCompletion: () => ({}), - executeCommand: () => ({}), setSelectedCommand: () => ({}), }, } satisfies Meta; diff --git a/src/components/ChatForm/ChatForm.tsx b/src/components/ChatForm/ChatForm.tsx index d2e7fafb..26f1aa73 100644 --- a/src/components/ChatForm/ChatForm.tsx +++ b/src/components/ChatForm/ChatForm.tsx @@ -41,7 +41,7 @@ const CapsSelect: React.FC<{ ); }; -export const ChatForm: React.FC<{ +export type ChatFormProps = { onSubmit: (str: string) => void; onClose?: () => void; className?: string; @@ -63,11 +63,12 @@ export const ChatForm: React.FC<{ number?: number, ) => void; setSelectedCommand: (command: string) => void; - executeCommand: (command: string, cursor: number) => void; filesInPreview: ChatContextFile[]; selectedSnippet: ChatState["selected_snippet"]; removePreviewFileByName: ComboBoxProps["removePreviewFileByName"]; -}> = ({ +}; + +export const ChatForm: React.FC = ({ onSubmit, onClose, className, @@ -85,12 +86,10 @@ export const ChatForm: React.FC<{ attachFile, requestCommandsCompletion, setSelectedCommand, - executeCommand, filesInPreview, selectedSnippet, removePreviewFileByName, }) => { - //TODO: handle attached snippet, when code is highlighted and chat is opened const [value, setValue] = React.useState(""); const [snippetAdded, setSnippetAdded] = React.useState(false); @@ -185,7 +184,6 @@ export const ChatForm: React.FC<{ commands.available_commands.length > 0 ? "Type @ for commands" : "" } render={(props) =>