Skip to content

test(frontend): update unit tests #1598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions frontend/src/components/chat/ChatInterface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@ const socketSpy = vi.spyOn(Socket, "send");
// TODO: Move this into test setup
HTMLElement.prototype.scrollIntoView = vi.fn();

const renderChatInterface = () =>
renderWithProviders(<ChatInterface />, {
preloadedState: {
task: {
completed: false,
},
},
});

describe("ChatInterface", () => {
it("should render the messages and input", () => {
renderChatInterface();
renderWithProviders(<ChatInterface />);
expect(screen.queryAllByTestId("message")).toHaveLength(1); // initial welcome message only
});

Expand Down Expand Up @@ -80,9 +71,6 @@ describe("ChatInterface", () => {
it("should send the a start event to the Socket", () => {
renderWithProviders(<ChatInterface />, {
preloadedState: {
task: {
completed: false,
},
agent: {
curAgentState: AgentState.INIT,
},
Expand All @@ -101,9 +89,6 @@ describe("ChatInterface", () => {
it("should send the a user message event to the Socket", () => {
renderWithProviders(<ChatInterface />, {
preloadedState: {
task: {
completed: false,
},
agent: {
curAgentState: AgentState.AWAITING_USER_INPUT,
},
Expand All @@ -125,9 +110,6 @@ describe("ChatInterface", () => {
it("should disable the user input if agent is not initialized", () => {
renderWithProviders(<ChatInterface />, {
preloadedState: {
task: {
completed: false,
},
agent: {
curAgentState: AgentState.LOADING,
},
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/chat/ChatInterface.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import React from "react";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { IoMdChatbubbles } from "react-icons/io";
import ChatInput from "./ChatInput";
import Chat from "./Chat";
import { RootState } from "#/store";
import AgentState from "#/types/AgentState";
import { sendChatMessage } from "#/services/chatService";
import { addUserMessage } from "#/state/chatSlice";

function ChatInterface() {
const dispatch = useDispatch();
const { messages } = useSelector((state: RootState) => state.chat);
const { curAgentState } = useSelector((state: RootState) => state.agent);

const handleSendMessage = (content: string) => {
const isTask = curAgentState === AgentState.INIT;
dispatch(addUserMessage(content));
sendChatMessage(content, isTask);
};

Expand Down
1 change: 0 additions & 1 deletion frontend/src/services/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Socket from "./socket";
import { addUserMessage } from "#/state/chatSlice";

export function sendChatMessage(message: string, isTask: boolean = true): void {
store.dispatch(addUserMessage(message));
let event;
if (isTask) {
event = { action: ActionType.START, args: { task: message } };
Expand Down