context-menu-list-item.test.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { describe, it, expect, vi } from "vitest";
  2. import { render, screen } from "@testing-library/react";
  3. import userEvent from "@testing-library/user-event";
  4. import { ContextMenuListItem } from "#/components/context-menu/context-menu-list-item";
  5. describe("ContextMenuListItem", () => {
  6. it("should render the component with the children", () => {
  7. render(<ContextMenuListItem onClick={vi.fn}>Test</ContextMenuListItem>);
  8. expect(screen.getByTestId("context-menu-list-item")).toBeInTheDocument();
  9. expect(screen.getByText("Test")).toBeInTheDocument();
  10. });
  11. it("should call the onClick callback when clicked", async () => {
  12. const user = userEvent.setup();
  13. const onClickMock = vi.fn();
  14. render(
  15. <ContextMenuListItem onClick={onClickMock}>Test</ContextMenuListItem>,
  16. );
  17. const element = screen.getByTestId("context-menu-list-item");
  18. await user.click(element);
  19. expect(onClickMock).toHaveBeenCalledOnce();
  20. });
  21. it("should not call the onClick callback when clicked and the button is disabled", async () => {
  22. const user = userEvent.setup();
  23. const onClickMock = vi.fn();
  24. render(
  25. <ContextMenuListItem onClick={onClickMock} isDisabled>
  26. Test
  27. </ContextMenuListItem>,
  28. );
  29. const element = screen.getByTestId("context-menu-list-item");
  30. await user.click(element);
  31. expect(onClickMock).not.toHaveBeenCalled();
  32. });
  33. });