mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com> Co-authored-by: Abhay Mishra <grabhaymishra@gmail.com> Co-authored-by: Hyun Han <62870362+smosco@users.noreply.github.com> Co-authored-by: Nhan Nguyen <nhan13574@gmail.com> Co-authored-by: Bharath A V <avbharath1221@gmail.com> Co-authored-by: hieptl <hieptl.developer@gmail.com> Co-authored-by: Chloe <chloe@openhands.com> Co-authored-by: HeyItsChloe <54480367+HeyItsChloe@users.noreply.github.com>
92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import React from "react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { renderWithProviders } from "test-utils";
|
|
import { ConfirmRemoveMemberModal } from "#/components/features/org/confirm-remove-member-modal";
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("react-i18next")>()),
|
|
Trans: ({
|
|
values,
|
|
components,
|
|
}: {
|
|
values: { email: string };
|
|
components: { email: React.ReactElement };
|
|
}) => React.cloneElement(components.email, {}, values.email),
|
|
}));
|
|
|
|
describe("ConfirmRemoveMemberModal", () => {
|
|
it("should display the member email in the confirmation message", () => {
|
|
// Arrange
|
|
const memberEmail = "test@example.com";
|
|
|
|
// Act
|
|
renderWithProviders(
|
|
<ConfirmRemoveMemberModal
|
|
onConfirm={vi.fn()}
|
|
onCancel={vi.fn()}
|
|
memberEmail={memberEmail}
|
|
/>,
|
|
);
|
|
|
|
// Assert
|
|
expect(screen.getByText(memberEmail)).toBeInTheDocument();
|
|
});
|
|
|
|
it("should call onConfirm when the confirm button is clicked", async () => {
|
|
// Arrange
|
|
const user = userEvent.setup();
|
|
const onConfirmMock = vi.fn();
|
|
renderWithProviders(
|
|
<ConfirmRemoveMemberModal
|
|
onConfirm={onConfirmMock}
|
|
onCancel={vi.fn()}
|
|
memberEmail="test@example.com"
|
|
/>,
|
|
);
|
|
|
|
// Act
|
|
await user.click(screen.getByTestId("confirm-button"));
|
|
|
|
// Assert
|
|
expect(onConfirmMock).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("should call onCancel when the cancel button is clicked", async () => {
|
|
// Arrange
|
|
const user = userEvent.setup();
|
|
const onCancelMock = vi.fn();
|
|
renderWithProviders(
|
|
<ConfirmRemoveMemberModal
|
|
onConfirm={vi.fn()}
|
|
onCancel={onCancelMock}
|
|
memberEmail="test@example.com"
|
|
/>,
|
|
);
|
|
|
|
// Act
|
|
await user.click(screen.getByTestId("cancel-button"));
|
|
|
|
// Assert
|
|
expect(onCancelMock).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("should disable buttons and show loading spinner when isLoading is true", () => {
|
|
// Arrange & Act
|
|
renderWithProviders(
|
|
<ConfirmRemoveMemberModal
|
|
onConfirm={vi.fn()}
|
|
onCancel={vi.fn()}
|
|
memberEmail="test@example.com"
|
|
isLoading
|
|
/>,
|
|
);
|
|
|
|
// Assert
|
|
expect(screen.getByTestId("confirm-button")).toBeDisabled();
|
|
expect(screen.getByTestId("cancel-button")).toBeDisabled();
|
|
expect(screen.getByTestId("loading-spinner")).toBeInTheDocument();
|
|
});
|
|
});
|