test: fix the failed unit tests. (#2721)

Signed-off-by: ifuryst <ifuryst@gmail.com>
This commit is contained in:
Leo
2024-07-01 23:27:27 +08:00
committed by GitHub
parent c88b9f8f6d
commit 82ea8b3556
2 changed files with 12 additions and 2 deletions

View File

@@ -3,11 +3,13 @@ import { screen, act, fireEvent } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "test-utils";
import { useTranslation } from "react-i18next";
import ChatInterface from "./ChatInterface";
import Session from "#/services/session";
import ActionType from "#/types/ActionType";
import { addAssistantMessage } from "#/state/chatSlice";
import AgentState from "#/types/AgentState";
import { I18nKey } from "#/i18n/declaration";
// avoid typing side-effect
vi.mock("#/hooks/useTyping", () => ({
@@ -113,7 +115,11 @@ describe("ChatInterface", () => {
},
});
const submitButton = screen.getByLabelText(/send message/i);
const { t } = useTranslation();
const submitButton = screen.getByLabelText(
t(I18nKey.CHAT_INTERFACE$TOOLTIP_SEND_MESSAGE),
);
expect(submitButton).toBeDisabled();
});

View File

@@ -13,6 +13,8 @@ const openMock = vi.fn();
const writeMock = vi.fn();
const writelnMock = vi.fn();
const disposeMock = vi.fn();
const onKeyMock = vi.fn();
const attachCustomKeyEventHandlerMock = vi.fn();
vi.mock("@xterm/xterm", async (importOriginal) => ({
...(await importOriginal<typeof import("@xterm/xterm")>()),
@@ -21,6 +23,8 @@ vi.mock("@xterm/xterm", async (importOriginal) => ({
write: writeMock,
writeln: writelnMock,
dispose: disposeMock,
onKey: onKeyMock,
attachCustomKeyEventHandler: attachCustomKeyEventHandlerMock,
loadAddon: vi.fn(),
})),
}));
@@ -42,7 +46,7 @@ describe("Terminal", () => {
it("should render a terminal", () => {
renderTerminal();
expect(screen.getByText("Terminal (read-only)")).toBeInTheDocument();
expect(screen.getByText("Terminal")).toBeInTheDocument();
expect(openMock).toHaveBeenCalledTimes(1);
expect(writeMock).toHaveBeenCalledWith("$ ");