Skip to content

Commit 35b248f

Browse files
authored
update/refactor unit tests (#1598)
1 parent 3dbd502 commit 35b248f

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

frontend/src/components/chat/ChatInterface.test.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,9 @@ const socketSpy = vi.spyOn(Socket, "send");
2121
// TODO: Move this into test setup
2222
HTMLElement.prototype.scrollIntoView = vi.fn();
2323

24-
const renderChatInterface = () =>
25-
renderWithProviders(<ChatInterface />, {
26-
preloadedState: {
27-
task: {
28-
completed: false,
29-
},
30-
},
31-
});
32-
3324
describe("ChatInterface", () => {
3425
it("should render the messages and input", () => {
35-
renderChatInterface();
26+
renderWithProviders(<ChatInterface />);
3627
expect(screen.queryAllByTestId("message")).toHaveLength(1); // initial welcome message only
3728
});
3829

@@ -80,9 +71,6 @@ describe("ChatInterface", () => {
8071
it("should send the a start event to the Socket", () => {
8172
renderWithProviders(<ChatInterface />, {
8273
preloadedState: {
83-
task: {
84-
completed: false,
85-
},
8674
agent: {
8775
curAgentState: AgentState.INIT,
8876
},
@@ -101,9 +89,6 @@ describe("ChatInterface", () => {
10189
it("should send the a user message event to the Socket", () => {
10290
renderWithProviders(<ChatInterface />, {
10391
preloadedState: {
104-
task: {
105-
completed: false,
106-
},
10792
agent: {
10893
curAgentState: AgentState.AWAITING_USER_INPUT,
10994
},
@@ -125,9 +110,6 @@ describe("ChatInterface", () => {
125110
it("should disable the user input if agent is not initialized", () => {
126111
renderWithProviders(<ChatInterface />, {
127112
preloadedState: {
128-
task: {
129-
completed: false,
130-
},
131113
agent: {
132114
curAgentState: AgentState.LOADING,
133115
},

frontend/src/components/chat/ChatInterface.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import React from "react";
2-
import { useSelector } from "react-redux";
2+
import { useDispatch, useSelector } from "react-redux";
33
import { IoMdChatbubbles } from "react-icons/io";
44
import ChatInput from "./ChatInput";
55
import Chat from "./Chat";
66
import { RootState } from "#/store";
77
import AgentState from "#/types/AgentState";
88
import { sendChatMessage } from "#/services/chatService";
9+
import { addUserMessage } from "#/state/chatSlice";
910

1011
function ChatInterface() {
12+
const dispatch = useDispatch();
1113
const { messages } = useSelector((state: RootState) => state.chat);
1214
const { curAgentState } = useSelector((state: RootState) => state.agent);
1315

1416
const handleSendMessage = (content: string) => {
1517
const isTask = curAgentState === AgentState.INIT;
18+
dispatch(addUserMessage(content));
1619
sendChatMessage(content, isTask);
1720
};
1821

frontend/src/services/chatService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Socket from "./socket";
66
import { addUserMessage } from "#/state/chatSlice";
77

88
export function sendChatMessage(message: string, isTask: boolean = true): void {
9-
store.dispatch(addUserMessage(message));
109
let event;
1110
if (isTask) {
1211
event = { action: ActionType.START, args: { task: message } };

0 commit comments

Comments
 (0)