OpenHands/frontend/__tests__/components/context-menu/context-menu-list-item.test.tsx
dependabot[bot] a1a87af69d
chore(deps): bump the version-all group across 1 directory with 18 updates (#6332)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: amanape <83104063+amanape@users.noreply.github.com>
2025-01-17 23:46:57 +04:00

45 lines
1.4 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ContextMenuListItem } from "#/components/features/context-menu/context-menu-list-item";
describe("ContextMenuListItem", () => {
it("should render the component with the children", () => {
const onClickMock = vi.fn();
render(
<ContextMenuListItem onClick={onClickMock}>Test</ContextMenuListItem>,
);
expect(screen.getByTestId("context-menu-list-item")).toBeInTheDocument();
expect(screen.getByText("Test")).toBeInTheDocument();
});
it("should call the onClick callback when clicked", async () => {
const user = userEvent.setup();
const onClickMock = vi.fn();
render(
<ContextMenuListItem onClick={onClickMock}>Test</ContextMenuListItem>,
);
const element = screen.getByTestId("context-menu-list-item");
await user.click(element);
expect(onClickMock).toHaveBeenCalledOnce();
});
it("should not call the onClick callback when clicked and the button is disabled", async () => {
const user = userEvent.setup();
const onClickMock = vi.fn();
render(
<ContextMenuListItem onClick={onClickMock} isDisabled>
Test
</ContextMenuListItem>,
);
const element = screen.getByTestId("context-menu-list-item");
await user.click(element);
expect(onClickMock).not.toHaveBeenCalled();
});
});