Skip to content
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

refactor(frontend): app layout and event handler #5279

Merged
merged 5 commits into from
Nov 26, 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
35 changes: 25 additions & 10 deletions frontend/__tests__/components/chat/chat-interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { act, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "test-utils";
import { ChatInterface } from "#/components/chat-interface";
import { addUserMessage } from "#/state/chat-slice";
import { SUGGESTIONS } from "#/utils/suggestions";
import * as ChatSlice from "#/state/chat-slice";
import { WsClientProviderStatus } from "#/context/ws-client-provider";
import { ChatInterface } from "#/routes/_oh.app/chat-interface";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const renderChatInterface = (messages: (Message | ErrorMessage)[]) =>
Expand All @@ -18,7 +18,11 @@ describe("Empty state", () => {
}));

const { useWsClient: useWsClientMock } = vi.hoisted(() => ({
useWsClient: vi.fn(() => ({ send: sendMock, status: WsClientProviderStatus.ACTIVE, isLoadingMessages: false })),
useWsClient: vi.fn(() => ({
send: sendMock,
status: WsClientProviderStatus.ACTIVE,
isLoadingMessages: false,
})),
}));

beforeAll(() => {
Expand Down Expand Up @@ -84,7 +88,9 @@ describe("Empty state", () => {
async () => {
// this is to test that the message is in the UI before the socket is called
useWsClientMock.mockImplementation(() => ({
send: sendMock, status: WsClientProviderStatus.ACTIVE, isLoadingMessages: false
send: sendMock,
status: WsClientProviderStatus.ACTIVE,
isLoadingMessages: false,
}));
const addUserMessageSpy = vi.spyOn(ChatSlice, "addUserMessage");
const user = userEvent.setup();
Expand Down Expand Up @@ -112,7 +118,9 @@ describe("Empty state", () => {
"should send the message to the socket only if the runtime is active",
async () => {
useWsClientMock.mockImplementation(() => ({
send: sendMock, status: WsClientProviderStatus.ACTIVE, isLoadingMessages: false
send: sendMock,
status: WsClientProviderStatus.ACTIVE,
isLoadingMessages: false,
}));
const user = userEvent.setup();
const { rerender } = renderWithProviders(<ChatInterface />, {
Expand All @@ -121,15 +129,16 @@ describe("Empty state", () => {
},
});


const suggestions = screen.getByTestId("suggestions");
const displayedSuggestions = within(suggestions).getAllByRole("button");

await user.click(displayedSuggestions[0]);
expect(sendMock).not.toHaveBeenCalled();

useWsClientMock.mockImplementation(() => ({
send: sendMock, status: WsClientProviderStatus.ACTIVE, isLoadingMessages: false
send: sendMock,
status: WsClientProviderStatus.ACTIVE,
isLoadingMessages: false,
}));
rerender(<ChatInterface />);

Expand Down Expand Up @@ -330,10 +339,16 @@ describe.skip("ChatInterface", () => {
rerender(<ChatInterface />);

// Verify only one button is shown
const pushToPrButton = screen.getByRole("button", { name: "Push changes to PR" });
const pushToPrButton = screen.getByRole("button", {
name: "Push changes to PR",
});
expect(pushToPrButton).toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Push to Branch" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Push & Create PR" })).not.toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Push to Branch" }),
).not.toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Push & Create PR" }),
).not.toBeInTheDocument();
});

it("should render feedback actions if there are more than 3 messages", () => {
Expand Down Expand Up @@ -379,4 +394,4 @@ describe.skip("ChatInterface", () => {
);
it.todo("should render the actions once more after new messages are added");
});
});
});
278 changes: 0 additions & 278 deletions frontend/src/components/chat-interface.tsx

This file was deleted.

Loading
Loading